доработан код по 22 видео

This commit is contained in:
ehermakov 2024-06-03 16:08:40 +03:00
parent 1b16b99650
commit a2bc915a4a
16 changed files with 101 additions and 76 deletions

View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Переделка.iml" filepath="$PROJECT_DIR$/.idea/Переделка.iml" />
</modules>
</component>
</project>

View File

@ -4,7 +4,7 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="b389cdea-22f5-4ba2-8b46-337091984b3c" name="Changes" comment=""> <list default="true" id="b389cdea-22f5-4ba2-8b46-337091984b3c" name="Changes" comment="код по 22 части урока">
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ShipView.py" beforeDir="false" afterPath="$PROJECT_DIR$/ShipView.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/ShipView.py" beforeDir="false" afterPath="$PROJECT_DIR$/ShipView.py" afterDir="false" />
@ -27,6 +27,9 @@
<component name="HighlightingSettingsPerFile"> <component name="HighlightingSettingsPerFile">
<setting file="file://$PROJECT_DIR$/main.py" root0="SKIP_INSPECTION" /> <setting file="file://$PROJECT_DIR$/main.py" root0="SKIP_INSPECTION" />
</component> </component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectColorInfo">{ <component name="ProjectColorInfo">{
&quot;associatedIndex&quot;: 0 &quot;associatedIndex&quot;: 0
}</component> }</component>
@ -35,20 +38,20 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent">{ <component name="PropertiesComponent"><![CDATA[{
&quot;keyToString&quot;: { "keyToString": {
&quot;Python.ShipField.executor&quot;: &quot;Run&quot;, "Python.ShipField.executor": "Run",
&quot;Python.main (1).executor&quot;: &quot;Run&quot;, "Python.main (1).executor": "Run",
&quot;Python.main.executor&quot;: &quot;Debug&quot;, "Python.main.executor": "Debug",
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, "RunOnceActivity.OpenProjectViewOnStart": "true",
&quot;git-widget-placeholder&quot;: &quot;main&quot;, "RunOnceActivity.ShowReadmeOnStart": "true",
&quot;last_opened_file_path&quot;: &quot;C:/Users/Eduardo/Documents/Программирование с Артуром/HNS/hnc-eduard/HNS/Excercises/ShipCraft/Переделка&quot; "git-widget-placeholder": "main",
"last_opened_file_path": "Y:/Downloads/временный гит/hnc-eduard/HNS/Excercises/ShipCraft/Переделка"
} }
}</component> }]]></component>
<component name="RunManager" selected="Python.main"> <component name="RunManager" selected="Python.main">
<configuration name="ShipField" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true"> <configuration name="ShipField" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="Переделка" /> <module name="Переделка" />
<option name="ENV_FILES" value="" />
<option name="INTERPRETER_OPTIONS" value="" /> <option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" /> <option name="PARENT_ENVS" value="true" />
<envs> <envs>
@ -70,7 +73,6 @@
</configuration> </configuration>
<configuration name="ShipView" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true"> <configuration name="ShipView" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="Переделка" /> <module name="Переделка" />
<option name="ENV_FILES" value="" />
<option name="INTERPRETER_OPTIONS" value="" /> <option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" /> <option name="PARENT_ENVS" value="true" />
<envs> <envs>
@ -92,7 +94,6 @@
</configuration> </configuration>
<configuration name="main (1)" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true"> <configuration name="main (1)" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="Переделка" /> <module name="Переделка" />
<option name="ENV_FILES" value="" />
<option name="INTERPRETER_OPTIONS" value="" /> <option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" /> <option name="PARENT_ENVS" value="true" />
<envs> <envs>
@ -114,7 +115,6 @@
</configuration> </configuration>
<configuration name="main" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true"> <configuration name="main" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="Переделка" /> <module name="Переделка" />
<option name="ENV_FILES" value="" />
<option name="INTERPRETER_OPTIONS" value="" /> <option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" /> <option name="PARENT_ENVS" value="true" />
<envs> <envs>
@ -161,12 +161,16 @@
</task> </task>
<servers /> <servers />
</component> </component>
<component name="VcsManagerConfiguration">
<MESSAGE value="код по 22 части урока" />
<option name="LAST_COMMIT_MESSAGE" value="код по 22 части урока" />
</component>
<component name="XDebuggerManager"> <component name="XDebuggerManager">
<breakpoint-manager> <breakpoint-manager>
<breakpoints> <breakpoints>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line"> <line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/main.py</url> <url>file://$PROJECT_DIR$/main.py</url>
<line>139</line> <line>136</line>
<option name="timeStamp" value="1" /> <option name="timeStamp" value="1" />
</line-breakpoint> </line-breakpoint>
</breakpoints> </breakpoints>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1 @@
{"shipField": {"field": [" ", " ", " ", "", " ", " ", " ", "", "", "1", "", "1", "1", "", "1", "1", " ", "", "", "1", "", "", "", "", "", "", " ", "", "", "1", "", "", "", "", "1", "1", " ", "", "", "1", "1", "1", "1", "", "", "", " ", " ", " ", "", "", "", "", "", "", "1", "1", "1", " ", " ", "", "", "", "", "", " ", " ", " ", " ", " ", "", "1", "", "1", "", "1", " ", "", "1", " ", " ", "", "", "", "", "", " ", " ", " ", " ", " ", " ", " ", "", "", "", "", " ", " ", " "], "ships": [], "field_size": 10, "field_mode": "PUT", "ship_size": 4, "ship_direction": "VERTICAL"}}

View File

@ -6,6 +6,7 @@ from ShipMode import ShipMode
class ShipField: class ShipField:
field_size = 10
def __init__(self): def __init__(self):
self.field = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', self.field = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
@ -20,7 +21,6 @@ class ShipField:
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '] ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
self.ships = [4, 3, 3, 2, 2, 2, 1, 1, 1, 1] self.ships = [4, 3, 3, 2, 2, 2, 1, 1, 1, 1]
self.field_size = 10
self.field_mode = ShipMode.PUT self.field_mode = ShipMode.PUT
self.ship_size = 4 self.ship_size = 4
self.ship_direction = ShipDirection.VERTICAL self.ship_direction = ShipDirection.VERTICAL
@ -28,7 +28,7 @@ class ShipField:
def from_json(self, obj): def from_json(self, obj):
self.field = obj['field'] self.field = obj['field']
self.ships = obj['ships'] self.ships = obj['ships']
self.field_size = obj['field_size'] ShipField.field_size = obj['field_size']
self.field_mode = ShipMode.from_string(obj['field_mode']) self.field_mode = ShipMode.from_string(obj['field_mode'])
self.ship_size = obj['ship_size'] self.ship_size = obj['ship_size']
self.ship_direction = ShipDirection.from_string(obj['ship_direction']) self.ship_direction = ShipDirection.from_string(obj['ship_direction'])
@ -66,18 +66,18 @@ class ShipField:
if self.ship_direction == ShipDirection.VERTICAL: if self.ship_direction == ShipDirection.VERTICAL:
for r in range(row, row + self.ship_size): for r in range(row, row + self.ship_size):
if self.ship_size in self.ships: if self.ship_size in self.ships:
self.field[r * self.field_size + col] = "p" self.field[r * ShipField.field_size + col] = "p"
else: else:
self.field[r * self.field_size + col] = "r" self.field[r * ShipField.field_size + col] = "r"
if self.ship_direction == ShipDirection.HORIZONTAL: if self.ship_direction == ShipDirection.HORIZONTAL:
for c in range(col, col + self.ship_size): for c in range(col, col + self.ship_size):
if self.ship_size in self.ships: if self.ship_size in self.ships:
self.field[row * self.field_size + c] = "p" self.field[row * ShipField.field_size + c] = "p"
else: else:
self.field[row * self.field_size + c] = "r" self.field[row * ShipField.field_size + c] = "r"
else: else:
self.field[row * self.field_size + col] += "+" self.field[row * ShipField.field_size + col] += "+"
def clear_marker(self): def clear_marker(self):
for i in range(0, len(self.field)): for i in range(0, len(self.field)):
@ -88,22 +88,22 @@ class ShipField:
self.field[i] = self.field[i].replace("+", "") self.field[i] = self.field[i].replace("+", "")
def set_ship(self, row, col): def set_ship(self, row, col):
if row < 0 or row > self.field_size: if row < 0 or row > ShipField.field_size:
return return
if col < 0 or col > self.field_size: if col < 0 or col > ShipField.field_size:
return return
index = row * self.field_size + col index = row * ShipField.field_size + col
if self.ship_direction == ShipDirection.VERTICAL: if self.ship_direction == ShipDirection.VERTICAL:
if self.field_size - row < self.ship_size: if ShipField.field_size - row < self.ship_size:
return return
for r in range(row, row + self.ship_size): for r in range(row, row + self.ship_size):
index = r * self.field_size + col index = r * ShipField.field_size + col
self.field[index] = "1" self.field[index] = "1"
if self.ship_direction == ShipDirection.HORIZONTAL: if self.ship_direction == ShipDirection.HORIZONTAL:
if self.field_size - col < self.ship_size: if ShipField.field_size - col < self.ship_size:
return return
for c in range(col, col + self.ship_size): for c in range(col, col + self.ship_size):
index = row * self.field_size + c index = row * ShipField.field_size + c
self.field[index] = "1" self.field[index] = "1"
if self.ship_size in self.ships: if self.ship_size in self.ships:
@ -111,22 +111,22 @@ class ShipField:
self.print_field() self.print_field()
def get_ship(self, row, col): def get_ship(self, row, col):
if row < 0 or row > self.field_size: if row < 0 or row > ShipField.field_size:
return return
if col < 0 or col > self.field_size: if col < 0 or col > ShipField.field_size:
return return
self.field[row * self.field_size + col] = "" self.field[row * ShipField.field_size + col] = ""
ship_size = 1 ship_size = 1
ship_direction = ShipDirection.UNKNOWN ship_direction = ShipDirection.UNKNOWN
# проверим вертикаль # проверим вертикаль
for r in range(row + 1, self.field_size): for r in range(row + 1, ShipField.field_size):
if self.check_ship(r, col): if self.check_ship(r, col):
ship_size += 1 ship_size += 1
ship_direction = ShipDirection.VERTICAL ship_direction = ShipDirection.VERTICAL
self.field[r * self.field_size + col] = "" self.field[r * ShipField.field_size + col] = ""
else: else:
break break
@ -134,18 +134,18 @@ class ShipField:
if self.check_ship(r, col): if self.check_ship(r, col):
ship_size += 1 ship_size += 1
ship_direction = ShipDirection.VERTICAL ship_direction = ShipDirection.VERTICAL
self.field[row * self.field_size + col] = "" self.field[row * ShipField.field_size + col] = ""
else: else:
break break
if ship_direction == ShipDirection.UNKNOWN: if ship_direction == ShipDirection.UNKNOWN:
# проверим горизонталь # проверим горизонталь
for c in range(col + 1, self.field_size): for c in range(col + 1, ShipField.field_size):
if self.check_ship(row, c): if self.check_ship(row, c):
ship_size += 1 ship_size += 1
ship_direction = ShipDirection.HORIZONTAL ship_direction = ShipDirection.HORIZONTAL
self.field[row * self.field_size + c] = "" self.field[row * ShipField.field_size + c] = ""
else: else:
break break
@ -153,7 +153,7 @@ class ShipField:
if self.check_ship(row, c): if self.check_ship(row, c):
ship_size += 1 ship_size += 1
ship_direction = ShipDirection.HORIZONTAL ship_direction = ShipDirection.HORIZONTAL
self.field[row * self.field_size + c] = "" self.field[row * ShipField.field_size + c] = ""
else: else:
break break
self.set_ship_direction(ship_direction) self.set_ship_direction(ship_direction)
@ -161,11 +161,11 @@ class ShipField:
self.ships.append(ship_size) self.ships.append(ship_size)
def shoot(self, row, col): def shoot(self, row, col):
if row < 0 or row > self.field_size - 1: if row < 0 or row > ShipField.field_size - 1:
return ShootResult.UNDEFINED return ShootResult.UNDEFINED
if col < 0 or col > self.field_size - 1: if col < 0 or col > ShipField.field_size - 1:
return ShootResult.UNDEFINED return ShootResult.UNDEFINED
index = row * self.field_size + col index = row * ShipField.field_size + col
if (self.field[index]).strip() == "": if (self.field[index]).strip() == "":
self.field[index] = "0" self.field[index] = "0"
return ShootResult.EMPTY return ShootResult.EMPTY
@ -178,14 +178,14 @@ class ShipField:
def check_ship(self, row, col): def check_ship(self, row, col):
# функция должна возвражать тру, если в заданной клетке есть корабль # функция должна возвражать тру, если в заданной клетке есть корабль
# в противном случае фолс # в противном случае фолс
return self.field[row * self.field_size + col].strip() == "1" return self.field[row * ShipField.field_size + col].strip() == "1"
def check_possible(self, row, col): def check_possible(self, row, col):
# Функция должна возвращать True, если можно поставить сюда корабль, # Функция должна возвращать True, если можно поставить сюда корабль,
# в противном случае - False # в противном случае - False
if self.ship_direction == ShipDirection.VERTICAL: if self.ship_direction == ShipDirection.VERTICAL:
# Здесь мы знаем, что корабль помещается на поле. # Здесь мы знаем, что корабль помещается на поле.
if self.field_size - row >= self.ship_size: if ShipField.field_size - row >= self.ship_size:
# Теперь нужно проверить, не заблокировано ли какое-то из полей, # Теперь нужно проверить, не заблокировано ли какое-то из полей,
for r in range(row, row + self.ship_size): for r in range(row, row + self.ship_size):
if not self.check_blocked(r, col): if not self.check_blocked(r, col):
@ -193,7 +193,7 @@ class ShipField:
return True return True
if self.ship_direction == ShipDirection.HORIZONTAL: if self.ship_direction == ShipDirection.HORIZONTAL:
if self.field_size - col >= self.ship_size: if ShipField.field_size - col >= self.ship_size:
for c in range(col, col + self.ship_size): for c in range(col, col + self.ship_size):
if not self.check_blocked(row, c): if not self.check_blocked(row, c):
return False return False
@ -206,8 +206,8 @@ class ShipField:
# либо находятся за пределами поля, либо в них нет корабля/они пустые # либо находятся за пределами поля, либо в них нет корабля/они пустые
for r in range(row - 1, row + 2): for r in range(row - 1, row + 2):
for c in range(col - 1, col + 2): for c in range(col - 1, col + 2):
if 0 <= r < self.field_size and 0 <= c < self.field_size: if 0 <= r < ShipField.field_size and 0 <= c < ShipField.field_size:
cell = (self.field[r * self.field_size + c]).strip() cell = (self.field[r * ShipField.field_size + c]).strip()
if cell != '' and cell != 'p': if cell != '' and cell != 'p':
return False return False
return True return True
@ -246,12 +246,12 @@ class ShipField:
def print_field(self): def print_field(self):
print(self.ships) print(self.ships)
for r in range(0, self.field_size): for r in range(0, ShipField.field_size):
blocked_string = "" blocked_string = ""
ship_string = "" ship_string = ""
for c in range(0, self.field_size): for c in range(0, ShipField.field_size):
blocked_string += str(self.check_blocked(r, c))[0] + ", " blocked_string += str(self.check_blocked(r, c))[0] + ", "
ship_string += self.field[r * self.field_size + c] + ', ' ship_string += self.field[r * ShipField.field_size + c] + ', '
print(ship_string[:-2]) print(ship_string[:-2])
# print(blocked_string[:-2] + ' ' + ship_string[:-2]) # print(blocked_string[:-2] + ' ' + ship_string[:-2])
print("********************************************************************") print("********************************************************************")

View File

@ -0,0 +1 @@
{"shipField": {"field": [" ", " ", "1", " ", " ", " ", " ", " ", " ", "1", "1", " ", " ", " ", " ", "1", "1", "1", " ", " ", "", " ", "1", " ", " ", "", "", "", " ", " ", "", "", "1", " ", "", "", "", "", "", "", "", "", "1", " ", "", "1", "1", "1", "", " ", "", "", "1", " ", " ", "", "", "", " ", "", "", "", "", " ", "1", "", "", " ", " ", "", "", "", " ", " ", "1", "", "1", "1", " ", " ", "", "1", "1", " ", "", "", " ", " ", " ", " ", " ", " ", " ", " ", "", " ", " ", " ", "1", " "], "ships": [], "field_size": 10, "field_mode": "PUT", "ship_size": 1, "ship_direction": "VERTICAL"}}

View File

@ -0,0 +1 @@
{"shipField": {"field": ["1", "", "", "", " ", " ", "1", " ", "1", " ", "1", "", "", "", " ", " ", " ", " ", " ", " ", "1", "", "", "1", "", "", "1", " ", "", " ", "1", "", "", "1", "", "", "1", " ", "", " ", " ", " ", "", "1", "", "", "1", " ", "", " ", " ", "1", " ", "", "", " ", " ", " ", "1", "", " ", " ", " ", "", "", "", "", "", "", "", " ", "1", "", "1", "1", "", "", "", "", "", " ", "1", "", "", " ", " ", " ", "", "", "", " ", " ", " ", " ", " ", "", "1", "1", "", ""], "ships": [], "field_size": 10, "field_mode": "PUT", "ship_size": 1, "ship_direction": "VERTICAL"}}

View File

@ -0,0 +1 @@
{"shipField": {"field": ["1", "", "", "", " ", " ", "1", " ", "1", " ", "1", "", "", "", " ", " ", " ", " ", " ", " ", "1", "", "", "1", "", "", "1", " ", "", " ", "1", "", "", "1", "", "", "1", " ", "", " ", " ", " ", "", "1", "", "", "1", " ", "", " ", " ", "1", " ", "", "", " ", " ", " ", "1", "", " ", " ", " ", "", "", "", "", "", "", "", " ", "1", "", "1", "1", "", "", "", "", "", " ", "1", "", "", " ", " ", " ", "", "", "", " ", " ", " ", " ", " ", "", "1", "1", "", ""], "ships": [], "field_size": 10, "field_mode": "PUT", "ship_size": 1, "ship_direction": "VERTICAL"}}

View File

@ -0,0 +1 @@
{"shipField": {"field": [" ", " ", "1", " ", " ", " ", " ", " ", " ", "1", "1", " ", " ", " ", " ", "1", "1", "1", " ", " ", "", " ", "1", " ", " ", "", "", "", " ", " ", "", "", "1", " ", "", "", "", "", "", "", "", "", "1", " ", "", "1", "1", "1", "", " ", "", "", "1", " ", " ", "", "", "", " ", "", "", "", "", " ", "1", "", "", " ", " ", "", "", "", " ", " ", "1", "", "1", "1", " ", " ", "", "1", "1", " ", "", "", " ", " ", " ", " ", " ", " ", " ", " ", "", " ", " ", " ", "1", " "], "ships": [], "field_size": 10, "field_mode": "PUT", "ship_size": 1, "ship_direction": "VERTICAL"}}

View File

@ -11,15 +11,16 @@ active_view ={}
def create_view(window, col_offset=0, row_offset=0): def create_view(window, col_offset=0, row_offset=0):
field = ShipField() field = ShipField()
buttons = [] buttons = []
view = ShipView(field, buttons)
for r in range(0, field.field_size): for r in range(0, field.field_size):
for c in range(0, field.field_size): for c in range(0, field.field_size):
btn = Button(window, text='', width=5, height=2) btn = Button(window, text='', width=5, height=2)
btn.grid(column=c + col_offset, row=r + row_offset) btn.grid(column=c + col_offset, row=r + row_offset)
btn.bind('<Button-1>', lambda e, x=r, y=c: left_button_click(x, y)) btn.bind('<Button-1>', lambda e, x=r, y=c: left_button_click(view, x, y))
btn.bind('<Button-3>', right_button_click) btn.bind('<Button-3>', lambda e: right_button_click(view))
btn.bind('<Enter>', lambda e, x=r, y=c: button_enter(buttons, x, y)) btn.bind('<Enter>', lambda e, x=r, y=c: button_enter(view, x, y))
buttons.append(btn) buttons.append(btn)
view = ShipView(field, buttons)
colorize(view) colorize(view)
return view return view
@ -42,6 +43,8 @@ def colorize(view):
bg = 'red' bg = 'red'
view.buttons[i].configure(bg=bg) view.buttons[i].configure(bg=bg)
refresh_remaining_ships_label(view)
def keypress_handler(e): def keypress_handler(e):
global active_view global active_view
@ -52,28 +55,22 @@ def keypress_handler(e):
active_view.ship_field.toggle_field_mode() active_view.ship_field.toggle_field_mode()
def left_button_click(row, col): def left_button_click(view, row, col):
view.ship_field.action(row, col)
colorize(view)
def right_button_click(view):
view.ship_field.toggle_ship_direction()
colorize(view)
def button_enter(view, row, col):
global active_view global active_view
active_view = view
active_view.ship_field.action(row, col) if view == my_view:
colorize(active_view)
refresh_remaining_ships_label(active_view)
def right_button_click(unused):
global active_view
active_view.ship_field.toggle_ship_direction()
def button_enter(buttons, row, col):
global active_view
if buttons == my_view.buttons:
active_view = my_view
enemy_view.ship_field.clear_marker() enemy_view.ship_field.clear_marker()
my_view.ship_field.target(row, col) my_view.ship_field.target(row, col)
elif view == enemy_view:
elif buttons == enemy_view.buttons:
active_view = enemy_view
my_view.ship_field.clear_marker() my_view.ship_field.clear_marker()
enemy_view.ship_field.target(row, col) enemy_view.ship_field.target(row, col)
@ -115,13 +112,13 @@ window.bind_all('<KeyPress>', keypress_handler)
start_column_my_field = 1 start_column_my_field = 1
start_row_my_field = 1 start_row_my_field = 1
start_column_enemy_field = start_column_my_field + 10 + 1 start_column_enemy_field = start_column_my_field + ShipField.field_size + 1
start_row_enemy_field = start_row_my_field start_row_enemy_field = start_row_my_field
col_vertical_separator = start_column_my_field + 10 col_vertical_separator = start_column_my_field + ShipField.field_size
row_horizontal_separator = start_row_my_field + 10 row_horizontal_separator = start_row_my_field + ShipField.field_size
load_button_row = start_row_my_field + 10 + 1 load_button_row = start_row_my_field + ShipField.field_size + 1
my_view = create_view(window, start_column_my_field, start_row_my_field) my_view = create_view(window, start_column_my_field, start_row_my_field)
enemy_view = create_view(window, start_column_enemy_field, start_row_enemy_field) enemy_view = create_view(window, start_column_enemy_field, start_row_enemy_field)