added winner lable

This commit is contained in:
ehermakov 2024-09-18 22:47:59 +03:00
parent 08591c71f6
commit 62271350c1
11 changed files with 36 additions and 41 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.9" project-jdk-type="Python SDK" /> <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11" project-jdk-type="Python SDK" />
</project> </project>

View File

@ -5,7 +5,9 @@
</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 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/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$/ShipField.py" beforeDir="false" afterPath="$PROJECT_DIR$/ShipField.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
</list> </list>
@ -38,21 +40,22 @@
<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": "Run", &quot;Python.main.executor&quot;: &quot;Run&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": "F:/hnc-eduard/HNS/Excercises/ShipCraft/Переделка", &quot;last_opened_file_path&quot;: &quot;C:/Users/Eduardo/Documents/Программирование с Артуром/hnc-eduard/HNS/Excercises/ShipCraft/Переделка&quot;,
"settings.editor.selected.configurable": "com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable" &quot;settings.editor.selected.configurable&quot;: &quot;configurable.group.editor&quot;
} }
}]]></component> }</component>
<component name="RunManager"> <component name="RunManager">
<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>
@ -74,6 +77,7 @@
</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>
@ -95,38 +99,18 @@
</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>
<env name="PYTHONUNBUFFERED" value="1" /> <env name="PYTHONUNBUFFERED" value="1" />
</envs> </envs>
<option name="SDK_HOME" value="" /> <option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/../../../../../../../1/hnc-eduard/HNS/Excercises/ShipCraft/Переделка" /> <option name="WORKING_DIRECTORY" value="$USER_HOME$/1/hnc-eduard/HNS/Excercises/ShipCraft/Переделка" />
<option name="IS_MODULE_SDK" value="false" /> <option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" /> <option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" /> <option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/../../../../../../../1/hnc-eduard/HNS/Excercises/ShipCraft/Переделка/main.py" /> <option name="SCRIPT_NAME" value="$USER_HOME$/1/hnc-eduard/HNS/Excercises/ShipCraft/Переделка/main.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="main" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="Переделка" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="$USER_HOME$/PycharmProjects/pythonProject/venv/bin/python" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/main.py" />
<option name="PARAMETERS" value="" /> <option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" /> <option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" /> <option name="EMULATE_TERMINAL" value="false" />
@ -137,9 +121,8 @@
</configuration> </configuration>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="Python.main" />
<item itemvalue="Python.ShipView" />
<item itemvalue="Python.main (1)" /> <item itemvalue="Python.main (1)" />
<item itemvalue="Python.ShipView" />
<item itemvalue="Python.ShipField" /> <item itemvalue="Python.ShipField" />
</list> </list>
</recent_temporary> </recent_temporary>

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="jdk" jdkName="Python 3.9" jdkType="Python SDK" /> <orderEntry type="jdk" jdkName="Python 3.11" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
</module> </module>

View File

@ -3,6 +3,7 @@ import copy
from ShootResult import ShootResult from ShootResult import ShootResult
from ShipDirection import ShipDirection from ShipDirection import ShipDirection
from ShipMode import ShipMode from ShipMode import ShipMode
from tkinter import StringVar
class ShipField: class ShipField:
@ -44,8 +45,6 @@ class ShipField:
return None return None
def mark_killed(self, row, col): def mark_killed(self, row, col):
if row < 0 or row > ShipField.field_size: if row < 0 or row > ShipField.field_size:
return return
@ -55,7 +54,6 @@ class ShipField:
self.field[row * ShipField.field_size + col] = 'x' self.field[row * ShipField.field_size + col] = 'x'
self.fill_empty_killed(row, col) self.fill_empty_killed(row, col)
#check vertical #check vertical
for r in range(row + 1, ShipField.field_size): for r in range(row + 1, ShipField.field_size):
if self.check_damaged(r, col): if self.check_damaged(r, col):

View File

@ -150,6 +150,16 @@ def refresh_remaining_ships_label(view):
view.remaining_ship_text.set(text[:-2]) view.remaining_ship_text.set(text[:-2])
def determine_winner():
if my_field.check_end():
winner_lable = "You won!"
elif my_field.check_end():
winner_lable = "Your enemy won!"
else:
winner_lable = ""
return winner_lable
def next_game_mode(): def next_game_mode():
global game_mode global game_mode
@ -244,6 +254,7 @@ def update_game_mode():
load_game_button.grid_forget() load_game_button.grid_forget()
exit_button.grid_forget() exit_button.grid_forget()
end_button.grid(column=start_column_enemy_field, row=load_button_row, columnspan=4) end_button.grid(column=start_column_enemy_field, row=load_button_row, columnspan=4)
lbl_winner.grid(column=start_column_enemy_field, row=load_button_row + 2, columnspan=2)
hide_view(my_view) hide_view(my_view)
hide_view(enemy_view) hide_view(enemy_view)
@ -270,6 +281,7 @@ load_button_row = start_row_my_field + ShipField.field_size + 1
my_view = create_view(window, False) my_view = create_view(window, False)
enemy_view = create_view(window, True) enemy_view = create_view(window, True)
winner_lable = StringVar
lbl_left_vertical = Label(window, text='', width=5, height=2) lbl_left_vertical = Label(window, text='', width=5, height=2)
lbl_center_vertical = Label(window, text='', width=5, height=2) lbl_center_vertical = Label(window, text='', width=5, height=2)
@ -285,6 +297,8 @@ start_button = Button(window, text='START', width=20, height=2, command=next_gam
load_game_button = Button(window, text='LOAD', width=20, height=2) load_game_button = Button(window, text='LOAD', width=20, height=2)
exit_button = Button(window, text='EXIT', width=20, height=2) exit_button = Button(window, text='EXIT', width=20, height=2)
end_button = Button(window, text='BACK TO MENU', width=20, height=2, command=next_game_mode) end_button = Button(window, text='BACK TO MENU', width=20, height=2, command=next_game_mode)
lbl_winner = Label(window, text='', width=20, height=2, textvariable=determine_winner)
game_mode = GameMode.MENU game_mode = GameMode.MENU
update_game_mode() update_game_mode()