aboutsummaryrefslogtreecommitdiff
path: root/src/sokoban.adb
diff options
context:
space:
mode:
authorJedidiah Barber <contact@jedbarber.id.au>2025-04-16 15:51:58 +1200
committerJedidiah Barber <contact@jedbarber.id.au>2025-04-16 15:51:58 +1200
commitbaa3a346cde2c2c965243e554a15ed3bd6f5c7fe (patch)
treef8ec8376a6a42053e15cb9607b0fef17bb4f321d /src/sokoban.adb
parentb3455e502f4491af22e190a14aba9565f534bb59 (diff)
Code style improvements, constants marked as constant
Diffstat (limited to 'src/sokoban.adb')
-rw-r--r--src/sokoban.adb91
1 files changed, 43 insertions, 48 deletions
diff --git a/src/sokoban.adb b/src/sokoban.adb
index 8b7ecdb..1f85266 100644
--- a/src/sokoban.adb
+++ b/src/sokoban.adb
@@ -46,22 +46,26 @@ package body Sokoban is
type Game_State is (Loading, Play, Complete);
- Loading_Message : String := "Loading...";
+ Loading_Message : constant String :=
+ "Loading...";
- Play_Message : String := "Move with the arrow keys. Press u for undo." & ASCII.LF &
+ Play_Message : constant String :=
+ "Move with the arrow keys. Press u for undo." & ASCII.LF &
"To move to a square where there is a clear path, click with the mouse." & ASCII.LF &
"Press n to skip this level, q to quit, and r to restart this level.";
- Complete_Message : String := "Level complete!" & ASCII.LF &
+ Complete_Message : constant String :=
+ "Level complete!" & ASCII.LF &
"Press enter to progress to the next level, or q to quit.";
- Fully_Complete_Message : String := "Congratulations! All levels complete!" & ASCII.LF &
+ Fully_Complete_Message : constant String :=
+ "Congratulations! All levels complete!" & ASCII.LF &
"Press enter to start again at the first level, or q to quit.";
- U_Key : FLTK.Key_Combo := FLTK.Press ('u');
- N_Key : FLTK.Key_Combo := FLTK.Press ('n');
- R_Key : FLTK.Key_Combo := FLTK.Press ('r');
- Q_Key : FLTK.Key_Combo := FLTK.Press ('q');
+ U_Key : constant FLTK.Key_Combo := FLTK.Press ('u');
+ N_Key : constant FLTK.Key_Combo := FLTK.Press ('n');
+ R_Key : constant FLTK.Key_Combo := FLTK.Press ('r');
+ Q_Key : constant FLTK.Key_Combo := FLTK.Press ('q');
@@ -88,7 +92,7 @@ package body Sokoban is
use Ada.Strings, Ada.Strings.Fixed, Ada.Strings.Maps;
Data_File : File_Type;
- Filename : String := ADir.Compose
+ Filename : constant String := ADir.Compose
(Misc.Level_Path, "level" & Trim (LevelID'Image (Number), Both) & ".data");
Rows, Cols : Natural;
@@ -99,8 +103,8 @@ package body Sokoban is
Open (Data_File, In_File, Filename);
declare
- Row_Line : String := Get_Line (Data_File);
- Col_Line : String := Get_Line (Data_File);
+ Row_Line : constant String := Get_Line (Data_File);
+ Col_Line : constant String := Get_Line (Data_File);
Start, Finish : Natural;
begin
Find_Token (Row_Line, To_Set ("0123456789"), 1, Inside, Start, Finish);
@@ -112,7 +116,7 @@ package body Sokoban is
for Y in Integer range 1 .. Rows loop
declare
- Working_Line : String := Get_Line (Data_File);
+ Working_Line : constant String := Get_Line (Data_File);
begin
for X in Integer range 1 .. Cols loop
Add_New_Grid_Item (X, Y, Working_Line (X));
@@ -132,16 +136,12 @@ package body Sokoban is
end Load_Level;
-
-
procedure Show is
begin
My_Display.Show;
end Show;
-
-
procedure Hide is
begin
My_Display.Hide;
@@ -202,8 +202,6 @@ package body Sokoban is
end Keypress;
-
-
function Mouseclick
(X, Y : in Integer)
return FLTK.Event_Outcome
@@ -246,45 +244,43 @@ package body Sokoban is
Temp : Squares.Square;
begin
case Char is
- when '#' =>
- My_Grid.Set_Square (X, Y, Squares.Wall);
+ when '#' =>
+ My_Grid.Set_Square (X, Y, Squares.Wall);
- when ' ' =>
- My_Grid.Set_Square (X, Y, Squares.Empty);
+ when ' ' =>
+ My_Grid.Set_Square (X, Y, Squares.Empty);
- when '$' =>
- Temp := Squares.Empty;
- Temp.Set_Contents (Things.Treasure);
- My_Grid.Set_Square (X, Y, Temp);
+ when '$' =>
+ Temp := Squares.Empty;
+ Temp.Set_Contents (Things.Treasure);
+ My_Grid.Set_Square (X, Y, Temp);
- when '*' =>
- Temp := Squares.Goal;
- Temp.Set_Contents (Things.Treasure);
- My_Grid.Set_Square (X, Y, Temp);
+ when '*' =>
+ Temp := Squares.Goal;
+ Temp.Set_Contents (Things.Treasure);
+ My_Grid.Set_Square (X, Y, Temp);
- when '!' =>
- My_Grid.Set_Square (X, Y, Squares.Space);
+ when '!' =>
+ My_Grid.Set_Square (X, Y, Squares.Space);
- when '.' =>
- My_Grid.Set_Square (X, Y, Squares.Goal);
- Goals_Remaining := Goals_Remaining + 1;
+ when '.' =>
+ My_Grid.Set_Square (X, Y, Squares.Goal);
+ Goals_Remaining := Goals_Remaining + 1;
- when '@' =>
- Temp := Squares.Empty;
- Temp.Set_Contents (Things.Man);
- My_Grid.Set_Square (X, Y, Temp);
- Current_Man_X := X;
- Current_Man_Y := Y;
+ when '@' =>
+ Temp := Squares.Empty;
+ Temp.Set_Contents (Things.Man);
+ My_Grid.Set_Square (X, Y, Temp);
+ Current_Man_X := X;
+ Current_Man_Y := Y;
- when others =>
- raise Program_Error;
+ when others =>
+ raise Program_Error;
end case;
end Add_New_Grid_Item;
-
-
procedure Move_Man
(Delta_X, Delta_Y : in Integer)
is
@@ -341,11 +337,9 @@ package body Sokoban is
end Move_Man;
-
-
procedure Undo_Movement
is
- Last : Moves.Move := Move_Record.Latest;
+ Last : constant Moves.Move := Move_Record.Latest;
Prev : Squares.Square :=
My_Grid.Get_Square (Current_Man_X - Last.Delta_X, Current_Man_Y - Last.Delta_Y);
@@ -382,3 +376,4 @@ begin
end Sokoban;
+