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(); }
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)]; } }
public bool Equals(GameBlock block) => X == block.X && Y == block.Y;