Example #1
0
 private void Snake_OnNewGame()
 {
     head = new GameBlock()
     {
         X = 10, Y = 10, Vector = Vector.Up, Color = GameColor.Green
     };
     body = new List <GameBlock>();
     body.Add(head);
     body.Add(new GameBlock()
     {
         X = 10, Y = 11, Vector = Vector.Up, Color = GameColor.Black
     });
     body.Add(new GameBlock()
     {
         X = 10, Y = 12, Vector = Vector.Up, Color = GameColor.Black
     });
     CreateEat();
     DrawField();
 }
Example #2
0
        private void CreateEat()
        {
            var emptyBlocks = new List <GameBlock>();

            for (int i = 0; i < MainForm.FIELD_SIZE; i++)
            {
                for (int j = 0; j < MainForm.FIELD_SIZE; j++)
                {
                    if (CheckEmptyBlock(i, j))
                    {
                        emptyBlocks.Add(new GameBlock()
                        {
                            X = i, Y = j, Color = GameColor.Red
                        });
                    }
                }
            }
            if (emptyBlocks.Count > 0)
            {
                eat = emptyBlocks[random.Next(emptyBlocks.Count)];
            }
        }
Example #3
0
 public bool Equals(GameBlock block) => X == block.X && Y == block.Y;