Compare commits

..

No commits in common. "60ae12717603b034d4884544f9b2cc96b39e8571" and "d51d6b9fd1009b5d2eec1276597e4b6e34e005b5" have entirely different histories.

10 changed files with 15 additions and 80 deletions

View File

@ -9,7 +9,7 @@ class ShipDirection(Enum):
@staticmethod
def from_string(raw_value):
if raw_value:
value = raw_value.upper()
value = raw_value.lower().capitalize()
if value in ShipDirection.__members__:
return ShipDirection[value]
return ShipDirection.UNKNOWN

View File

@ -28,16 +28,10 @@ class ShipField:
self.field = obj['field']
self.ships = obj['ships']
self.field_size = obj['field_size']
self.field_mode = ShipMode.from_string(obj['field_mode'])
self.field_mode = obj['field_mode']
self.ship_size = obj['ship_size']
<<<<<<< HEAD
self.ship_direction = ShipDirection.from_string(obj['ship_direction'])
=======
self.ship_direction = obj['ship_direction']
>>>>>>> d51d6b9fd1009b5d2eec1276597e4b6e34e005b5
def __getitem__(self, item):
if item is None:
return None
@ -83,10 +77,6 @@ class ShipField:
self.field[row * self.field_size + c] = "r"
else:
self.field[row * self.field_size + col] += "+"
<<<<<<< HEAD
=======
>>>>>>> d51d6b9fd1009b5d2eec1276597e4b6e34e005b5
def clear_marker(self):
for i in range(0, len(self.field)):
@ -96,7 +86,6 @@ class ShipField:
if "+" in self.field[i]:
self.field[i] = self.field[i].replace("+", "")
def set_ship(self, row, col):
if row < 0 or row > self.field_size:
return
@ -119,7 +108,6 @@ class ShipField:
if self.ship_size in self.ships:
self.ships.remove(self.ship_size)
def get_ship(self, row, col):
if row < 0 or row > self.field_size:
return

View File

@ -3,13 +3,3 @@ from enum import Enum
class ShipMode(Enum):
PUT = "PUT"
SHOOT = "SHOOT"
UNKNOWN = "UNKNOWN"
@staticmethod
def from_string(raw_value):
if raw_value:
value = raw_value.upper()
if value in ShipMode.__members__:
return ShipMode[value]
return ShipMode.UNKNOWN

View File

@ -1 +0,0 @@
{"enemy_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": 1, "ship_direction": "VERTICAL"}}

View File

@ -1,7 +1,4 @@
import json
import os
import time
from tkinter import filedialog
from tkinter import *
from ShipField import ShipField
@ -40,10 +37,7 @@ def colorize(field, buttons):
bg = 'red'
if "+" in field.field[i]:
bg = 'orange'
<<<<<<< HEAD
=======
>>>>>>> d51d6b9fd1009b5d2eec1276597e4b6e34e005b5
buttons[i].configure(bg=bg)
@ -85,46 +79,20 @@ def button_enter(buttons, row, col):
colorize(enemy_field, enemy_buttons)
def savebutton_click():
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)
def savebutton_click(event):
with open('test.json', 'w') as f:
json.dump({'my_field': my_field}, f, default=ShipField.convert_to_json)
def loadbutton_click():
def loadbutton_click(event):
global my_field
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"])
with open('test.json') as lines:
my_field.from_json(json.load(lines)["my_field"])
colorize(my_field, my_buttons)
def savebutton_click_enemy():
file_path = filedialog.asksaveasfilename(filetypes=[("JSON files", "*.json")])
if file_path:
with open(file_path, 'w') as f:
json.dump({'enemy_field': enemy_field}, f, default=ShipField.convert_to_json)
def loadbutton_click_enemy():
global enemy_field
file_path = filedialog.askopenfilename(filetypes=[("JSON files", "*.json")])
if os.path.isfile(file_path):
with open(file_path) as lines:
enemy_field.from_json(json.load(lines)["enemy_field"])
colorize(enemy_field, enemy_buttons)
window = Tk()
window.title("Ship Craft!")
window.geometry('940x510')
@ -136,21 +104,12 @@ 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)
savebutton.bind('<Button-1>', savebutton_click)
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)
loadbutton.bind('<Button-1>', loadbutton_click)
loadbutton.grid(column=5, row=11, columnspan=4)
<<<<<<< HEAD
savebutton_enemy = Button(window, text='Save_enemy', width=20, height=2, command=savebutton_click_enemy)
savebutton_enemy.grid(column=11, row=11, columnspan=4)
loadbutton_enemy = Button(window, text='Load_enemy', width=20, height=2, command=loadbutton_click_enemy)
loadbutton_enemy.grid(column=16, row=11, columnspan=4)
window.mainloop()
=======
window.mainloop()
>>>>>>> d51d6b9fd1009b5d2eec1276597e4b6e34e005b5

View File

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

View File

@ -1 +1 @@
{"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": 4, "ship_direction": "VERTICAL"}}
{"my_field": {"field": ["1", "", "", " ", " ", "1", "1", "1", " ", "1", " ", " ", " ", "", " ", " ", "", "", " ", "1", " ", "1", "", "", "", " ", "", "1", "", "", " ", "1", "", "", "", "", "", "", "", "", " ", "1", "", "", "", "1", "", "", "", "", " ", "1", "", "", "", "1", "", "", "", "", "", "", "", "", "", "", "", "", "1", "", "", "", "", "", "", "", "", "", "", "", "1", "", "1", "", "r", " ", " ", " ", " ", " ", "1", " ", "", " ", " ", " ", " ", "1", "1", "1"], "ships": [], "field_size": 10, "field_mode": "PUT", "ship_size": 1, "ship_direction": "VERTICAL"}}