repl.it
@Seazyns/

Forest Tycoon

Python

No description

fork
loading
Files
  • main.py
  • filename.txt
  • profile.txt
main.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
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
# Plug-Ins
import random
import replit
import time
import threading
import sys
# Saving / Loading Progress
import pickle
import os

# Colors
orange = '\033[33m'
reset = '\033[0m'
green = '\033[32m'
blue = '\033[36m'
red = '\033[31m'
purple = '\033[35m'

# Design
line = "{}================={}".format(purple,reset)

# Movement
cursor_up = '\x1b[1A'
erase_line = '\x1b[2K'

# Currencies
money = 0

# Satchel Variable
max_satchel = 20
satchel_level = 0

# Satchels Costs (Always Default)
levelone_satchel = 250
levelone_storage = 50

# Forest Costs (Always Default)
birch_forest = 1000

# Trees Satchels
oak_wood_satchel = 0

# Levels
forest_level = 1

# Save / Load
load = 0

# Tutorial
def tutorial():
	replit.clear()
	print(line)
	print("{}Forest Tycoon{}".format(red,reset))
	print(line)
	print("{}IMPORTANT NOTE:{} If you are playing this game and want to save your progress, fork this project! If there is an update, copy the code from the main.py file in the updated version of the game and paste it in the version you forked!".format(orange,reset))
	print(line)
	print("{}TUTORIAL:{} You cut trees at the forest, go to the shop to buy upgrades and visit the market to buy and sell wood! You can save and load your progress within the game.".format(orange,reset))
	print(line)
	input("Press {}'Enter'{} to continue!".format(green,reset))
	replit.clear()

# Tutorial Process
def tutorial_process():
	while True:
		replit.clear()
		print(line)
		print("{}Forest Tycoon Menu{}".format(red,reset))
		print("{}Important:{} Type the number corresponding to the action!".format(green,reset))
		print(line)
		print("{}> 1.{} Tutorial".format(orange,reset))
		print("{}> 2.{} Play Game".format(orange,reset))
		print(line)
		game_input = input("{}>{} ".format(blue,reset))
		if game_input == "1":
			tutorial()
		if game_input == "2":
			game()

# Game
def game():
	while True:
		replit.clear()
		print(line)
		print("{}Forest Tycoon{}".format(red,reset))
		print(line)
		print("{}Currencies{}".format(green,reset))
		print("{}Money:{} ${}".format(orange,reset,money))
		print(line)
		print("{}> 0.{} Exit Game".format(orange,reset))
		print("{}> 1.{} Forests".format(orange,reset))
		print("{}> 2.{} Shop".format(orange,reset))
		print("{}> 3.{} Market".format(orange,reset))
		print("{}> 4.{} Options".format(orange,reset))
		print(line)
		game_input = input("{}>{} ".format(blue,reset))
		if game_input == "0":
			end_game()
		if game_input == "1":
			forest()
		if game_input == "2":
			shop()
		if game_input == "3":
			market()
		if game_input == "4":
			options()

# Forest Hub
def forest():
	while True:
		replit.clear()
		if forest_level == 1:
			oak_forest()
		if forest_level > 1:
			print("{}Forest Level{}: {}".format(green,reset,forest_level))
			print("{}Unlocked Forests{}".format(orange,reset))
			print(line)
			print("{}> 0.{} Leave Forest".format(orange,reset))
			print(line)
			print("{}> 1.{} Oak Forest".format(orange,reset))
			if forest_level >= 2:
				print("{}> 2.{} Birch Forest".format(orange,reset))
			if forest_level >= 3:
				print("{}> 3.{} Spruce Forest".format(orange,reset))
			if forest_level >= 4:
				print("{}> 4.{} Jungle".format(orange,reset))
			if forest_level >= 5:
				print("{}> 5.{} Dark Oak Forest".format(orange,reset))
			if forest_level >= 6:
				print("{}> 6.{} Acacia Forest".format(orange,reset))
			print(line)
			forest_input = input("{}>{} ".format(blue,reset))
			if forest_input == "0":
				game()
			if forest_input == "1":
				oak_forest()

# Shop
def shop():
	global money
	global satchel_level
	global max_satchel
	global forest_level
	while True:
		replit.clear()
		print(line)
		print("{}Market Hub{}".format(red,reset))
		print(line)
		print("{}Important:{} Buy Items at the Shop".format(green,reset))
		print("{}Money:{} ${}".format(orange,reset,money))
		print(line)
		print("{}>{} Type {}'satchel'{} for Satchel Upgrades".format(orange,reset,orange,reset))
		print("{}>{} Type {}'forest'{} for Forest Upgrades".format(orange,reset,orange,reset))
		print("{}> 1.{} Leave Shop".format(orange,reset))
		print(line)
		shop_input = input("{}>{} ".format(blue,reset))
		if shop_input == "1":
			game()
		if shop_input.lower() == "satchel":
			print(cursor_up + erase_line + "{}>{} {}{} | {}List of Satchels{}".format(blue,orange,shop_input,reset,green,reset))
			print(line)
			if satchel_level == 0:
				print("{}> 1.{} Level 1 Satchel{} | {}Storage:{} {}{} | {}Cost:{} ${}{}".format(orange,green,reset,orange,green,levelone_storage,reset,orange,green,levelone_satchel,reset))
			print(line)
			satchel_input = input("{}>{} ".format(blue,reset))
			if satchel_input == "1":
				if money >= levelone_satchel and satchel_level == 0:
					money -= levelone_satchel
					satchel_level += 1
					max_satchel += (levelone_storage - max_satchel)
					print(line)
					print("{}Successful Purchase{}".format(green,reset))
					print("{}-{} Money{}".format(red,levelone_satchel,reset))
					print("{}{} Max Storage{}".format(green,max_satchel,reset))
					print(line)
					input("Press {}'Enter'{} to continue!".format(green,reset))
				elif money < levelone_satchel or satchel_level > 0:
					print(line)
					print("{}Unavailable Purchase{}".format(red,reset))
					print(line)
					input("Press {}'Enter'{} to continue!".format(green,reset))
		if shop_input.lower() == "forest":
			print(cursor_up + erase_line + "{}>{} {}{} | {}List of Forest Upgrades{}".format(blue,orange,shop_input,reset,green,reset))
			print(line)
			if forest_level == 1:
				print("{}> 1.{} Birch Forest{} | {}Cost:{} ${}{}".format(orange,green,reset,orange,green,birch_forest,reset))
			print(line)
			forest_input = input("{}>{} ".format(blue,reset))
			if forest_input == "1":
				if money >= birch_forest and forest_level == 1:
					money -= birch_forest
					forest_level += 1
					print(line)
					print("{}Successful Purchase{}".format(green,reset))
					print("{}-{} Money{}".format(red,birch_forest,reset))
					print("{}Birch Forest Unlocked{}".format(green,reset))
					print(line)
					input("Press {}'Enter'{} to continue!".format(green,reset))
				elif money < birch_forest or forest_level > 1:
					print(line)
					print("{}Unavailable Purchase{}".format(red,reset))
					print(line)
					input("Press {}'Enter'{} to continue!".format(green,reset))

# Market
def market():
	while True:
		replit.clear()
		if forest_level == 1:
			oak_market()
		if forest_level > 1:
			print(line)
			print("{}Market Hub{}".format(red,reset))
			print(line)
			print("{}Important:{} Visit Different Markets".format(green,reset))
			print(line)
			print("{}> 1.{} Oak Wood".format(orange,reset))
			if forest_level >= 2:
				print("{}> 2.{} Birch Wood".format(orange,reset))
			if forest_level >= 3:
				print("{}> 3.{} Spruce Wood".format(orange,reset))
			if forest_level >= 4:
				print("{}> 4.{} Jungle Wood".format(orange,reset))
			if forest_level >= 5:
				print("{}> 5.{} Dark Oak Wood".format(orange,reset))
			if forest_level >= 6:
				print("{}> 6.{} Acacia Wood".format(orange,reset))
			print(line)
			market_input = input("{}>{} ".format(blue,reset))
			if market_input == "1":
				oak_market()

# Oak Forest
def oak_forest():
	global oak_wood_satchel
	while True:
		replit.clear()
		print(line)
		print("{}Oak Forest{}".format(red,reset))
		print(line)
		print("{}Important:{} Cut Trees Here".format(green,reset))
		print("{}Oak Wood Satchel:{} {}/{}".format(orange,reset,oak_wood_satchel,max_satchel))
		print("Press {}'Enter'{} to cut trees!".format(orange,reset))
		print(line)
		print("{}> 1.{} Leave Forest".format(orange,reset))
		print(line)
		forest_input = input("{}>{} ".format(blue,reset))
		if forest_input == "1":
			game()
		else:
			if oak_wood_satchel < max_satchel:
				oak_wood_satchel += 1

# Oak Market
def oak_market():
	global oak_wood_satchel
	global money
	while True:
		replit.clear()
		print(line)
		print("{}Oak Market{}".format(red,reset))
		print(line)
		print("{}Important:{} Buy and Sell Trees Here! Press {}'Enter'{} to refresh prices!".format(green,reset,orange,reset))
		print("{}Oak Wood Satchel:{} {}/{}".format(orange,reset,oak_wood_satchel,max_satchel))
		print("{}Money:{} ${}".format(orange,reset,money))
		print(line)
		# Random Pricing
		buy_oak = random.randint(4,6)
		sell_oak = random.randint(1,3)
		print("{}>{} Type {}'buy'{} to Buy Wood | Buy Price / Wood: {}${}{}".format(orange,reset,orange,reset,green,buy_oak,reset))
		print("{}>{} Type {}'sell'{} to Sell Wood | Sell Price / Wood: {}${}{}".format(orange,reset,orange,reset,green,sell_oak,reset))
		print("{}> 1.{} Leave Oak Market".format(orange,reset))
		print(line)
		oak_market = input("{}>{} ".format(blue,reset))
		if oak_market == "1":
			game()
		if oak_market.lower() == "buy":
			print(cursor_up + erase_line + "{}>{} {}{} | {}Type Buy Amount{}".format(blue,orange,oak_market,reset,green,reset))
			buy_amount = input("{}>{} ".format(blue,reset))
			if money >= (int(buy_amount) * buy_oak):
				if int(buy_amount) <= 0:
					print(line)
				elif oak_wood_satchel > (max_satchel - int(buy_amount)):
					print(line)
					print("{}You cannot hold {} oak wood in your satchel{}".format(red,int(buy_amount),reset))
					print(line)
					input("Press {}'Enter'{} to continue!".format(green,reset))
				else:
					money -= (int(buy_amount) * buy_oak)
					oak_wood_satchel += int(buy_amount)
					print(line)
					print("{}Successful Purchase{}".format(green,reset))
					print("{}-{} Money{}".format(red,(int(buy_amount)*buy_oak),reset))
					print("{}+{} Oak Wood{}".format(green,int(buy_amount),reset))
					print(line)
					input("Press {}'Enter'{} to continue!".format(green,reset))
			else:
				print(line)
				print("{}Not Enough Money{}".format(red,reset))
				print(line)
				input("Press {}'Enter'{} to continue!".format(green,reset))
		if oak_market.lower() == "sell":
			print(cursor_up + erase_line + "{}>{} {}{} | {}Type Amount of Trees to Sell{}".format(blue,orange,oak_market,reset,green,reset))
			sell_amount = input("{}>{} ".format(blue,reset))
			# Calculation
			if int(sell_amount) <= 0:
				print(line)
			elif oak_wood_satchel >= int(sell_amount):
				oak_wood_satchel -= int(sell_amount)
				money += (int(sell_amount)*sell_oak)
				print(line)
				print("{}Successful Sell{}".format(green,reset))
				print("{}-{} Oak Wood{}".format(red,int(sell_amount),reset))
				print("{}+{} Money{}".format(green,(int(sell_amount)*sell_oak),reset))
				print(line)
				input("Press {}'Enter'{} to continue!".format(green,reset))
			else:
				print(line)
				print("{}Not enough oak wood{}".format(red,reset))
				print(line)
				input("Press {}'Enter'{} to continue!".format(green,reset))

# Options
def options():
	while True:
		replit.clear()
		print(line)
		print("{}Options{}".format(red,reset))
		print(line)
		print("{}> 1.{} Exit Options".format(orange,reset))
		print("{}> 2.{} Load / Save Progress".format(orange,reset))
		print(line)
		options_input = input("{}>{} ".format(blue,reset))
		if options_input == "1":
			game()
		if options_input == "2":
			data()

# Load / Save
def data():
	global load
	global money
	global max_satchel
	global satchel_level
	global oak_wood_satchel
	global forest_level
	while True:
		replit.clear()
		print(line)
		print("{}Load / Save Progress{}".format(red,reset))
		f = open("profile.txt","r")
		profile = f.read()
		f.close()
		print("{}Profile Username: {}{}".format(orange,profile,reset))
		print(line)
		print("{}> 1.{} Exit Load / Save Menu".format(orange,reset))
		print("{}> 2.{} Save Game".format(orange,reset))
		print("{}> 3.{} Load Game".format(orange,reset))
		print(line)
		data_input = input("{}>{} ".format(blue,reset))
		if data_input == "1":
			options()
		if data_input == "2":
			if load == 0:
				replit.clear()
				print(line)
				print("{}Save Progress{}".format(red,reset))
				print(line)
				username = input("{}Username:{} ".format(orange,reset))
				password = input("{}Password:{} ".format(orange,reset))
				filename = ('{}.{}.pickle'.format(username,password))
				if os.path.exists(filename):
					os.remove(filename)
				with open('{}.{}.pickle'.format(username,password), 'wb') as f:
					# Variable to Save
					pickle.dump(money,f)
					pickle.dump(max_satchel,f)
					pickle.dump(satchel_level,f)
					pickle.dump(oak_wood_satchel,f)
					pickle.dump(forest_level,f)
				f = open("filename.txt","w")
				f.write("{}.{}".format(username,password))
				f.close()
				f = open("profile.txt","w")
				f.write("{}".format(username))
				f.close()
				print(line)
				load += 1
				print("{}Successful Save{}".format(green,reset))
				input("Press {}'Enter'{} to continue!".format(green,reset))
				replit.clear()
			elif load == 1:
				replit.clear()
				print(line)
				print("{}Save Progress{}".format(red,reset))
				print(line)
				f = open("filename.txt","r")
				filename = f.read()
				f.close()
				if os.path.exists(filename):
					os.remove(filename)
				with open('{}.pickle'.format(filename), 'wb') as f:
					# Variable to Save
					pickle.dump(money,f)
					pickle.dump(max_satchel,f)
					pickle.dump(satchel_level,f)
					pickle.dump(oak_wood_satchel,f)
					pickle.dump(forest_level,f)
				print("{}Successful Save{}".format(green,reset))
				input("Press {}'Enter'{} to continue!".format(green,reset))
				replit.clear()
		if data_input == "3":
			replit.clear()
			print(line)
			print("{}Load Progress{}".format(red,reset))
			print(line)
			print("{}Important:{} Do you want to save your progress before loading{}".format(green,orange,reset))
			print("{}If you already saved your progress, then you don't need to again{}".format(orange,reset))
			print(line)
			print("Type {}'yes'{} to save before loading!".format(orange,reset))
			print("Type {}'no'{} to continue loading!".format(orange,reset))
			print("{}> 1.{} Exit Menu".format(orange,reset))
			print(line)
			preload_input = input("{}>{} ".format(blue,reset))
			if preload_input == "1":
				options()
			elif preload_input.lower() == "yes":
				data()
			elif preload_input.lower() == "no":
				replit.clear()
				print(line)
				print("{}Load Progress{}".format(red,reset))
				print(line)
				try:
					if load == 0:
						username = input("{}Username:{} ".format(orange,reset))
						password = input("{}Password:{} ".format(orange,reset))
						with open('{}.{}.pickle'.format(username,password), 'rb') as f:
							# Load Variables
							money = pickle.load(f)
							max_satchel = pickle.load(f)
							satchel_level = pickle.load(f)
							oak_wood_satchel = pickle.load(f)
							forest_level = pickle.load(f)
						print(line)
						# Saving Filename
						f = open("filename.txt","w")
						f.write("{}.{}".format(username,password))
						f.close()
						f = open("profile.txt","w")
						f.write("{}".format(username))
						f.close()
						load += 1
						print("{}Successful Load{}".format(green,reset))
						input("Press {}'Enter'{} to continue!".format(green,reset))
						game()
					elif load == 1:
						username = input("{}Username:{} ".format(orange,reset))
						password = input("{}Password:{} ".format(orange,reset))
						with open('{}.{}.pickle'.format(username,password), 'rb') as f:
							# Load Variables
							money = pickle.load(f)
							max_satchel = pickle.load(f)
							satchel_level = pickle.load(f)
							oak_wood_satchel = pickle.load(f)
							forest_level = pickle.load(f)
						print(line)
						# Saving Filename
						f = open('filename.txt','w')
						f.write("{}.{}".format(username,password))
						f.close()
						f = open("profile.txt","w")
						f.write("{}".format(username))
						f.close
						print("{}Successful Load{}".format(green,reset))
						input("Press {}'Enter'{} to continue!".format(green,reset))
						game()
				except:
					print("{}Incorrect Username or Password!{}".format(red,reset))
					input("Press {}'Enter'{} to continue!".format(green,reset))
					options()
			else:
				options()

# End Game
def end_game():
	while True:
		replit.clear()
		print(line)
		print("{}End Game{}".format(red,reset))
		print(line)
		print("{}Important:{} Make sure you have saved your progress before quitting.{}".format(green,orange,reset))
		print(line)
		print("Type {}'save'{} to save before quitting!".format(orange,reset))
		print("Type {}'quit'{} to quit!".format(orange,reset))
		print("{}> 1.{} Exit Menu".format(orange,reset))
		print(line)
		exit_input = input("{}>{} ".format(blue,reset))
		if exit_input.lower() == "save":
			data()
		if exit_input.lower() == "quit":
			f = open("filename.txt","w")
			f.close()
			f = open("profile.txt","w")
			f.close()
			sys.exit()
		if exit_input == "1":
			game()

tutorial_process()