Schiffeversenken.py 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  1. #/!usr/bin/python
  2. #ChunyuYulong 4068559
  3. #JeremyGabrysch 4068244
  4. #SimonPense 4068350
  5. #-MT2018
  6. #Dieses Programm stellt das Spiel "Schiffeversenken" dar.
  7. #Moeglichkeiten im Singleplayer oder im Multiplayer zu spielen.
  8. import Tkinter as tk
  9. import sys,time,random #Module einsetzen
  10. from tkMessageBox import *
  11. Buttons1 = [] #globale Variablen definieren
  12. ButtonS1 = []
  13. Buttons2 = [] #Knoepfe fuer Gitter und fuer Funktionsschalter
  14. ButtonS2 = []
  15. ButtonP1 ={'1':0,'2':0,'3':0,'4':0,'5':0,'6':0,'7':0, #Daten der Felder werden gespeichert
  16. '8':0,'9':0,'10':0,'11':0,'12':0,'13':0,'14':0,
  17. '15':0,'16':0,'17':0,'18':0,'19':0,'20':0,'21':0,
  18. '22':0,'23':0,'24':0,'25':0,'26':0,'27':0,'28':0,
  19. '29':0,'30':0,'31':0,'32':0,'33':0,'34':0,'35':0,
  20. '36':0,'37':0,'38':0,'39':0,'40':0,'41':0,'42':0,
  21. '43':0,'44':0,'45':0,'46':0,'47':0,'48':0,'49':0}
  22. ButtonP2 ={'1':0,'2':0,'3':0,'4':0,'5':0,'6':0,'7':0,
  23. '8':0,'9':0,'10':0,'11':0,'12':0,'13':0,'14':0,
  24. '15':0,'16':0,'17':0,'18':0,'19':0,'20':0,'21':0,
  25. '22':0,'23':0,'24':0,'25':0,'26':0,'27':0,'28':0,
  26. '29':0,'30':0,'31':0,'32':0,'33':0,'34':0,'35':0,
  27. '36':0,'37':0,'38':0,'39':0,'40':0,'41':0,'42':0,
  28. '43':0,'44':0,'45':0,'46':0,'47':0,'48':0,'49':0}
  29. ai = 0 #Auswaehlen Singelplayer
  30. Scf = 0 #Auswahl fuer Schiffsmarkierung
  31. PW = 2 #Player Auswahl
  32. Rot = 0 #Rotationsbutton
  33. Wel = 0 #Spiel beginnen
  34. z= [] #Speichern der AI Aufstellung
  35. SumS=[] #gesetzte Schiffe
  36. def p1(): #P1 start
  37. cv1 = tk.Canvas(root1,width = 1200,height = 600).pack() #Formatierung des Fensters
  38. zlh = 200
  39. for wl in range(7): #Spielfeld Massstab
  40. Zahlen = tk.Label(root1,text = str(wl+1),font = '30').place(x = zlh ,y = 50, width = 50, height = 50)
  41. zlh = zlh +50 #y-Achse mit Zahlen
  42. zlv = 100
  43. z = 'A','B','C','D','E','F','G' #x-Achse
  44. for wh in range(7):
  45. zahlen = tk.Label(root1,text = z[wh],font = '30' ).place(x = 150,y = zlv,width = 50, height = 50)
  46. zlv = zlv + 50
  47. #zeile 1 #komplettes Spielfeld von P1
  48. Button1 = tk.Button(root1,bg = 'lightblue',command = lambda:color(0,Buttons1,ButtonP1)) #Formatierung der einzelnen Knoepfe
  49. Buttons1.append(Button1)
  50. Buttons1[0].place(x = 200 ,y = 100, width = 50, height = 50)
  51. Button2 = tk.Button(root1,bg = 'lightblue',command = lambda:color(1,Buttons1,ButtonP1))
  52. Buttons1.append(Button2)
  53. Buttons1[1].place(x = 250 ,y = 100, width = 50, height = 50)
  54. Button3 = tk.Button(root1,bg = 'lightblue',command = lambda:color(2,Buttons1,ButtonP1))
  55. Buttons1.append(Button3)
  56. Buttons1[2].place(x = 300 ,y = 100, width = 50, height = 50)
  57. Button4 = tk.Button(root1,bg = 'lightblue',command = lambda:color(3,Buttons1,ButtonP1))
  58. Buttons1.append(Button4)
  59. Buttons1[3].place(x = 350 ,y = 100, width = 50, height = 50)
  60. Button5 = tk.Button(root1,bg = 'lightblue',command = lambda:color(4,Buttons1,ButtonP1))
  61. Buttons1.append(Button5)
  62. Buttons1[4].place(x = 400 ,y = 100, width = 50, height = 50)
  63. Button6 = tk.Button(root1,bg = 'lightblue',command = lambda:color(5,Buttons1,ButtonP1))
  64. Buttons1.append(Button6)
  65. Buttons1[5].place(x = 450 ,y = 100, width = 50, height = 50)
  66. Button7 = tk.Button(root1,bg = 'lightblue',command = lambda:color(6,Buttons1,ButtonP1))
  67. Buttons1.append(Button7)
  68. Buttons1[6].place(x = 500 ,y = 100, width = 50, height = 50)
  69. #zeile 2
  70. Button8 = tk.Button(root1,bg = 'lightblue',command = lambda:color(7,Buttons1,ButtonP1))
  71. Buttons1.append(Button8)
  72. Buttons1[7].place(x = 200 ,y = 150, width = 50, height = 50)
  73. Button9 = tk.Button(root1,bg = 'lightblue',command = lambda:color(8,Buttons1,ButtonP1))
  74. Buttons1.append(Button9)
  75. Buttons1[8].place(x = 250 ,y = 150, width = 50, height = 50)
  76. Button10 = tk.Button(root1,bg = 'lightblue',command = lambda:color(9,Buttons1,ButtonP1))
  77. Buttons1.append(Button10)
  78. Buttons1[9].place(x = 300 ,y = 150, width = 50, height = 50)
  79. Button11 = tk.Button(root1,bg = 'lightblue',command = lambda:color(10,Buttons1,ButtonP1))
  80. Buttons1.append(Button11)
  81. Buttons1[10].place(x = 350 ,y = 150, width = 50, height = 50)
  82. Button12 = tk.Button(root1,bg = 'lightblue',command = lambda:color(11,Buttons1,ButtonP1))
  83. Buttons1.append(Button12)
  84. Buttons1[11].place(x = 400 ,y = 150, width = 50, height = 50)
  85. Button13 = tk.Button(root1,bg = 'lightblue',command = lambda:color(12,Buttons1,ButtonP1))
  86. Buttons1.append(Button13)
  87. Buttons1[12].place(x = 450 ,y = 150, width = 50, height = 50)
  88. Button14 = tk.Button(root1,bg = 'lightblue',command = lambda:color(13,Buttons1,ButtonP1))
  89. Buttons1.append(Button14)
  90. Buttons1[13].place(x = 500 ,y = 150, width = 50, height = 50)
  91. #zeile 3
  92. Button15 = tk.Button(root1,bg = 'lightblue',command = lambda:color(14,Buttons1,ButtonP1))
  93. Buttons1.append(Button15)
  94. Buttons1[14].place(x = 200 ,y = 200, width = 50, height = 50)
  95. Button16 = tk.Button(root1,bg = 'lightblue',command = lambda:color(15,Buttons1,ButtonP1))
  96. Buttons1.append(Button16)
  97. Buttons1[15].place(x = 250 ,y = 200, width = 50, height = 50)
  98. Button17 = tk.Button(root1,bg = 'lightblue',command = lambda:color(16,Buttons1,ButtonP1))
  99. Buttons1.append(Button17)
  100. Buttons1[16].place(x = 300 ,y = 200, width = 50, height = 50)
  101. Button18 = tk.Button(root1,bg = 'lightblue',command = lambda:color(17,Buttons1,ButtonP1))
  102. Buttons1.append(Button18)
  103. Buttons1[17].place(x = 350 ,y = 200, width = 50, height = 50)
  104. Button19 = tk.Button(root1,bg = 'lightblue',command = lambda:color(18,Buttons1,ButtonP1))
  105. Buttons1.append(Button19)
  106. Buttons1[18].place(x = 400 ,y = 200, width = 50, height = 50)
  107. Button20 = tk.Button(root1,bg = 'lightblue',command = lambda:color(19,Buttons1,ButtonP1))
  108. Buttons1.append(Button20)
  109. Buttons1[19].place(x = 450 ,y = 200, width = 50, height = 50)
  110. Button21 = tk.Button(root1,bg = 'lightblue',command = lambda:color(20,Buttons1,ButtonP1))
  111. Buttons1.append(Button21)
  112. Buttons1[20].place(x = 500 ,y = 200, width = 50, height = 50)
  113. #zeile 4
  114. Button22 = tk.Button(root1,bg = 'lightblue',command = lambda:color(21,Buttons1,ButtonP1))
  115. Buttons1.append(Button22)
  116. Buttons1[21].place(x = 200 ,y = 250, width = 50, height = 50)
  117. Button23 = tk.Button(root1,bg = 'lightblue',command = lambda:color(22,Buttons1,ButtonP1))
  118. Buttons1.append(Button23)
  119. Buttons1[22].place(x = 250 ,y = 250, width = 50, height = 50)
  120. Button24 = tk.Button(root1,bg = 'lightblue',command = lambda:color(23,Buttons1,ButtonP1))
  121. Buttons1.append(Button24)
  122. Buttons1[23].place(x = 300 ,y = 250, width = 50, height = 50)
  123. Button25 = tk.Button(root1,bg = 'lightblue',command = lambda:color(24,Buttons1,ButtonP1))
  124. Buttons1.append(Button25)
  125. Buttons1[24].place(x = 350 ,y = 250, width = 50, height = 50)
  126. Button26 = tk.Button(root1,bg = 'lightblue',command = lambda:color(25,Buttons1,ButtonP1))
  127. Buttons1.append(Button26)
  128. Buttons1[25].place(x = 400 ,y = 250, width = 50, height = 50)
  129. Button27 = tk.Button(root1,bg = 'lightblue',command = lambda:color(26,Buttons1,ButtonP1))
  130. Buttons1.append(Button27)
  131. Buttons1[26].place(x = 450 ,y = 250, width = 50, height = 50)
  132. Button28 = tk.Button(root1,bg = 'lightblue',command = lambda:color(27,Buttons1,ButtonP1))
  133. Buttons1.append(Button28)
  134. Buttons1[27].place(x = 500 ,y = 250, width = 50, height = 50)
  135. #zeile 5
  136. Button29 = tk.Button(root1,bg = 'lightblue',command = lambda:color(28,Buttons1,ButtonP1))
  137. Buttons1.append(Button29)
  138. Buttons1[28].place(x = 200 ,y = 300, width = 50, height = 50)
  139. Button30 = tk.Button(root1,bg = 'lightblue',command = lambda:color(29,Buttons1,ButtonP1))
  140. Buttons1.append(Button30)
  141. Buttons1[29].place(x = 250 ,y = 300, width = 50, height = 50)
  142. Button31 = tk.Button(root1,bg = 'lightblue',command = lambda:color(30,Buttons1,ButtonP1))
  143. Buttons1.append(Button31)
  144. Buttons1[30].place(x = 300 ,y = 300, width = 50, height = 50)
  145. Button32 = tk.Button(root1,bg = 'lightblue',command = lambda:color(31,Buttons1,ButtonP1))
  146. Buttons1.append(Button32)
  147. Buttons1[31].place(x = 350 ,y = 300, width = 50, height = 50)
  148. Button33 = tk.Button(root1,bg = 'lightblue',command = lambda:color(32,Buttons1,ButtonP1))
  149. Buttons1.append(Button33)
  150. Buttons1[32].place(x = 400 ,y = 300, width = 50, height = 50)
  151. Button34 = tk.Button(root1,bg = 'lightblue',command = lambda:color(33,Buttons1,ButtonP1))
  152. Buttons1.append(Button34)
  153. Buttons1[33].place(x = 450 ,y = 300, width = 50, height = 50)
  154. Button35 = tk.Button(root1,bg = 'lightblue',command = lambda:color(34,Buttons1,ButtonP1))
  155. Buttons1.append(Button35)
  156. Buttons1[34].place(x = 500 ,y = 300, width = 50, height = 50)
  157. #zeile 6
  158. Button36 = tk.Button(root1,bg = 'lightblue',command = lambda:color(35,Buttons1,ButtonP1))
  159. Buttons1.append(Button36)
  160. Buttons1[35].place(x = 200 ,y = 350, width = 50, height = 50)
  161. Button37 = tk.Button(root1,bg = 'lightblue',command = lambda:color(36,Buttons1,ButtonP1))
  162. Buttons1.append(Button37)
  163. Buttons1[36].place(x = 250 ,y = 350, width = 50, height = 50)
  164. Button38 = tk.Button(root1,bg = 'lightblue',command = lambda:color(37,Buttons1,ButtonP1))
  165. Buttons1.append(Button38)
  166. Buttons1[37].place(x = 300 ,y = 350, width = 50, height = 50)
  167. Button39 = tk.Button(root1,bg = 'lightblue',command = lambda:color(38,Buttons1,ButtonP1))
  168. Buttons1.append(Button39)
  169. Buttons1[38].place(x = 350 ,y = 350, width = 50, height = 50)
  170. Button40 = tk.Button(root1,bg = 'lightblue',command = lambda:color(39,Buttons1,ButtonP1))
  171. Buttons1.append(Button40)
  172. Buttons1[39].place(x = 400 ,y = 350, width = 50, height = 50)
  173. Button41 = tk.Button(root1,bg = 'lightblue',command = lambda:color(40,Buttons1,ButtonP1))
  174. Buttons1.append(Button41)
  175. Buttons1[40].place(x = 450 ,y = 350, width = 50, height = 50)
  176. Button42 = tk.Button(root1,bg = 'lightblue',command = lambda:color(41,Buttons1,ButtonP1))
  177. Buttons1.append(Button42)
  178. Buttons1[41].place(x = 500 ,y = 350, width = 50, height = 50)
  179. #zeile 7
  180. Button43 = tk.Button(root1,bg = 'lightblue',command = lambda:color(42,Buttons1,ButtonP1))
  181. Buttons1.append(Button43)
  182. Buttons1[42].place(x = 200 ,y = 400, width = 50, height = 50)
  183. Button44 = tk.Button(root1,bg = 'lightblue',command = lambda:color(43,Buttons1,ButtonP1))
  184. Buttons1.append(Button44)
  185. Buttons1[43].place(x = 250 ,y = 400, width = 50, height = 50)
  186. Button45 = tk.Button(root1,bg = 'lightblue',command = lambda:color(44,Buttons1,ButtonP1))
  187. Buttons1.append(Button45)
  188. Buttons1[44].place(x = 300 ,y = 400, width = 50, height = 50)
  189. Button46 = tk.Button(root1,bg = 'lightblue',command = lambda:color(45,Buttons1,ButtonP1))
  190. Buttons1.append(Button46)
  191. Buttons1[45].place(x = 350 ,y = 400, width = 50, height = 50)
  192. Button47 = tk.Button(root1,bg = 'lightblue',command = lambda:color(46,Buttons1,ButtonP1))
  193. Buttons1.append(Button47)
  194. Buttons1[46].place(x = 400 ,y = 400, width = 50, height = 50)
  195. Button48 = tk.Button(root1,bg = 'lightblue',command = lambda:color(47,Buttons1,ButtonP1))
  196. Buttons1.append(Button48)
  197. Buttons1[47].place(x = 450 ,y = 400, width = 50, height = 50)
  198. Button49 = tk.Button(root1,bg = 'lightblue',command = lambda:color(48,Buttons1,ButtonP1))
  199. Buttons1.append(Button49)
  200. Buttons1[48].place(x = 500 ,y = 400, width = 50, height = 50)
  201. #Funktion der Knoepfe
  202. ButtonSS = tk.Button(root1,text = 'Boot (1)',bg = 'yellow',command = lambda:schiffwehlen(1))
  203. ButtonS1.append(ButtonSS)
  204. ButtonS1[0].place(x = 50 ,y = 200, width = 100, height = 50)
  205. ButtonSM1 = tk.Button(root1,text = 'U-Boot (2)',bg = 'yellow',command = lambda:schiffwehlen(2))
  206. ButtonS1.append(ButtonSM1)
  207. ButtonS1[1].place(x = 50 ,y = 300, width = 100, height = 50)
  208. ButtonSM2 = tk.Button(root1,text = 'U-Boot (2)',bg = 'yellow',command = lambda:schiffwehlen(3))
  209. ButtonS1.append(ButtonSM2)
  210. ButtonS1[2].place(x = 50 ,y = 400, width = 100, height = 50)
  211. ButtonSL = tk.Button(root1,text = 'Kreuzer (5)',bg = 'yellow',command = lambda:schiffwehlen(4))
  212. ButtonS1.append(ButtonSL)
  213. ButtonS1[3].place(x = 50 ,y = 500, width = 250, height = 50)
  214. ButtonR = tk.Button(root1,text = 'Rotieren!',bg = 'green',command = Rot)
  215. ButtonS1.append(ButtonR)
  216. ButtonS1[4].place(x = 50 ,y = 100, width = 100, height = 50)
  217. ButtonEX = tk.Button(root1,text = 'Beenden',bg = 'red',command = lambda:ex(root1))
  218. ButtonS1.append(ButtonEX)
  219. ButtonS1[5].place(x = 10 ,y = 20, width = 100, height = 50)
  220. root1.mainloop()
  221. def p2(): #siehe P1
  222. del SumS[:] #Speicher wird geleert
  223. zlh = 800
  224. for wl in range(7):
  225. Zahlen = tk.Label(root1,text = str(wl+1),font = '30').place(x = zlh ,y = 50, width = 50, height = 50)
  226. zlh = zlh +50
  227. zlv = 100
  228. z = 'A','B','C','D','E','F','G'
  229. for wh in range(7):
  230. zahlen = tk.Label(root1,text = z[wh],font = '30' ).place(x = 750,y = zlv,width = 50, height = 50)
  231. zlv = zlv + 50
  232. #zeile 1
  233. Button1 = tk.Button(root1,bg = 'lightblue',command = lambda:color(0,Buttons2,ButtonP2))
  234. Buttons2.append(Button1)
  235. Buttons2[0].place(x = 800 ,y = 100, width = 50, height = 50)
  236. Button2 = tk.Button(root1,bg = 'lightblue',command = lambda:color(1,Buttons2,ButtonP2))
  237. Buttons2.append(Button2)
  238. Buttons2[1].place(x = 850 ,y = 100, width = 50, height = 50)
  239. Button3 = tk.Button(root1,bg = 'lightblue',command = lambda:color(2,Buttons2,ButtonP2))
  240. Buttons2.append(Button3)
  241. Buttons2[2].place(x = 900 ,y = 100, width = 50, height = 50)
  242. Button4 = tk.Button(root1,bg = 'lightblue',command = lambda:color(3,Buttons2,ButtonP2))
  243. Buttons2.append(Button4)
  244. Buttons2[3].place(x = 950 ,y = 100, width = 50, height = 50)
  245. Button5 = tk.Button(root1,bg = 'lightblue',command = lambda:color(4,Buttons2,ButtonP2))
  246. Buttons2.append(Button5)
  247. Buttons2[4].place(x = 1000 ,y = 100, width = 50, height = 50)
  248. Button6 = tk.Button(root1,bg = 'lightblue',command = lambda:color(5,Buttons2,ButtonP2))
  249. Buttons2.append(Button6)
  250. Buttons2[5].place(x = 1050 ,y = 100, width = 50, height = 50)
  251. Button7 = tk.Button(root1,bg = 'lightblue',command = lambda:color(6,Buttons2,ButtonP2))
  252. Buttons2.append(Button7)
  253. Buttons2[6].place(x = 1100 ,y = 100, width = 50, height = 50)
  254. #zeile 2
  255. Button8 = tk.Button(root1,bg = 'lightblue',command = lambda:color(7,Buttons2,ButtonP2))
  256. Buttons2.append(Button8)
  257. Buttons2[7].place(x = 800 ,y = 150, width = 50, height = 50)
  258. Button9 = tk.Button(root1,bg = 'lightblue',command = lambda:color(8,Buttons2,ButtonP2))
  259. Buttons2.append(Button9)
  260. Buttons2[8].place(x = 850 ,y = 150, width = 50, height = 50)
  261. Button10 = tk.Button(root1,bg = 'lightblue',command = lambda:color(9,Buttons2,ButtonP2))
  262. Buttons2.append(Button10)
  263. Buttons2[9].place(x = 900 ,y = 150, width = 50, height = 50)
  264. Button11 = tk.Button(root1,bg = 'lightblue',command = lambda:color(10,Buttons2,ButtonP2))
  265. Buttons2.append(Button11)
  266. Buttons2[10].place(x = 950 ,y = 150, width = 50, height = 50)
  267. Button12 = tk.Button(root1,bg = 'lightblue',command = lambda:color(11,Buttons2,ButtonP2))
  268. Buttons2.append(Button12)
  269. Buttons2[11].place(x = 1000 ,y = 150, width = 50, height = 50)
  270. Button13 = tk.Button(root1,bg = 'lightblue',command = lambda:color(12,Buttons2,ButtonP2))
  271. Buttons2.append(Button13)
  272. Buttons2[12].place(x = 1050 ,y = 150, width = 50, height = 50)
  273. Button14 = tk.Button(root1,bg = 'lightblue',command = lambda:color(13,Buttons2,ButtonP2))
  274. Buttons2.append(Button14)
  275. Buttons2[13].place(x = 1100 ,y = 150, width = 50, height = 50)
  276. #zeile 3
  277. Button15 = tk.Button(root1,bg = 'lightblue',command = lambda:color(14,Buttons2,ButtonP2))
  278. Buttons2.append(Button15)
  279. Buttons2[14].place(x = 800 ,y = 200, width = 50, height = 50)
  280. Button16 = tk.Button(root1,bg = 'lightblue',command = lambda:color(15,Buttons2,ButtonP2))
  281. Buttons2.append(Button16)
  282. Buttons2[15].place(x = 850 ,y = 200, width = 50, height = 50)
  283. Button17 = tk.Button(root1,bg = 'lightblue',command = lambda:color(16,Buttons2,ButtonP2))
  284. Buttons2.append(Button17)
  285. Buttons2[16].place(x = 900 ,y = 200, width = 50, height = 50)
  286. Button18 = tk.Button(root1,bg = 'lightblue',command = lambda:color(17,Buttons2,ButtonP2))
  287. Buttons2.append(Button18)
  288. Buttons2[17].place(x = 950 ,y = 200, width = 50, height = 50)
  289. Button19 = tk.Button(root1,bg = 'lightblue',command = lambda:color(18,Buttons2,ButtonP2))
  290. Buttons2.append(Button19)
  291. Buttons2[18].place(x = 1000 ,y = 200, width = 50, height = 50)
  292. Button20 = tk.Button(root1,bg = 'lightblue',command = lambda:color(19,Buttons2,ButtonP2))
  293. Buttons2.append(Button20)
  294. Buttons2[19].place(x = 1050 ,y = 200, width = 50, height = 50)
  295. Button21 = tk.Button(root1,bg = 'lightblue',command = lambda:color(20,Buttons2,ButtonP2))
  296. Buttons2.append(Button21)
  297. Buttons2[20].place(x = 1100 ,y = 200, width = 50, height = 50)
  298. #zeile 4
  299. Button22 = tk.Button(root1,bg = 'lightblue',command = lambda:color(21,Buttons2,ButtonP2))
  300. Buttons2.append(Button22)
  301. Buttons2[21].place(x = 800 ,y = 250, width = 50, height = 50)
  302. Button23 = tk.Button(root1,bg = 'lightblue',command = lambda:color(22,Buttons2,ButtonP2))
  303. Buttons2.append(Button23)
  304. Buttons2[22].place(x = 850 ,y = 250, width = 50, height = 50)
  305. Button24 = tk.Button(root1,bg = 'lightblue',command = lambda:color(23,Buttons2,ButtonP2))
  306. Buttons2.append(Button24)
  307. Buttons2[23].place(x = 900 ,y = 250, width = 50, height = 50)
  308. Button25 = tk.Button(root1,bg = 'lightblue',command = lambda:color(24,Buttons2,ButtonP2))
  309. Buttons2.append(Button25)
  310. Buttons2[24].place(x = 950 ,y = 250, width = 50, height = 50)
  311. Button26 = tk.Button(root1,bg = 'lightblue',command = lambda:color(25,Buttons2,ButtonP2))
  312. Buttons2.append(Button26)
  313. Buttons2[25].place(x = 1000 ,y = 250, width = 50, height = 50)
  314. Button27 = tk.Button(root1,bg = 'lightblue',command = lambda:color(26,Buttons2,ButtonP2))
  315. Buttons2.append(Button27)
  316. Buttons2[26].place(x = 1050 ,y = 250, width = 50, height = 50)
  317. Button28 = tk.Button(root1,bg = 'lightblue',command = lambda:color(27,Buttons2,ButtonP2))
  318. Buttons2.append(Button28)
  319. Buttons2[27].place(x = 1100 ,y = 250, width = 50, height = 50)
  320. #zeile 5
  321. Button29 = tk.Button(root1,bg = 'lightblue',command = lambda:color(28,Buttons2,ButtonP2))
  322. Buttons2.append(Button29)
  323. Buttons2[28].place(x = 800 ,y = 300, width = 50, height = 50)
  324. Button30 = tk.Button(root1,bg = 'lightblue',command = lambda:color(29,Buttons2,ButtonP2))
  325. Buttons2.append(Button30)
  326. Buttons2[29].place(x = 850 ,y = 300, width = 50, height = 50)
  327. Button31 = tk.Button(root1,bg = 'lightblue',command = lambda:color(30,Buttons2,ButtonP2))
  328. Buttons2.append(Button31)
  329. Buttons2[30].place(x = 900 ,y = 300, width = 50, height = 50)
  330. Button32 = tk.Button(root1,bg = 'lightblue',command = lambda:color(31,Buttons2,ButtonP2))
  331. Buttons2.append(Button32)
  332. Buttons2[31].place(x = 950 ,y = 300, width = 50, height = 50)
  333. Button33 = tk.Button(root1,bg = 'lightblue',command = lambda:color(32,Buttons2,ButtonP2))
  334. Buttons2.append(Button33)
  335. Buttons2[32].place(x = 1000 ,y = 300, width = 50, height = 50)
  336. Button34 = tk.Button(root1,bg = 'lightblue',command = lambda:color(33,Buttons2,ButtonP2))
  337. Buttons2.append(Button34)
  338. Buttons2[33].place(x = 1050 ,y = 300, width = 50, height = 50)
  339. Button35 = tk.Button(root1,bg = 'lightblue',command = lambda:color(34,Buttons2,ButtonP2))
  340. Buttons2.append(Button35)
  341. Buttons2[34].place(x = 1100 ,y = 300, width = 50, height = 50)
  342. #zeile 6
  343. Button36 = tk.Button(root1,bg = 'lightblue',command = lambda:color(35,Buttons2,ButtonP2))
  344. Buttons2.append(Button36)
  345. Buttons2[35].place(x = 800 ,y = 350, width = 50, height = 50)
  346. Button37 = tk.Button(root1,bg = 'lightblue',command = lambda:color(36,Buttons2,ButtonP2))
  347. Buttons2.append(Button37)
  348. Buttons2[36].place(x = 850 ,y = 350, width = 50, height = 50)
  349. Button38 = tk.Button(root1,bg = 'lightblue',command = lambda:color(37,Buttons2,ButtonP2))
  350. Buttons2.append(Button38)
  351. Buttons2[37].place(x = 900 ,y = 350, width = 50, height = 50)
  352. Button39 = tk.Button(root1,bg = 'lightblue',command = lambda:color(38,Buttons2,ButtonP2))
  353. Buttons2.append(Button39)
  354. Buttons2[38].place(x = 950 ,y = 350, width = 50, height = 50)
  355. Button40 = tk.Button(root1,bg = 'lightblue',command = lambda:color(39,Buttons2,ButtonP2))
  356. Buttons2.append(Button40)
  357. Buttons2[39].place(x = 1000 ,y = 350, width = 50, height = 50)
  358. Button41 = tk.Button(root1,bg = 'lightblue',command = lambda:color(40,Buttons2,ButtonP2))
  359. Buttons2.append(Button41)
  360. Buttons2[40].place(x = 1050 ,y = 350, width = 50, height = 50)
  361. Button42 = tk.Button(root1,bg = 'lightblue',command = lambda:color(41,Buttons2,ButtonP2))
  362. Buttons2.append(Button42)
  363. Buttons2[41].place(x = 1100 ,y = 350, width = 50, height = 50)
  364. #zeile 7
  365. Button43 = tk.Button(root1,bg = 'lightblue',command = lambda:color(42,Buttons2,ButtonP2))
  366. Buttons2.append(Button43)
  367. Buttons2[42].place(x = 800 ,y = 400, width = 50, height = 50)
  368. Button44 = tk.Button(root1,bg = 'lightblue',command = lambda:color(43,Buttons2,ButtonP2))
  369. Buttons2.append(Button44)
  370. Buttons2[43].place(x = 850 ,y = 400, width = 50, height = 50)
  371. Button45 = tk.Button(root1,bg = 'lightblue',command = lambda:color(44,Buttons2,ButtonP2))
  372. Buttons2.append(Button45)
  373. Buttons2[44].place(x = 900 ,y = 400, width = 50, height = 50)
  374. Button46 = tk.Button(root1,bg = 'lightblue',command = lambda:color(45,Buttons2,ButtonP2))
  375. Buttons2.append(Button46)
  376. Buttons2[45].place(x = 950 ,y = 400, width = 50, height = 50)
  377. Button47 = tk.Button(root1,bg = 'lightblue',command = lambda:color(46,Buttons2,ButtonP2))
  378. Buttons2.append(Button47)
  379. Buttons2[46].place(x = 1000 ,y = 400, width = 50, height = 50)
  380. Button48 = tk.Button(root1,bg = 'lightblue',command = lambda:color(47,Buttons2,ButtonP2))
  381. Buttons2.append(Button48)
  382. Buttons2[47].place(x = 1050 ,y = 400, width = 50, height = 50)
  383. Button49 = tk.Button(root1,bg = 'lightblue',command = lambda:color(48,Buttons2,ButtonP2))
  384. Buttons2.append(Button49)
  385. Buttons2[48].place(x = 1100 ,y = 400, width = 50, height = 50)
  386. ButtonSS = tk.Button(root1,text = 'Boot (1)',bg = 'yellow',command = lambda:schiffwehlen(1))
  387. ButtonS2.append(ButtonSS)
  388. ButtonS2[0].place(x = 650 ,y = 200, width = 100, height = 50)
  389. ButtonSM1 = tk.Button(root1,text = 'U-Boot (2)',bg = 'yellow',command = lambda:schiffwehlen(2))
  390. ButtonS2.append(ButtonSM1)
  391. ButtonS2[1].place(x = 650 ,y = 300, width = 100, height = 50)
  392. ButtonSM2 = tk.Button(root1,text = 'U-Boot (2)',bg = 'yellow',command = lambda:schiffwehlen(3))
  393. ButtonS2.append(ButtonSM2)
  394. ButtonS2[2].place(x = 650 ,y = 400, width = 100, height = 50)
  395. ButtonSL = tk.Button(root1,text = 'Kreuzer (5)',bg = 'yellow',command = lambda:schiffwehlen(4))
  396. ButtonS2.append(ButtonSL)
  397. ButtonS2[3].place(x = 650 ,y = 500, width = 250, height = 50)
  398. ButtonR = tk.Button(root1,text = 'Rotieren!',bg = 'green',command = Rot)
  399. ButtonS2.append(ButtonR)
  400. ButtonS2[4].place(x = 650 ,y = 100, width = 100, height = 50)
  401. ButtonSw = tk.Button(root1,text = 'Fertig!',bg = 'green',command = wehlen)
  402. ButtonS2.append(ButtonSw)
  403. ButtonS2[5].place(x = 1000 ,y = 500, width = 120, height = 50)
  404. def wehlen(): #Funktion Spielstart
  405. global Wel
  406. for i in range(49):
  407. Buttons1[i].configure(bg = "lightblue")
  408. Buttons2[i].configure(bg = "lightblue")
  409. Wel = 1
  410. if ai == 1:
  411. ButtonSede = tk.Button(root1,text = 'AI ist dran',command = lambda:Versuch_AI(Buttons1,ButtonP1))
  412. ButtonS2.append(ButtonSede)
  413. ButtonS2[6].place(x = 600 ,y = 30, width = 100, height = 50)
  414. Versuch_AI(Buttons1,ButtonP1)
  415. def Rot(): #Rotation der Schiffe
  416. global Rot
  417. Rot = 1
  418. def Wintest(): #Probe wer gewonnen hat
  419. dic1 = (ButtonP1.values())
  420. dic2 = (ButtonP2.values())
  421. if 1 not in dic1 and ai == 1:
  422. WinAI= showinfo(title='Schade!',message='AI GEWINNT!!!')
  423. root1.destroy()
  424. elif 1 not in dic1 and ai == 0:
  425. Win1= showinfo(title='GLUECKWUNSCH!',message='P2 GEWINNT!!!')
  426. root1.destroy()
  427. elif 1 not in dic2:
  428. Win2= showinfo(title='GLUECKWUNSCH!',message='P1 GEWINNT!!!')
  429. root1.destroy()
  430. def Versuch_AI(Buttons,Button): #AI versuch
  431. global PW,z
  432. if Wel == 1 and ai == 1:
  433. while True:
  434. i = random.randint(0,48)
  435. if i not in z:
  436. if Buttons == Buttons1 and PW == 2:
  437. if Button[str(i+1)] == 1:
  438. Button[str(i+1)] = 'X'
  439. Buttons[i].configure(bg = "red")
  440. z.append(i)
  441. elif Button[str(i+1)] == 0:
  442. Button[str(i+1)] = 'm'
  443. Buttons[i].configure(bg = "blue")
  444. z.append(i)
  445. Wintest()
  446. PW = 1
  447. break
  448. elif Buttons == Buttons1 and PW == 1:
  449. break
  450. else:
  451. continue
  452. def Schiffesetzen_AI(Buttons,Button): #AI Schiffe setzen
  453. global Scf
  454. Scfs = []
  455. while True:
  456. Scf = random.randint(1,4)
  457. if Scf not in Scfs:
  458. Rot = random.randint (0,1)
  459. i = random.randint (0,48)
  460. if Rot == 1:
  461. if Scf == 1: #Schiffe werden zufaellig platziert
  462. if Button[str(i+1)] == 0:
  463. Button[str(i+1)] = 1
  464. Scfs.append(Scf)
  465. Scf = 0
  466. else:
  467. continue
  468. elif Scf == 2:
  469. if i>41:
  470. if Button[str(i+1)] == 0 and Button[str(i+1-7)] == 0:
  471. Button[str(i+1)] = 1
  472. Button[str(i+1-7)] = 1
  473. Scfs.append(Scf)
  474. Scf = 0
  475. else:
  476. continue
  477. else:
  478. if Button[str(i+1)] == 0 and Button[str(i+1+7)] == 0:
  479. Button[str(i+1)] = 1
  480. Button[str(i+1+7)] = 1
  481. Scfs.append(Scf)
  482. Scf = 0
  483. else:
  484. continue
  485. elif Scf == 3:
  486. if i>41:
  487. if Button[str(i+1)] == 0 and Button[str(i+1-7)] == 0:
  488. Button[str(i+1)] = 1
  489. Button[str(i+1-7)] = 1
  490. Scfs.append(Scf)
  491. Scf = 0
  492. else:
  493. continue
  494. else:
  495. if Button[str(i+1)] == 0 and Button[str(i+1+7)] == 0:
  496. Button[str(i+1)] = 1
  497. Button[str(i+1+7)] = 1
  498. Scfs.append(Scf)
  499. Scf = 0
  500. else:
  501. continue
  502. elif Scf == 4:
  503. if i <21:
  504. if Button[str(i+1)] == 0 and Button[str(i+1+7)] == 0 and Button[str(i+1+14)] == 0 and Button[str(i+1+21)] == 0 and Button[str(i+1+28)] == 0:
  505. for m in range(5):
  506. Button[str(i+1)] = 1
  507. i = i + 7
  508. Scfs.append(Scf)
  509. Scf = 0
  510. else:
  511. continue
  512. elif i/7 == 3:
  513. if Button[str(i+1)] == 0 and Button[str(i+1+7)] == 0 and Button[str(i+1+14)] == 0 and Button[str(i+1+21)] == 0 and Button[str(i+1-7)] == 0:
  514. Button[str(i+1-7)] = 1
  515. Button[str(i+1)] = 1
  516. Button[str(i+1+7)] = 1
  517. Button[str(i+1+14)] = 1
  518. Button[str(i+21)] = 1
  519. Scfs.append(Scf)
  520. Scf = 0
  521. else:
  522. continue
  523. elif i/7 == 4:
  524. if Button[str(i+1)] == 0 and Button[str(i+1+7)] == 0 and Button[str(i+1+14)] == 0 and Button[str(i+1-14)] == 0 and Button[str(i+1-7)] == 0:
  525. Button[str(i+1-14)] = 1
  526. Button[str(i+1-7)] = 1
  527. Button[str(i+1)] = 1
  528. Button[str(i+1+7)] = 1
  529. Button[str(i+1+14)] = 1
  530. Scfs.append(Scf)
  531. Scf = 0
  532. else:
  533. continue
  534. elif i/7 == 5:
  535. if Button[str(i+1)] == 0 and Button[str(i+1+7)] == 0 and Button[str(i+1-21)] == 0 and Button[str(i+1-14)] == 0 and Button[str(i+1-7)] == 0:
  536. Button[str(i+1-21)] = 1
  537. Button[str(i+1-14)] = 1
  538. Button[str(i+1-7)] = 1
  539. Button[str(i+1)] = 1
  540. Button[str(i+1+7)] = 1
  541. Scfs.append(Scf)
  542. Scf = 0
  543. else:
  544. continue
  545. elif i/7 == 6:
  546. if Button[str(i+1)] == 0 and Button[str(i+1-28)] == 0 and Button[str(i+1-21)] == 0 and Button[str(i+1-14)] == 0 and Button[str(i+1-7)] == 0:
  547. Button[str(i+1-28)] = 1
  548. Button[str(i+1-21)] = 1
  549. Button[str(i+1-14)] = 1
  550. Button[str(i+1-7)] = 1
  551. Button[str(i+1)] = 1
  552. Scfs.append(Scf)
  553. Scf = 0
  554. else:
  555. continue
  556. Rot = 0
  557. else:
  558. if Scf == 1:
  559. if Button[str(i+1)] == 0:
  560. Button[str(i+1)] = 1
  561. Scfs.append(Scf)
  562. Scf = 0
  563. else:
  564. continue
  565. elif Scf == 2 :
  566. if i%7 == 6:
  567. if Button[str(i+1)] == 0 and Button[str(i)] == 0:
  568. Button[str(i+1)] = 1
  569. Button[str(i)] = 1
  570. Scfs.append(Scf)
  571. Scf = 0
  572. else:
  573. continue
  574. else:
  575. if Button[str(i+1)] == 0 and Button[str(i+2)] == 0:
  576. Button[str(i+1)] = 1
  577. Button[str(i+1+1)] = 1
  578. Scfs.append(Scf)
  579. Scf = 0
  580. else:
  581. continue
  582. elif Scf == 3 :
  583. if i%7 == 6:
  584. if Button[str(i+1)] == 0 and Button[str(i)] == 0:
  585. Button[str(i+1)] = 1
  586. Button[str(i)] = 1
  587. Scfs.append(Scf)
  588. Scf = 0
  589. else:
  590. continue
  591. else:
  592. if Button[str(i+1)] == 0 and Button[str(i+2)] == 0:
  593. Button[str(i+1)] = 1
  594. Button[str(i+1+1)] = 1
  595. Scfs.append(Scf)
  596. Scf = 0
  597. else:
  598. continue
  599. elif Scf == 4:
  600. if i%7<3:
  601. if Button[str(i+1)] == 0 and Button[str(i+2)] == 0 and Button[str(i+3)] == 0 and Button[str(i+4)] == 0 and Button[str(i+5)] == 0:
  602. for m in range(5):
  603. Button[str(i+1)] = 1
  604. i = i + 1
  605. Scfs.append(Scf)
  606. Scf = 0
  607. else:
  608. continue
  609. elif i%7 == 3:
  610. if Button[str(i-1)] == 0 and Button[str(i)] == 0 and Button[str(i+1)] == 0 and Button[str(i+2)] == 0 and Button[str(i+3)] == 0:
  611. Button[str(i)] = 1
  612. Button[str(i+1)] = 1
  613. Button[str(i+1+1)] = 1
  614. Button[str(i+1+2)] = 1
  615. Button[str(i+1+3)] = 1
  616. Scfs.append(Scf)
  617. Scf = 0
  618. else:
  619. continue
  620. elif i%7 == 4:
  621. if Button[str(i-2)] == 0 and Button[str(i-1)] == 0 and Button[str(i+1)] == 0 and Button[str(i+2)] == 0 and Button[str(i)] == 0:
  622. Button[str(i-1)] = 1
  623. Button[str(i)] = 1
  624. Button[str(i+1)] = 1
  625. Button[str(i+2)] = 1
  626. Button[str(i+3)] = 1
  627. Scfs.append(Scf)
  628. Scf = 0
  629. else:
  630. continue
  631. elif i%7 == 5:
  632. if Button[str(i-1)] == 0 and Button[str(i)] == 0 and Button[str(i+1)] == 0 and Button[str(i+2)] == 0 and Button[str(i-2)] == 0:
  633. Button[str(i-2)] = 1
  634. Button[str(i-1)] = 1
  635. Button[str(i)] = 1
  636. Button[str(i+1)] = 1
  637. Button[str(i+2)] = 1
  638. Scfs.append(Scf)
  639. Scf = 0
  640. else:
  641. continue
  642. elif i%7 == 6:
  643. if Button[str(i-1)] == 0 and Button[str(i)] == 0 and Button[str(i+1)] == 0 and Button[str(i-2)] == 0 and Button[str(i-3)] == 0:
  644. Button[str(i-3)] = 1
  645. Button[str(i-2)] = 1
  646. Button[str(i-1)] = 1
  647. Button[str(i)] = 1
  648. Button[str(i+1)] = 1
  649. Scfs.append(Scf)
  650. Scf = 0
  651. else:
  652. continue
  653. if len(Scfs) == 4:
  654. break
  655. def color(i,Buttons,Button): #Grundfunktionen der einzelnen Knoepfe
  656. global Rot,Scf,PW
  657. if Wel == 1: #Schiffe auswaehlen
  658. if Buttons == Buttons1 and PW == 2 and ai == 0:
  659. if Button[str(i+1)] == 1:
  660. Button[str(i+1)] = 'X'
  661. Buttons[i].configure(bg = "red")
  662. elif Button[str(i+1)] == 0:
  663. Button[str(i+1)] = 'm'
  664. Buttons[i].configure(bg = "blue")
  665. Wintest()
  666. PW = 1
  667. elif Buttons == Buttons2 and PW == 1:
  668. if Button[str(i+1)] == 1:
  669. Button[str(i+1)] = 'X'
  670. Buttons[i].configure(bg = "red")
  671. elif Button[str(i+1)] == 0:
  672. Button[str(i+1)] = 'm'
  673. Buttons[i].configure(bg = "blue")
  674. Wintest()
  675. PW = 2
  676. elif Buttons == Buttons1 and PW == 2 and ai == 1:
  677. achtung= showinfo(title='Achtung!!',message='Singleplayermodus! Button "AI Turn" klicken, um weiter zu spielen!')
  678. else:
  679. achtung= showinfo(title='Achtung!!',message='Der Andere Spieler ist an der Reihe!')
  680. else:
  681. if Rot == 1: #Schiffe setzen
  682. if Scf == 1:
  683. if Button[str(i+1)] == 0:
  684. Buttons[i].configure(bg = "yellow")
  685. Button[str(i+1)] = 1
  686. Scf = 0
  687. else:
  688. achtung= showinfo(title='Achtung!',message='Diese(s) Feld(er) ist/sind schon belegt!')
  689. elif Scf == 2:
  690. if i>41:
  691. if Button[str(i+1)] == 0 and Button[str(i+1-7)] == 0:
  692. Buttons[i].configure(bg = "yellow")
  693. Buttons[i-7].configure(bg = "yellow")
  694. Button[str(i+1)] = 1
  695. Button[str(i+1-7)] = 1
  696. Scf = 0
  697. else:
  698. achtung= showinfo(title='Achtung!',message='Diese(s) Feld(er) ist/sind schon belegt')
  699. else:
  700. if Button[str(i+1)] == 0 and Button[str(i+1+7)] == 0:
  701. Buttons[i].configure(bg = "yellow")
  702. Button[str(i+1)] = 1
  703. Buttons[i+7].configure(bg = "yellow")
  704. Button[str(i+1+7)] = 1
  705. Scf = 0
  706. else:
  707. achtung= showinfo(title='Achtung!',message='Diese(s) Feld(er) ist/sind schon belegt')
  708. elif Scf == 3:
  709. if i>41:
  710. if Button[str(i+1)] == 0 and Button[str(i+1-7)] == 0:
  711. Buttons[i].configure(bg = "yellow")
  712. Button[str(i+1)] = 1
  713. Buttons[i-7].configure(bg = "yellow")
  714. Button[str(i+1-7)] = 1
  715. Scf = 0
  716. else:
  717. achtung= showinfo(title='Achtung!',message='Diese(s) Feld(er) ist/sind schon belegt')
  718. else:
  719. if Button[str(i+1)] == 0 and Button[str(i+1+7)] == 0:
  720. Buttons[i].configure(bg = "yellow")
  721. Button[str(i+1)] = 1
  722. Buttons[i+7].configure(bg = "yellow")
  723. Button[str(i+1+7)] = 1
  724. Scf = 0
  725. else:
  726. achtung= showinfo(title='Achtung!',message='Diese(s) Feld(er) ist/sind schon belegt')
  727. elif Scf == 4:
  728. if i <21:
  729. if Button[str(i+1)] == 0 and Button[str(i+1+7)] == 0 and Button[str(i+1+14)] == 0 and Button[str(i+1+21)] == 0 and Button[str(i+1+28)] == 0:
  730. for m in range(5):
  731. Buttons[i].configure(bg = "yellow")
  732. Button[str(i+1)] = 1
  733. i = i + 7
  734. Scf = 0
  735. else:
  736. achtung= showinfo(title='Achtung!',message='Diese(s) Feld(er) ist/sind schon belegt')
  737. elif i/7 == 3:
  738. if Button[str(i+1)] == 0 and Button[str(i+1+7)] == 0 and Button[str(i+1+14)] == 0 and Button[str(i+1+21)] == 0 and Button[str(i+1-7)] == 0:
  739. Buttons[i-7].configure(bg = "yellow")
  740. Button[str(i+1-7)] = 1
  741. Buttons[i].configure(bg = "yellow")
  742. Button[str(i+1)] = 1
  743. Buttons[i+7].configure(bg = "yellow")
  744. Button[str(i+1+7)] = 1
  745. Buttons[i+14].configure(bg = "yellow")
  746. Button[str(i+1+14)] = 1
  747. Buttons[i+21].configure(bg = "yellow")
  748. Button[str(i+21)] = 1
  749. Scf = 0
  750. else:
  751. achtung= showinfo(title='Achtung!',message='Diese(s) Feld(er) ist/sind schon belegt')
  752. elif i/7 == 4:
  753. if Button[str(i+1)] == 0 and Button[str(i+1+7)] == 0 and Button[str(i+1+14)] == 0 and Button[str(i+1-14)] == 0 and Button[str(i+1-7)] == 0:
  754. Buttons[i-14].configure(bg = "yellow")
  755. Button[str(i+1-14)] = 1
  756. Buttons[i-7].configure(bg = "yellow")
  757. Button[str(i+1-7)] = 1
  758. Buttons[i].configure(bg = "yellow")
  759. Button[str(i+1)] = 1
  760. Buttons[i+7].configure(bg = "yellow")
  761. Button[str(i+1+7)] = 1
  762. Buttons[i+14].configure(bg = "yellow")
  763. Button[str(i+1+14)] = 1
  764. Scf = 0
  765. else:
  766. achtung= showinfo(title='Achtung!',message='Diese(s) Feld(er) ist/sind schon belegt!')
  767. elif i/7 == 5:
  768. if Button[str(i+1)] == 0 and Button[str(i+1+7)] == 0 and Button[str(i+1-21)] == 0 and Button[str(i+1-14)] == 0 and Button[str(i+1-7)] == 0:
  769. Buttons[i-21].configure(bg = "yellow")
  770. Button[str(i+1-21)] = 1
  771. Buttons[i-14].configure(bg = "yellow")
  772. Button[str(i+1-14)] = 1
  773. Buttons[i-7].configure(bg = "yellow")
  774. Button[str(i+1-7)] = 1
  775. Buttons[i].configure(bg = "yellow")
  776. Button[str(i+1)] = 1
  777. Buttons[i+7].configure(bg = "yellow")
  778. Button[str(i+1+7)] = 1
  779. Scf = 0
  780. else:
  781. achtung= showinfo(title='Achtung!',message='Diese(s) Feld(er) ist/sind schon belegt')
  782. elif i/7 == 6:
  783. if Button[str(i+1)] == 0 and Button[str(i+1-28)] == 0 and Button[str(i+1-21)] == 0 and Button[str(i+1-14)] == 0 and Button[str(i+1-7)] == 0:
  784. Buttons[i-28].configure(bg = "yellow")
  785. Button[str(i+1-28)] = 1
  786. Buttons[i-21].configure(bg = "yellow")
  787. Button[str(i+1-21)] = 1
  788. Buttons[i-14].configure(bg = "yellow")
  789. Button[str(i+1-14)] = 1
  790. Buttons[i-7].configure(bg = "yellow")
  791. Button[str(i+1-7)] = 1
  792. Buttons[i].configure(bg = "yellow")
  793. Button[str(i+1)] = 1
  794. Scf = 0
  795. else:
  796. achtung= showinfo(title='Achtung!',message='Diese(s) Feld(er) ist/sind schon belegt!')
  797. Rot = 0
  798. else:
  799. if Scf == 1:
  800. if Button[str(i+1)] == 0:
  801. Buttons[i].configure(bg = "yellow")
  802. Button[str(i+1)] = 1
  803. Scf = 0
  804. else:
  805. achtung= showinfo(title='Achtung!',message='Diese(s) Feld(er) ist/sind schon belegt')
  806. elif Scf == 2 :
  807. if i%7 == 6:
  808. if Button[str(i+1)] == 0 and Button[str(i)] == 0:
  809. Buttons[i].configure(bg = "yellow")
  810. Button[str(i+1)] = 1
  811. Buttons[i-1].configure(bg = "yellow")
  812. Button[str(i)] = 1
  813. Scf = 0
  814. else:
  815. achtung= showinfo(title='Achtung!',message='Diese(s) Feld(er) ist/sind schon belegt!')
  816. else:
  817. if Button[str(i+1)] == 0 and Button[str(i+2)] == 0:
  818. Buttons[i].configure(bg = "yellow")
  819. Button[str(i+1)] = 1
  820. Buttons[i+1].configure(bg = "yellow")
  821. Button[str(i+1+1)] = 1
  822. Scf = 0
  823. else:
  824. achtung= showinfo(title='Achtung!',message='Diese(s) Feld(er) ist/sind schon belegt')
  825. elif Scf == 3 :
  826. if i%7 == 6:
  827. if Button[str(i+1)] == 0 and Button[str(i)] == 0:
  828. Buttons[i].configure(bg = "yellow")
  829. Button[str(i+1)] = 1
  830. Buttons[i-1].configure(bg = "yellow")
  831. Button[str(i)] = 1
  832. Scf = 0
  833. else:
  834. achtung= showinfo(title='Achtung!',message='Diese(s) Feld(er) ist/sind schon belegt')
  835. else:
  836. if Button[str(i+1)] == 0 and Button[str(i+2)] == 0:
  837. Buttons[i].configure(bg = "yellow")
  838. Button[str(i+1)] = 1
  839. Buttons[i+1].configure(bg = "yellow")
  840. Button[str(i+1+1)] = 1
  841. Scf = 0
  842. else:
  843. achtung= showinfo(title='Achtung!',message='Diese(s) Feld(er) ist/sind schon belegt')
  844. elif Scf == 4:
  845. if i%7<3:
  846. if Button[str(i+1)] == 0 and Button[str(i+2)] == 0 and Button[str(i+3)] == 0 and Button[str(i+4)] == 0 and Button[str(i+5)] == 0:
  847. for m in range(5):
  848. Buttons[i].configure(bg = "yellow")
  849. Button[str(i+1)] = 1
  850. i = i + 1
  851. Scf = 0
  852. else:
  853. achtung= showinfo(title='Achtung!',message='Diese(s) Feld(er) ist/sind schon belegt')
  854. elif i%7 == 3:
  855. if Button[str(i-1)] == 0 and Button[str(i)] == 0 and Button[str(i+1)] == 0 and Button[str(i+2)] == 0 and Button[str(i+3)] == 0:
  856. Buttons[i-1].configure(bg = "yellow")
  857. Button[str(i)] = 1
  858. Buttons[i].configure(bg = "yellow")
  859. Button[str(i+1)] = 1
  860. Buttons[i+1].configure(bg = "yellow")
  861. Button[str(i+1+1)] = 1
  862. Buttons[i+2].configure(bg = "yellow")
  863. Button[str(i+1+2)] = 1
  864. Buttons[i+3].configure(bg = "yellow")
  865. Button[str(i+1+3)] = 1
  866. Scf = 0
  867. else:
  868. achtung= showinfo(title='Achtung!',message='Diese(s) Feld(er) ist/sind schon belegt')
  869. elif i%7 == 4:
  870. if Button[str(i-2)] == 0 and Button[str(i-1)] == 0 and Button[str(i+1)] == 0 and Button[str(i+2)] == 0 and Button[str(i)] == 0:
  871. Buttons[i-2].configure(bg = "yellow")
  872. Button[str(i-1)] = 1
  873. Buttons[i-1].configure(bg = "yellow")
  874. Button[str(i)] = 1
  875. Buttons[i].configure(bg = "yellow")
  876. Button[str(i+1)] = 1
  877. Buttons[i+1].configure(bg = "yellow")
  878. Button[str(i+2)] = 1
  879. Buttons[i+2].configure(bg = "yellow")
  880. Button[str(i+3)] = 1
  881. Scf = 0
  882. else:
  883. achtung= showinfo(title='Achtung!',message='Diese(s) Feld(er) ist/sind schon belegt')
  884. elif i%7 == 5:
  885. if Button[str(i-1)] == 0 and Button[str(i)] == 0 and Button[str(i+1)] == 0 and Button[str(i+2)] == 0 and Button[str(i-2)] == 0:
  886. Buttons[i-3].configure(bg = "yellow")
  887. Button[str(i-2)] = 1
  888. Buttons[i-2].configure(bg = "yellow")
  889. Button[str(i-1)] = 1
  890. Buttons[i-1].configure(bg = "yellow")
  891. Button[str(i)] = 1
  892. Buttons[i].configure(bg = "yellow")
  893. Button[str(i+1)] = 1
  894. Buttons[i+1].configure(bg = "yellow")
  895. Button[str(i+2)] = 1
  896. Scf = 0
  897. else:
  898. achtung= showinfo(title='Achtung!',message='Diese(s) Feld(er) ist/sind schon belegt')
  899. elif i%7 == 6:
  900. if Button[str(i-1)] == 0 and Button[str(i)] == 0 and Button[str(i+1)] == 0 and Button[str(i-2)] == 0 and Button[str(i-3)] == 0:
  901. Buttons[i-4].configure(bg = "yellow")
  902. Button[str(i-3)] = 1
  903. Buttons[i-3].configure(bg = "yellow")
  904. Button[str(i-2)] = 1
  905. Buttons[i-2].configure(bg = "yellow")
  906. Button[str(i-1)] = 1
  907. Buttons[i-1].configure(bg = "yellow")
  908. Button[str(i)] = 1
  909. Buttons[i].configure(bg = "yellow")
  910. Button[str(i+1)] = 1
  911. Scf = 0
  912. if len(SumS) == 4: #Pruefen ob alle Schiffe gesetzt wurden
  913. ButtonSw = tk.Button(root1,text = 'Spieler wechseln',bg = 'green',command = was)
  914. ButtonS1.append(ButtonSw)
  915. ButtonS1[6].place(x = 450 ,y = 500, width = 120, height = 50)
  916. def schiffwehlen(W): #Spieler soll Schiffe auswaehlen
  917. global Scf
  918. if W in SumS:
  919. achtung= showinfo(title='Achtung!',message='Das Schiff wurde schon gesetzt!')
  920. else:
  921. if W == 1:
  922. Scf = 1
  923. SumS.append(W)
  924. elif W == 2:
  925. SumS.append(W)
  926. Scf = 2
  927. elif W == 3:
  928. SumS.append(W)
  929. Scf = 3
  930. elif W == 4:
  931. SumS.append(W)
  932. Scf = 4
  933. else:
  934. print 'falsche Eingabe!'
  935. def was(): #AI oder P2
  936. p2()
  937. if ai == 1:
  938. Schiffesetzen_AI(Buttons2,ButtonP2)
  939. def menu(): #Menu
  940. root = tk.Tk()
  941. root.title("Menu")
  942. fens = tk.Canvas(root,width = 800,height = 600,bg = 'lightblue')
  943. fens.pack()
  944. thema = tk.Label(root,text = "Schiffe Versenken!",font = "Arial 30",fg = "White",padx = 50,pady = 10,background="blue",relief="ridge",borderwidth=10)
  945. thema.place(height=100, width=400 ,x = 200, y = 100)
  946. button1 = tk.Button(root,text = "Mensch vs AI",bg = 'black',activebackground = 'Green',font = '20',fg = 'White',command = lambda:sing())
  947. button1.place(x = 200, y = 250,height = 50,width = 150)
  948. button2 = tk.Button(root,text = "Mensch vs Mensch",bg = 'black',activebackground = 'Blue',font = '20',fg = 'White',command = lambda:muti())
  949. button2.place(x = 500, y = 250,height = 50,width = 150)
  950. button3 = tk.Button(root,text = "Hilfe",bg = 'black',activebackground = 'White',font = '20',fg = 'White',command = lambda:Hilfe())
  951. button3.place(x = 200, y = 400,height = 50,width = 150)
  952. button4 = tk.Button(root,text = "Beenden",bg = 'red',font = '20',fg = 'White',command = lambda:ex(root))
  953. button4.place(x = 500, y = 400,height = 50,width = 150)
  954. root.mainloop()
  955. def sing(): #Singl player
  956. global ai
  957. global root1
  958. root1 = tk.Tk()
  959. root1.title('Schiffe Versenken')
  960. ai = 1
  961. p1()
  962. def muti(): #multi player
  963. global root1
  964. root1 = tk.Tk()
  965. root1.title('Schiffe Versenken')
  966. p1()
  967. def Hilfe(): #Hilfe
  968. Hilfe = tk.Tk()
  969. Hilfe.title('Hilfe')
  970. text = tk.Label(Hilfe,text = "Dieses Programm wurde entwickelt, um das Spiel Schiffe Versenken zu Spielen.",font = "Arial 15").pack()
  971. button1 = tk.Button(Hilfe,text = 'Zurueck',bg = "green",font = "20",command = lambda:ex(Hilfe)).pack()
  972. def ex(root):
  973. root.destroy()
  974. menu()