forked from CaMeLCa5e/daily
-
Notifications
You must be signed in to change notification settings - Fork 0
/
crafting.py
132 lines (85 loc) · 2.07 KB
/
crafting.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#! /usr/bin/python
"""crafting challenge -
1 - make a tent and firepit
2 - add more items
3 - create rules to make more items
"""
commands = { "i" : "see inventory",
"c": "see crafting options",
"craft [item]" : "craft something from inventory items",
}
#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 items
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 "Building your game..."
print "Try to survive by creating a tent and a firepit!"
while True:
command = imput (">").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 craftL
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("you have survived!")
break
else:
print("you can't")
else:
print("you can't")