небольшие изменения

This commit is contained in:
eduard ermakov 2024-06-10 23:08:50 +03:00
parent 5e0cf283d6
commit 1cc445bec8
14 changed files with 53 additions and 27 deletions

View File

@ -3,5 +3,5 @@
<component name="Black"> <component name="Black">
<option name="sdkName" value="Python 3.11" /> <option name="sdkName" value="Python 3.11" />
</component> </component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11" project-jdk-type="Python SDK" /> <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
</project> </project>

View File

@ -4,7 +4,15 @@
<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="код по 22 части урока" /> <list default="true" id="b389cdea-22f5-4ba2-8b46-337091984b3c" name="Changes" comment="код по 22 части урока">
<change afterPath="$PROJECT_DIR$/GameMode.py" 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/Переделка.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/Переделка.iml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ShipField.py" beforeDir="false" afterPath="$PROJECT_DIR$/ShipField.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ShipMode.py" beforeDir="false" afterPath="$PROJECT_DIR$/ShipMode.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@ -34,21 +42,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"><![CDATA[{ <component name="PropertiesComponent">{
"keyToString": { &quot;keyToString&quot;: {
"Python.ShipField.executor": "Run", &quot;Python.ShipField.executor&quot;: &quot;Run&quot;,
"Python.main (1).executor": "Run", &quot;Python.main (1).executor&quot;: &quot;Run&quot;,
"Python.main.executor": "Debug", &quot;Python.main.executor&quot;: &quot;Debug&quot;,
"RunOnceActivity.OpenProjectViewOnStart": "true", &quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
"RunOnceActivity.ShowReadmeOnStart": "true", &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
"git-widget-placeholder": "main", &quot;git-widget-placeholder&quot;: &quot;main&quot;,
"last_opened_file_path": "C:/Users/Eduardo/Documents/Программирование с Артуром/HNS/hnc-eduard/HNS/Excercises/ShipCraft" &quot;last_opened_file_path&quot;: &quot;C:/Users/Eduardo/Documents/Программирование с Артуром/HNS/hnc-eduard/HNS/Excercises/ShipCraft&quot;
} }
}]]></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 +77,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 +98,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 +119,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>
@ -170,7 +174,7 @@
<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>133</line> <line>129</line>
<option name="timeStamp" value="1" /> <option name="timeStamp" value="1" />
</line-breakpoint> </line-breakpoint>
</breakpoints> </breakpoints>

View File

@ -2,7 +2,7 @@
<module type="PYTHON_MODULE" version="4"> <module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager"> <component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" /> <content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" /> <orderEntry type="jdk" jdkName="Python 3.9" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
</module> </module>

View File

@ -0,0 +1,16 @@
from enum import Enum
class GameMode(Enum):
MENU = 'MENU'
PLAN = 'PLAN'
BATTLE = 'BATTLE'
END = 'END'
@staticmethod
def from_string(raw_value):
if raw_value:
value = raw_value.upper()
if value in GameMode.__members__:
return GameMode[value]
return GameMode.MENU

View File

@ -21,7 +21,7 @@ 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_mode = ShipMode.PUT self.field_mode = ShipMode.INACTIVE
self.ship_size = 4 self.ship_size = 4
self.ship_direction = ShipDirection.VERTICAL self.ship_direction = ShipDirection.VERTICAL
@ -76,7 +76,7 @@ class ShipField:
self.field[row * ShipField.field_size + c] = "p" self.field[row * ShipField.field_size + c] = "p"
else: else:
self.field[row * ShipField.field_size + c] = "r" self.field[row * ShipField.field_size + c] = "r"
else: elif self.field_mode == ShipMode.SHOOT:
self.field[row * ShipField.field_size + col] += "+" self.field[row * ShipField.field_size + col] += "+"
def clear_marker(self): def clear_marker(self):

View File

@ -4,7 +4,7 @@ from enum import Enum
class ShipMode(Enum): class ShipMode(Enum):
PUT = 'PUT' PUT = 'PUT'
SHOOT = 'SHOOT' SHOOT = 'SHOOT'
UNKNOWN = 'UNKNOWN' INACTIVE = 'INACTIVE'
@staticmethod @staticmethod
def from_string(raw_value): def from_string(raw_value):
@ -12,6 +12,6 @@ class ShipMode(Enum):
value = raw_value.upper() value = raw_value.upper()
if value in ShipMode.__members__: if value in ShipMode.__members__:
return ShipMode[value] return ShipMode[value]
return ShipMode.UNKNOWN return ShipMode.INACTIVE

View File

@ -5,7 +5,9 @@ from tkinter import *
from tkinter import filedialog from tkinter import filedialog
from ShipView import ShipView from ShipView import ShipView
from ShipField import ShipField from ShipField import ShipField
from GameMode import GameMode
game_mode = GameMode.MENU
active_view ={} active_view ={}
def create_view(window, col_offset=0, row_offset=0): def create_view(window, col_offset=0, row_offset=0):
@ -50,9 +52,6 @@ def keypress_handler(e):
global active_view global active_view
if e.keysym.isnumeric(): if e.keysym.isnumeric():
active_view.ship_field.set_ship_size(e.keysym) active_view.ship_field.set_ship_size(e.keysym)
else:
if e.keysym == 'm':
active_view.ship_field.toggle_field_mode()
def left_button_click(view, row, col): def left_button_click(view, row, col):
@ -106,7 +105,7 @@ def refresh_remaining_ships_label(view):
window = Tk() window = Tk()
window.title("Ship Craft!") window.title("Ship Craft!")
window.geometry('1020x540') window.geometry('1020x640')
window.bind_all('<KeyPress>', keypress_handler) window.bind_all('<KeyPress>', keypress_handler)
start_column_my_field = 1 start_column_my_field = 1
@ -150,6 +149,13 @@ savebutton_enemy = Button(window, text='Save', width=20, height=2, command=lambd
savebutton_enemy.grid(column=start_column_enemy_field, row=load_button_row, columnspan=4) savebutton_enemy.grid(column=start_column_enemy_field, row=load_button_row, columnspan=4)
loadbutton_enemy = Button(window, text='Load', width=20, height=2, command=lambda: loadbutton_click(enemy_view)) loadbutton_enemy = Button(window, text='Load', width=20, height=2, command=lambda: loadbutton_click(enemy_view))
loadbutton_enemy.grid(column=start_column_enemy_field + 6, row=load_button_row, columnspan=4) loadbutton_enemy.grid(column=start_column_enemy_field + 6, row=load_button_row + 1, columnspan=4)
prev_button = Button(window, text='<=', width=20, height=2)
prev_button.grid(column=start_column_enemy_field, row=load_button_row, columnspan=4)
next_button = Button(window, text='>=', width=20, height=2)
next_button.grid(column=start_column_enemy_field + 6, row=load_button_row, columnspan=4)
window.mainloop() window.mainloop()