Esempio n. 1
0
 public Game(LEDMatrix ledMatrix)
 {
     IsRunning = false;
     Player = new Player(Columns, Rows);
     Board = new Board(ledMatrix, Player);
     Level = (Player.Length / 2);
 }
Esempio n. 2
0
        public bool Crash(Board Board, Point newHeadPosition)
        {
            if (Positions.Exists(point => point.X == newHeadPosition.X && point.Y == newHeadPosition.Y))
            {
                var tailPosition = Positions.Last();

                if (tailPosition.X == newHeadPosition.X && tailPosition.Y == newHeadPosition.Y)
                {
                    if (!Board.DidEat(newHeadPosition))
                    {
                        return false;
                    }
                }

                return true;
            }

            return false;
        }
Esempio n. 3
0
 public void ResetGame()
 {
     Player = new Player(Columns, Rows);
     Board = new Board(Board.LEDGameBoard, Player);
     Level = (Player.Length / 2);
 }
Esempio n. 4
0
        public void Tick(Board Board)
        {
            var newHeadPosition = new Point();
            switch (CurrentDirection)
            {
                case Direction.Up:
                    newHeadPosition = new Point(Positions[0].X, mod((int)Positions[0].Y - 1, Rows));
                    break;
                case Direction.Right:
                    newHeadPosition = new Point(mod((int)Positions[0].X + 1, Columns), Positions[0].Y);
                    break;
                case Direction.Down:
                    newHeadPosition = new Point(Positions[0].X, mod((int)Positions[0].Y + 1, Rows));
                    break;
                case Direction.Left:
                    newHeadPosition = new Point(mod((int)Positions[0].X - 1, Columns), Positions[0].Y);
                    break;
            }

            IsAlive = !Crash(Board, newHeadPosition);

            Positions.Insert(0, newHeadPosition);

            if (Board.DidEat(newHeadPosition))
            {
                Length++;
            }
            else
            {
                Positions.RemoveAt(Positions.Count - 1);
            }
        }