загружаю мейн с учетом проведенного урока 05022024
This commit is contained in:
parent
3cb6dc31e1
commit
23fd823e50
|
@ -1,19 +0,0 @@
|
||||||
import tkinter as tk
|
|
||||||
|
|
||||||
root = tk.Tk()
|
|
||||||
|
|
||||||
l1 = tk.Label(root, text='Col:8 Row:1', bg='red')
|
|
||||||
l1.grid(column=8, row=1)
|
|
||||||
|
|
||||||
l2 = tk.Label(root, text='Col:1 Row:8', bg='red')
|
|
||||||
l2.grid(column=1, row=8)
|
|
||||||
|
|
||||||
# add empty label in row 0 and column 0
|
|
||||||
l0 = tk.Label(root, text=' \n ', bg='green')
|
|
||||||
l0.grid(column=0, row=0)
|
|
||||||
|
|
||||||
# add empty label in row 9 and column 9
|
|
||||||
l9 = tk.Label(root, text=' ', bg='green')
|
|
||||||
l9.grid(column=9, row=9)
|
|
||||||
|
|
||||||
root.mainloop()
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
from main import ShootResult
|
||||||
|
|
||||||
|
|
||||||
|
class ShipField:
|
||||||
|
|
||||||
|
field = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
|
||||||
|
|
||||||
|
field_size = 10
|
||||||
|
field_mode = 0
|
||||||
|
ship_size = 4
|
||||||
|
ship_direction = 0
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def set_ship(self, row, col):
|
||||||
|
if row < 0 or row > self.field_size:
|
||||||
|
return
|
||||||
|
if col < 0 or col > self.field_size:
|
||||||
|
return
|
||||||
|
index = row * self.field_size + col
|
||||||
|
if self.ship_direction == 0:
|
||||||
|
if self.field_size - row < self.ship_size:
|
||||||
|
return
|
||||||
|
for r in range(row, row + self.ship_size):
|
||||||
|
index = r * self.field_size + col
|
||||||
|
self.field[index] = "1"
|
||||||
|
if self.ship_direction == 1:
|
||||||
|
if self.field_size - col < self.ship_size:
|
||||||
|
return
|
||||||
|
for c in range(col, col + self.ship_size):
|
||||||
|
index = row * self.field_size + c
|
||||||
|
self.field[index] = "1"
|
||||||
|
|
||||||
|
def shoot(self, row, col):
|
||||||
|
if row < 0 or row > self.field_size - 1:
|
||||||
|
return ShootResult.UNDEFINED
|
||||||
|
if col < 0 or col > self.field_size - 1:
|
||||||
|
return ShootResult.UNDEFINED
|
||||||
|
index = row * self.field_size + col
|
||||||
|
if (self.field[index]).strip() == "":
|
||||||
|
self.field[index] = "0"
|
||||||
|
return ShootResult.EMPTY
|
||||||
|
elif (self.field[index]).strip() == "1":
|
||||||
|
self.field[index] = "\\"
|
||||||
|
return ShootResult.DAMAGED
|
||||||
|
else:
|
||||||
|
return ShootResult.UNDEFINED
|
Loading…
Reference in New Issue