Probe_PL.py 51 KB

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