diff --git a/.DS_Store b/.DS_Store
index 19e5e43..1b232ba 100644
Binary files a/.DS_Store and b/.DS_Store differ
diff --git a/HNS/.DS_Store b/HNS/.DS_Store
index e88d2b3..3175dc3 100644
Binary files a/HNS/.DS_Store and b/HNS/.DS_Store differ
diff --git a/HNS/Excercises/.DS_Store b/HNS/Excercises/.DS_Store
index f9f9bb9..979d852 100644
Binary files a/HNS/Excercises/.DS_Store and b/HNS/Excercises/.DS_Store differ
diff --git a/HNS/Excercises/ShipCraft/.DS_Store b/HNS/Excercises/ShipCraft/.DS_Store
new file mode 100644
index 0000000..07bf8be
Binary files /dev/null and b/HNS/Excercises/ShipCraft/.DS_Store differ
diff --git a/HNS/Excercises/ShipCraft/Переделка/.idea/misc.xml b/HNS/Excercises/ShipCraft/Переделка/.idea/misc.xml
index 94888fc..a6218fe 100644
--- a/HNS/Excercises/ShipCraft/Переделка/.idea/misc.xml
+++ b/HNS/Excercises/ShipCraft/Переделка/.idea/misc.xml
@@ -3,5 +3,5 @@
-
+
\ No newline at end of file
diff --git a/HNS/Excercises/ShipCraft/Переделка/.idea/workspace.xml b/HNS/Excercises/ShipCraft/Переделка/.idea/workspace.xml
index 6ed4e92..cb52cbc 100644
--- a/HNS/Excercises/ShipCraft/Переделка/.idea/workspace.xml
+++ b/HNS/Excercises/ShipCraft/Переделка/.idea/workspace.xml
@@ -5,12 +5,14 @@
-
-
+
+
+
+
+
+
-
-
-
+
@@ -46,11 +48,11 @@
"keyToString": {
"Python.ShipField.executor": "Run",
"Python.main (1).executor": "Run",
- "Python.main.executor": "Debug",
+ "Python.main.executor": "Run",
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"git-widget-placeholder": "main",
- "last_opened_file_path": "C:/Users/Eduardo/Documents/Программирование с Артуром/HNS/hnc-eduard/HNS/Excercises/ShipCraft"
+ "last_opened_file_path": "Z:/Documents/Обучение с Новым Кодом (Артур)/Git/hnc-eduard/HNS/Excercises/ShipCraft/Переделка"
}
}
@@ -124,9 +126,9 @@
-
+
-
+
@@ -150,7 +152,7 @@
-
+
@@ -165,6 +167,17 @@
+
+
+
@@ -174,7 +187,7 @@
file://$PROJECT_DIR$/main.py
- 129
+ 135
diff --git a/HNS/Excercises/ShipCraft/Переделка/.idea/Переделка.iml b/HNS/Excercises/ShipCraft/Переделка/.idea/Переделка.iml
index 8388dbc..d0876a7 100644
--- a/HNS/Excercises/ShipCraft/Переделка/.idea/Переделка.iml
+++ b/HNS/Excercises/ShipCraft/Переделка/.idea/Переделка.iml
@@ -2,7 +2,7 @@
-
+
\ No newline at end of file
diff --git a/HNS/Excercises/ShipCraft/Переделка/ShipView.py b/HNS/Excercises/ShipCraft/Переделка/ShipView.py
index e9a33cb..b3f1247 100644
--- a/HNS/Excercises/ShipCraft/Переделка/ShipView.py
+++ b/HNS/Excercises/ShipCraft/Переделка/ShipView.py
@@ -4,7 +4,9 @@ from tkinter import StringVar
class ShipView:
- def __init__(self, ship_field, buttons):
+ def __init__(self, ship_field, buttons, enemy):
self.ship_field = ship_field
self.buttons = buttons
self.remaining_ship_text = StringVar()
+ self.enemy = enemy
+ self.active = False
diff --git a/HNS/Excercises/ShipCraft/Переделка/__pycache__/GameMode.cpython-311.pyc b/HNS/Excercises/ShipCraft/Переделка/__pycache__/GameMode.cpython-311.pyc
index 2633edb..4d3f14e 100644
Binary files a/HNS/Excercises/ShipCraft/Переделка/__pycache__/GameMode.cpython-311.pyc and b/HNS/Excercises/ShipCraft/Переделка/__pycache__/GameMode.cpython-311.pyc differ
diff --git a/HNS/Excercises/ShipCraft/Переделка/__pycache__/ShipDirection.cpython-311.pyc b/HNS/Excercises/ShipCraft/Переделка/__pycache__/ShipDirection.cpython-311.pyc
index 44876d4..45fb80f 100644
Binary files a/HNS/Excercises/ShipCraft/Переделка/__pycache__/ShipDirection.cpython-311.pyc and b/HNS/Excercises/ShipCraft/Переделка/__pycache__/ShipDirection.cpython-311.pyc differ
diff --git a/HNS/Excercises/ShipCraft/Переделка/__pycache__/ShipField.cpython-311.pyc b/HNS/Excercises/ShipCraft/Переделка/__pycache__/ShipField.cpython-311.pyc
index e74b867..8c7daeb 100644
Binary files a/HNS/Excercises/ShipCraft/Переделка/__pycache__/ShipField.cpython-311.pyc and b/HNS/Excercises/ShipCraft/Переделка/__pycache__/ShipField.cpython-311.pyc differ
diff --git a/HNS/Excercises/ShipCraft/Переделка/__pycache__/ShipMode.cpython-311.pyc b/HNS/Excercises/ShipCraft/Переделка/__pycache__/ShipMode.cpython-311.pyc
index e7d1ce2..51e36d4 100644
Binary files a/HNS/Excercises/ShipCraft/Переделка/__pycache__/ShipMode.cpython-311.pyc and b/HNS/Excercises/ShipCraft/Переделка/__pycache__/ShipMode.cpython-311.pyc differ
diff --git a/HNS/Excercises/ShipCraft/Переделка/__pycache__/ShipView.cpython-311.pyc b/HNS/Excercises/ShipCraft/Переделка/__pycache__/ShipView.cpython-311.pyc
index f4a7be3..45adcd3 100644
Binary files a/HNS/Excercises/ShipCraft/Переделка/__pycache__/ShipView.cpython-311.pyc and b/HNS/Excercises/ShipCraft/Переделка/__pycache__/ShipView.cpython-311.pyc differ
diff --git a/HNS/Excercises/ShipCraft/Переделка/__pycache__/ShootResult.cpython-311.pyc b/HNS/Excercises/ShipCraft/Переделка/__pycache__/ShootResult.cpython-311.pyc
index 4a68bab..2ee7306 100644
Binary files a/HNS/Excercises/ShipCraft/Переделка/__pycache__/ShootResult.cpython-311.pyc and b/HNS/Excercises/ShipCraft/Переделка/__pycache__/ShootResult.cpython-311.pyc differ
diff --git a/HNS/Excercises/ShipCraft/Переделка/main.py b/HNS/Excercises/ShipCraft/Переделка/main.py
index 77d9d44..b080607 100644
--- a/HNS/Excercises/ShipCraft/Переделка/main.py
+++ b/HNS/Excercises/ShipCraft/Переделка/main.py
@@ -11,10 +11,10 @@ from GameMode import GameMode
active_view = {}
-def create_view(window):
+def create_view(window, enemy):
field = ShipField()
buttons = []
- view = ShipView(field, buttons)
+ view = ShipView(field, buttons, enemy)
for r in range(0, field.field_size):
for c in range(0, field.field_size):
btn = Button(window, text='', width=5, height=2)
@@ -43,7 +43,7 @@ def colorize(view):
field = view.ship_field
for i in range(len(field.field)):
bg = "white"
- if field[i] == "1":
+ if field[i] == "1" and not view.enemy:
bg = 'pink'
if field[i] == "\\":
bg = 'red'
@@ -51,7 +51,7 @@ def colorize(view):
bg = 'black'
if field[i] == "p":
bg = 'blue'
- if "+" in field[i]:
+ if "+" in field[i] and view.enemy:
bg = 'orange'
if "r" in field[i]:
bg = 'red'
@@ -61,9 +61,11 @@ def colorize(view):
def keypress_handler(e):
- global active_view
if e.keysym.isnumeric():
- active_view.ship_field.set_ship_size(e.keysym)
+ if my_view.active:
+ my_view.ship_field.set_ship_size(e.keysym)
+ elif enemy_view.active:
+ enemy_view.ship_field.set_ship_size(e.keysym)
def left_button_click(view, row, col):
@@ -77,15 +79,19 @@ def right_button_click(view):
def button_enter(view, row, col):
- global active_view
- active_view = view
- if view == my_view:
- enemy_view.ship_field.clear_marker()
- my_view.ship_field.target(row, col)
- elif view == enemy_view:
+ if view.enemy:
my_view.ship_field.clear_marker()
enemy_view.ship_field.target(row, col)
+ enemy_view.active = True
+ my_view.active = False
+ else:
+ enemy_view.ship_field.clear_marker()
+ my_view.ship_field.target(row, col)
+
+ enemy_view.active = False
+ my_view.active = True
+
colorize(my_view)
colorize(enemy_view)
@@ -99,13 +105,17 @@ def savebutton_click(view):
def loadbutton_click(view):
file_path = filedialog.askopenfilename(filetypes=[('JSON files', '*.json')])
+
+ load_field(view, file_path)
+
+
+def load_field(view, file_path):
if os.path.isfile(file_path):
with open(file_path) as lines:
view.ship_field.from_json(json.load(lines)['shipField'])
colorize(view)
-
def refresh_remaining_ships_label(view):
text = ''
for i in range(1, 5):
@@ -151,6 +161,9 @@ def update_game_mode():
elif game_mode == GameMode.PLAN:
window.geometry('1020x640')
+
+ load_field(view, file_path)
+
my_view.ship_field.set_field_mode(ShipMode.PUT)
enemy_view.ship_field.set_field_mode(ShipMode.INACTIVE)
@@ -223,9 +236,8 @@ row_horizontal_separator = start_row_my_field + ShipField.field_size
load_button_row = start_row_my_field + ShipField.field_size + 1
-my_view = create_view(window)
-enemy_view = create_view(window)
-active_view = my_view
+my_view = create_view(window, False)
+enemy_view = create_view(window, True)
lbl_left_vertical = Label(window, text='', width=5, height=2)
lbl_center_vertical = Label(window, text='', width=5, height=2)