Example #1
0
        private void StartANewGame(bool Bot = false, dynamic Settings = null)
        {
            int width  = mapUI.GetLength(0);
            int height = mapUI.GetLength(1);
            Map map    = new Map(new Size(width, height));

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    mapUI[i, j].Land = map.Locations[i, j];
                }
            }
            if (!Bot)
            {
                GameHandle.Initialize(this, map, new Func <int, int>[] { AddFood });
                GameHandle.OnSnakeMoves += GameHandle_OnSnakeMoves;
                GameHandle.OnSnakeEats  += GameHandle_OnSnakeEats;
                GameHandle.OnGameStops  += GameHandle_OnGameStops;
                GameHandle.GameFinished += (sender, e) => {
                    Speech.SpeakAsync("You are officially, an expert");
                    MessageBox.Show("The game has finished due to your fenomenal skillz!", "Astonishing!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                };
            }
            else
            {
                SnakeBot bot = new SnakeBot(this, map, Settings.Food);
                bot.Interval = Settings.Time;
                this.bot     = bot;
                bot.Start();
                bot.snake.OnSnakeMoves += GameHandle_OnSnakeMoves;
                bot.snake.OnSnakeEats  += GameHandle_OnSnakeEats;
            }
        }