From da5e8b0bb4ec4ed1e7e3d0aa2887cc567f23d45c Mon Sep 17 00:00:00 2001 From: Ian Mulet Date: Tue, 1 Oct 2019 16:26:25 -0400 Subject: [PATCH 1/3] another weird game --- hello.py | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 101 insertions(+), 8 deletions(-) diff --git a/hello.py b/hello.py index 72647ca..11fb7e2 100755 --- a/hello.py +++ b/hello.py @@ -1,11 +1,104 @@ -#!/usr/bin/env python3 +[code]#------------------------------------------------ +# it's a game +# More programs at Bibou Ja +#------------------------------------------------ +#------------------------------------------------ +# Challenge 1: Can you craft a tent and a firepit? +# Challenge 2: Can you add more items? +# Challenge 3: Can you create crafting rules +# to make more items? +# Challenge 4: Add comments to the code below! +#------------------------------------------------ +commands = { + "i" : "see inventory", + "c" : "see crafting options", + "craft [item]" : "craft something from inventory items", + } +#an inventory of items +items = { + "flint" : 50, + "grass" : 100, + "hay" : 0, + "tree" : 100, + "log" : 0, + "sapling" : 100, + "twig" : 0, + "boulder" : 30, + "rock" : 0, + "pickaxe" : 0, + "axe" : 0, + "firepit" : 0, + "tent" : 0, + "torch" : 0, + } +#rules to make new objects +craft = { + "hay" : { "grass" : 1 }, + "twig" : { "sapling" : 1 }, + "log" : { "axe" : 1, "tree" : 1 }, + "axe" : { "twig" : 3, "flint" : 1 }, + "tent" : { "twig" : 10, "hay" : 15 }, + "firepit" : { "boulder" : 5, "log" : 3, "twig" : 1, "torch" : 1 }, + "torch" : { "flint" : 1, "grass" : 1, "twig" : 1 }, + "pickaxe" : { "flint" : 2, "twig" : 1 } + } + +print("'Crafting Challenge' Game") +print("More programs at Bibou Ja") +print("-----------------------------------------\n") + +print("TRY TO SURVIVE BY CRAFTING A TENT AND A FIREPIT!") +print("type '?' for help") +while True: + command = input(">").split() + if len(command) == 0: + continue + if len(command) > 0: + verb = command[0].lower() + if len(command) > 1: + item = command[1].lower() + if verb == "?": + for key in commands: + print(key + " : " + commands[key]) + print("\n") + elif verb == "i": + for key in items: + print(key + " : " + str(items[key])) + print("\n") + elif verb == "c": + for key in craft: + print(key + " can be made with:") + for i in craft[key]: + print(str(craft[key][i]) + " " + i) + print("\n") + + elif verb == "craft": + print("making " + item + ":") + if item in craft: + for i in craft[item]: + print(" you need : " + str(craft[item][i]) + " " + i + " and you have " + str(items[i])) + canBeMade = True + for i in craft[item]: + if craft[item][i] > items[i]: + print("item cannot be crafted\n") + canBeMade = False + break + + if canBeMade == True: + for i in craft[item]: + items[i] -= craft[item][i] + items[item] += 1 + print("item crafted\n") + + if items["tent"] >= 1 and items["firepit"] >= 1: + print("\n**YOU HAVE MANAGED TO SURVIVE!\nWELL DONE!") + break + else: + print("you can't") + else: + print("you can't") -def helloworld(): - pass -def add_numbers(x, y): - pass -if __name__ == '__main__': - # do something! - pass + + #copyright https://www.quora.com/Whats-the-most-beautiful-line-of-Python-code \ No newline at end of file From ffe326478dea7a34993329be61787031b0e9cd5d Mon Sep 17 00:00:00 2001 From: Ian Mulet Date: Tue, 1 Oct 2019 16:30:16 -0400 Subject: [PATCH 2/3] another weird game --- hello.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hello.py b/hello.py index 11fb7e2..b667147 100755 --- a/hello.py +++ b/hello.py @@ -1,4 +1,4 @@ -[code]#------------------------------------------------ +#------------------------------------------------ # it's a game # More programs at Bibou Ja #------------------------------------------------ From dd8b5ed4ec8ff19b9a8ef24a32f5e103f4d65a8c Mon Sep 17 00:00:00 2001 From: Philip Hicks Date: Tue, 1 Oct 2019 16:38:01 -0400 Subject: [PATCH 3/3] made it weirder --- hello.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hello.py b/hello.py index b667147..a27a7d9 100755 --- a/hello.py +++ b/hello.py @@ -83,7 +83,7 @@ print("item cannot be crafted\n") canBeMade = False break - + #made a change to make it reader if canBeMade == True: for i in craft[item]: items[i] -= craft[item][i]