pascalabcnet/CodeExamples/SPython/delete_by_mouse.pys
Александр Земляк 4e871c1f3a
Исправление переменных с именем, совпадающим с именами сущностей из других модулей, в SPython (#3360)
* Fix variables with special names declaration in SPython

* Add new syntax tree converters applying flag checking in Intellisense

* Fix IsVariableOrConstant function in Intellisense

* Optimize CollectNamesFromUsedUnits function in Compiler
2025-11-29 14:27:00 +03:00

42 lines
1.4 KiB
Plaintext
Raw 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