diff --git a/HNS/Excercises/ShipCraft/Переделка/.idea/workspace.xml b/HNS/Excercises/ShipCraft/Переделка/.idea/workspace.xml new file mode 100644 index 0000000..8a9b710 --- /dev/null +++ b/HNS/Excercises/ShipCraft/Переделка/.idea/workspace.xml @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1715534761567 + + + + \ No newline at end of file diff --git a/HNS/Excercises/ShipCraft/Переделка/__pycache__/ShipModeDirection.cpython-311.pyc b/HNS/Excercises/ShipCraft/Переделка/__pycache__/ShipModeDirection.cpython-311.pyc deleted file mode 100644 index c6ffea0..0000000 Binary files a/HNS/Excercises/ShipCraft/Переделка/__pycache__/ShipModeDirection.cpython-311.pyc and /dev/null differ diff --git a/HNS/Excercises/ShipCraft/Переделка/__pycache__/test_ShipField.cpython-311.pyc b/HNS/Excercises/ShipCraft/Переделка/__pycache__/test_ShipField.cpython-311.pyc deleted file mode 100644 index f2c30bb..0000000 Binary files a/HNS/Excercises/ShipCraft/Переделка/__pycache__/test_ShipField.cpython-311.pyc and /dev/null differ diff --git a/HNS/Excercises/ShipCraft/Переделка/file_path b/HNS/Excercises/ShipCraft/Переделка/file_path index bdf64fb..60a44d5 100644 --- a/HNS/Excercises/ShipCraft/Переделка/file_path +++ b/HNS/Excercises/ShipCraft/Переделка/file_path @@ -1 +1 @@ -{"my_field": {"field": [" ", " ", " ", " ", " ", " ", "1", " ", " ", " ", " ", "1", "1", "1", "1", " ", "1", " ", " ", " ", " ", " ", " ", " ", " ", " ", "1", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "", " ", " ", " ", " ", " ", " ", " ", "", " ", "", "", "", "1", " ", " ", " ", " ", "", " ", " ", " ", " ", "", " ", " ", " ", " ", "", " ", "1", " ", "", "", " ", " ", " ", " ", "", " ", " ", " ", "", " ", " ", " ", " ", " ", " ", "p", "", "", " ", " ", " ", " ", " "], "ships": [3, 2, 2, 2, 1, 1], "field_size": 10, "field_mode": "PUT", "ship_size": 1, "ship_direction": "VERTICAL"}} \ No newline at end of file +{"shipField": {"field": [" ", " ", " ", " ", " ", " ", "1", " ", " ", " ", " ", "1", "1", "1", "1", " ", "1", " ", " ", " ", " ", " ", " ", " ", " ", " ", "1", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "1", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "p", ""], "ships": [3, 2, 2, 2, 1, 1, 1], "field_size": 10, "field_mode": "PUT", "ship_size": 1, "ship_direction": "VERTICAL"}} \ No newline at end of file diff --git a/HNS/Excercises/ShipCraft/Переделка/game1.json b/HNS/Excercises/ShipCraft/Переделка/game1.json deleted file mode 100644 index 9aaf6a2..0000000 --- a/HNS/Excercises/ShipCraft/Переделка/game1.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "my field": { - "field": [], - "ships": [], - "field_mode": "PUT" - } -} \ No newline at end of file diff --git a/HNS/Excercises/ShipCraft/Переделка/game1.txt b/HNS/Excercises/ShipCraft/Переделка/game1.txt deleted file mode 100644 index 8ebffb6..0000000 --- a/HNS/Excercises/ShipCraft/Переделка/game1.txt +++ /dev/null @@ -1,10 +0,0 @@ -0, 0, 1, 1, 1, 0, 0, 0, 0, 0, -0, 0, 0, 0, 0, 0, 0, 0, 0, \\, -0, 0, 0, 0, 0, 1, 0, 0, 0, \\, -0, 0, 0, 0, 0, 1, 0, 0, 0, \\, -0, 0, 0, 0, 0, 1, 0, 0, 0, 0, -0, 0, 0, 0, 0, 1, 0, 0, 0, 0, -0, 0, 0, 0, 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0, 0, 0, 1, 0, 0, 0, 0, 0, 0, -0, 0, 0, 0, 0, 0, 0, 0, 1, 0 \ No newline at end of file diff --git a/HNS/Excercises/ShipCraft/Переделка/main.py b/HNS/Excercises/ShipCraft/Переделка/main.py index 74005d2..6c2587d 100644 --- a/HNS/Excercises/ShipCraft/Переделка/main.py +++ b/HNS/Excercises/ShipCraft/Переделка/main.py @@ -83,22 +83,21 @@ def button_enter(buttons, row, col): colorize(enemy_field, enemy_buttons) -def savebutton_click(): - file_path = filedialog.asksaveasfilename(filetypes=[('JSON files', '*.json')]) +def savebutton_click(field): + file_path = filedialog.asksaveasfilename(filetypes=[("JSON files", "*.json")]) if file_path: - with open("file_path", 'w') as f: - json.dump({'my_field': my_field}, f, default=ShipField.convert_to_json) + with open("file_path", "w") as f: + json.dump({"shipField": field}, f, default=ShipField.convert_to_json) -def loadbutton_click(): - global my_field +def loadbutton_click(field, buttons): file_path = filedialog.askopenfilename(filetypes=[('JSON files', '*.json')]) if os.path.isfile(file_path): with open("file_path") as lines: - my_field.from_json(json.load(lines)['my_field']) + my_field.from_json(json.load(lines)['shipField']) - colorize(my_field, my_buttons) + colorize(field, buttons) def refresh_remaining_ships_label(): @@ -131,14 +130,20 @@ enemy_buttons = draw_field(window, enemy_field, 11) lbl = Label(window, text='', width=5, height=2) lbl.grid(column=10, row=0) -savebutton = Button(window, text='Save', width=20, height=2, command=savebutton_click) +savebutton = Button(window, text='Save', width=20, height=2, command=lambda: savebutton_click(my_field)) savebutton.grid(column=0, row=11, columnspan=4) -loadbutton = Button(window, text='Load', width=20, height=2, command=loadbutton_click) +loadbutton = Button(window, text='Load', width=20, height=2, command=lambda: loadbutton_click(my_field, my_buttons)) loadbutton.grid(column=5, row=11, columnspan=4) +savebutton_enemy = Button(window, text='Save_enemy', width=20, height=2, command=lambda: savebutton_click(enemy_field)) +savebutton_enemy.grid(column=11, row=11, columnspan=4) + +loadbutton_enemy = Button(window, text='Load_enemy', width=20, height=2, command=lambda: loadbutton_click(enemy_field, enemy_buttons)) +loadbutton_enemy.grid(column=16, row=11, columnspan=4) + remainingShipsText = StringVar() lbl = Label(window, width=50, height=2, textvariable=remainingShipsText) -lbl.grid(column=11, row=11, columnspan=10) +lbl.grid(column=1, row=13, columnspan=10) window.mainloop() diff --git a/HNS/Excercises/ShipCraft/Переделка/test.json b/HNS/Excercises/ShipCraft/Переделка/test.json deleted file mode 100644 index c748bd8..0000000 --- a/HNS/Excercises/ShipCraft/Переделка/test.json +++ /dev/null @@ -1 +0,0 @@ -{"my_field": {"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": 2, "ship_direction": "VERTICAL"}} \ No newline at end of file