-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
206 lines (163 loc) · 7.89 KB
/
main.py
File metadata and controls
206 lines (163 loc) · 7.89 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
from tkinter import *
from tkinter import ttk
from tkinter.font import Font
import power
import json
''' Ôóíêöèè'''
def moneyPlusOne():
money.set(money.get() + money_get.get())
def moneyGetterUpgrade(): # Óëó÷øåíèå
if (money.get() >= power_upgrade_cost.get()):
money_get.set(money_get.get() + 1)
money.set(money.get() - power_upgrade_cost.get())
power_upgrade_cost.set(10 * 1.4 ** (money_get.get() - 1))
def moneyGetterUpgradeX10(): # Óëó÷øåíèå X10
if (money.get() >= power_upgrade_costX10.get()):
money_get.set(money_get.get() + 10)
money.set(money.get() - power_upgrade_costX10.get())
power_upgrade_cost.set(power_upgrade_cost.get() * 14)
def moneyGetterUpgradeX100(): # Óëó÷øåíèå X100
if (money.get() >= power_upgrade_costX100.get()):
money_get.set(money_get.get() + 100)
money.set(money.get() - power_upgrade_costX100.get())
power_upgrade_cost.set(power_upgrade_cost.get() * 140)
def update_vars_values():
get = lambda x: power_upgrade_cost.get() * x
costX10 = power.humanizeFunc(get(10))
costX100 = power.humanizeFunc(get(100))
cost = power.humanizeFunc(get(1))
power_upgrade_costX10.set(power_upgrade_cost.get() * 10)
power_upgrade_costX100.set(power_upgrade_cost.get() * 100)
power_upgrade_cost_Str.set(cost)
power_upgrade_costX10_Str.set(costX10)
power_upgrade_costX100_Str.set(costX100)
moneyStr.set(power.humanizeFunc(money.get()))
root.createtimerhandler(16, update_vars_values)
def buy_worker():
if money.get() >= worker_cost.get():
money.set(money.get() - worker_cost.get())
workers.set(workers.get() + 1)
worker_cost.set(worker_cost.get() * 1.5)
worker_costStr.set(power.humanizeFunc(worker_cost.get()))
if workers.get() == 1:
workers_work()
def workers_work():
money.set(money.get() + money_get.get() * workers.get())
root.createtimerhandler(500, workers_work)
def buy_manager():
if money.get() >= manager_cost.get():
money.set(money.get() - manager_cost.get())
managers.set(managers.get() + 1)
manager_cost.set(manager_cost.get() * 1.5)
manager_costStr.set(power.humanizeFunc(manager_cost.get()))
if managers.get() == 1:
managers_work()
def managers_work():
money.set(money.get() + money_get.get() * managers.get() * 15)
root.createtimerhandler(500, managers_work)
def buy_industrial():
if money.get() >= industrial_cost.get():
money.set(money.get() - industrial_cost.get())
industrials.set(industrials.get() + 1)
industrial_cost.set(industrial_cost.get() * 1.5)
industrial_costStr.set(power.humanizeFunc(industrial_cost.get()))
if industrials.get() == 1:
industrials_work()
def industrials_work():
money.set(money.get() + money_get.get() * industrials.get() * 205)
root.createtimerhandler(500, industrials_work)
def saveEveryThing():
save = {"money" : 0, "workers" : 0, "managers" : 0, "industrials" : 0, "money_get" : 1}
save["money"] = money.get()
save["workers"] = workers.get()
save["managers"] = managers.get()
save["industrials"] = industrials.get()
save["money_get"] = money_get.get()
with open("save.json", 'w') as f:
f.write(json.dumps(save))
root.destroy()
def loadSave():
try:
with open("save.json", "r") as f:
save = json.loads(f.read())
money.set(save["money"])
workers.set(save["workers"])
managers.set(save["managers"])
industrials.set(save["industrials"])
money_get.set(save["money_get"])
if (workers.get() >= 1):
root.createtimerhandler(500, workers_work)
if (managers.get() >= 1):
root.createtimerhandler(500, managers_work)
if (industrials.get() >= 1):
root.createtimerhandler(500, industrials_work)
industrial_cost.set(industrial_cost.get() * (1.5 ** industrials.get()))
manager_cost.set(manager_cost.get() * (1.5 ** managers.get()))
worker_cost.set(worker_cost.get() * (1.5 ** workers.get()))
worker_costStr.set(power.humanizeFunc(worker_cost.get()))
industrial_costStr.set(power.humanizeFunc(industrial_cost.get()))
manager_costStr.set(power.humanizeFunc(manager_cost.get()))
power_upgrade_cost.set(power_upgrade_cost.get() * (1.4 ** (money_get.get() - 1)))
except FileNotFoundError:
print("Save File Not Found")
root = Tk() # Ñîçäàíèå ãëàâíîãî îêíà
root.title("Clicker Game")
root.resizable(False, False)
root.geometry("300x300")
root.iconbitmap(default="icon.ico")
# Variables
industrials = IntVar(value=0)
workers = IntVar(value=0)
managers = IntVar(value=0)
money = IntVar(value=0)
money_get = IntVar(value=1)
moneyStr = StringVar(value="0")
power_upgrade_cost = IntVar(value=10) # Ïåðåìåííàÿ ñ öåííîé óëó÷øåíèÿ
power_upgrade_costX10 = IntVar(value=100) # Ïåðåìåííàÿ ñ öåííîé óëó÷øåíèÿ (10 * 10 Ïî óìîë÷àíèþ) (Ñìûñëà ñòàâèòü power_upgrade_cost.get() íåò)
power_upgrade_costX100 = IntVar(value=1000) # Ïåðåìåííàÿ ñ öåííîé óëó÷øåíèÿ
worker_cost = IntVar(value=100)
worker_costStr = StringVar(value="100")
manager_cost = IntVar(value=10000)
manager_costStr = StringVar(value="10К")
industrial_cost = IntVar(value=1000000)
industrial_costStr = StringVar(value="1M")
power_upgrade_cost_Str = StringVar(value="10")
power_upgrade_costX10_Str = StringVar(value="100")
power_upgrade_costX100_Str = StringVar(value="1К")
upgrades = [moneyGetterUpgrade, moneyGetterUpgradeX10, moneyGetterUpgradeX100] # Ñïèñîê ñ ôóíêöèÿìè
names = ["Upgrade", "UpdX10", "UpdX100"]
costs = [power_upgrade_cost_Str, power_upgrade_costX10_Str, power_upgrade_costX100_Str]
money_shower = ttk.Label(root, textvariable=moneyStr, font=Font(size=20)) # Ìåòêà òåêñòà
money_shower.pack() # Ðàçìåùåíèå íà ïîëå
for i in range(len(upgrades)): # Ðàçìåùåíèå êíîïîê öèêëîì
button = ttk.Button(root, text=f"{names[i]}", command=upgrades[i])
button.pack(anchor=SW, padx=10, pady=5)
upgrade_label = ttk.Label(root, textvariable=costs[i])
upgrade_label.place(x=90, y=40*(i+1))
loadSave()
power_getter_counter = ttk.Label(root, textvariable=money_get)
power_getter_counter.place(relx=.13, rely=.05)
worker_button = ttk.Button(root, text="Buy Worker", command=buy_worker)
worker_button.place(relx=.73, rely=.12)
worker_label_cost = ttk.Label(root, textvariable=worker_costStr)
worker_label_cost.place(relx=.6, rely=.12)
worker_label_count = ttk.Label(root, textvariable=workers)
worker_label_count.place(relx=.8, rely=.06)
manager_button = ttk.Button(root, text="Buy manger", command=buy_manager)
manager_button.place(relx=.73, rely=.26)
manager_label_cost = ttk.Label(root, textvariable=manager_costStr)
manager_label_cost.place(relx=.6, rely=.26)
manager_label_count = ttk.Label(root, textvariable=managers)
manager_label_count.place(relx=.8, rely=.2)
industrial_button = ttk.Button(root, text="Buy Indstrial", command=buy_industrial)
industrial_button.place(relx=.73, rely=.4)
industrial_label_cost = ttk.Label(root, textvariable=industrial_costStr)
industrial_label_cost.place(relx=.6, rely=.4)
industrial_label_count = ttk.Label(root, textvariable=industrials)
industrial_label_count.place(relx=.8, rely=.34)
add_money_button = ttk.Button(root, text="Add Money", command=moneyPlusOne)
add_money_button.place(relx=.3, rely=.7, width=125, height=50)
exit_button = ttk.Button(root, text="Save & Exit", command=saveEveryThing)
exit_button.pack(side=BOTTOM)
update_vars_values()
root.mainloop()