pascalabcnet/InstallerSamples/SPython/delete_by_mouse.pys
Mikhalkovich Stanislav 6d15540895 SPython в 3.11
2025-08-31 17:21:18 +03:00

42 lines
1.4 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from WPFObjects import RectangleWPF, ObjectUnderPoint
from WPFObjects import Colors, Window, OnMouseDown
from PABCSystem import Random, Inc, Milliseconds
CountSquares = 10
StatusRect: RectangleWPF
CurrentDigit = 1
Mistakes = 0
def DrawStatusText():
if CurrentDigit <= CountSquares:
StatusRect.Text = ('Удалено квадратов: ' + str(CurrentDigit-1)
+ '\tОшибок: ' + str(Mistakes))
else:
StatusRect.Text = ('Игра окончена. Время: ' + str(Milliseconds() // 1000)
+ ' с.\tОшибок: ' + str(Mistakes))
def MyMouseDown(x: float, y: float, mb: int):
ob = ObjectUnderPoint(x, y)
if ob is RectangleWPF and ob != StatusRect:
if ob.Number == CurrentDigit:
ob.Destroy()
Inc(CurrentDigit)
DrawStatusText()
else:
ob.Color = Colors.Red
Inc(Mistakes)
DrawStatusText()
Window.Title = 'Игра: удали все квадраты по порядку'
for i in range(1, CountSquares + 1):
x = Random(Window.Width - 50)
y = Random(Window.Height - 100)
ob = new RectangleWPF(x, y, 50, 50, Colors.LightGreen, 1)
ob.FontSize = 25
ob.Number = i
StatusRect = new RectangleWPF(0, Window.Height - 40,
Window.Width, 40, Colors.LightBlue)
DrawStatusText()
OnMouseDown = MyMouseDown