diff options
author | Jed Barber <jjbarber@y7mail.com> | 2017-08-05 19:49:18 +1000 |
---|---|---|
committer | Jed Barber <jjbarber@y7mail.com> | 2017-08-05 19:49:18 +1000 |
commit | 751f0ac7e8f695413d8c1a56deefa428d5314b9b (patch) | |
tree | 20d62e601eb79b132aa71518e191af46e98bf650 /src/sokoban.adb | |
parent | e63ddbaa05da3aa302a330a71f45f49d0343691d (diff) |
Undo and level/move number display boxes added
Diffstat (limited to 'src/sokoban.adb')
-rw-r--r-- | src/sokoban.adb | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/src/sokoban.adb b/src/sokoban.adb index b58874b..16b646e 100644 --- a/src/sokoban.adb +++ b/src/sokoban.adb @@ -123,6 +123,8 @@ package body Sokoban is My_Display.Centre_On_Screen; Move_Record := Moves.Empty_Path; My_Display.Set_Message (Play_Message); + My_Display.Set_Level_Number (Natural (Current_Level)); + My_Display.Set_Move_Number (Move_Record.Length); My_Grid.Redraw; Level_State := Play; end Load_Level; @@ -169,7 +171,9 @@ package body Sokoban is elsif Key = FLTK.Right_Key then Move_Man (1, 0); elsif Key = U_Key then - Undo_Movement; + if Move_Record.Length > 0 then + Undo_Movement; + end if; elsif Key = N_Key then if Current_Level = LevelID'Last then My_Display.Set_Message (Fully_Complete_Message); @@ -266,11 +270,13 @@ package body Sokoban is Current_Man_Y := Current_Man_Y + Delta_Y; Next.Set_Contents (Things.Man); My_Grid.Set_Square (Current_Man_X, Current_Man_Y, Next); + Move_Record.Add ((Delta_X => Delta_X, Delta_Y => Delta_Y, Push => False)); + My_Display.Set_Move_Number (Move_Record.Length); My_Grid.Redraw; - elsif - Next.Get_Contents = Things.Treasure and Next_Next.Is_Walkable and - Next_Next.Get_Contents = Things.Nothing + + elsif Next.Get_Contents = Things.Treasure and + Next_Next.Is_Walkable and Next_Next.Get_Contents = Things.Nothing then Current.Set_Contents (Things.Nothing); My_Grid.Set_Square (Current_Man_X, Current_Man_Y, Current); @@ -280,7 +286,9 @@ package body Sokoban is My_Grid.Set_Square (Current_Man_X, Current_Man_Y, Next); Next_Next.Set_Contents (Things.Treasure); My_Grid.Set_Square (Current_Man_X + Delta_X, Current_Man_Y + Delta_Y, Next_Next); + Move_Record.Add ((Delta_X => Delta_X, Delta_Y => Delta_Y, Push => True)); + My_Display.Set_Move_Number (Move_Record.Length); My_Grid.Redraw; if Next = Squares.Goal and Next_Next /= Squares.Goal then @@ -300,9 +308,32 @@ package body Sokoban is - procedure Undo_Movement is + procedure Undo_Movement + is + Last : Moves.Move := Move_Record.Latest; + + Prev : Squares.Square := + My_Grid.Get_Square (Current_Man_X - Last.Delta_X, Current_Man_Y - Last.Delta_Y); + Current : Squares.Square := + My_Grid.Get_Square (Current_Man_X, Current_Man_Y); + Next : Squares.Square := + My_Grid.Get_Square (Current_Man_X + Last.Delta_X, Current_Man_Y + Last.Delta_Y); begin - null; + if Last.Push then + Current.Set_Contents (Things.Treasure); + Next.Set_Contents (Things.Nothing); + else + Current.Set_Contents (Things.Nothing); + end if; + Prev.Set_Contents (Things.Man); + My_Grid.Set_Square (Current_Man_X, Current_Man_Y, Current); + My_Grid.Set_Square (Current_Man_X + Last.Delta_X, Current_Man_Y + Last.Delta_Y, Next); + My_Grid.Set_Square (Current_Man_X - Last.Delta_X, Current_Man_Y - Last.Delta_Y, Prev); + Current_Man_X := Current_Man_X - Last.Delta_X; + Current_Man_Y := Current_Man_Y - Last.Delta_Y; + Move_Record.Drop_Latest; + My_Display.Set_Move_Number (Move_Record.Length); + My_Grid.Redraw; end Undo_Movement; |