Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #LIS BIEN LES COMMENTAIRES QYU COMMENCE PAR ----------
- #----------CREER UN FICHIER blocks.py et mets le 1er code
- class blocks:
- def __init__(self, durability: int = 5):
- self.durability = durability
- if type(self.durability) != int:
- print("Durability should be an integer.")
- self.durability = 5
- #Derived class of "blocks"
- class Stone(blocks):
- def __name__(self):
- return "Stone"
- pass
- class Dirt(blocks):
- def __name__(self):
- return "Dirt"
- pass
- class Wood(blocks):
- def __name__(self):
- return "Wood"
- pass
- class Bricks(blocks):
- def __name__(self):
- return "Bricks"
- pass
- class Ore(blocks):
- def __name__(self):
- return "Ore"
- #Defining blocks
- Stone = Stone(3)
- Dirt = Dirt(2)
- Wood = Wood(4)
- Bricks = Bricks(5)
- Ore = Ore(5)
- if __name__ == "__main__":
- print(dir(Ore))
- #-----------CREER UN FICHIER player.py ET COLLE CE CODE DEDANS:
- import blocks
- import items
- from time import localtime
- class Player:
- def __init__(self,name):
- self.name = name
- self.inventory = { blocks.Stone: 0, blocks.Dirt: 0, blocks.Wood: 0, blocks.Bricks: 0, items.Diamond: 0}
- def ShowInventory(self):
- print("\n Ouverture de l'inventaire... ")
- for key in self.inventory:
- value = self.inventory[key]
- print("{}: {}".format(key.__name__(),value))
- #-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
- def mineBlock(self,block):
- if not isinstance(block,blocks.blocks):
- print("Erreur lors du minage.\n")
- return
- #Stopping..
- for i in range(0,block.durability):
- print("Crick..")
- print("Crack !")
- print("Vous avez miné 1 de {}. \n".format(block.__name__()))
- if block == blocks.Ore:
- print("1 minerais a été ajouté !")
- self.inventory[items.Diamond]+=1
- #Adding one block to the inventory
- self.inventory[blocks.Stone]+=1
- def Inventory(self):
- CH = []
- for key in self.inventory:
- value = self.inventory[key]
- CH.append("{}: {}".format(key.__name__(),value))
- return CH
- def Save(self,bool):
- if not bool:
- return
- SAVE_FILE = open("savePlayer.py","a")
- Time = "[ {}:{}:{} ]".format(localtime().tm_hour, localtime().tm_min, localtime().tm_sec)
- save = "\n Logs: {} \n Name = {}, \n inventory = {}".format(Time,self.name,self.Inventory())
- SAVE_FILE.write(save)
- SAVE_FILE.close()
- if __name__ == "__main__":
- play = Player("Jack")
- play.mineBlock("blocks.Ston")
- play.mineBlock("blocks.Or")
- play.ShowInventory()
- #----------CREER UN FICHIER items.py ET COLLE CE CODE DEDANS
- import player
- class items:
- def __init__(self,hasDurability=True,durabilities=60):
- self.hasDurability = hasDurability
- self.durabilities = durabilities
- class Diamond(items):
- def __name__(self):
- return "Diamond"
- pass
- class Pickaxe(items):
- def __name__(self):
- return "Pickaxe"
- pass
- class Sword(items):
- def __name__(self):
- return "Sword"
- pass
- Pickaxe = Pickaxe(True,150)
- Sword = Sword(True,80)
- Diamond = Diamond(False, -1)
- #----------CREER UN FICHIER savePlayer.py SANS RIEN DEDANS
- #-----------CREER UN FICHIER mainMinecraft.py ET METS CEDCODE DEDANS:
- #THE MAIN OF OUR PROGRAM
- from player import Player
- import player
- from blocks import *
- from time import sleep
- name = input("Pseudo: ")
- print("Création du compte en cours..")
- sleep(1)
- player = Player(name=name)
- #Create the object Name
- print("Terminé ! \n Bienvenue {} !".format(name))
- #Mine fonction
- def GoMine():
- MINE = True
- listMine = [None, Stone, Wood, Dirt, Bricks, Ore]
- while MINE:
- ask = input("\nQue voulez-vous miner ? Tapez help \n")
- if type(ask) != int:
- if ask == "QUIT":
- print("Minage fini !")
- return
- elif ask.lower() == "help":
- print("\n Commandes minages:")
- print(" • QUIT - Arrêter de miner")
- print(" • 1: Stone, 2:Wood, 3:Dirt, 4:Bricks, 5:Ore, à miner ")
- print("Tapez 1, 2, 3, 4 ou 5")
- else:
- print("Pour miner un bloc, veuillez entrer son numéro.")
- if type(ask) == int:
- player.mineBlock(listMine[ask])
- print("Minage fini !")
- MINE = False
- #End function
- #Main
- QUIT = False
- while not QUIT:
- action = input("Que voulez-vous faire ? Tapez help \n")
- if action == "mine":
- GoMine()
- if action == "QUIT":
- QUIT = True
- if action.lower() == "help":
- print("\n Liste des options: ")
- print(" • QUIT - Arrêter le jeu")
- print(" • mine - Aller miner")
- print(" • inv - Ouvrir l'inventaire")
- if action.lower() == "inv":
- player.ShowInventory()
- #end of the game
- action = input("\n Sauvegarder ? [o/n] \n")
- if action.lower() == "n":
- action = False
- else:
- action = True
- player.Save(action)
- print("Merci d'avoir joué !")
Advertisement
Add Comment
Please, Sign In to add comment