-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathether.py
More file actions
230 lines (211 loc) · 8.21 KB
/
ether.py
File metadata and controls
230 lines (211 loc) · 8.21 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
import random
import time
import csv
import os
variables = {
# metals
"bronze": 0,
"iron": 0,
"copper": 0,
"steel": 0,
"gold": 0,
"diamond": 0,
"platinum": 0,
"titanium": 0,
"tungsten": 0,
"damascus": 0,
# materials
"bismuth": 0, # mined
"wood": 0, # forage
"stone": 0, # mined
# machines
# Drills: makes mining easier
"bronze_drill": 0,
"copper_drill": 0,
# magic circle: multiplies the resource
"bronze_magic_circle": 0,
"copper_magic_circle": 0,
# mine
"mine": "quarry",
# scrolls
"scroll_caverns": 0,
"scroll_ether": 0,
}
def save_game():
with open('data.csv', 'w', newline='') as fp:
writer = csv.writer(fp)
for key, value in variables.items():
writer.writerow([key, value])
def load_game():
global variables
if os.path.exists('data.csv'):
with open('data.csv', 'r') as fp:
reader = csv.reader(fp)
variables = {rows[0]: int(rows[1]) if rows[1].isdigit() else rows[1] for rows in reader}
def mine_materials():
temp_bronze, temp_copper = variables["bronze"], variables["copper"]
lowestbronze = 5 + variables["bronze_magic_circle"] * 2
highestbronze = 8 + variables["bronze_magic_circle"] * 2
lowestcopper = 5 + variables["copper_magic_circle"] * 2
highestcopper = 8 + variables["copper_magic_circle"] * 2
variables["bronze"] += random.randint(lowestbronze, highestbronze)
variables["copper"] += random.randint(lowestcopper, highestcopper)
print("Mining...\n")
timesleep = 3 - (variables["bronze_drill"] * 0.01) - (variables["copper_drill"] * 0.01)
time.sleep(max(timesleep, 0.1))
print(f"Finished mining. You mined {variables['bronze'] - temp_bronze} bronze and {variables['copper'] - temp_copper} copper.\n")
print(f"You now have {variables['bronze']} bronze and {variables['copper']} copper now.")
def shop():
print("category?")
print("1) machine: improves the efficiency of mining")
print("2) scrolls: to different places we go!")
shop_actions = {
"1": buy_machine,
"2": buy_scroll
}
while True:
usershopchoice = input("Choice (or 'back' to exit): ").lower()
if usershopchoice == "back":
break
action = shop_actions.get(usershopchoice)
if action:
action()
else:
print("Invalid choice! Please try again.")
def buy_machine():
print("Options:")
bronzedrillprice = 8 + ((variables["bronze_drill"] + 1) * 2)
copperdrillprice = 10 + ((variables["copper_drill"] + 1) * 2)
bronzemagicprice = 15 + ((variables["bronze_magic_circle"] + 1) * 2)
coppermagicprice = 18 + ((variables["copper_magic_circle"] + 1) * 2)
print(f"1) Bronze Drill: Reduce the amount of time to mine in the quarry\nPrice: {bronzedrillprice}\n")
print(f"2) Copper Drill: Reduce the amount of time to mine in the quarry\nPrice: {copperdrillprice}\n")
print(f"3) Bronze Magic Circle: Increase the amount of bronze mined per mining session.\nPrice: {bronzemagicprice}\n")
print(f"4) Copper Magic Circle: Increase the amount of copper mined per mining session.\nPrice: {coppermagicprice}")
machine_options = {
"1": ("bronze_drill", bronzedrillprice, "bronze"),
"2": ("copper_drill", copperdrillprice, "copper"),
"3": ("bronze_magic_circle", bronzemagicprice, "bronze"),
"4": ("copper_magic_circle", coppermagicprice, "copper")
}
while True:
userbuymachine = input("Buy anything? (or 'back' to exit): ").lower()
if userbuymachine == "back":
break
item = machine_options.get(userbuymachine)
if item:
buy_item(*item)
else:
print("Invalid choice! Please try again.")
def buy_item(item, price, currency):
while True:
try:
howmany = int(input("How many? "))
if howmany <= 0:
print("Please enter a positive number.")
continue
total_price = price * howmany
if variables[currency] >= total_price:
variables[item] += howmany
variables[currency] -= total_price
print(f"You have bought {howmany} {item.replace('_', ' ')}!")
else:
print(f"You don't have enough! You need {total_price - variables[currency]} more {currency}!")
break
except ValueError:
print("Invalid input! Please enter a valid number.")
def buy_scroll():
print("Options:")
print("1) Scroll to the caverns")
print("Would you like to buy this? (y/n) price: 1000 bronze and 1000 copper")
while True:
userbuyscroll = input().lower()
if userbuyscroll == "y":
if variables["bronze"] >= 1000 and variables["copper"] >= 1000 and variables["scroll_caverns"] != 1:
print("Successfully bought!")
variables["scroll_caverns"] = 1
variables["bronze"] -= 1000
variables["copper"] -= 1000
elif variables["scroll_caverns"] == 1:
print("You already have bought the max amount (1) of this!")
else:
print("Not enough resources!")
break
elif userbuyscroll == "n":
break
else:
print("Invalid input! Please enter 'y' or 'n'.")
def display_help():
print("Mine Materials: \"mine\"")
print("Shop: \"shop\"")
print("Current Mine: \"cmine\"")
print("Check Resources: \"cr\"")
print("Different Resources: \"r\"")
print("The bazaar: \"bz\"")
def check_resources():
print(f"Amount of bronze: {variables['bronze']}")
print(f"Amount of copper: {variables['copper']}")
print(f"Amount of bronze drills: {variables['bronze_drill']}")
print(f"Amount of copper drills: {variables['copper_drill']}")
print(f"Amount of bronze magic circles: {variables['bronze_magic_circle']}")
print(f"Amount of copper magic circles: {variables['copper_magic_circle']}")
def warp():
print("You can warp to:")
print("Quarry (Currently Here)")
if variables["scroll_caverns"] == 1:
print("Caverns")
if variables["scroll_ether"] == 1:
print("Ether")
while True:
warpto = input("Where do you want to warp to? (or 'back' to quit): ").lower()
if warpto == "back":
break
elif warpto == "caverns" and variables["scroll_caverns"] == 1:
variables["mine"] = "caverns"
print("You have warped to the caverns")
break
elif warpto == "ether" and variables["scroll_ether"] == 1:
variables["mine"] = "ether"
print("You have warped to the ether")
break
else:
print("Invalid choice or you don't have the required scroll! Please try again.")
def main():
global user
user = ""
if os.path.exists('data.csv'):
load_game()
print("Welcome back to the ether.")
else:
time.sleep(1)
print("Welcome to the ether.")
print("Version 1.5")
time.sleep(1)
print("The story:")
time.sleep(1)
print("You are in a universe #278BBUC where everyone has equal rights to mines, as mines are now able to regenerate at an incredible pace. Thus, ores are infinite and society prospers. You are a healthy miner as well as adventurer, and you start off your journey at the starter mine, \"The Quarry\".\n")
print("Start by trying out the command 'h' or 'mine' to mine for materials.")
user_actions = {
"h": display_help,
"mine": mine_materials,
"shop": shop,
"cmine": lambda: print("The Quarry"),
"cr": check_resources,
"r": lambda: print("Different Resources: \"r\""),
"warp": warp
}
while True:
user = input("What do you want to do next? (h for help, q to quit): ").lower()
if variables["mine"].lower() == "quarry":
time.sleep(0.25)
action = user_actions.get(user)
if action:
action()
elif user == "q":
break
else:
print("Error! Not a command! Type 'h' for help.")
save_game()
print("Goodbye!")
if __name__ == "__main__":
main()