repl.it
@PYer/

Farming Game Endless Mode

Python

No description

fork
loading
Files
  • main.py
  • poetry.lock
  • pyproject.toml
  • requirements.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
from replit import clear
from random import randint as r
from random import choice
from readchar import readkey
from sys import stdout 
from time import sleep

mult = 1

def newinput(prompt): 
  stdout.write(prompt)
  stdout.flush()
  return str(readkey())

def intro():
  global days, mult
  print('Hello and welcome to THE FARMING GAME - Endless Mode! By PYer.')
  c = newinput('Press any key to view instructions, or type s to skip.')
  if not c == 's':
    clear()
    print('''The point of this game is to score the most amount of points possible. You get scored when your time is up. Your points are found by a combination of the lifetime amount of crops you have harvested as well as the amount of crops you had by the end of the game.''')
    newinput('Press any key...')
    clear()
    print('''At the top part of the screen while playing, you will see a list of important statistics:

          Days Left    [365]
          Crops        [50]
          Seeds        [10]
          Total Land   [25]ft
          Unused Land  [25]ft
          Workers      [6]
          Harvested    [0] crops!

Above is shown what your stats will be at the start of the game. (Days Left excluded.) Underneath this section, you will spot and introduction message:

          Nothing extraordinary happened today. (Welcome,btw)

This message notifies you of anything extraordinary occuring during your day. 

For the more curious: There is a 1/5 chance of something occuring. 1/4 chance of it being a good thing, 1/4 chance of it being bad, and 1/2 of a change in the price of some supply. (1/3 chance of either land, workers, or seeds, and a 1/2 chance of it going up and 1/2 of it going down.)''')
    newinput('Press any key...')
    clear()
    print('''Underneath their will be a prompt asking you: 
          Would you like to (1) enter the shop, (2) plant seeds, or (3) end the day?

By entering either 1, 2, or 3 you can acheive the action.''')
    newinput('Press any key...')
    clear()
    print('''There are a few rules determining the amount of crops you harvest at the end of the day.
    1) Each worker can harvest up to 2 crops.
    2) You can only harvest up to the amount of land you have. (1 crop per foot) 
    3) Unused land does not produce any crops.
    4) After land is harvested, it becomes unused.
    5) Unrelated, but crops are used as money.
    ''')
    newinput('Almost there... (press any key) ')
    clear()
    print('''A few thing to know for those who are creating a strategy.

SCORING

      1) The total amount of crops you have harvested weighs 80% of your score, whereas the amount of crops you currentely have is 20%.
      2) Each foot of land (unused+used) counts towards and additional 3pts.
      3) Each worker left at the end counts as an additional 1pt
      4) Every 50 seeds count as 1pt.''')
  
    newinput('Press any key...')
    clear()
    print('''A few thing to know for those who are creating a strategy.

EXTRAORDINARY OCCURENCES

      "God's Granting A Plentiful Harvest" [ \u001b[1m+ \u001b[0m]
          This makes your harvested crops that turn multiplied by a random number (2-4). Regular rules for maximum harvesting are forgotten with this bonus.
      
      "Alien's Depositing Crops" [ \u001b[1m+ \u001b[0m]
          This is similar, but makes your gain increase by a random number between your gain and your gain multiplied by two. 

      "A Disease Plauged Your Workers" [ \u001b[1m- \u001b[0m]
          This causes your workes to decrease between 16% to 33%. Uh-oh

      "Some Crops Have Rotted" [ \u001b[1m- \u001b[0m]
          All the crops you have been saving decrease by 16% to 33%. This does not affect your total lifetime crops harvested.

      "Lower Price On A Supply" [ \u001b[1m+ \u001b[0m]
          On a random item (workers, land, or seeds), the price decreases by 10%-50%.
      
      "Higher Price On A Supply" [ \u001b[1m- \u001b[0m]
          On a random item (workers, land, or seeds), the price increases by 10-50%.''')
    newinput('Begin the game (press any key)...')

prices = {
  'people': 10,
  'land': 30,
  'seeds': 1
}

life = 0
crop = 50
people = 6
land = 5*5
seeds = 10
unused_land = land
gain = 0
days = 365

def new_day(d, c, p, l, g, u,s):
  print(f'''THE FARMING GAME    ||
     By PYer        ||
======================
SCORE        [ \u001b[1m{d} \u001b[0m] 
Crops        [ \u001b[1m{c} \u001b[0m]
Seeds        [ \u001b[1m{s} \u001b[0m]
Total Land   [ \u001b[1m{l} \u001b[0m] feet
Unused Land  [ \u001b[1m{u} \u001b[0m] feet
Workers      [ \u001b[1m{p} \u001b[0m]
Harvested    [ \u001b[1m{g} \u001b[0m] crops!
===================================''')


def score():
  s = 0
  s += life/5*4
  s += (crop-50)/5
  s += (land-25)*3
  s += people - 6
  s += (seeds - 10)/50
  s *= mult
  return float(int(s))

def benefit(n, gain, people, crop):
  if n == 1:
    o = r(1, 2)
    if o == 1:
      extrabanner = 'The god\'s have granted you a plentiful harvest!'
      gain *= r(2,4)
    elif o == 2:
      extrabanner = 'Aliens deposited a bunch of crops into your fields!'
      gain += r(gain, gain*2)
  elif n == 2:
    o = r(1, 2)
    if o == 1:
      extrabanner = 'A disease has plagued your workers!'
      people -= int(people/r(3, 6))
    elif o == 2:
      extrabanner = 'Some of your crops have rotted!'
      crop -= int(crop/r(3, 6))
  elif n == 3 or n == 4:
    item = choice(('people', 'land', 'seeds'))
    uorn = r(1,2)
    change = int(prices[item]/r(2,10))
    if uorn == 1:
      prices[item] += change
      extrabanner = 'Higher Price on ' + item + '. New cost ' + str(prices[item]) + ' crops.'
    elif uorn == 2:
      prices[item] -= change
      extrabanner = 'Lower Price on ' + item + '. New cost ' + str(prices[item]) + ' crops.'
  return extrabanner, gain, people, crop

extrabanner = 'Nothing extraordinary happened today. (Welcome, btw)'

def main():
  global life, extrabanner, gain, unused_land, seeds, land, people, prices, crop, won
  while True:
    clear()
    new_day(score(), crop, people, land, gain, unused_land, seeds)
    print(extrabanner)
    extrabanner = 'Nothing extraordinary happened today.'
    print('===================================')
    while True:
      try:
        opt = int(newinput('Would you like to (1) enter the shop, (2) plant seeds, or (3) end the day? '))
        break
      except: pass
    if opt==1:
      clear()
      new_day(score(), crop, people, land, gain, unused_land, seeds)
      print(f'''SHOP:
      (1) Land        - 25ft [ \u001b[1m{int(crop/prices["land"])} \u001b[0m] available [ \u001b[1mCost: {prices["land"]} \u001b[0m] crops
      (2) Workers     - 1 Person [ \u001b[1m{int(crop/prices["people"])} \u001b[0m] available [ \u001b[1mCost: {prices["people"]} \u001b[0m] crops
      (3) Seed Packet - 5 seeds [ \u001b[1m{int(crop/prices["seeds"])} \u001b[0m] available [ \u001b[1mCost: {prices["seeds"]} \u001b[0m] crops
      (0) EXIT
      ''')
      while True:
        try:
          opt = int(newinput('What would you like to buy? [0, 1, 2, or 3] '))
          break
        except: pass
      if opt==1:
        available = int(crop/30)
        if available == 0:
          print('You can\'t buy any land!')
          newinput('Press any key...')
        else:
          print('\nYou can buy', available, 'fields of 25 feet.')
          while True:
            try:
              am = int(input('How many do you buy? '))
              break
            except: pass
          if am > available:
            print('Wow there thats too much!')
            newinput('Press any key...')
          else:
            crop -= am * 30
            land += am*(5*5)
            unused_land += am*(5*5)
      elif opt==2:
        available = int(crop/10)
        if available == 0:
          print('You can\'t hire any workers!')
          newinput('Press any key...')
        else:
          print('\nYou can hire', available, 'workers.')
          while True:
            try:
              am = int(input('How many do you hire? '))
              break
            except: pass
          if am > available:
            print('Wow there thats too much!')
            newinput('Press any key...')
          else:
            crop -= am * 10
            people += am
      elif opt==3:
        available = crop
        if available == 0:
          print('You can\'t buy any seed packets!')
          newinput('Press any key...')
        else:
          while True:
            try:
              am = int(input('\nYou can buy ' + str(available) + ' seed packets. How many do you buy? '))
              break
            except: pass
          if am > available:
            print('Wow there thats too much!')
            newinput('Press any key...')
          else:
            seeds += am*5
            crop -= am
    elif opt==2:
      if unused_land == 0:
        print('You have already used all your land!')
        newinput('Press any key...')
      else:
        if seeds == 0:
          print('You don\'t have any seeds.')
          newinput('Press any key...')
        else:
          print('You have', unused_land ,'feet of unused land and', seeds, 'seeds. We\'ll fill your land as much as we can!')
          newinput('Press any key...')
          if unused_land <= seeds:
            sleep(2)
            seeds -= unused_land
            unused_land = 0
          else:
            sleep(2)
            unused_land -= seeds
            seeds = 0
    elif opt==3:
      gain = int((land-unused_land)- ((land-unused_land)-(people*2)))
      if gain > land-unused_land: 
        gain = land-unused_land
      unused_land += gain
      if r(1,5) == 2: 
        extrabanner, gain, people, crop = benefit(r(1, 4), gain, people, crop)
      crop += gain
      life += gain
    new_day(score(), crop, people, land, gain, unused_land, seeds)

intro()
main()