Beispiel #1
0
        private void gameButton_Click(object sender, EventArgs e)
        {
            Task.Delay(2000);

            if (snakeClass == null || snakeClass.gameOver)
            {
                if (levelClass != null)
                {
                    levelClass.game = JsonConvert.DeserializeObject <structLevelGame>(level);
                }

                newGame(levelClass == null ? new int[] { snakeGame.Properties.Settings.Default.numCellsX, snakeGame.Properties.Settings.Default.numCellsY } : new int[] { levelClass.game.tableSize[0], levelClass.game.tableSize[1] }, levelClass == null ? snakeGame.Properties.Settings.Default.cellSize : levelClass.game.cellSize, levelClass == null ? snakeGame.Properties.Settings.Default.barrier : levelClass.game.barrier, direction);
                if (levelClass != null)
                {
                    levelClass.drawLevel(snakeClass.snakeTable, snakeClass.stata);
                    snakeClass.foodMap(levelClass.game);
                }
            }

            gameButton.Enabled = false;

            if (timerFood == null)
            {
                timerFoodInit(levelClass == null ? snakeGame.Properties.Settings.Default.timeFood : levelClass.game.timeFood);
            }
            if (timerSnake == null)
            {
                timerSnakeInit(levelClass == null ? snakeGame.Properties.Settings.Default.timeSnake : levelClass.game.speedSnake);
            }
            if (gameTimer == null)
            {
                gameTimer = new timerGame(snakeClass, (levelClass == null ? -1 : levelClass.game.timeLeft));
                gameTimer.gameTimeInit();
            }

            timerFood.Enabled          = !timerFood.Enabled;
            timerSnake.Enabled         = !timerSnake.Enabled;
            gameTimer.gameTime.Enabled = !gameTimer.gameTime.Enabled;
        }
Beispiel #2
0
        public void timerSnakeTick(object sender, EventArgs e)
        {
            snakeClass.snakeDirection(snakeClass.direction);
            if (levelClass != null)
            {
                levelClass.checkPos(snakeClass);
                levelClass.drawLevel(snakeClass.snakeTable, snakeClass.stata);
            }
            if (!snakeClass.gameOver)
            {
                snakeClass.snakeDraw();
            }

            if (lastScore != snakeClass.stata.score)
            {
                lastScore = snakeClass.stata.score;
                if (levelClass != null)
                {
                    snakeClass.foodMap(levelClass.game);
                }
            }

            if (snakeClass.gameOver)
            {
                timerSnake.Enabled         = false;
                timerFood.Enabled          = false;
                timerSnake                 = null;
                timerFood                  = null;
                gameTimer.gameTime.Enabled = false;
                gameTimer                  = null;

                string time;
                if (levelClass != null && levelClass.game.timeLeft > 0)
                {
                    time = ((levelClass.game.timeLeft - snakeClass.stata.time) / 60) + " мин " + ((levelClass.game.timeLeft - snakeClass.stata.time) - ((((levelClass.game.timeLeft - snakeClass.stata.time) / 60) * 60))) + " сек";
                }
                else
                {
                    time = (snakeClass.stata.time / 60) + " мин " + (snakeClass.stata.time - (((snakeClass.stata.time / 60) * 60))) + " сек";
                }
                MessageBox.Show("Ваш счет: " + snakeClass.stata.score.ToString() + "\nВремя: " + time + "\nСъедено обычной еды: " + snakeClass.stata.foodEat + "\nСъедено большой еды: " + snakeClass.stata.foodEatMass + "\nДлина змейки: " + snakeClass.stata.length, "Конец игры!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if (snakeClass.winGame)
            {
                timerSnake.Enabled         = false;
                timerFood.Enabled          = false;
                timerSnake                 = null;
                timerFood                  = null;
                gameTimer.gameTime.Enabled = false;
                gameTimer                  = null;

                string time;
                if (levelClass != null && levelClass.game.timeLeft > 0)
                {
                    time = ((levelClass.game.timeLeft - snakeClass.stata.time) / 60) + " мин " + ((levelClass.game.timeLeft - snakeClass.stata.time) - ((((levelClass.game.timeLeft - snakeClass.stata.time) / 60) * 60))) + " сек";
                }
                else
                {
                    time = (snakeClass.stata.time / 60) + " мин " + (snakeClass.stata.time - (((snakeClass.stata.time / 60) * 60))) + " сек";
                }

                MessageBox.Show("Ваш счет: " + snakeClass.stata.score.ToString() + "\nВремя: " + time + "\nСъедено обычной еды: " + snakeClass.stata.foodEat + "\nСъедено большой еды: " + snakeClass.stata.foodEatMass + "\nДлина змейки: " + snakeClass.stata.length, "Конец игры! Уровень пройден!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }