загружаю дз до 34 мин 18 часть
This commit is contained in:
parent
d8ce3de627
commit
6322addc99
|
@ -25,9 +25,6 @@ def load (file):
|
|||
|
||||
# а - массив строк, в которых хранятся числа
|
||||
b = []
|
||||
for x in a:
|
||||
b.append(int(x))
|
||||
# b - массив чисел из а
|
||||
|
||||
f.close()
|
||||
return b
|
||||
return a
|
||||
|
|
|
@ -249,3 +249,9 @@ class ShipField:
|
|||
print(ship_string[:-2])
|
||||
# print(blocked_string[:-2] + ' ' + ship_string[:-2])
|
||||
print("********************************************************************")
|
||||
|
||||
@staticmethod
|
||||
def convert_to_json(obj):
|
||||
if isinstance(obj, ShipField):
|
||||
result = obj.__dict__
|
||||
return result
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"my field": {
|
||||
"field": [],
|
||||
"ships": [],
|
||||
"field_mode": "PUT"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
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
|
|
@ -1,7 +1,7 @@
|
|||
import json
|
||||
from tkinter import *
|
||||
from ShipField import ShipField
|
||||
|
||||
|
||||
my_field = ShipField()
|
||||
enemy_field = ShipField()
|
||||
|
||||
|
@ -79,9 +79,14 @@ def button_enter(buttons, row, col):
|
|||
colorize(enemy_field, enemy_buttons)
|
||||
|
||||
|
||||
def savebutton_click(event):
|
||||
with open("test.json", 'w') as f:
|
||||
json.dump({'shapes': my_field}, f, default=ShipField.convert_to_json)
|
||||
|
||||
|
||||
window = Tk()
|
||||
window.title("Ship Craft!")
|
||||
window.geometry('940x410')
|
||||
window.geometry('940x510')
|
||||
window.bind_all('<KeyPress>', keypress_handler)
|
||||
|
||||
my_field.toggle_ship_direction()
|
||||
|
@ -99,4 +104,8 @@ 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)
|
||||
savebutton.bind("<Button-1>", savebutton_click)
|
||||
savebutton.grid(column=0, row=11, columnspan=4)
|
||||
|
||||
window.mainloop()
|
|
@ -0,0 +1 @@
|
|||
{"shapes": {"field": [" ", " ", " ", " ", " ", " ", "1", " ", " ", " ", " ", "1", "1", "1", "1", " ", "1", " ", " ", " ", " ", " ", " ", " ", " ", " ", "1", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "", " ", " ", " ", "1", " ", " ", " ", "", "", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "p", "", " ", " ", " ", " ", " ", " "], "ships": [3, 2, 2, 2, 1, 1, 1], "field_size": 10, "field_mode": null, "ship_size": 1, "ship_direction": null}}
|
Loading…
Reference in New Issue