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
| # -*- coding:Latin-1 -*-
#
#
#
from Tkinter import *
from random import randrange
#----définition de la fenêtre : lanceur
class XLanceur(Tk) :
def __init__(self):
Tk.__init__(self)
self.protocol("WM_DELETE_WINDOW", self.Intercepte)
# Variables
self.NConfig=IntVar()
self.NConfig.set(0)
self.image1=PhotoImage(file='Terrain/Ocean.ppm')
self.image2=PhotoImage(file='Terrain/Prairie.ppm')
self.image3=PhotoImage(file='Terrain/Plaine.ppm')
self.image4=PhotoImage(file='Terrain/Toundra.ppm')
self.image5=PhotoImage(file='Terrain/Desert.ppm')
self.image6=PhotoImage(file='Terrain/Glace+C+Diamant.ppm')
self.image7=PhotoImage(file='Terrain/Glace+C+Fer.ppm')
self.image8=PhotoImage(file='Terrain/Glace+C+Or.ppm')
self.image9=PhotoImage(file='Terrain/Glace+C+Pierre.ppm')
self.image10=PhotoImage(file='Terrain/Glace+C.ppm')
self.image11=PhotoImage(file='Terrain/Glace+Fourrure.ppm')
self.image12=PhotoImage(file='Terrain/Glace+Petrole.ppm')
self.image13=PhotoImage(file='Terrain/Glace+Phoque.ppm')
self.image14=PhotoImage(file='Terrain/Glace+Uranium.ppm')
self.image15=PhotoImage(file='Terrain/Glace.ppm')
Image = Canvas(self, width = 500 , height = 300, bg = 'blue')
Image.pack(side = TOP, padx = 5, pady = 5)
#----Bouton Quitter le lanceur----
Quitter_Lanceur = Button (self, text = "Quitter le jeu", width=8, height = 3 , command = self.destroy)
Quitter_Lanceur.pack (side = RIGHT , padx = 5, pady = 5)
#---- Boutton lanceur : Jouer ----
Jouer_lanceur = Button (self, text = "Jouer", width=8, height = 3, command = self.XJouer)
Jouer_lanceur.pack (side = LEFT , padx = 5, pady = 5)
#--- Bouton lanceur : configurer---
Config_lanceur = Button (self, text = "Configurer", width=8, height = 3, command = self.XConfigurer)
Config_lanceur.pack (side = LEFT , padx = 5, pady = 5)
def Intercepte(self, event = None):
for widget in self.winfo_children():
if isinstance(widget,Toplevel): widget.destroy()
self.destroy()
# définition parties enregsitrée
def Ouvrir_Enr(self):
Fen_Ouvrir_Enr=Toplevel()
#--définition nouveau jeu
def NJeu(self):
self.Fen_Menu.destroy()
X=26
Y=26
if self.NConfig.get() ==1:
Xmax=677
Ymax=377
self.XMAP(X,Y,Xmax,Ymax)
elif self.NConfig.get() ==2:
Xmax=927
Ymax=527
self.XMAP(X,Y,Xmax,Ymax)
elif self.NConfig.get() ==3:
Xmax=1027 #-24
Ymax=627 #-74
self.XMAP(X,Y,Xmax,Ymax)
elif self.NConfig.get() ==4:
Xmax=1177 #-24
Ymax=727 #-74
self.XMAP(X,Y,Xmax,Ymax)
elif self.NConfig.get() ==5:
Xmax=1277 #-24
Ymax=827 #-74
self.XMAP(X,Y,Xmax,Ymax)
elif self.NConfig.get() ==6:
Xmax=1577 #-24
Ymax=827 #-74
self.XMAP(X,Y,Xmax,Ymax)
elif self.NConfig.get() ==7:
Xmax=1827 #-24
Ymax=977 #-74
self.XMAP(X,Y,Xmax,Ymax)
else:
self.RLanceur()
#--définition sauvegarder
def NSauvegarde(self):
self.Fen_NSauvegarde=Toplevel()
#---definition des différentes configurations
def XMAP(self, X,Y,Xmax,Ymax):
if X<Xmax:
Z=randrange(1,101)
if Z<41:
self.MAP.create_image(X, Y, image=self.image1)
X=X+50
self.XMAP(X,Y,Xmax,Ymax)
elif Z<61:
self.MAP.create_image(X, Y, image=self.image2)
X=X+50
self.XMAP(X,Y,Xmax,Ymax)
elif Z<76:
self.MAP.create_image(X, Y, image=self.image3)
X=X+50
self.XMAP(X,Y,Xmax,Ymax)
elif Z<86:
self.MAP.create_image(X, Y, image=self.image4)
X=X+50
self.XMAP(X,Y,Xmax,Ymax)
elif Z<96:
self.MAP.create_image(X, Y, image=self.image5)
X=X+50
self.XMAP(X, Y, Xmax, Ymax)
else:
Z=randrange(1,5)
if Z>3:
Z=randrange(1,11)
if Z>8:
Z=randrange(1,5)
if Z==1:
self.MAP.create_image(X, Y, image=self.image6)
X=X+50
self.XMAP(X, Y, Xmax, Ymax)
elif Z==2:
self.MAP.create_image(X, Y, image=self.image7)
X=X+50
self.XMAP(X, Y, Xmax, Ymax)
elif Z==3:
self.MAP.create_image(X, Y, image=self.image8)
X=X+50
self.XMAP(X, Y, Xmax, Ymax)
else:
self.MAP.create_image(X, Y, image=self.image9)
X=X+50
self.XMAP(X, Y, Xmax, Ymax)
else:
self.MAP.create_image(X, Y, image=self.image10)
X=X+50
self.XMAP(X, Y, Xmax, Ymax)
else:
Z=randrange(1,11)
if Z>8:
Z=randrange(1,5)
if Z==1:
self.MAP.create_image(X, Y, image=self.image11)
X=X+50
self.XMAP(X, Y, Xmax, Ymax)
elif Z==2:
self.MAP.create_image(X, Y, image=self.image12)
X=X+50
self.XMAP(X, Y, Xmax, Ymax)
elif Z==3:
self.MAP.create_image(X, Y, image=self.image13)
X=X+50
self.XMAP(X, Y, Xmax, Ymax)
else:
self.MAP.create_image(X, Y, image=self.image14)
X=X+50
self.XMAP(X, Y, Xmax, Ymax)
else:
self.MAP.create_image(X, Y, image=self.image15)
X=X+50
self.XMAP(X, Y, Xmax, Ymax)
elif Y<Ymax:
X=26
Y=Y+50
print "Y"
print Y
self.XMAP(X, Y, Xmax, Ymax)
# Utile menuh ? C'est toujours 35... A toi de voir
def XConfig(self, globx, globy, menuh, gameh, txth, canmapw, canwapw, canh):
print "Jouer", globx, "*", globy
self.withdraw()
self.Fen_Jouer = Toplevel()
self.Fen_Jouer.protocol("WM_DELETE_WINDOW", self.Intercepte)
self.Fen_Jouer.geometry("%dx%d" % (globx, globy))
Fram_Menu = Frame(self.Fen_Jouer, width=globx, height=menuh, bg="#FFFFC0")
Fram_Game=Frame(self.Fen_Jouer, width=globx, height=gameh)
Fram_Txt=Frame(self.Fen_Jouer, width=globx, height=txth, bg="#C0FFC0")
self.MAP = Canvas(Fram_Game, width=canmapw , height=canh, bg ="#FF00FF")
self.WAP=Canvas(Fram_Game, width=canwapw , height=canh, bg = "#FFDCA8")
Fram_Menu.pack_propagate(False)
Fram_Menu.pack()
Fram_Game.pack()
Fram_Txt.pack()
self.MAP.pack(side = LEFT)
self.WAP.pack(side = RIGHT)
BMenu = Button(Fram_Menu, text="MENU", width=6, height=2 , command=self.XMenu)
BMenu.pack(side=RIGHT , padx=5, pady=5)
#--Définition fenètre jouer"
def XJouer(self):
print "Jouer"
print "Configuration :", self.NConfig.get()
if self.NConfig.get() == 1:
self.XConfig(800, 525, 35, 452, 38, 701, 98, 451)
elif self.NConfig.get() == 2:
self.XConfig(1024, 768, 35, 602, 56, 951, 72, 601)
elif self.NConfig.get() == 3:
self.XConfig(1152, 789, 35, 502, 52, 1051, 101, 701)
elif self.NConfig.get() == 4:
self.XConfig(1280, 885, 35, 802, 48, 1201, 79, 801)
elif self.NConfig.get() == 5:
self.XConfig(1400, 975, 35, 902, 38, 1301, 99, 901)
elif self.NConfig.get() == 6:
self.XConfig(1680, 975, 35, 902, 38, 1601, 79, 901)
elif self.NConfig.get() == 7:
self.XConfig(1920, 1125, 35, 1052, 38, 1851, 51, 1051)
else :
print "configuration non définie"
self.W_Config=Toplevel()
self.W_Config.protocol("WM_DELETE_WINDOW", self.RLanceur)
Text_WConfig = Label(self.W_Config, text='VOUS DEVEZ DEFINIR VOTRE CONFIGURATION !', fg='red')
Text_WConfig.pack()
Quitter_W_Config= Button (self.W_Config, text = "OK", width=24, height = 3 , command = self.RLanceur)
Quitter_W_Config.pack (padx = 5, pady = 5)
#---Définition MENU----
def XMenu(self):
self.Fen_Menu = Toplevel()
Nouvelle = Button (self.Fen_Menu, text = "NOUVELLE PARTIE", width=24, height = 3 , command = self.NJeu)
Nouvelle.pack (side = TOP , padx = 5, pady = 5)
Enregistr = Button (self.Fen_Menu, text = "PARTIE ENREGISTREE", width=24, height = 3 , command = self.Ouvrir_Enr)
Enregistr.pack (side = TOP , padx = 5, pady = 5)
Sauvegarde = Button (self.Fen_Menu, text = "SAUVEGARDER", width=24, height = 3 , command = self.NSauvegarde)
Sauvegarde.pack (side = TOP , padx = 5, pady = 5)
Retour_Lanceur = Button (self.Fen_Menu, text = "RETOUR AU LANCEUR", width=24, height = 3 , command = self.RLanceur)
Retour_Lanceur.pack (side = TOP , padx = 5, pady = 5)
Quitter_jeu = Button (self.Fen_Menu, text = "QUITTER LE JEU", width=24, height = 3 , command = self.QJeu)
Quitter_jeu.pack (side = TOP , padx = 5, pady = 5)
#---nettoyage--
def supprwi(self):
for widget in self.winfo_children():
if isinstance(widget,Toplevel): widget.destroy()
#--Quitter le jeu--
def QJeu(self):
self.supprwi()
print "Vous avez Bien quitter le jeu"
self.destroy()
#--Définition retour lanceur--
def RLanceur(self):
self.supprwi()
self.deiconify()
#---Définition fenêtre : configurer
def XConfigurer(self):
self.Fen_Config = Toplevel()
modesgraph = [("FENETRE 800*600", 1), ("FENETRE 1024*768", 2), ("FENETRE 1152*864", 3), ("FENETRE 1280*960", 4), ("FENETRE 1400*1050", 5), ("FENETRE 1680*1050", 6), ("FENETRE 1920*1200", 7),]
for text, mode in modesgraph:
Config = Radiobutton(self.Fen_Config, text=text, variable=self.NConfig, value=mode)
Config.grid()
BQuit = Button(self.Fen_Config, text="Quitter", command=self.Fen_Config.destroy)
BQuit.grid()
# début du programme
if __name__ == "__main__":
app=XLanceur()
app.mainloop() |