Esempio n. 1
0
 public void elapsed(object sender, ElapsedEventArgs e)
 {
     if (Butter.gameOver)
     {
         gameover();
     }
     else
     {
         if (Butter.score == 2)
         {
             timer.Enabled = !timer.Enabled;
             Nextlvl.Serialize(2, Butter.username, 20, 20, 1, 3);
             System.Diagnostics.Process.Start(System.AppDomain.CurrentDomain.FriendlyName);
             Environment.Exit(0);
         }
         else
         if (Butter.score == 5)
         {
             timer.Enabled = !timer.Enabled;
             Nextlvl.Serialize(3, Butter.username, 20, 20, 1, 6);
             System.Diagnostics.Process.Start(System.AppDomain.CurrentDomain.FriendlyName);
             Environment.Exit(0);
         }
         worm.Clear();
         worm.Move();
         worm.Draw();
         CheckCollision();
     }
 }
Esempio n. 2
0
 public static void gameover()
 {
     if (Butter.gameOver)
     {
         Nextlvl.Serialize(1, "n", 20, 20, 0, -1);
         Console.SetCursorPosition(15, 34);
         Console.WriteLine("Game over!");
         Console.WriteLine(Butter.username + " your score: " + Butter.score);
         Console.WriteLine("Press R to reset the game!");
         Console.WriteLine("Press ESC to save your record and close the game!");
     }
 }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Nextlvl.Deserialize();
            GameState game = new GameState();

            if (Returnlvl.count == 1)
            {
                Butter.username = Returnlvl.login;
                Butter.score    = Returnlvl.score;
                Savescore.Deserialize();
                Console.Clear();

                game.Run2();

                while (true)
                {
                    if (Butter.gameOver)
                    {
                        GameState.gameover();
                    }
                    game.DrawScore();

                    ConsoleKeyInfo consoleKeyInfo = Console.ReadKey();
                    game.ProcessKeyEvent(consoleKeyInfo);
                }
            }
            else
            {
                Console.WriteLine("Champions:");
                Savescore.Deserialize();
                DesOutput.PrintScore();
                Console.WriteLine("Enter username:");
                Butter.username = Console.ReadLine();
                Console.Clear();
                game.Run();


                while (true)
                {
                    if (Butter.gameOver)
                    {
                        GameState.gameover();
                    }
                    ConsoleKeyInfo consoleKeyInfo = Console.ReadKey();
                    game.ProcessKeyEvent(consoleKeyInfo);
                    game.DrawScore();
                }
            }
        }
Esempio n. 4
0
        public void ProcessKeyEvent(ConsoleKeyInfo consoleKeyInfo)
        {
            switch (consoleKeyInfo.Key)
            {
            case ConsoleKey.UpArrow:
                worm.dx = 0;
                worm.dy = -1;
                break;

            case ConsoleKey.DownArrow:
                worm.dx = 0;
                worm.dy = 1;
                break;

            case ConsoleKey.RightArrow:
                worm.dx = 1;
                worm.dy = 0;
                break;

            case ConsoleKey.LeftArrow:
                worm.dx = -1;
                worm.dy = 0;
                break;

            case ConsoleKey.Escape:
                timer.Enabled = !timer.Enabled;
                Savescore.Serialize();
                Nextlvl.Serialize(1, "n", 20, 20, 0, -1);
                Environment.Exit(0);
                break;

            case ConsoleKey.R:
                System.Diagnostics.Process.Start(System.AppDomain.CurrentDomain.FriendlyName);
                Environment.Exit(0);
                break;
            }
        }