-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
398 lines (347 loc) · 11.8 KB
/
main.py
File metadata and controls
398 lines (347 loc) · 11.8 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
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
#tkinter
import tkinter as tk
from tkinter import *
from tkinter import ttk
#pillow
from PIL import Image, ImageTk
#random int lib
import random
#json
import json
class item:
name = "Dull Sword"
value = 1
dullSword = item()
dullSword.name = "Dull Sword"
dullSword.value = 1
crown = item()
crown.name = "Crown"
crown.value = 5
#resources
class resources:
def __init__(self, gold, subjects, soldiers, lumber, stone, castles, towns, taxRate):
self.gold = gold
self.subjects = subjects
self.soldiers = soldiers
self.lumber = lumber
self.stone = stone
self.castles = castles
self.towns = towns
self.taxRate = taxRate
playerResources = resources(15, 15, 10, 10, 10, 1, 1, 1)
prepAction = "doNothing"
def turn():
global prepAction
if(prepAction == "doNothing"):
message1.config(text = "You have not selected an action, my liege.")
return
elif(prepAction == "mine"):
mineAction()
elif(prepAction == "log"):
loggingAction()
elif(prepAction == "buildTown"):
buildTownAction()
elif(prepAction == "buildCastle"):
buildCastleAction()
elif(prepAction == "tax"):
taxAction()
elif(prepAction == "crusade"):
crusadeAction()
playerResources.gold = playerResources.gold + (playerResources.towns + round(playerResources.subjects / 3))
playerResources.subjects = playerResources.subjects - ((playerResources.towns * playerResources.taxRate) ** 2)
if(playerResources.subjects < 0):
playerResources.subjects = 0
playerResources.subjects = playerResources.subjects + round(random.randint(0, playerResources.subjects) / 2)
prepAction = "doNothing"
updateResources()
message1.config(text = "What would you like to do next turn, my lord?")
def mineAction():
playerResources.gold = playerResources.gold - 5
playerResources.subjects = playerResources.subjects - random.randint(1, 2)
playerResources.gold = playerResources.gold + random.randint(1, 5)
playerResources.stone = playerResources.stone + random.randint(10, 20)
updateResources()
def mineActionPrep():
if(playerResources.gold < 5):
message1.config(text = "You do not have the gold to begin a mining expedition, my lord.")
elif(playerResources.subjects < 2):
message1.config(text = "You do not have the subjects to begin a mining expedition, my lord.")
else:
message1.config(text = "Yes, my lord. We will begin mining when you end your turn.")
global prepAction
prepAction = "mine"
def loggingAction():
playerResources.gold = playerResources.gold - 3
playerResources.subjects = playerResources.subjects - random.randint(1, 2)
playerResources.lumber = playerResources.lumber + random.randint(10, 20)
updateResources()
def loggingActionPrep():
if(playerResources.gold < 3):
message1.config(text = "You do not have the gold to begin a logging expedition, my lord.")
elif(playerResources.subjects < 2):
message1.config(text = "You do not have the subjects to begin a logging expedition, my lord.")
else:
message1.config(text = "Yes, my lord. We will begin logging when you end your turn.")
global prepAction
prepAction = "log"
def buildTownAction():
playerResources.subjects = playerResources.subjects + random.randint(5, 15)
playerResources.lumber = playerResources.lumber - 50
playerResources.stone = playerResources.stone - 25
playerResources.towns = playerResources.towns + 1
updateResources()
def buildTownActionPrep():
if(playerResources.lumber < 50):
message1.config(text = "You do not have the lumber to build a town, my lord.")
elif(playerResources.stone < 25):
message1.config(text = "You do not have the stone to build a town, my lord.")
else:
message1.config(text = "Yes, my lord. We will build a town when you end your turn.")
global prepAction
prepAction = "buildTown"
def taxActionRaise():
playerResources.taxRate = playerResources.taxRate + 1
updateResources()
def taxActionLower():
if(playerResources.taxRate > 0):
playerResources.taxRate = playerResources.taxRate - 1
else:
message1.config(text = "The tax rate cannot be lower than 0, my lord.")
updateResources()
def buildCastleAction():
playerResources.subjects = playerResources.subjects - 15
playerResources.lumber = playerResources.lumber - 30
playerResources.stone = playerResources.stone - 50
playerResources.soldiers = playerResources.soldiers + 15
playerResources.castle = playerResources.castle + 1
updateResources()
def buildCastleActionPrep():
if(playerResources.stone < 50):
message1.config(text = "You do not have enough stone to build a castle, my lord.")
elif(playerResources.lumber < 30):
message1.config(text = "You do not have enough lumber to build a castle, my lord.")
elif(playerResources.subjects < 15):
message1.config(text = "You do not have enough subjects to train, my lord.")
else:
message1.config(text = "Yes, my lord. We will build a castle when you end your turn.")
global prepAction
prepAction = "buildCastle"
def crusadeAction():
playerResources.soldiers = playerResources.soldiers - random.randint(0, 15)
playerResources.gold = playerResources.gold + random.randint(15, 45)
updateResources()
def crusadeActionPrep():
if(playerResources.soldiers < 15):
message1.config(text = "You do not have enough soldiers to start a crusade, my lord.")
else:
message1.config(text = "Yes, my lord. We will begin a crusade when you end your turn.")
global prepAction
prepAction = "buildCastle"
def debugWinAction():
playerResources.gold = 1000
updateResources()
inventory = [dullSword, crown]
xPrev = 1
def clickResponse():
x = random.randint(1, 5)
global xPrev
if(x == xPrev):
x = x + 1
if(x == 1):
customText = "Many monarchy."
elif(x == 2):
customText = "So regal."
elif(x == 3):
customText = "Much kingly."
elif(x == 4):
customText = "Very fantasy."
else:
customText = inventory[random.randint(0, (len(inventory) - 1))].name + "."
message1.config(text = customText)
xPrev = x
def advisorNameGen():
advisorNameList = ["Emphion", "Corvo", "Parvati", "Eliza", "Glados", "Morokei", "Poppy", "Burch", "Alex", "Emily", "Colville", "Meganz", "Leslie", "Ramos"]
x = random.randint(0, (len(advisorNameList) - 1))
return advisorNameList[x]
#root/main window geometry and setup
root = tk.Tk()
root.title("mainProgram")
root.iconbitmap('assets\squids\squid.ico')
root.rowconfigure(0, weight = 2)
root.rowconfigure(1, weight = 5)
upperFrame = ttk.Frame(root)
lowerFrame = ttk.Frame(root)
upperFrame.grid(column = 0, row = 0)
lowerFrame.grid(column = 0, row = 1)
#grid geometry for the lowerFrame
lowerFrame.rowconfigure(0, weight = 1)
lowerFrame.rowconfigure(1, weight = 1)
lowerFrame.rowconfigure(2, weight = 1)
lowerFrame.rowconfigure(3, weight = 1)
lowerFrame.columnconfigure(0, weight = 1)
lowerFrame.columnconfigure(1, weight = 1)
lowerFrame.columnconfigure(2, weight = 1)
lowerFrame.columnconfigure(3, weight = 1)
lowerFrame.columnconfigure(4, weight = 1)
#messages
advisorName = "Bren"
advisorName = advisorNameGen()
message = ttk.Label(upperFrame, text = "Local Lord")
message.pack()
message1 = ttk.Label(upperFrame, text = "Why haven't you pressed me yet?")
message1.pack()
message2 = ttk.Label(upperFrame, text = "I am " + advisorName + " the advisor. At your service, my liege.")
message2.pack()
resourceDescription = ttk.Label(upperFrame, text = "Gold = " + str(playerResources.gold) + "\nSubjects = " + str(playerResources.subjects) + "\nSoldiers = " + str(playerResources.soldiers) + "\nLumber = " + str(playerResources.lumber) + "\nStone = " + str(playerResources.stone))
resourceDescription.pack(
expand = True,
side = "left"
)
resourceDescription2 = ttk.Label(upperFrame, text = "Castles = " + str(playerResources.castles) + "\nTowns = " + str(playerResources.towns) + "\nTax Rate = " + str(playerResources.taxRate))
resourceDescription2.pack(
expand = True,
side = "left"
)
def gameEnd():
mineButton.grid_forget()
loggingButton.grid_forget()
buildTownButton.grid_forget()
buildCastleButton.grid_forget()
taxRaiseButton.grid_forget()
taxLowerButton.grid_forget()
turnButton.grid_forget()
crusadeButton.grid_forget()
def updateResources():
resourceDescription.config(text = "Gold = " + str(playerResources.gold) + "\nSubjects = " + str(playerResources.subjects) + "\nSoldiers = " + str(playerResources.soldiers) + "\nLumber = " + str(playerResources. lumber) + "\nStone = " + str(playerResources.stone))
resourceDescription2.config(text = "Castles = " + str(playerResources.castles) + "\nTowns = " + str(playerResources.towns) + "\nTax Rate = " + str(playerResources.taxRate))
if((playerResources.gold <= 0 ) or (playerResources.subjects <= 0)):
gameEnd()
message1.config(text = "Your kingdom is in ruins. You lose.")
return
elif(playerResources.gold > 999):
gameEnd()
message1.config(text = "Congratulations! You win.")
return
decisionButton = ttk.Button(
lowerFrame,
text = "Make decisions.",
command = clickResponse,
compound = tk.LEFT
)
decisionButton.grid(
column = 0,
row = 0,
sticky = tk.EW
)
debugWinButton = ttk.Button(
lowerFrame,
text = "Win. (DEBUG)",
command = debugWinAction,
compound = tk.LEFT
)
debugWinButton.grid(
column = 0,
row = 1,
sticky = tk.EW
)
mineButton = ttk.Button(
lowerFrame,
text = "Mine.",
command = mineActionPrep,
compound = tk.LEFT
)
mineButton.grid(
column = 1,
row = 0,
sticky = tk.EW
)
loggingButton = ttk.Button(
lowerFrame,
text = "Chop Trees.",
command = loggingActionPrep,
compound = tk.LEFT
)
loggingButton.grid(
column = 1,
row = 1,
sticky = tk.EW
)
buildTownButton = ttk.Button(
lowerFrame,
text = "Build town.",
command = buildTownActionPrep,
compound = tk.LEFT
)
buildTownButton.grid(
column = 1,
row = 2,
sticky = tk.EW
)
taxRaiseButton = ttk.Button(
lowerFrame,
text = "Raise Taxes.",
command = taxActionRaise,
compound = tk.LEFT
)
taxRaiseButton.grid(
column = 2,
row = 0,
sticky = tk.EW
)
taxLowerButton = ttk.Button(
lowerFrame,
text = "Lower Taxes.",
command = taxActionLower,
compound = tk.LEFT
)
taxLowerButton.grid(
column = 2,
row = 1,
sticky = tk.EW
)
buildCastleButton = ttk.Button(
lowerFrame,
text = "Build Castle.",
command = buildCastleActionPrep,
compound = tk.LEFT
)
buildCastleButton.grid(
column = 2,
row = 2,
sticky = tk.EW
)
crusadeButton = ttk.Button(
lowerFrame,
text = "Launch Crusade.",
command = crusadeActionPrep,
compound = tk.LEFT
)
crusadeButton.grid(
column = 2,
row = 3,
sticky = tk.EW
)
turnButton = ttk.Button(
lowerFrame,
text = "End Turn.",
command = turn,
compound = tk.LEFT
)
turnButton.grid(
column = 3,
row = 0,
rowspan = 3,
sticky = tk.EW
)
#closeProgramButton
quitButton = ttk.Button(
lowerFrame,
text = "Quit Program.",
command = lambda: root.quit()
)
quitButton.grid(
column = 4,
row = 3,
sticky = tk.EW
)
root.mainloop()