Skip to content
This repository has been archived by the owner on Aug 20, 2020. It is now read-only.

Weird game #53

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 101 additions & 8 deletions hello.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,104 @@
#!/usr/bin/env python3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oof you rekt my shebang :<

#------------------------------------------------
# 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
#made a change to make it reader
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow is this even open source licensed?