This repository has been archived by the owner on May 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.py
416 lines (361 loc) · 13.3 KB
/
game.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
from tkinter import *
from tkinter.ttk import *
from tkinter.messagebox import *
import _thread
import time
import zlib
run = True
img_dir = "img/"
img_ext = ".png"
title = "Le Camerounais Billionaire"
n_x = 1
fen_size = (320, 640)
fen_size_tiny = (int(320 * 2 / 3), int(800 * 2 / 3))
high_score = {
100: "Le President BOBO",
57: "Pythonbrad",
40: "Le bobo",
50: "Grand pere",
20: "Ton keke",
10: "Ton voisin",
60: "Le chef de village",
}
player = {
"money": 500,
"build": 125,
"upgrade": 10,
"building": 0,
"begin": True,
"tuto": 0,
}
# item, number, price, product, level
items = {
"orange": [0, 5, 0.5, 1],
"call_box": [0, 25, 1.25, 1],
"boutique": [0, 100, 10, 1],
"boulangerie": [0, 500, 50, 1],
"resto": [0, 1000, 160, 1],
"hospital": [0, 10000, 500, 1],
}
items_img = {
"orange": img_dir + "orange" + img_ext,
"call_box": img_dir + "call_box" + img_ext,
"boutique": img_dir + "boutique" + img_ext,
"boulangerie": img_dir + "boulangerie" + img_ext,
"resto": img_dir + "resto" + img_ext,
"hospital": img_dir + "hospital" + img_ext,
}
def aide():
showinfo(
title="Besoin d aide?",
message="Vous etes sans emploie, vous venez de recevoir de l argent.\n"
"Le but du jeu consiste a investir enfin de devenir le plus riche\n"
"Au debut vous devez payer un stand de vente d orange\n"
"C est obliger plus que les autres seront au dessus de vos moyens\n"
"Apres avoir payer le stand d orange, vous pouvez l ameliorer en fin de gagner plus\n"
"Econnomisez enfin de pouvoir investir sur de nouveaux infractructures\n"
"Le boutton x1 que vous verrez au debut, vous permet de dubliquer vos actions\n"
"Cet a dire x1 est equivaut a un clic, x2 2 clic etc...\n"
"C est utile pour ameliorer ou payer x fois un batiment\n"
"Le prix des batiments et le cout des ameliorations depand des chois que vous ferez\n"
"Tu peux comparer ton rang avec les meilleurs scores des autres\n"
"Vous gagnerez de l argent meme si le jeux est fermee"
"Un petit conseil, eviter de trop ameliorer\n"
"Bonne chance! XD",
)
def screen(size):
if size == "tiny":
fen.geometry("%sx%s" % (int(fen_size_tiny[0]), int(fen_size_tiny[1])))
label0.config(image=img_orange2)
label1.config(image=img_call_box2)
label2.config(image=img_boutique2)
label3.config(image=img_boulangerie2)
label4.config(image=img_resto2)
label5.config(image=img_hospital2)
else:
fen.geometry("%sx%s" % fen_size)
label0.config(image=img_orange)
label1.config(image=img_call_box)
label2.config(image=img_boutique)
label3.config(image=img_boulangerie)
label4.config(image=img_resto)
label5.config(image=img_hospital)
def load(ask=False):
if ask:
resp = askquestion(
title="Etes vous sur?", message="Votre parti en cour sera perdu"
)
else:
resp = "yes"
if resp == "yes":
open("save.data", "ab").write(b"")
data = open("save.data", "rb").read()
try:
data = zlib.decompress(data)
exec("global player, items\n" + data.decode())
if "lastconnect" in player:
print("rest")
nb = int(time.time() - player["lastconnect"])
for i in range(nb):
add_money()
if ask:
showinfo(title=title, message="Parti charger")
except Exception as error:
print(error)
if ask:
showinfo(title=title, message="Impossible de charger la parti")
else:
pass
def save(ask=False):
player["lastconnect"] = time.time()
if ask:
resp = askquestion(
title="Voulez vous sauvegarder",
message="Vous etes sur le point de sauvegarder votre partir",
)
else:
resp = "yes"
if resp == "yes":
data = "player = %s;items = %s" % (player, items)
open("save.data", "wb").write(zlib.compress(data.encode()))
if ask:
showinfo(title=title, message="Parti sauvegarder")
else:
pass
def print_money(x):
print("print_money")
x = str(int(x))
x = x[::-1]
r = ""
it = 0
for i in range(len(x)):
if i % 3 == 0:
r = r + "."
r = r + x[i]
return r[1::][::-1]
def multi():
if not player["begin"]:
global n_x
if n_x >= 20:
n_x = 1
else:
n_x = n_x + 1
button.config(text="x%s" % n_x)
else:
showinfo(
title="Info",
message="Cet option est disponible apres avoir fini le dictentiel",
)
def player_rang():
score = {}
for i in high_score:
score[i] = high_score[i]
score[get_player_level()] = "Moi"
text = ""
while len(score) != 0:
i = max(score)
text = text + "[%s] level(%s)\n" % (score[i], i)
score.pop(i)
showinfo(title="Mon rang", message=text)
def get_player_level():
return int(player["build"] * player["upgrade"] * player["building"] / 1000)
def player_level():
showinfo(
title="Mon status social",
message="Vous etes au niveaux %s" % get_player_level(),
)
def get_items(name):
if items[name][0]:
return "%s x %s F/s Level %s" % (
items[name][0],
print_money(items[name][1]),
items[name][3],
)
else:
return "Non disponible"
def add_money():
for item in items:
if items[item][0]:
player["money"] += items[item][1] * items[item][0]
else:
pass
def add_item(name):
global n_x
price = (items[name][0] + 1) * items[name][1] * items[name][2] * player["build"] / 2
price = price * n_x
resp = askquestion(
title=title,
message="Requis %s F \nCliquer sur OK pour valider" % print_money(price),
)
if resp == "yes" and player["money"] >= price:
player["money"] -= price
items[name][0] += 1 * n_x
player["building"] += 1 * n_x
elif resp == "no":
pass
else:
showwarning("Argent insuffisant", "Requis %s F" % print_money(price))
def upgrade(name):
global n_x
price = (items[name][0] + 1) * items[name][1] * items[name][2] * items[name][3]
price = price * n_x
if items[name][0]:
resp = askquestion(
title=title,
message="Requis %s F \nCliquer sur OK pour valider" % print_money(price),
)
if resp == "yes" and player["money"] >= price:
player["money"] -= price
items[name][1] += (
int(items[name][2] * player["upgrade"] * (items[name][3] + 1) * 0.1)
* n_x
)
items[name][3] += 1 * n_x
elif resp == "no":
pass
else:
showwarning("Argent insuffisant", "Requis %s F" % print_money(price))
else:
showwarning("Manquant", "Requis %s" % name)
def main():
global run
load()
while run:
time.sleep(1.5)
try:
if player["begin"] and player["building"] == player["tuto"] == 0:
showinfo(
title="Dictentiel",
message="Bonjour mon enfant\n"
"J ai un orangier chez moi qui me sert a rien je pense que sa peut t aider\n"
"Prend aussi c est %s F pour etablir ton commerce\n"
"HELP\n"
"Pour pouvoir ajouter un stand\n"
"Va dans le menu ajouter" % player["money"],
)
player["tuto"] += 1
if (
player["begin"]
and player["building"] == player["tuto"] == 1
and player["money"] > 400
or player["building"] == player["tuto"] + 1 == 2
):
showinfo(
title="Dictentiel",
message="Je vois que mon vieux orangier ta servi\n"
"Je connais un ami qui vend des telephones commercials\n"
"Mais il faudra gagnez de l argent pour payer un telephone\n"
"HELP\n"
"Pour la suite de l aide cliquer sur le menu aide",
)
player["tuto"] += 1
if (
player["begin"]
and player["building"] == player["tuto"] == 2
and player["money"] > 500
):
showinfo(
title="Dictentiel",
message="Mon petit, je vois que tu peux deja continuer sans moi\n"
"Un jour tu deviendra riche, ca je le suis sur\n"
"Bon je te laisse\n",
)
player["tuto"] += 1
if player["begin"] and player["tuto"] == 3:
showinfo(
title="Dictentiel",
message="HELP\n"
"Vous venez de terminez le dictentiel\n"
"N oubliez pas que le menu aide est disponible en cas de probleme",
)
player["begin"] = False
add_money()
save()
label.config(text="Money: %s F" % print_money(player["money"]))
label0.config(text="%s" % get_items("orange"))
label1.config(text="%s" % get_items("call_box"))
label2.config(text="%s" % get_items("boutique"))
label3.config(text="%s" % get_items("boulangerie"))
label4.config(text="%s" % get_items("resto"))
label5.config(text="%s" % get_items("hospital"))
except:
pass
fen = Tk()
fen.title(title)
fen.geometry("%sx%s" % fen_size)
img_orange = PhotoImage(file=items_img["orange"])
img_call_box = PhotoImage(file=items_img["call_box"])
img_boutique = PhotoImage(file=items_img["boutique"])
img_boulangerie = PhotoImage(file=items_img["boulangerie"])
img_resto = PhotoImage(file=items_img["resto"])
img_hospital = PhotoImage(file=items_img["hospital"])
img_orange2 = img_orange.subsample(2, 2)
img_call_box2 = img_call_box.subsample(2, 2)
img_boutique2 = img_boutique.subsample(2, 2)
img_boulangerie2 = img_boulangerie.subsample(2, 2)
img_resto2 = img_resto.subsample(2, 2)
img_hospital2 = img_hospital.subsample(2, 2)
menubar = Menu(fen)
menu_add = Menu(menubar, tearoff=1)
menu_add.add_command(label="Orange", command=lambda: add_item("orange"))
menu_add.add_command(label="Call_box", command=lambda: add_item("call_box"))
menu_add.add_command(label="Boutique", command=lambda: add_item("boutique"))
menu_add.add_command(label="Boulangerie", command=lambda: add_item("boulangerie"))
menu_add.add_command(label="Restorant", command=lambda: add_item("resto"))
menu_add.add_command(label="Hospital", command=lambda: add_item("hospital"))
menubar.add_cascade(label="Ajouter", menu=menu_add)
menu_upgrade = Menu(menubar, tearoff=1)
menu_upgrade.add_command(label="Orange", command=lambda: upgrade("orange"))
menu_upgrade.add_command(label="Call_box", command=lambda: upgrade("call_box"))
menu_upgrade.add_command(label="Boutique", command=lambda: upgrade("boutique"))
menu_upgrade.add_command(label="Boulangerie", command=lambda: upgrade("boulangerie"))
menu_upgrade.add_command(label="Restorant", command=lambda: upgrade("resto"))
menu_upgrade.add_command(label="Hospital", command=lambda: upgrade("hospital"))
menubar.add_cascade(label="Ameliorer", menu=menu_upgrade)
menu_player = Menu(menubar, tearoff=1)
menu_player.add_command(label="Mon Niveau social", command=player_level)
menu_player.add_command(label="Mon Rang", command=player_rang)
menubar.add_cascade(label="Player", menu=menu_player)
menu_screen = Menu(menubar, tearoff=1)
menu_screen.add_command(label="Normal", command=lambda: screen("normal"))
menu_screen.add_command(label="Petit", command=lambda: screen("tiny"))
menubar.add_cascade(label="Screen", menu=menu_screen)
menubar.add_command(label="Aide", command=aide)
fen.config(menu=menubar)
button = Button(text="x%s" % n_x, width=5, command=multi)
button.place(x=0, y=0)
label = Label(fen, text="Money: %s F" % player["money"], font=(9))
label.pack()
label0 = Label(
fen, image=img_orange, text="%s" % get_items("orange"), compound=TOP, font=(9)
)
label0.pack()
label1 = Label(
fen, image=img_call_box, text="%s" % get_items("call_box"), compound=TOP, font=(9)
)
label1.pack()
label2 = Label(
fen, image=img_boutique, text="%s" % get_items("boutique"), compound=TOP, font=(9)
)
label2.pack()
label3 = Label(
fen,
image=img_boulangerie,
text="%s" % get_items("boulangerie"),
compound=TOP,
font=(9),
)
label3.pack()
label4 = Label(
fen, image=img_resto, text="%s" % get_items("resto"), compound=TOP, font=(9)
)
label4.pack()
label5 = Label(
fen, image=img_hospital, text="%s" % get_items("hospital"), compound=TOP, font=(9)
)
label5.pack()
_thread.start_new_thread(main, (()))
fen.resizable(width=False, height=False)
fen.mainloop()
run = False
time.sleep(3)