commicu
This commit is contained in:
parent
9bd85a86bb
commit
d97e27b8b6
|
@ -0,0 +1,79 @@
|
||||||
|
from tkinter import *
|
||||||
|
|
||||||
|
empty_field = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
|
||||||
|
|
||||||
|
# set_ship(1, 1, 4, 1)
|
||||||
|
step1_field = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', '1', '1', '1', '1', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
|
||||||
|
|
||||||
|
# set_ship(0, 5, 3, 0)
|
||||||
|
step2_field = [' ', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
|
||||||
|
|
||||||
|
my_field = list(empty_field)
|
||||||
|
enemy_field = list(empty_field)
|
||||||
|
|
||||||
|
buttons = []
|
||||||
|
|
||||||
|
|
||||||
|
def set_ship(field, row, col, size, direction):
|
||||||
|
# size - 1, 2, 3, 4
|
||||||
|
# direction - вниз(0), вправо(1)
|
||||||
|
if row < 0 or row > size - 1:
|
||||||
|
return
|
||||||
|
if col < 0 or col > size - 1:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if direction == 0:
|
||||||
|
if row + size > size - 1:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
for i in range(row, row + size):
|
||||||
|
index = i * size + col
|
||||||
|
size[index] = '1'
|
||||||
|
|
||||||
|
|
||||||
|
def draw_field(window, field):
|
||||||
|
btn = Button(window, text=" ")
|
||||||
|
btn.grid(column=0, row=0)
|
||||||
|
btn1 = Button(window, text=" ", bg='pink')
|
||||||
|
btn1.grid(column=1, row=0)
|
||||||
|
btn2 = Button(window, text=" ")
|
||||||
|
btn2.grid(column=2, row=0)
|
||||||
|
|
||||||
|
|
||||||
|
window = Tk()
|
||||||
|
window.title("Ship Craft!")
|
||||||
|
window.geometry('800x400')
|
||||||
|
|
||||||
|
set_ship(my_field, 1, 1, 4, 1)
|
||||||
|
set_ship(1, 5, 3, 0)
|
||||||
|
|
||||||
|
draw_field(window, my_field)
|
||||||
|
|
||||||
|
window.mainloop()
|
Loading…
Reference in New Issue