Skip to content

Commit fc522b1

Browse files
Alexei BezborodovAlexei Bezborodov
Alexei Bezborodov
authored and
Alexei Bezborodov
committed
table
1 parent 4730691 commit fc522b1

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

chess.py renamed to chess_1.py

File renamed without changes.

chess_2.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- coding: utf-8 -*-
2+
3+
width = 3 # ширина
4+
height = 3 # высота
5+
6+
# Данные
7+
data = [" " for i in range(height * width)]
8+
9+
# Получаем элемент с координатами x, y из данных
10+
def GetElement(x, y):
11+
return data[y * width + x]
12+
13+
# Печатаем линию для таблицы
14+
def PrintLine(width):
15+
for i in range(width):
16+
print("+--", end = "")
17+
print("+")
18+
19+
# draw - Функция рисования поля для игры
20+
def draw(data):
21+
mini = "| "
22+
for y in range(height):
23+
PrintLine(width)
24+
for x in range(width):
25+
print(mini + GetElement(x, y), end = "")
26+
print(mini)
27+
PrintLine(width)
28+
29+
while True:
30+
x = int(input("Введите Х:"))
31+
y = int(input("Введите У:"))
32+
33+
if x < 0 or x > 2 or y < 0 or y > 2 or GetElement(x, y) != " ":
34+
print("Так ходить нельзя")
35+
else:
36+
data[width * y + x] = "Х"
37+
38+
draw(data)

table.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
3+
width = 3 # ширина
4+
height = 3 # высота
5+
6+
# Разделительная линия
7+
table_line = ""
8+
for i in range(width):
9+
table_line += "+--"
10+
table_line += "+"
11+
12+
# Таблица
13+
delim = "| "
14+
for y in range(height):
15+
print(table_line)
16+
data_line = ""
17+
for x in range(width):
18+
data_line += delim + " "
19+
print(data_line + delim)
20+
print(table_line)

0 commit comments

Comments
 (0)