Guest User

Code Minecraft python noGUI

a guest
Jul 6th, 2018
1,851
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.80 KB | None | 0 0
  1. #LIS BIEN LES COMMENTAIRES QYU COMMENCE PAR ----------
  2. #----------CREER UN FICHIER blocks.py et mets le 1er code
  3.  
  4. class blocks:
  5.     def __init__(self, durability: int = 5):
  6.         self.durability = durability
  7.        
  8.         if type(self.durability) != int:
  9.             print("Durability should be an integer.")
  10.             self.durability = 5
  11.    
  12.    
  13.    
  14.    
  15. #Derived class of "blocks"
  16. class Stone(blocks):
  17.    
  18.     def __name__(self):
  19.         return "Stone"
  20.        
  21.     pass
  22.    
  23.    
  24. class Dirt(blocks):
  25.    
  26.     def __name__(self):
  27.         return "Dirt"
  28.        
  29.     pass
  30.  
  31.  
  32. class Wood(blocks):
  33.    
  34.     def __name__(self):
  35.         return "Wood"
  36.        
  37.     pass
  38.    
  39.    
  40. class Bricks(blocks):
  41.    
  42.     def __name__(self):
  43.         return "Bricks"
  44.        
  45.     pass
  46.    
  47.  
  48. class Ore(blocks):
  49.    
  50.     def __name__(self):
  51.         return "Ore"
  52.    
  53.    
  54.        
  55. #Defining blocks
  56. Stone = Stone(3)
  57. Dirt = Dirt(2)
  58. Wood = Wood(4)
  59. Bricks = Bricks(5)
  60. Ore = Ore(5)
  61.  
  62. if __name__ == "__main__":
  63.     print(dir(Ore))
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. #-----------CREER UN FICHIER player.py ET COLLE CE CODE DEDANS:
  71.  
  72.  
  73.  
  74.  
  75. import blocks
  76. import items
  77. from time import localtime
  78.  
  79. class Player:
  80.    
  81.     def __init__(self,name):
  82.         self.name = name
  83.         self.inventory = { blocks.Stone: 0, blocks.Dirt: 0, blocks.Wood: 0, blocks.Bricks: 0, items.Diamond: 0}
  84.    
  85.    
  86.     def ShowInventory(self):
  87.         print("\n Ouverture de l'inventaire... ")
  88.        
  89.        
  90.         for key in self.inventory:
  91.            
  92.             value = self.inventory[key]
  93.             print("{}: {}".format(key.__name__(),value))
  94. #-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
  95.        
  96.     def mineBlock(self,block):
  97.        
  98.         if not isinstance(block,blocks.blocks):
  99.             print("Erreur lors du minage.\n")
  100.             return
  101.             #Stopping..
  102.            
  103.         for i in range(0,block.durability):
  104.             print("Crick..")
  105.        
  106.         print("Crack !")
  107.         print("Vous avez miné 1 de {}. \n".format(block.__name__()))
  108.        
  109.         if block == blocks.Ore:
  110.             print("1 minerais a été ajouté !")
  111.             self.inventory[items.Diamond]+=1
  112.            
  113.        
  114.         #Adding one block to the inventory
  115.         self.inventory[blocks.Stone]+=1
  116.  
  117.  
  118.     def Inventory(self):
  119.        
  120.         CH = []
  121.        
  122.    
  123.         for key in self.inventory:
  124.            
  125.             value = self.inventory[key]
  126.            
  127.             CH.append("{}: {}".format(key.__name__(),value))
  128.  
  129.         return CH
  130.  
  131.     def Save(self,bool):
  132.    
  133.         if not bool:
  134.             return
  135.    
  136.         SAVE_FILE = open("savePlayer.py","a")
  137.    
  138.         Time = "[ {}:{}:{} ]".format(localtime().tm_hour, localtime().tm_min, localtime().tm_sec)
  139.    
  140.         save = "\n Logs: {} \n Name = {}, \n inventory =  {}".format(Time,self.name,self.Inventory())
  141.        
  142.        
  143.         SAVE_FILE.write(save)
  144.    
  145.         SAVE_FILE.close()
  146.  
  147. if __name__ == "__main__":
  148.     play = Player("Jack")
  149.     play.mineBlock("blocks.Ston")
  150.     play.mineBlock("blocks.Or")
  151.     play.ShowInventory()
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158. #----------CREER UN FICHIER items.py ET COLLE CE CODE DEDANS
  159.  
  160.  
  161. import player
  162.  
  163. class items:
  164.     def __init__(self,hasDurability=True,durabilities=60):
  165.         self.hasDurability = hasDurability
  166.         self.durabilities = durabilities
  167.        
  168.    
  169. class Diamond(items):
  170.     def __name__(self):
  171.         return "Diamond"
  172.        
  173.     pass
  174.  
  175. class Pickaxe(items):
  176.     def __name__(self):
  177.         return "Pickaxe"
  178.        
  179.     pass
  180.    
  181.  
  182. class Sword(items):
  183.     def __name__(self):
  184.         return "Sword"
  185.        
  186.     pass
  187.    
  188.    
  189. Pickaxe = Pickaxe(True,150)
  190. Sword = Sword(True,80)
  191. Diamond = Diamond(False, -1)
  192.  
  193.  
  194.  
  195.  
  196. #----------CREER UN FICHIER savePlayer.py SANS RIEN DEDANS
  197.  
  198. #-----------CREER UN FICHIER mainMinecraft.py ET METS CEDCODE DEDANS:
  199.  
  200.  
  201.  
  202.  
  203. #THE MAIN OF OUR PROGRAM
  204. from player import Player
  205. import player
  206. from blocks import *
  207. from time import sleep
  208.  
  209. name = input("Pseudo: ")
  210. print("Création du compte en cours..")
  211. sleep(1)
  212. player = Player(name=name)
  213. #Create the object Name
  214.  
  215. print("Terminé ! \n Bienvenue {} !".format(name))
  216.  
  217. #Mine fonction
  218. def GoMine():
  219.     MINE = True
  220.     listMine = [None, Stone, Wood, Dirt, Bricks, Ore]
  221.    
  222.     while MINE:
  223.        
  224.         ask = input("\nQue voulez-vous miner ? Tapez help \n")
  225.        
  226.         if type(ask) != int:
  227.             if ask == "QUIT":
  228.                 print("Minage fini !")
  229.                 return
  230.    
  231.             elif ask.lower() == "help":
  232.                 print("\n Commandes minages:")
  233.                 print(" • QUIT - Arrêter de miner")
  234.                 print(" • 1: Stone, 2:Wood, 3:Dirt, 4:Bricks, 5:Ore, à miner ")
  235.                 print("Tapez 1, 2, 3, 4 ou 5")
  236.            
  237.             else:
  238.                 print("Pour miner un bloc, veuillez entrer son numéro.")
  239.                
  240.                
  241.         if type(ask) == int:
  242.             player.mineBlock(listMine[ask])
  243.            
  244.    
  245.             print("Minage fini !")
  246.             MINE = False
  247. #End function
  248.  
  249. #Main
  250. QUIT = False
  251. while not QUIT:
  252.    
  253.     action = input("Que voulez-vous faire ? Tapez help \n")
  254.    
  255.     if action == "mine":
  256.         GoMine()
  257.  
  258.    
  259.     if action == "QUIT":
  260.         QUIT = True
  261.    
  262.     if action.lower() == "help":
  263.         print("\n Liste des options: ")
  264.         print(" • QUIT - Arrêter le jeu")
  265.         print(" • mine - Aller miner")
  266.         print(" • inv - Ouvrir l'inventaire")
  267.        
  268.     if action.lower() == "inv":
  269.         player.ShowInventory()
  270.  
  271. #end of the game
  272. action = input("\n Sauvegarder ? [o/n] \n")
  273.  
  274. if action.lower() == "n":
  275.     action = False
  276. else:
  277.     action = True
  278.    
  279. player.Save(action)
  280.  
  281.  
  282. print("Merci d'avoir joué !")
Advertisement
Add Comment
Please, Sign In to add comment