Загружаю ДЗ с доработкой с урока
This commit is contained in:
parent
fefb73a2ab
commit
f9e0d24478
|
@ -53,42 +53,48 @@ def set_ship(row, col, size, direction):
|
|||
|
||||
def shoot(field, row, col):
|
||||
if row < 0 or row > field_size - 1:
|
||||
return
|
||||
return ShootResult.UNDEFINED
|
||||
if col < 0 or col > field_size - 1:
|
||||
return
|
||||
return ShootResult.UNDEFINED
|
||||
index = row * field_size + col
|
||||
if field[index] == "":
|
||||
field[index] = 0
|
||||
if (field[index]).strip() == "":
|
||||
field[index] = '0'
|
||||
return ShootResult.EMPTY
|
||||
elif field[index] == "1":
|
||||
elif (field[index]).strip() == "1":
|
||||
field[index] = "\\"
|
||||
return ShootResult.DAMAGED
|
||||
elif field[index] == "1" or field[index] == "\\" or field[index] == "x":
|
||||
return ShootResult.DAMAGED
|
||||
else:
|
||||
return ShootResult.UNDEFINED
|
||||
|
||||
|
||||
def draw_field(window, field):
|
||||
for r in range(0, field_size):
|
||||
for c in range(0, field_size):
|
||||
index = r * field_size + c
|
||||
bg = 'Lightgray'
|
||||
bg = 'white'
|
||||
if field[index] == '1':
|
||||
bg = 'pink'
|
||||
btn = Button(window, text='', bg=bg, width=5, height=2)
|
||||
btn.grid(column=c, row=r)
|
||||
btn.bind('<Button-1>', lambda e, x=r, y=c: shoot(field, x, y))
|
||||
buttons.append(btn)
|
||||
|
||||
|
||||
def colorize(field, buttons):
|
||||
bg = "grey"
|
||||
for i in range(len(field)):
|
||||
if i == '1':
|
||||
bg = "white"
|
||||
if field[i] == '1':
|
||||
bg = 'pink'
|
||||
if i == '\\':
|
||||
if field[i] == '\\':
|
||||
bg = 'red'
|
||||
if i == '0':
|
||||
if field[i] == '0':
|
||||
bg = 'black'
|
||||
buttons.configure(bg=bg)
|
||||
buttons[i].configure(bg=bg)
|
||||
|
||||
|
||||
def button_click(field, row, col):
|
||||
shoot(field, row, col)
|
||||
colorize(field, buttons)
|
||||
|
||||
|
||||
window = Tk()
|
||||
|
@ -100,6 +106,6 @@ set_ship(9, 9, 1, 0)
|
|||
set_ship(0, 0, 1, 0)
|
||||
set_ship(9, 0, 1, 0)
|
||||
set_ship(9, 2, 4, 1)
|
||||
shoot(my_field, 9, 2)
|
||||
draw_field(window, my_field)
|
||||
colorize(my_field, buttons)
|
||||
window.mainloop()
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
|
@ -0,0 +1,6 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (ДЗ по визуализации)" project-jdk-type="Python SDK" />
|
||||
</project>
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/ДЗ по визуализации.iml" filepath="$PROJECT_DIR$/.idea/ДЗ по визуализации.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -0,0 +1,20 @@
|
|||
from tkinter import *
|
||||
|
||||
def clicked():
|
||||
res = 'Привет {}'.format(txt.get())
|
||||
lbl.configure(text=res)
|
||||
|
||||
|
||||
window = Tk()
|
||||
window.title('Добро пожаложенине в приложение PythonRu')
|
||||
window.geometry('400x250')
|
||||
lbl = Label(window,text='Привет', font=('Arial Bold', 50))
|
||||
lbl.grid(column=0, row=0)
|
||||
txt = Entry(window, width=10)
|
||||
txt.grid(column=1, row=0)
|
||||
btn = Button(window, text='Клик', bg='black', fg='red', command=clicked)
|
||||
btn.grid(column=2, row=0)
|
||||
window.mainloop()
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue