Skip to content

Commit

Permalink
refactor - changed list to queue
Browse files Browse the repository at this point in the history
  • Loading branch information
daerup committed May 12, 2024
1 parent 50293ab commit b3545b7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The controls are buffered, so you can press keys in rapid succession and the sna

>**Note**: Only logged in players with verified email addresses get to have their highscores saved.
> **Disclaimer**: The performance is horrendous. I would not recommend increasing the area size over 10x10.
# Run
To run the game, clone the repository and open the solution in Visual Studio or your preferred IDE.

Expand Down
8 changes: 4 additions & 4 deletions Schnacc.UserInterface/PlayAreaView/PlayAreaPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class PlayAreaViewModel : ViewModelBase, INavigableViewModel
private Timer _movementTimer;
private const int _renderSpeedInMilliSeconds = 50;
private readonly int _gameSpeedInMilliSeconds;
private readonly List<Direction> _directionsBuffer = new List<Direction>();
private readonly Queue<Direction> _directionsBuffer = new Queue<Direction>();
private readonly object _directionLock = new object();
private int _moveCount;
private Direction _lastDirection = Direction.None;
Expand All @@ -51,8 +51,8 @@ private Direction Direction
{
return Direction.None;
}
var nextDirection = this._directionsBuffer.First();
this._directionsBuffer.Remove(nextDirection);

var nextDirection = this._directionsBuffer.Dequeue();
this._moveCount++;
return nextDirection;
}
Expand All @@ -72,7 +72,7 @@ private Direction Direction
}

this._lastDirectionChange = DateTime.Now;
this._directionsBuffer.Add(value);
this._directionsBuffer.Enqueue(value);
this._lastDirection = value;
}
}
Expand Down

0 comments on commit b3545b7

Please sign in to comment.