Exemple #1
0
        private void loadLevel_Click(object sender, EventArgs e)
        {
            levelClass = new snakeLevelGame();

            level = levelClass.loadLevel();

            if (levelClass.game != null)
            {
                foreach (int[] block in levelClass.game.table)
                {
                    if (block[2] == 2)
                    {
                        direction = block[3];
                        break;
                    }
                }

                //while (levelClass.game.tableSize[0] * levelClass.game.cellSize > Screen.PrimaryScreen.Bounds.Width - 80 || levelClass.game.tableSize[1] * levelClass.game.cellSize > Screen.PrimaryScreen.Bounds.Height - 240)
                //{
                //    levelClass.game.cellSize -= 1;
                //}


                newGame(new int[] { levelClass.game.tableSize[0], levelClass.game.tableSize[1] }, levelClass.game.cellSize, levelClass.game.barrier, direction);

                levelClass.drawLevel(snakeClass.snakeTable, snakeClass.stata);
                snakeClass.foodMap(levelClass.game);
            }
        }
Exemple #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);
            }
        }