Example #1
0
File: game.cs Project: zsonbi/snake
        //-----------------------------------------------------------------------
        //Spawns the food
        private void SpawnFood()
        {
            bool isFound;

            do
            {
                isFound     = false;
                Foodcord[0] = (sbyte)rnd.Next(0, maxXsize);
                Foodcord[1] = (sbyte)rnd.Next(0, maxYsize);

                sbyte[,] cords = Player.Getcords();
                //So that the food can't spawn into the snake
                for (int i = 0; i < Player.size; i++)
                {
                    if (Foodcord[0] == cords[i, 0] && Foodcord[1] == cords[i, 1])
                    {
                        isFound = true;
                        break;
                    } //if
                }     //for
            } while (isFound);
        }