убран active view

This commit is contained in:
ehermakov 2024-07-03 19:12:30 +03:00
parent 9e7c7c9a74
commit 884e01b0e8
15 changed files with 57 additions and 30 deletions

BIN
.DS_Store vendored

Binary file not shown.

BIN
HNS/.DS_Store vendored

Binary file not shown.

Binary file not shown.

BIN
HNS/Excercises/ShipCraft/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -3,5 +3,5 @@
<component name="Black">
<option name="sdkName" value="Python 3.11" />
</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>

View File

@ -5,12 +5,14 @@
</component>
<component name="ChangeListManager">
<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$/../../../../HNC/Excercises/hw1.py" beforeDir="false" afterPath="$PROJECT_DIR$/../../../../HNC/Excercises/hw1.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../../../../HNC/Excercises/hw2.py" beforeDir="false" afterPath="$PROJECT_DIR$/../../../../HNC/Excercises/hw2.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../../../../HNC/Excercises/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/../../../../HNC/Excercises/main.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../../../../HNC/Excercises/тест.py" beforeDir="false" afterPath="$PROJECT_DIR$/../../../../HNC/Excercises/тест.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../../13082023 ДЗ по фигурам JSON/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/../../13082023 ДЗ по фигурам JSON/main.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../../13082023 ДЗ по фигурам JSON/shapes.json" beforeDir="false" afterPath="$PROJECT_DIR$/../../13082023 ДЗ по фигурам JSON/shapes.json" 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$/ShipView.py" beforeDir="false" afterPath="$PROJECT_DIR$/ShipView.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" />
@ -46,11 +48,11 @@
&quot;keyToString&quot;: {
&quot;Python.ShipField.executor&quot;: &quot;Run&quot;,
&quot;Python.main (1).executor&quot;: &quot;Run&quot;,
&quot;Python.main.executor&quot;: &quot;Debug&quot;,
&quot;Python.main.executor&quot;: &quot;Run&quot;,
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;main&quot;,
&quot;last_opened_file_path&quot;: &quot;C:/Users/Eduardo/Documents/Программирование с Артуром/HNS/hnc-eduard/HNS/Excercises/ShipCraft&quot;
&quot;last_opened_file_path&quot;: &quot;Z:/Documents/Обучение с Новым Кодом (Артур)/Git/hnc-eduard/HNS/Excercises/ShipCraft/Переделка&quot;
}
}</component>
<component name="RunManager" selected="Python.main">
@ -124,9 +126,9 @@
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<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="true" />
<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" />
@ -150,7 +152,7 @@
<component name="SharedIndexes">
<attachedChunks>
<set>
<option value="bundled-python-sdk-babbdf50b680-746f403e7f0c-com.jetbrains.pycharm.community.sharedIndexes.bundled-PC-241.15989.155" />
<option value="bundled-python-sdk-67fca87a943a-d3b881c8e49f-com.jetbrains.pycharm.community.sharedIndexes.bundled-PC-233.11799.259" />
</set>
</attachedChunks>
</component>
@ -165,6 +167,17 @@
</task>
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State />
</value>
</entry>
</map>
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="код по 22 части урока" />
<option name="LAST_COMMIT_MESSAGE" value="код по 22 части урока" />
@ -174,7 +187,7 @@
<breakpoints>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/main.py</url>
<line>129</line>
<line>135</line>
<option name="timeStamp" value="1" />
</line-breakpoint>
</breakpoints>

View File

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

View File

@ -4,7 +4,9 @@ from tkinter import StringVar
class ShipView:
def __init__(self, ship_field, buttons):
def __init__(self, ship_field, buttons, enemy):
self.ship_field = ship_field
self.buttons = buttons
self.remaining_ship_text = StringVar()
self.enemy = enemy
self.active = False

View File

@ -11,10 +11,10 @@ from GameMode import GameMode
active_view = {}
def create_view(window):
def create_view(window, enemy):
field = ShipField()
buttons = []
view = ShipView(field, buttons)
view = ShipView(field, buttons, enemy)
for r in range(0, field.field_size):
for c in range(0, field.field_size):
btn = Button(window, text='', width=5, height=2)
@ -43,7 +43,7 @@ def colorize(view):
field = view.ship_field
for i in range(len(field.field)):
bg = "white"
if field[i] == "1":
if field[i] == "1" and not view.enemy:
bg = 'pink'
if field[i] == "\\":
bg = 'red'
@ -51,7 +51,7 @@ def colorize(view):
bg = 'black'
if field[i] == "p":
bg = 'blue'
if "+" in field[i]:
if "+" in field[i] and view.enemy:
bg = 'orange'
if "r" in field[i]:
bg = 'red'
@ -61,9 +61,11 @@ def colorize(view):
def keypress_handler(e):
global active_view
if e.keysym.isnumeric():
active_view.ship_field.set_ship_size(e.keysym)
if my_view.active:
my_view.ship_field.set_ship_size(e.keysym)
elif enemy_view.active:
enemy_view.ship_field.set_ship_size(e.keysym)
def left_button_click(view, row, col):
@ -77,15 +79,19 @@ def right_button_click(view):
def button_enter(view, row, col):
global active_view
active_view = view
if view == my_view:
enemy_view.ship_field.clear_marker()
my_view.ship_field.target(row, col)
elif view == enemy_view:
if view.enemy:
my_view.ship_field.clear_marker()
enemy_view.ship_field.target(row, col)
enemy_view.active = True
my_view.active = False
else:
enemy_view.ship_field.clear_marker()
my_view.ship_field.target(row, col)
enemy_view.active = False
my_view.active = True
colorize(my_view)
colorize(enemy_view)
@ -99,13 +105,17 @@ def savebutton_click(view):
def loadbutton_click(view):
file_path = filedialog.askopenfilename(filetypes=[('JSON files', '*.json')])
load_field(view, file_path)
def load_field(view, file_path):
if os.path.isfile(file_path):
with open(file_path) as lines:
view.ship_field.from_json(json.load(lines)['shipField'])
colorize(view)
def refresh_remaining_ships_label(view):
text = ''
for i in range(1, 5):
@ -151,6 +161,9 @@ def update_game_mode():
elif game_mode == GameMode.PLAN:
window.geometry('1020x640')
load_field(view, file_path)
my_view.ship_field.set_field_mode(ShipMode.PUT)
enemy_view.ship_field.set_field_mode(ShipMode.INACTIVE)
@ -223,9 +236,8 @@ row_horizontal_separator = start_row_my_field + ShipField.field_size
load_button_row = start_row_my_field + ShipField.field_size + 1
my_view = create_view(window)
enemy_view = create_view(window)
active_view = my_view
my_view = create_view(window, False)
enemy_view = create_view(window, True)
lbl_left_vertical = Label(window, text='', width=5, height=2)
lbl_center_vertical = Label(window, text='', width=5, height=2)