コード例 #1
0
        public static void ExitGame(ExitGameReason reason)
        {
            switch (reason)
            {
            case ExitGameReason.ExitCommand:
                Console.WriteLine("Good Bye.");
                break;

            case ExitGameReason.PlayerDie:
                for (int i = 0; i < 10; i++)
                {
                    Console.ForegroundColor = ConsoleColor.DarkRed;
                    Console.WriteLine("     You Die. Game Over!     You Die. Game Over!     You Die. Game Over!");
                }
                break;

            case ExitGameReason.PlayerWinTheGame:
                for (int i = 0; i < 10; i++)
                {
                    Thread.Sleep(300);
                    Console.ForegroundColor = ConsoleColor.DarkCyan;
                    Console.WriteLine("Congratulations! You Win.  Congratulations! You Win.  Congratulations! You Win.");
                }
                break;
            }

            Save.SaveHeroInformation();
            Game.LogoutUser();
            Game.IsGameRunning = false;
        }
コード例 #2
0
ファイル: Engine.cs プロジェクト: OOP-Team-Tapani/RPG-Game
 public static void ExitGame(ExitGameReason reason)
 {
     switch (reason)
     {
         case ExitGameReason.ExitCommand:
             Console.WriteLine("Good Bye.");
             break;
         case ExitGameReason.PlayerDie:
             for (int i = 0; i < i+1; i++)
             {
                 Console.ForegroundColor = ConsoleColor.DarkRed;
                 Console.WriteLine("     You Die. Game Over!     You Die. Game Over!     You Die. Game Over!");
             }
             break;
         case ExitGameReason.PlayerWinTheGame:
             for (int i = 0; i < 10; i++)
             {
                 Thread.Sleep(300);
                 Console.ForegroundColor = ConsoleColor.DarkCyan;
                 Console.WriteLine("Congratulations! You Win.  Congratulations! You Win.  Congratulations! You Win.");
             }
             break;
     }
     Game.IsGameRunning = false;
 }
コード例 #3
0
        /// <summary>
        /// Exit a game. If game was active and had not finished, player will loose the game.
        /// </summary>
        /// <param name="uid">Game id.</param>
        /// <param name="reason">Reason for exit.</param>
        /// <returns>True if request was sent.</returns>
        public async Task <bool> ExitGame(uint uid, ExitGameReason reason)
        {
            var result = false;

            // Catch the event for game exit
            var source = new TaskCompletionSource <bool>();
            EventHandler <ExitGameEventArgs> handler = (sender, args) =>
            {
                source.TrySetResult(true);
            };

            // In case no answer was received, we have to cancel
            using (var ct = new CancellationTokenSource(NetworkTimeout * 1000))
            {
                ct.Token.Register(() => source.TrySetResult(false));
                try
                {
                    GameExitReceived += handler;
                    var pak = new ExitGame {
                        UID = uid, Reason = reason
                    };
                    if (Send(JsonConvert.SerializeObject(pak, _serializerSettings), NetworkPacketType.ExitGame))
                    {
                        result = await source.Task;
                    }
                }
                catch (Exception e) { Log.WriteLine(LogPriority.Error, "NetworkGameClient::ExitGame(): " + e.Message); }
                finally { GameExitReceived -= handler; }
            }
            if (!result) // Screw it!
            {
                UID      = 0;
                IsJoined = false;
            }
            return(result);
        }
コード例 #4
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="reason"></param>
 public ExitGameEventArgs(ExitGameReason reason)
 {
     Reason = reason;
 }