' Program "Nature". Version 0.15. 19.04.2024 (translated by Google translator)
'
' This program is the engine of the World of the game "AI Snake" and the interface for communication with human.
' The LitDev extension v1.2.26 is used.
'
'----------------------------------------
' Variables of the "Nature" system
'----------------------------------------
'--- various variables
x = 0 ' free variable
y = 0 ' free variable
'--- GUI parameters
cell_size = 15 ' cell size of the playing field in pixels
number_of_cells = 30 ' number of cells in the length and width of the playing field
n_startingPoint_X = cell_size * number_of_cells + 20
n_startingPoint_Y = 18
n_redSwitchDefaultPosX = n_startingPoint_X + 71
n_redSwitchDefaultPosY = n_startingPoint_Y + 3
n_rabBrushText_X = n_startingPoint_X + 10 'Rabbit Brush Text
n_rabBrushText_Y = n_startingPoint_Y + 67
n_snakeBrushText_X = n_startingPoint_X + 10
n_snakeBrushText_Y = n_startingPoint_Y + 127
'--- variables of objects of the program "Nature"
t_switchStatus = "OFF" ' Server switch status
t_serverStatus = "OFF" ' Server status
shp_LastEventShape = ""
evtp_LastEventType = ""
chbx_LastClickedCheckBox = ""
b_checkBoxChanged = "False"
b_rabbitMindConnected = "False"
b_snakeMindConnected = "False"
'---
Initialization()
GraphicsWindow.Show()
'--- MAIN LOOP ---
While "True"
Program.Delay(50)
'--- checking the click on the Server switch
If evtp_LastEventType = "MouseUp" Then
If shp_LastEventShape = sh_RedSwitch_OFF Then
OnRedSwitchOFF_Click()
shp_LastEventShape = ""
ElseIf shp_LastEventShape = sh_RedSwitch_ON Then
OnRedSwitchON_Click()
shp_LastEventShape = ""
ElseIf shp_LastEventShape = sh_GreenSwitch_ON Then
OnGreenSwitchON_Click()
shp_LastEventShape = ""
EndIf
evtp_LastEventType = ""
EndIf
'--- checking connection flags
If b_checkBoxChanged = "True" Then
If chbx_LastClickedCheckBox = CheckBox1 Then
If LDControls.CheckBoxGetState(CheckBox1) = "False" Then
b_rabbitMindConnected = "False"
OnRabbitDisconnected()
Else
b_rabbitMindConnected = "True"
OnRabbitConnected()
EndIf
Else
If LDControls.CheckBoxGetState(CheckBox2) = "False" Then
b_snakeMindConnected = "False"
OnSnakeDisconnected()
Else
b_snakeMindConnected = "True"
OnSnakeConnected()
EndIf
EndIf
'--- setting the color of the Server switch
If t_switchStatus = "ON" Then
If t_serverStatus = "OFF" Then
If (b_rabbitMindConnected = "True") And (b_snakeMindConnected = "True") Then
t_serverStatus = "ON"
SetSvitchColor_Green()
EndIf
Else
If (b_rabbitMindConnected = "False") Or (b_snakeMindConnected = "False") Then
t_serverStatus = "OFF"
SetSvitchColor_Red()
EndIf
EndIf
Else
b_rabbitMindConnected = "False"
OnRabbitDisconnected()
LDControls.CheckBoxState(CheckBox1, "False")
b_snakeMindConnected = "False"
OnSnakeDisconnected()
LDControls.CheckBoxState(CheckBox2, "False")
EndIf
EndWhile
'*****************************
'======================
' SUBROUTINES
'======================
Sub Initialization
'--- Creating a startup graphical interface
x = cell_size * number_of_cells
'--- playing field
GraphicsWindow.BrushColor = "#FFBBDB9D"
GraphicsWindow.PenColor = "#FFC27452"
Field = Shapes.AddRectangle(x, x)
Shapes.Move(Field,10,10)