repl.it
@Pythonier/

Mayan Civilization Game-1

Python

Build your empire!

fork
loading
Files
  • main.py
  • Files
  • scores.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
 from replit import clear as c
from random import randint
from sys import stdout
from time import sleep

#Functions

def red(s):
  return ('\u001b[31m' + str(s) + '\033[0m')
def cyan(s):
  return ('\u001b[36m' + str(s) + '\033[0m')
def green(s):
  return ('\u001b[32m' + str(s) + '\033[0m')
def magenta(s):
  return ('\u001b[35m' + str(s) + '\033[0m')

def write(string):
  for char in string:
    stdout.write(char)
    stdout.flush()
    sleep(.03)
  stdout.write('\n')

def printShop():
  c()
  print(green("S H O P:"))
  print("Gold: "+ red(str(gold)))
  print("Silver: " + red(str(silver)))
  print("")
  
  if ns == 0:
    print("1) Number System : 50 silver")
  else: 
    print(red("1) Number System (BOUGHT)"))
  if cf == 0:
    print("2) Cacao Farm: 70 silver")
  else: 
    print(red("2) Cacao Farm (BOUGHT)"))
  if ast == 0:
    print("3) Astronomy: 60 gold")
  else:
    print(red("3) Astronomy (BOUGHT)")) 
  if py == 0:
    print("4) Limestone Pyramid: 100 silver")
  else:
    print(red("4) Limestone Pyramid (BOUGHT)"))
  if cf == 1:
    if sf == 0:
      print("5) Squash and Avacado Farm: 100 gold") 
    else: 
      print(red("5) Squash and Avacado Farm (BOUGHT)"))
  else:
    print(cyan("5) Buy the Cacao Farm to unlock this (LOCKED)"))
  if ast == 1:
    if cl == 0:
      print("6) Calendar: 50 gold")
    else:
      print(red("6) Calendar (BOUGHT)"))
  else:
    print(cyan("6) Buy Astronomy to unlock this (LOCKED)"))
  if cf and sf == 1:
    if army == 0:
      print("7) Army Rank 1: 50 silver and 50 gold")
    elif army == 1:
      print("7) Army Rank 2: 60 silver and 60 gold")
    elif army == 2:
      print("7) Army Rank 3: 70 silver and 70 gold")
    else:
      print(red("7) Maxed out army"))
  else: 
      print(cyan("7) Buy both farms to unlock this LOCKED"))
  

c()
# Variables
day = 0
food = 0 
silver = 0
gold = 0
ap = 0
army = 0
# Items From Shop
ns = 0
cf = 0
py = 0 
sf = 0
cl = 0
ast = 0

def farm():
  c()
  global food
  if sf == 1:
    fg = randint(0,10)
    food += fg
    print("You gained " + green(str(fg)) + " food!" )
  elif sf == 0:
    fg = randint(0,4)
    food += fg
    print("You gained " + green(str(fg)) + " food!" )


def mine():
  c()
  global gold
  global silver
  gp = randint(0,6)
  sp = randint(0,11)
  gold += gp
  silver += sp
  print("You mined " + red(gp) + " gold, and " + red(sp) + " silver!")

def shop(): 
  global gold, silver
  global silver
  global ns
  global cf
  global sf
  global py
  global ast
  global army
  global ap
  global cl
  # SHOP
  printShop()

  # BUY FROM SHOP
  buy = input(green("\nEnter number of item you want to buy. Enter lowercase l to leave.")+red("\n(You can only buy one item!):") + cyan("\n"))
  if buy == 'l':
    c()
    print("Do you want to " + green("1) mine?") + " or " + green("2) farm?"))
    other = input("Enter number: ")
    other = int(other)
    if other == 1:
      mine()
    elif other == 2:
      farm()
    else: 
      print(red("Invalid Input! Don't make that same mistake next time.")) 
  elif buy == '1' or '2' or '3' or '4' or '5' or '6' or '7':
    c()
    if buy == '1':
      if ns == 0:
        if silver >= 50:
          ns += 1 
          printShop()
          sleep(1)
          c()
          print("You bought the number system. The Maya devised one of the first number systems and the first symbol to represent 0.")
          print(green("+ 1 achievement point"))
          ap += 1
          silver -= 50
        else:
          print(red("You cannot buy this. You wasted your whole day doing nothing. BUMMER!"))
      else: 
        print("You already have that item. Don't make that same mistake next time.")
    elif buy == '2':
      if cf == 0:
        if silver >= 70:
          cf += 1
          printShop()
          sleep(1)
          c()
          print("You bought the cacao farm. The Maya used cacao beans as currency.")
          print(green("+ 2 achievement points"))
          ap += 2
          silver -= 70
        else:
          print(red("You cannot buy this. You wasted your whole day doing nothing. BUMMER!"))  
      else: 
        print("You already have that item. Don't make that same mistake next time.")
    elif buy == '3':
      if ast == 0:
        if gold >= 60:
          ast += 1
          printShop()
          sleep(1)
          c()
          print("You bought Astronomy. Astronomy is the study of celestial objects and space. Using astronomy, the Maya created a celandar.")
          print(green("+ 3 achievement points"))
          ap += 3
          gold -= 60
        else:
          print(red("You cannot buy this. You wasted your whole day doing nothing. BUMMER!"))
      else:
        print("You already have that item. Don't make that same mistake next time.")
    elif buy == '4':
      if py == 0:
        if silver >= 100: 
          py += 1
          printShop()
          sleep(1)
          c()
          print("You purchased Limestone Pyramid. The Maya built pyramids for religious purposes, such as sacrifices.")
          print(green("+ 5 achievement points"))
          ap += 5
          silver -= 100
        else:
          print(red("You cannot buy this. You wasted your whole day doing nothing. BUMMER!"))
      else:
        print("You already have that item. Don't make that same mistake next time.")
    elif buy == '5':
      if cf == 1:
        if sf == 0:
          if gold >= 100:
            sf += 1
            printShop()
            sleep(1)
            c()
            print("You bought the squash and avacado farm. The Maya farmed these two things and used them for food. Increases food production.")
            print(green("+ 8 achievement points"))
            ap += 8
            gold -= 100
          else:
            print(red("You cannot buy this. You wasted your whole day doing nothing. BUMMER!"))
        else:
          print("You already have that item. Don't make that same mistake next time.")
      else:
        print("You haven't unlocked this yet. Don't make that same mistake next time.")
    elif buy == '6':
      if ast == 1:
        if cl == 0:
          if gold >= 50:
            cl += 1
            printShop()
            sleep(1)
            c()
            print("You bought the calendar. The Maya were the first to develop a calendar. The calendar was so accurate that they were able to predict eclipses. The calendar was made up of 18 months with 20 days each. The 19'th month was made up of 5 days, adding up to a total of 365 days. ")
            print(green("+ 12 achievement points"))
            ap += 12
            gold -= 50
          else:
            print(red("You cannot buy this. You wasted your whole day doing nothing. BUMMER!"))
        else:
          print("You already have that item. Don't make that same mistake next time.")
      else:
        print("You haven't unlocked this yet. Don't make that same mistake next time.")
    elif buy == '7':
      if cf and sf == 1:
        if army == 0:
          if gold >= 50 and silver >= 50:
            army += 1
            printShop()
            sleep(1)
            c()
            print("You purchased army rank 1. The Maya army was used to conquer other places. When they conquered others, they tried to take prisoners rather than killing.")
            print(green("+ 15 achievement points"))
            ap += 15
            gold -= 50
            silver -= 50
          else:
            print(red("You cannot buy this. You wasted your whole day doing nothing. BUMMER!"))
        elif army == 1:
          if gold >= 60 and silver >= 60:
            army += 1
            printShop()
            sleep(1)
            c()
            print("You purchased army rank 2. The Maya army was used to conquer other places. When they conquered others, they tried to take prisoners rather than killing.")  
            print(green("+ 19 achievement points"))
            ap += 19
            silver -= 60
            gold -= 60 
          else:
            print(red("You cannot buy this. You wasted your whole day doing nothing. BUMMER!"))
        elif army == 2:
          if gold >= 70 and silver >= 70:
            army += 1
            printShop()
            sleep(1)
            c()
            print("You purchased army rank 3. The Maya army was used to conquer other places. When they conquered others, they tried to take prisoners rather than killing.")
            print(green("+ 30 achievement points"))
            ap += 30
            gold -= 70
            silver -= 70
          else:
            print(red("You cannot buy this. You wasted your whole day doing nothing. BUMMER!"))
        else: 
          print("You already maxed out that item. Don't make that mistake again.")
      else:
        print("You haven't unlocked this yet.")
    else:
      write(red("Invalid Input!"))
      c()
      print("Do you want to " + green("1) mine?") + " or " + green("2) farm?"))
      other = input("Enter number: ")
      other = int(other)
      if other == 1:
       mine()
      elif other == 2:
       farm()
      else: 
       print(red("Invalid Input! Don't make that same mistake next time."))
    
          

# game

#intro
def ins():
  c()
  print("""
How to play:

Goal:
The goal of this game is to build the biggest empire at the end of 100 days, which is determined by your score. 

Score:
The score is affected by the amount of silver, gold, and food you have left at the of the game. It is also affected by army rank and achievement points.

Achievement Points and Army Rank:
You receive achievement points from the shop. Different items from the shop give you different amounts achievement points. Army Rank can be upgraded in the shop, with rank three being the last rank.

Gold and Silver:
You will be given an option to mine, farm, or go to the shop. When you mine you get a certain amount of gold and silver. Then it continues to the next day.

Food:
When you choose to farm you get a certain amount of food. You can farm after you have purchased a farm in the shop. After you buy two farms, the food production increases.

Shop:
In the shop you can buy different things with gold and silver, that the Maya once developed. Ex: The Mayan Calendar. Different things in the shop give you different amounts of Achievement points. 
  """)
  input("\nPress enter to continue:")
#play game
ins()
while day <= 99:
  day += 1
  c()
  print("Day: " + red(str(day)))
  print("Gold: " + red(str(gold)))
  print("Silver: " + red(str(silver)))
  print("Food: " + red(str(food)))
  print("Army Rank: "+red(str(army)))
  print("Achievement Points: " +red(str(ap)))
  
  if day <= 40:
    print("\nDo you want to " + green("1) mine, 2) farm, 3) visit the shop, or 4) see 'How To Play'?\nEnter number:"))
  else:
    print("\nDo you want to " + green("1) mine, 2) farm, or 3) visit the shop?"))
  choice = input("")
  if choice == '1':
    mine()
  elif choice == '2':
    if cf == 1:
      farm()
    else:
      write("You haven't unlocked farming yet, mining instead...")
      mine()
  elif choice == '3':
    shop()
  elif choice == '4':
    ins()
  else:
    write(red("Invalid Input! Mining instead."))
    mine()
  input("Press enter to move on to next day:")

# End
c()
for i in range(0,4):
  print(green("You finished the game with a score of"))
  sleep(.2)
  c()
  print(green("You finished the game with a score of."))
  sleep(.2)
  c()
  print(green("You finished the game with a score of.."))
  sleep(.2)
  c()
  print(green("You finished the game with a score of..."))
  sleep(.2)
  c()
score = (1.9*(gold)+1.3*(silver)+3.6*(food)+8*(ap)+55*(army))
print(green("You finished the game with a score of " + green(str(score)) + "!\n")) 
print("Enter Username to save score: ")
un = input("")
if un == "":
  un = 'unknown'

c()  
write("Day: " + red(str(day)))
write("Gold: " + red(str(gold)))
write("Silver: " + red(str(silver)))
write("Food: " + red(str(food)))
write("Army Rank: "+red(str(army)))
write("Achievement Points: " +red(str(ap)))
with open('scores.txt','a') as f:
  f.write('\n'+str(un)+":"+str(score))
with open('scores.txt','r') as p:
  s = p.read()
  write("\nPrinting all time scores:\n")
  sleep(2)
  print(green(s))

sleep(3)
write(red("""
   _____ _              _     __   __        
  |_   _| |_  __ _ _ _ | |__  \ \ / /__ _  _ 
    | | | ' \/ _` | ' \| / /   \ V / _ \ || |
    |_| |_||_\__,_|_||_|_\_\    |_|\___/\_,_|
  ___           ___ _           _            
 | __|__ _ _   | _ \ |__ _ _  _(_)_ _  __ _  
 | _/ _ \ '_|  |  _/ / _` | || | | ' \/ _` | 
 |_|\___/_|    |_| |_\__,_|\_, |_|_||_\__, | 
                           |__/       |___/  
"""))
  
 
?