убран active view
This commit is contained in:
parent
9e7c7c9a74
commit
884e01b0e8
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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>
|
|
@ -5,12 +5,14 @@
|
||||||
</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$/../../../../HNC/Excercises/hw1.py" beforeDir="false" afterPath="$PROJECT_DIR$/../../../../HNC/Excercises/hw1.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/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/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$/ShipView.py" beforeDir="false" afterPath="$PROJECT_DIR$/ShipView.py" 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" />
|
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
|
@ -46,11 +48,11 @@
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"Python.ShipField.executor": "Run",
|
"Python.ShipField.executor": "Run",
|
||||||
"Python.main (1).executor": "Run",
|
"Python.main (1).executor": "Run",
|
||||||
"Python.main.executor": "Debug",
|
"Python.main.executor": "Run",
|
||||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"git-widget-placeholder": "main",
|
"git-widget-placeholder": "main",
|
||||||
"last_opened_file_path": "C:/Users/Eduardo/Documents/Программирование с Артуром/HNS/hnc-eduard/HNS/Excercises/ShipCraft"
|
"last_opened_file_path": "Z:/Documents/Обучение с Новым Кодом (Артур)/Git/hnc-eduard/HNS/Excercises/ShipCraft/Переделка"
|
||||||
}
|
}
|
||||||
}</component>
|
}</component>
|
||||||
<component name="RunManager" selected="Python.main">
|
<component name="RunManager" selected="Python.main">
|
||||||
|
@ -124,9 +126,9 @@
|
||||||
<envs>
|
<envs>
|
||||||
<env name="PYTHONUNBUFFERED" value="1" />
|
<env name="PYTHONUNBUFFERED" value="1" />
|
||||||
</envs>
|
</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="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_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$/main.py" />
|
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/main.py" />
|
||||||
|
@ -150,7 +152,7 @@
|
||||||
<component name="SharedIndexes">
|
<component name="SharedIndexes">
|
||||||
<attachedChunks>
|
<attachedChunks>
|
||||||
<set>
|
<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>
|
</set>
|
||||||
</attachedChunks>
|
</attachedChunks>
|
||||||
</component>
|
</component>
|
||||||
|
@ -165,6 +167,17 @@
|
||||||
</task>
|
</task>
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</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">
|
<component name="VcsManagerConfiguration">
|
||||||
<MESSAGE value="код по 22 части урока" />
|
<MESSAGE value="код по 22 части урока" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="код по 22 части урока" />
|
<option name="LAST_COMMIT_MESSAGE" value="код по 22 части урока" />
|
||||||
|
@ -174,7 +187,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>129</line>
|
<line>135</line>
|
||||||
<option name="timeStamp" value="1" />
|
<option name="timeStamp" value="1" />
|
||||||
</line-breakpoint>
|
</line-breakpoint>
|
||||||
</breakpoints>
|
</breakpoints>
|
||||||
|
|
|
@ -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="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
|
@ -4,7 +4,9 @@ from tkinter import StringVar
|
||||||
|
|
||||||
class ShipView:
|
class ShipView:
|
||||||
|
|
||||||
def __init__(self, ship_field, buttons):
|
def __init__(self, ship_field, buttons, enemy):
|
||||||
self.ship_field = ship_field
|
self.ship_field = ship_field
|
||||||
self.buttons = buttons
|
self.buttons = buttons
|
||||||
self.remaining_ship_text = StringVar()
|
self.remaining_ship_text = StringVar()
|
||||||
|
self.enemy = enemy
|
||||||
|
self.active = False
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -11,10 +11,10 @@ from GameMode import GameMode
|
||||||
active_view = {}
|
active_view = {}
|
||||||
|
|
||||||
|
|
||||||
def create_view(window):
|
def create_view(window, enemy):
|
||||||
field = ShipField()
|
field = ShipField()
|
||||||
buttons = []
|
buttons = []
|
||||||
view = ShipView(field, buttons)
|
view = ShipView(field, buttons, enemy)
|
||||||
for r in range(0, field.field_size):
|
for r in range(0, field.field_size):
|
||||||
for c in range(0, field.field_size):
|
for c in range(0, field.field_size):
|
||||||
btn = Button(window, text='', width=5, height=2)
|
btn = Button(window, text='', width=5, height=2)
|
||||||
|
@ -43,7 +43,7 @@ def colorize(view):
|
||||||
field = view.ship_field
|
field = view.ship_field
|
||||||
for i in range(len(field.field)):
|
for i in range(len(field.field)):
|
||||||
bg = "white"
|
bg = "white"
|
||||||
if field[i] == "1":
|
if field[i] == "1" and not view.enemy:
|
||||||
bg = 'pink'
|
bg = 'pink'
|
||||||
if field[i] == "\\":
|
if field[i] == "\\":
|
||||||
bg = 'red'
|
bg = 'red'
|
||||||
|
@ -51,7 +51,7 @@ def colorize(view):
|
||||||
bg = 'black'
|
bg = 'black'
|
||||||
if field[i] == "p":
|
if field[i] == "p":
|
||||||
bg = 'blue'
|
bg = 'blue'
|
||||||
if "+" in field[i]:
|
if "+" in field[i] and view.enemy:
|
||||||
bg = 'orange'
|
bg = 'orange'
|
||||||
if "r" in field[i]:
|
if "r" in field[i]:
|
||||||
bg = 'red'
|
bg = 'red'
|
||||||
|
@ -61,9 +61,11 @@ def colorize(view):
|
||||||
|
|
||||||
|
|
||||||
def keypress_handler(e):
|
def keypress_handler(e):
|
||||||
global active_view
|
|
||||||
if e.keysym.isnumeric():
|
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):
|
def left_button_click(view, row, col):
|
||||||
|
@ -77,15 +79,19 @@ def right_button_click(view):
|
||||||
|
|
||||||
|
|
||||||
def button_enter(view, row, col):
|
def button_enter(view, row, col):
|
||||||
global active_view
|
if view.enemy:
|
||||||
active_view = view
|
|
||||||
if view == my_view:
|
|
||||||
enemy_view.ship_field.clear_marker()
|
|
||||||
my_view.ship_field.target(row, col)
|
|
||||||
elif view == enemy_view:
|
|
||||||
my_view.ship_field.clear_marker()
|
my_view.ship_field.clear_marker()
|
||||||
enemy_view.ship_field.target(row, col)
|
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(my_view)
|
||||||
colorize(enemy_view)
|
colorize(enemy_view)
|
||||||
|
|
||||||
|
@ -99,13 +105,17 @@ def savebutton_click(view):
|
||||||
|
|
||||||
def loadbutton_click(view):
|
def loadbutton_click(view):
|
||||||
file_path = filedialog.askopenfilename(filetypes=[('JSON files', '*.json')])
|
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):
|
if os.path.isfile(file_path):
|
||||||
with open(file_path) as lines:
|
with open(file_path) as lines:
|
||||||
view.ship_field.from_json(json.load(lines)['shipField'])
|
view.ship_field.from_json(json.load(lines)['shipField'])
|
||||||
|
|
||||||
colorize(view)
|
colorize(view)
|
||||||
|
|
||||||
|
|
||||||
def refresh_remaining_ships_label(view):
|
def refresh_remaining_ships_label(view):
|
||||||
text = ''
|
text = ''
|
||||||
for i in range(1, 5):
|
for i in range(1, 5):
|
||||||
|
@ -151,6 +161,9 @@ def update_game_mode():
|
||||||
|
|
||||||
elif game_mode == GameMode.PLAN:
|
elif game_mode == GameMode.PLAN:
|
||||||
window.geometry('1020x640')
|
window.geometry('1020x640')
|
||||||
|
|
||||||
|
load_field(view, file_path)
|
||||||
|
|
||||||
my_view.ship_field.set_field_mode(ShipMode.PUT)
|
my_view.ship_field.set_field_mode(ShipMode.PUT)
|
||||||
enemy_view.ship_field.set_field_mode(ShipMode.INACTIVE)
|
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
|
load_button_row = start_row_my_field + ShipField.field_size + 1
|
||||||
|
|
||||||
my_view = create_view(window)
|
my_view = create_view(window, False)
|
||||||
enemy_view = create_view(window)
|
enemy_view = create_view(window, True)
|
||||||
active_view = my_view
|
|
||||||
|
|
||||||
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)
|
||||||
|
|
Loading…
Reference in New Issue