1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
from tkinter import *
def KeyBoard(event):
global Tank1L,Tank1C,Tank2L,Tank2C,LC
New1L,New1C=Tank1L,Tank1C
New2L,New2C=Tank2L,Tank2C
Key = event.keysym
if Key == 'Up':
New1L,New1C=Tank1L,Tank1C-1
if Key == 'Left':
New1L,New1C=Tank1L-1,Tank1C
if Key == 'Down':
New1L,New1C=Tank1L,Tank1C+1
if Key == 'Right':
New1L,New1C=Tank1L+1,Tank1C
if Key == 'z' or Key == 'Z':
New2L,New2C=Tank2L,Tank2C-1
if Key == 'q' or Key == 'Q':
New2L,New2C=Tank2L-1,Tank2C
if Key == 's'or Key == 'S':
New2L,New2C=Tank2L,Tank2C+1
if Key == 'd'or Key == 'D':
New2L,New2C=Tank2L+1,Tank2C
Verification1(New1L,New1C)
Verification2(New2L,New2C)
def Verification1(New1L,New1C):
global Tank1L,Tank1C,LC
if LC[New1L][New1C]==0:
LC[Tank1L][Tank1C]=0
Tank1L,Tank1C=New1L,New1C
LC[Tank1L][Tank1C]=2
MyCanvas.coords(Piece1,Tank1L*20,Tank1C*20 , Tank1L*20 +20, Tank1C*20 +20)
def Verification2(New2L,New2C):
global Tank2L,Tank2C,LC
if LC[New2L][New2C]==0:
LC[Tank2L][Tank2C]=0
Tank2L,Tank2C=New2L,New2C
LC[Tank2L][Tank2C]=2
MyCanvas.coords(Piece2,Tank2L*20,Tank2C*20 , Tank2L*20 +20, Tank2C*20 +20)
MyWindow = Tk()
MyWindow.title('Piece')
Tank1L = 10
Tank1C = 7
Tank2L = 5
Tank2C = 2
MyCanvas = Canvas(MyWindow, width = 400, height =400, bg ='white')
Tank1 = MyCanvas.create_oval(Tank1L*20,Tank1C*20,Tank1L*20+20,Tank1C*20+20,width=2,outline='black',fill='red')
Tank2 = MyCanvas.create_oval(Tank2L*20,Tank2C*20,Tank2L*20+20,Tank2C*20+20,width=2,outline='black',fill='red')
MyCanvas.focus_set()
MyCanvas.bind('<Key>',KeyBoard)
MyCanvas.pack(padx =50, pady =50)
Button(MyWindow, text ='Exit', command = MyWindow.destroy).pack(side=LEFT,padx=5,pady=5)
LC=[[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0],
[0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0],
[0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0],
[0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0],
[0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]
LC[5][5]=1
print(LC)
#partie murs du
for j in range(20):
for i in range(20):
if LC[j][i]==1:
MyCanvas.create_rectangle(j*20,i*20,j*20+20,i*20+20,fill='brown')
"""
i=0
j=0
while j < 15:
while i<20:
if LC[j][i]==1:
MyCanvas.create_rectangle(j*20,i*20,j*20+20,i*20+20,fill='black')
i=i+1
i=0
j=j+1"""
MyWindow.mainloop() |
Partager