Example #1
0
        /// <summary>
        /// Launch the game
        /// </summary>
        /// <param name="args">the arguments to create/join a game</param>
        public static void Main(string[] args)
        {
            // Check the program arguments
            CheckArguments(args);

            try
            {
                Game game = null;

                // Create a game
                if (mode == Mode.CREATE)
                {
                    Console.WriteLine("Creating the game...");
                    game      = GameBusiness.CreateGame(gameName, speedy, versusPlayer);
                    gameToken = game.Token;
                }
                // Then join the game
                Console.WriteLine();
                Console.WriteLine("Joining the game...");
                game = GameBusiness.JoinGame(gameToken, playerKey, character.ToString(), playerName);

                // Wait for the opponent
                if (game.Status == GameStatus.WAITING)
                {
                    Console.WriteLine("Waiting the future victim to join the game...");
                    while (game.Status == GameStatus.WAITING)
                    {
                        Thread.Sleep(500);
                        game = GameBusiness.GetGame(game.Token, playerKey);
                    }
                }

                // Opponent is connected. Waiting the countdown
                game = GameBusiness.GetGame(game.Token, playerKey);
                Console.WriteLine("Waiting countdown during " + game.CountDown + "ms...");
                Thread.Sleep((int)game.CountDown);

                Console.WriteLine();
                Console.WriteLine("Fight !");
                Console.WriteLine();

                // AI playing the game
                game = PlayGame(game);

                Console.WriteLine();
                // game result
                if (game.Me.HealthPoints > 0)
                {
                    Console.WriteLine("You WIN ! :D");
                }
                else
                {
                    Console.WriteLine("You lose... :'(");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Something goes wrong...");
                Console.WriteLine(e.Message);
            }

            QuitApplication();
        }