public static void PlayFlappyBird()
        {
            Console.SetWindowSize(95, 28);
            Console.OutputEncoding = Encoding.Unicode;
            HeightOfGameWindow     = 25;
            WidhtOfGameWindow      = 94;
            bool playAgain = true;

            GreenField.StartYPositionForWhole           = 3;
            GreenField.HeightOfWholeInField             = 6;
            GreenField.WidthSizeOfField                 = 8;
            GreenField.NumberOfPositionBetweenEachField = 22;
            GreenField.StartPositonFirstField           = 40;
            while (playAgain)
            {
                playAgain           = false;
                LapNumber           = 0;
                Points              = 0;
                Bird.Alive          = true;
                Bird.XStartPosition = 12;
                Bird.YStartPosition = 10;
                Screen.XHere        = 0;

                Field1 = new GreenField(GreenField.StartPositonFirstField);
                Field2 = new GreenField(GreenField.StartPositonFirstField + GreenField.NumberOfPositionBetweenEachField);
                Field3 = new GreenField(GreenField.StartPositonFirstField + GreenField.NumberOfPositionBetweenEachField * 2);
                Field4 = new GreenField(GreenField.StartPositonFirstField + GreenField.NumberOfPositionBetweenEachField * 3);
                Field5 = new GreenField(GreenField.StartPositonFirstField + GreenField.NumberOfPositionBetweenEachField * 4);
                Bird.CreateBird();
                Screen.StringsMakingScreen = new string[FlappyBirdGame.HeightOfGameWindow, FlappyBirdGame.WidhtOfGameWindow];

                Screen.StartGame();

                while (Bird.Alive)
                {
                    LapNumber++;
                    Console.SetCursorPosition(0, 0);

                    if (LapNumber < 1000)
                    {
                        if (LapNumber % 2 == 0)
                        {
                            GreenField.SetStartPositionOneStepBack();
                        }
                    }
                    else if (LapNumber > 1000 && LapNumber < 2000)
                    {
                        if (LapNumber % 2 == 0 || LapNumber % 3 == 0)
                        {
                            GreenField.SetStartPositionOneStepBack();
                        }
                    }
                    else
                    {
                        GreenField.SetStartPositionOneStepBack();
                    }

                    if (LapNumber % 2 == 0)
                    {
                        Bird.YStartPosition++;
                        if (Bird.YStartPosition + Bird.BirdSizeY > 26)
                        {
                            Bird.Alive = false;
                        }
                    }
                    if (Bird.YStartPosition < 0)
                    {
                        Bird.Alive = false;
                    }
                    if (Console.KeyAvailable)
                    {
                        switch (Console.ReadKey(true).Key)
                        {
                        case ConsoleKey.UpArrow:
                        {
                            Bird.YStartPosition = Bird.YStartPosition - 2;
                        }
                        break;

                        case ConsoleKey.Spacebar:
                        {
                            Bird.YStartPosition = Bird.YStartPosition - 3;
                        }
                        break;

                        case ConsoleKey.Escape:
                        {
                            Bird.Alive = false;
                        }
                        break;

                        default:
                            break;
                        }
                    }

                    Screen.CreateScreen();
                    Screen.PrintScreen();

                    System.Threading.Thread.Sleep(15);
                }

                Console.SetCursorPosition(0, 0);
                Screen.EndGame();
                Console.SetWindowSize(110, 45);
                Console.Clear();
                HighScoreEachGame.OpenHighscores("flappybirdhighscore.txt", HighScoreEachGame.ListFlappyBird);
                HighScoreEachGame.PrintOutHighscores("-------------FLAPPY BIRD-------------", HighScoreEachGame.ListFlappyBird);
                Console.WriteLine();
                Console.WriteLine($"\t\t\t\t\tDu fick {FlappyBirdGame.Points} poäng.\n");
                int maybeHighscore = HighScoreEachGame.SeeIfHighscore(HighScoreEachGame.ListFlappyBird, FlappyBirdGame.Points);
                if (maybeHighscore < 11)
                {
                    Console.WriteLine("\t\t\t\t\tGrattis! Du kom in på Highscore-listan!");
                    HighScoreEachGame.PutHighScoreInList(maybeHighscore, Points, HighScoreEachGame.ListFlappyBird);
                    HighScoreEachGame.PutHighScoreInFile("flappybirdhighscore.txt", HighScoreEachGame.ListFlappyBird);
                    Console.Clear();
                    HighScoreEachGame.OpenHighscores("flappybirdhighscore.txt", HighScoreEachGame.ListFlappyBird);
                    HighScoreEachGame.PrintOutHighscores("-------------FLAPPY BIRD-------------", HighScoreEachGame.ListFlappyBird);
                    Console.WriteLine();
                }
                else
                {
                    Console.WriteLine("\t\t\t\t\tBättre lycka nästa gång!\n\n");
                }
                Console.ForegroundColor = ConsoleColor.Blue;
                Console.WriteLine("\t\t\t\t\tVill du spela igen?");
                Console.WriteLine("\t\t\t\t\t[1] --> JA!");
                Console.WriteLine("\t\t\t\t\t[0] --> EXIT.");
                Console.Write("\t\t\t\t\t");
                int choice = InputNumber(0, 1);
                if (choice == 1)
                {
                    playAgain = true;
                }
                Console.Clear();
            }
            Console.Clear();
            Console.ReadLine();
        }
Esempio n. 2
0
        public static void PlaySnake()
        {
            bool playAgain = true;

            Console.OutputEncoding = Encoding.Unicode;
            while (playAgain)
            {
                playAgain = false;

                Counter = 0;
                GameBoardSnake.XSize = 25;
                GameBoardSnake.YSize = 15;
                Apple         apple         = new Apple();
                Snake         snake         = new Snake(5, 5);
                SnakeFragment snakeFragment = new SnakeFragment(0, 0);
                Console.Clear();
                Intro();
                Console.ForegroundColor = ConsoleColor.Gray;
                //Console.WriteLine("\u263A");
                Console.WriteLine("\n");
                Console.WriteLine("\t\t\t\tTryck valfri tangent för att starta.\n");
                Console.ReadKey(true);
                Console.Clear();
                while (snake.Alive)
                {
                    AddSnakeFragment = false;
                    Console.SetCursorPosition(0, 0);
                    Console.WriteLine("\n\n\n\n");
                    GameBoardSnake.PrintOutGameBoard(snake.WholeSnake, apple);

                    if (Console.KeyAvailable)
                    {
                        switch (Console.ReadKey(true).Key)
                        {
                        case ConsoleKey.UpArrow:
                            if (snake.DirectionY != 1)
                            {
                                snake.DirectionX = 0;
                                snake.DirectionY = -1;
                            }
                            break;

                        case ConsoleKey.DownArrow:
                            if (snake.DirectionY != -1)
                            {
                                snake.DirectionX = 0;
                                snake.DirectionY = +1;
                            }
                            break;

                        case ConsoleKey.LeftArrow:
                            if (snake.DirectionX != 1)
                            {
                                snake.DirectionX = -1;
                                snake.DirectionY = 0;
                            }
                            break;

                        case ConsoleKey.RightArrow:
                            if (snake.DirectionX != -1)
                            {
                                snake.DirectionX = +1;
                                snake.DirectionY = 0;
                            }
                            break;

                        default:
                            break;
                        }
                    }

                    //if (AddSnakeFragment)
                    //{ snakeFragment = snake.LastSnakeFragment(); }
                    snake.WholeSnake = snake.NewPositionsForSnakeFragments();
                    //if (AddSnakeFragment)
                    //{ snake.AddOneMoreSnakeFragment(snakeFragment); }
                    Console.WriteLine();
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine($"\t\t\t\t\tPOÄNG: {SnakeGame.Counter}");
                    snake.CheckIfDies();
                    if (snake.DirectionY != 0)
                    {
                        System.Threading.Thread.Sleep(150);
                    }
                    else
                    {
                        System.Threading.Thread.Sleep(100);
                    }
                }
                Console.WriteLine();
                Console.WriteLine("\t\t\t\t\tDu är död :(\n\n");
                System.Threading.Thread.Sleep(1000);
                Console.WriteLine("\t\t\t\t\tTryck för att se Highscore.");
                Console.ReadKey(true);

                Console.Clear();
                HighScoreEachGame.OpenHighscores("highscoresnake.txt", HighScoreEachGame.ListSnake);
                HighScoreEachGame.PrintOutHighscores("----------------------SNAKE--------------------", HighScoreEachGame.ListSnake);
                Console.WriteLine();
                Console.WriteLine($"\t\t\t\t\tDu fick {SnakeGame.Counter} poäng.\n");
                int maybeHighscore = HighScoreEachGame.SeeIfHighscore(HighScoreEachGame.ListSnake, SnakeGame.Counter);
                if (maybeHighscore < 11)
                {
                    Console.WriteLine("\t\t\t\t\tGrattis! Du kom in på Highscore-listan!");
                    HighScoreEachGame.PutHighScoreInList(maybeHighscore, SnakeGame.Counter, HighScoreEachGame.ListSnake);
                    HighScoreEachGame.PutHighScoreInFile("highscoresnake.txt", HighScoreEachGame.ListSnake);
                    Console.Clear();
                    HighScoreEachGame.OpenHighscores("highscoresnake.txt", HighScoreEachGame.ListSnake);
                    HighScoreEachGame.PrintOutHighscores("----------------SNAKE----------------", HighScoreEachGame.ListSnake);
                    Console.WriteLine();
                }
                else
                {
                    Console.WriteLine("\t\t\t\t\tBättre lycka nästa gång!\n\n");
                }
                Console.ForegroundColor = ConsoleColor.Blue;
                Console.WriteLine("\t\t\t\t\tVill du spela igen?");
                Console.WriteLine("\t\t\t\t\t[1] --> JA!");
                Console.WriteLine("\t\t\t\t\t[0] --> EXIT.");
                Console.Write("\t\t\t\t\t");
                int choice = InputNumber(0, 1);
                if (choice == 1)
                {
                    playAgain = true;
                }
            }
            Console.ReadLine();
        }