Merge remote-tracking branch 'origin/main'
This commit is contained in:
parent
201f58a58f
commit
34b594ac28
|
@ -1 +1 @@
|
|||
main4.py
|
||||
main (4).py
|
|
@ -1,5 +1,7 @@
|
|||
from tkinter import *
|
||||
from enum import Enum
|
||||
|
||||
field_size = 10
|
||||
empty_field = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||
|
@ -38,33 +40,52 @@ step2_field = [' ', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ',
|
|||
my_field = list(empty_field)
|
||||
enemy_field = list(empty_field)
|
||||
|
||||
buttons = []
|
||||
|
||||
class ShootResult(Enum):
|
||||
Enum = 0
|
||||
Damaged = '\\'
|
||||
Killed = X
|
||||
Underfined = 'undefined'
|
||||
|
||||
|
||||
def set_ship(field, row, col, size, direction):
|
||||
# size - 1, 2, 3, 4
|
||||
# direction - вниз(0), вправо(1)
|
||||
if row < 0 or row > size - 1:
|
||||
if row < 0 or row > field_size - 1:
|
||||
return
|
||||
if col < 0 or col > field_size - 1:
|
||||
return
|
||||
if col < 0 or col > size - 1:
|
||||
return 0
|
||||
|
||||
if direction == 0:
|
||||
if row + size > size - 1:
|
||||
return 0
|
||||
if row + size > field_size - 1:
|
||||
return
|
||||
|
||||
for i in range(row, row + size):
|
||||
index = i * size + col
|
||||
size[index] = '1'
|
||||
for r in range(row, row + size):
|
||||
index = r * field_size + col
|
||||
field[index] = '1'
|
||||
|
||||
if direction == 1:
|
||||
if col + size > field_size - 1:
|
||||
return
|
||||
for c in range(col, col + size):
|
||||
index = c * field_size + row
|
||||
field[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)
|
||||
def draw_field(field):
|
||||
for r in range(0, field_size):
|
||||
for c in range(0, field_size):
|
||||
bg = 'white'
|
||||
if field[index] == '1':
|
||||
bg = 'ping'
|
||||
elif field[index] == '\\':
|
||||
bg = 'red'
|
||||
elif field[index] == '0':
|
||||
bg = 'black'
|
||||
btn.configupe(bg=bg)
|
||||
|
||||
|
||||
def button_action(field, row, col):
|
||||
shoot(field, row, col)
|
||||
colorize(field)
|
||||
|
||||
|
||||
window = Tk()
|
||||
|
@ -72,8 +93,8 @@ 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)
|
||||
|
||||
draw_field(field_size)
|
||||
|
||||
window.mainloop()
|
||||
|
|
Loading…
Reference in New Issue