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; }
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; }
/// <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); }
/// <summary> /// ctor /// </summary> /// <param name="reason"></param> public ExitGameEventArgs(ExitGameReason reason) { Reason = reason; }