mirror of
https://github.com/Fare-spec/cours.git
synced 2025-12-07 10:50:36 +00:00
start the gui using turtle
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import time as tm
|
||||
import turtle as tl
|
||||
|
||||
import board as bd
|
||||
|
||||
screen = tl.Screen()
|
||||
screen.setup(width=800, height=600)
|
||||
screen.tracer(0, 0)
|
||||
|
||||
|
||||
def draw_board(board: bd.Grid):
|
||||
tl.clear() # instead of resetscreen()
|
||||
tl.hideturtle()
|
||||
tl.penup()
|
||||
|
||||
if not board:
|
||||
screen.update()
|
||||
return
|
||||
|
||||
cell_size = 60
|
||||
|
||||
rows = len(board)
|
||||
cols = max(len(line) for line in board)
|
||||
|
||||
origin_x = -cols * cell_size / 2
|
||||
origin_y = rows * cell_size / 2
|
||||
|
||||
for i, line in enumerate(board):
|
||||
for j, cell in enumerate(line):
|
||||
x = origin_x + j * cell_size
|
||||
y = origin_y - i * cell_size
|
||||
|
||||
tl.goto(x, y)
|
||||
tl.pendown()
|
||||
for _ in range(4):
|
||||
tl.forward(cell_size)
|
||||
tl.right(90)
|
||||
tl.penup()
|
||||
|
||||
tl.goto(x + cell_size / 2, y - 0.8 * cell_size)
|
||||
tl.write(
|
||||
cell, align="center", font=("Courier", int(cell_size / 2), "normal")
|
||||
)
|
||||
|
||||
screen.update()
|
||||
tm.sleep(100)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from mailbox import linesep
|
||||
|
||||
import board as bd
|
||||
import drawer as dw
|
||||
|
||||
|
||||
def creerGrille(N, M, v=0):
|
||||
@@ -31,6 +30,12 @@ def getCoords(known_grid, N, M):
|
||||
return bd.get_coords(known_grid)
|
||||
|
||||
|
||||
def main2():
|
||||
grid = creerGrille(8, 8)
|
||||
placerMine(grid, 10)
|
||||
dw.draw_board(grid)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
N, M = 8, 8
|
||||
grid = creerGrille(N, M)
|
||||
@@ -64,4 +69,4 @@ def main() -> None:
|
||||
known_grid[coord[1]][coord[0]] = True
|
||||
|
||||
|
||||
main()
|
||||
main2()
|
||||
|
||||
@@ -4,4 +4,6 @@ version = "0.1.0"
|
||||
description = "Add your description here"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.13"
|
||||
dependencies = []
|
||||
dependencies = [
|
||||
"pythonturtle>=0.3.2",
|
||||
]
|
||||
|
||||
15
university/tp8/uv.lock
generated
15
university/tp8/uv.lock
generated
@@ -2,7 +2,22 @@ version = 1
|
||||
revision = 3
|
||||
requires-python = ">=3.13"
|
||||
|
||||
[[package]]
|
||||
name = "pythonturtle"
|
||||
version = "0.3.2"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/32/b1/2267c041fd484f864c575d69ebac593bb511d2f91d14dfaea24e63203025/PythonTurtle-0.3.2.tar.gz", hash = "sha256:bd5628ab23a73189ec1cb9effbddf2f9fb43613ee9c971cf0954700b202d8534", size = 513879, upload-time = "2020-09-24T23:39:42.273Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/5e/df/b83ffcf5626d59af2247d257cb252996df0559f2e07bec3de1bad9a619f0/PythonTurtle-0.3.2-py3-none-any.whl", hash = "sha256:255d1912c79e34c47e93684e915ea74c584d38bc94637c16a161212ce332b6b5", size = 518363, upload-time = "2020-09-24T23:39:40.472Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tp8"
|
||||
version = "0.1.0"
|
||||
source = { virtual = "." }
|
||||
dependencies = [
|
||||
{ name = "pythonturtle" },
|
||||
]
|
||||
|
||||
[package.metadata]
|
||||
requires-dist = [{ name = "pythonturtle", specifier = ">=0.3.2" }]
|
||||
|
||||
Reference in New Issue
Block a user