static void Main(string[] args) { WordScrambleGameClient proxy = new WordScrambleGameClient(); bool canPlayGame = true; Console.WriteLine("Player's name?"); String playerName = Console.ReadLine(); if (!proxy.isGameBeingHosted()) { Console.WriteLine("Welcome " + playerName + "! Do you want to host the game?"); if (Console.ReadLine().CompareTo("yes") == 0) { Console.WriteLine("Type the word to scramble."); string inputWord = Console.ReadLine(); string scrambledWord = proxy.hostGame(playerName, "", inputWord); canPlayGame = false; Console.WriteLine("You're hosting the game with word '" + inputWord + "' scrambled as '" + scrambledWord + "'"); Console.ReadKey(); } } if (canPlayGame) { Console.WriteLine("Do you want to play the game?"); if (Console.ReadLine().CompareTo("yes") == 0) { Word gameWords = proxy.join(playerName); Console.WriteLine("Can you unscramble this word? => " + gameWords.scrambledWord); String guessedWord; bool gameOver = false; while (!gameOver) { guessedWord = Console.ReadLine(); gameOver = proxy.guessWord(playerName, guessedWord, gameWords.unscrambledWord); if (!gameOver) { Console.WriteLine("Nope, try again..."); } } Console.WriteLine("You WON!!!"); } } }
private static void GameLoop(WordScrambleGameClient proxy, String playerName, Word gameWords) { InformUser("Can you unscramble this word? => " + gameWords.ScrambledWord, wait: false); bool gameOver = false; while (!gameOver) { gameWords.UnscrambledWord = Console.ReadLine(); try { gameOver = proxy.GuessWord(playerName, gameWords); } catch (FaultException<WordMismatchFault> fault) { InformUser(fault.Detail.Message); // Inform user but let them try to keep playing } catch (FaultException<PlayerNotPlayingTheGameFault> fault) { try { gameWords = proxy.Join(playerName); // Try joining and trying again gameOver = proxy.GuessWord(playerName, gameWords); } catch (Exception exception) { // If anything else bad happends, we can return the first fault, the second exception and error out to console. InformUser(fault.Message); InformUser(exception.GetBaseException().Message); throw fault; } } if (!gameOver) { InformUser("Nope, try again...", wait: false); } } InformUser("You WON!!!"); }
/// <summary> /// Input Method /// </summary> static void Input() { WordScrambleGameClient proxy = new WordScrambleGameClient(); bool canPlayGame = true; Console.WriteLine("Player's name?"); String playerName = Console.ReadLine(); if (!proxy.isGameBeingHosted()) { Console.WriteLine("Welcome " + playerName + "! Do you want to host the game?"); if (Console.ReadLine().CompareTo("yes") == 0) { Console.WriteLine("Type the word to scramble."); string inputWord = Console.ReadLine(); try { string scrambledWord = proxy.hostGame(playerName, "", inputWord); canPlayGame = false; Console.WriteLine("You're hosting the game with word '" + inputWord + "' scrambled as '" + scrambledWord + "'"); Console.ReadKey(); } catch (FaultException<GameBeingHostedFault> fault) { Console.WriteLine(fault.Detail.Reason); return; } } } if (canPlayGame) { Console.WriteLine("Do you want to play the game?"); if (Console.ReadLine().CompareTo("yes") == 0) { Word gameWords; try { gameWords = proxy.join(playerName); } catch (FaultException<MaxPlayersReachedFault> fault) { Console.WriteLine(fault.Detail.Reason); return; } catch (FaultException<HostCantJoinGameFault> fault) { Console.WriteLine(fault.Detail.Reason); return; } catch (FaultException<GameIsNotBeingHostedFault> fault) { Console.WriteLine(fault.Detail.Reason); return; } Console.WriteLine("Can you unscramble this word? => " + gameWords.scrambledWord); String guessedWord; bool gameOver = false; while (!gameOver) { guessedWord = Console.ReadLine(); try { gameOver = proxy.guessWord(playerName, guessedWord, gameWords.unscrambledWord); } catch (FaultException<PlayerNotPlayingTheGameFault> fault) { Console.WriteLine(fault.Detail.Reason); return; } if (!gameOver) { Console.WriteLine("Nope, try again..."); } } Console.WriteLine("You WON!!!"); } } }
static void Main(string[] args) { IWordScrambleGame game = new WordScrambleClient.WordScrambleGameService.WordScrambleGameClient(); WordScrambleGameClient proxy = new WordScrambleGameClient(); bool canPlayGame = true; Console.WriteLine("Player's name?"); String playerName = Console.ReadLine(); if (!proxy.isGameBeingHosted()) { Console.WriteLine("Welcome " + playerName + "! Do you want to host the game?"); if (Console.ReadLine().CompareTo("yes") == 0) { Console.WriteLine("Type the word to scramble."); string inputWord = Console.ReadLine(); inputWord = inputWord.Trim(); string scrambledWord = ""; try { scrambledWord = proxy.hostGame(playerName, "", inputWord); } catch (FaultException <GameBeingHostedFault> e) { Console.WriteLine("WARNING: {0}", e.Detail.problem); } canPlayGame = false; Console.WriteLine("You're hosting the game with word '" + inputWord + "' scrambled as '" + scrambledWord + "'"); Console.ReadKey(); } } if (canPlayGame) { Console.WriteLine("Do you want to play the game?"); if (Console.ReadLine().CompareTo("yes") == 0) { //catch the host cannot join game exception try { //catch the nogame hosted exception try { //catch the maxium players reached exception try { Word gameWords = proxy.join(playerName); Console.WriteLine("Can you unscramble this word? => " + gameWords.scrambledWord); String guessedWord; bool gameOver = false; while (!gameOver && !proxy.isGameOver()) { guessedWord = Console.ReadLine(); //catch the 'not playing game' fault try { gameOver = proxy.guessWord(playerName, guessedWord, gameWords.unscrambledWord); } catch (FaultException <PlayerNotPlayingGameFault> e) { Console.WriteLine("Warning: {0}", e.Detail.problem); } if (!gameOver) { Console.WriteLine("Nope, try again..."); } else if (proxy.isGameOver()) { Console.WriteLine("Game is over. YOU HAVE LOST!"); } } Console.WriteLine("You WON!!!"); } catch (FaultException <MaximumPlayersReachedFault> e) { Console.WriteLine("WARNING: you, {1} cannot join due to {0}", e.Detail.problem, e.Detail.playerName); } } catch (FaultException <NoGameHostedFault> e) { Console.WriteLine("WARNING: {0}", e.Detail.problem); } } catch (FaultException <HostCannotJoinGameFault> e) { Console.WriteLine("WARNING: {0} due to your name {1} hosting.", e.Detail.problem, e.Detail.userName); } } } }
static void Main(string[] args) { IWordScrambleGame game = new WordScrambleClient.WordScrambleGameService.WordScrambleGameClient(); WordScrambleGameClient proxy = new WordScrambleGameClient(); bool canPlayGame = true; Console.WriteLine("Player's name?"); String playerName = Console.ReadLine(); if (!proxy.isGameBeingHosted()) { Console.WriteLine("Welcome " + playerName + "! Do you want to host the game?"); if (Console.ReadLine().CompareTo("yes") == 0) { Console.WriteLine("Type the word to scramble."); string inputWord = Console.ReadLine(); inputWord = inputWord.Trim(); string scrambledWord = ""; try { scrambledWord = proxy.hostGame(playerName, "", inputWord); } catch (FaultException<GameBeingHostedFault> e) { Console.WriteLine("WARNING: {0}", e.Detail.problem); } canPlayGame = false; Console.WriteLine("You're hosting the game with word '" + inputWord + "' scrambled as '" + scrambledWord + "'"); Console.ReadKey(); } } if (canPlayGame) { Console.WriteLine("Do you want to play the game?"); if (Console.ReadLine().CompareTo("yes") == 0) { //catch the host cannot join game exception try { //catch the nogame hosted exception try { //catch the maxium players reached exception try { Word gameWords = proxy.join(playerName); Console.WriteLine("Can you unscramble this word? => " + gameWords.scrambledWord); String guessedWord; bool gameOver = false; while (!gameOver && !proxy.isGameOver()) { guessedWord = Console.ReadLine(); //catch the 'not playing game' fault try { gameOver = proxy.guessWord(playerName, guessedWord, gameWords.unscrambledWord); } catch(FaultException<PlayerNotPlayingGameFault> e) { Console.WriteLine("Warning: {0}", e.Detail.problem); } if (!gameOver) { Console.WriteLine("Nope, try again..."); } else if(proxy.isGameOver()) { Console.WriteLine("Game is over. YOU HAVE LOST!"); } } Console.WriteLine("You WON!!!"); } catch (FaultException<MaximumPlayersReachedFault> e) { Console.WriteLine("WARNING: you, {1} cannot join due to {0}", e.Detail.problem, e.Detail.playerName); } } catch (FaultException<NoGameHostedFault> e) { Console.WriteLine("WARNING: {0}", e.Detail.problem); } } catch (FaultException<HostCannotJoinGameFault> e) { Console.WriteLine("WARNING: {0} due to your name {1} hosting.", e.Detail.problem, e.Detail.userName); } } } }
static void Main(string[] args) { WordScrambleGameClient proxy = new WordScrambleGameClient(); bool canPlayGame = true; String playerName = Question("Player's name?"); if (!proxy.IsGameBeingHosted()) { if (YesOrNo("Welcome " + playerName + "! Do you want to host the game?")) { string inputWord = Question("Type the word to scramble."); string scrambledWord; try { scrambledWord = proxy.HostGame(playerName, inputWord); canPlayGame = false; Console.WriteLine("You're hosting the game with word '" + inputWord + "' scrambled as '" + scrambledWord + "'"); Console.ReadKey(); } catch (FaultException<GameBeingHostedFault> fault) { InformUser(fault.Detail.Message + " ", wait: false); } } } if (canPlayGame) { if (YesOrNo("Do you want to play the game?")) { Word gameWords = null; do { try { gameWords = proxy.Join(playerName); } catch (FaultException<MaximumNumberOfPlayersReachedFault> fault) { InformUser(fault.Detail.Message, wait: false); } catch (FaultException<PlayerAlreadyInGameFault> fault) { InformUser(fault.Detail.Message, wait: false); } catch (FaultException<HostCannotJoinTheGameFault> fault) { InformUser(fault.Detail.Message, wait: false); } catch (FaultException<GameIsNotBeingHostedFault> fault) { InformUser(fault.Detail.Message, wait: false); } } while (gameWords == null && YesOrNo("You failed to join, try again?")); if (gameWords != null) GameLoop(proxy, playerName, gameWords); } } }
/// <summary> /// Input Method /// </summary> static void Input() { WordScrambleGameClient proxy = new WordScrambleGameClient(); bool canPlayGame = true; Console.WriteLine("Player's name?"); String playerName = Console.ReadLine(); if (!proxy.isGameBeingHosted()) { Console.WriteLine("Welcome " + playerName + "! Do you want to host the game?"); if (Console.ReadLine().CompareTo("yes") == 0) { Console.WriteLine("Type the word to scramble."); string inputWord = Console.ReadLine(); try { string scrambledWord = proxy.hostGame(playerName, "", inputWord); canPlayGame = false; Console.WriteLine("You're hosting the game with word '" + inputWord + "' scrambled as '" + scrambledWord + "'"); Console.ReadKey(); } catch (FaultException <GameBeingHostedFault> fault) { Console.WriteLine(fault.Detail.Reason); return; } } } if (canPlayGame) { Console.WriteLine("Do you want to play the game?"); if (Console.ReadLine().CompareTo("yes") == 0) { Word gameWords; try { gameWords = proxy.join(playerName); } catch (FaultException <MaxPlayersReachedFault> fault) { Console.WriteLine(fault.Detail.Reason); return; } catch (FaultException <HostCantJoinGameFault> fault) { Console.WriteLine(fault.Detail.Reason); return; } catch (FaultException <GameIsNotBeingHostedFault> fault) { Console.WriteLine(fault.Detail.Reason); return; } Console.WriteLine("Can you unscramble this word? => " + gameWords.scrambledWord); String guessedWord; bool gameOver = false; while (!gameOver) { guessedWord = Console.ReadLine(); try { gameOver = proxy.guessWord(playerName, guessedWord, gameWords.unscrambledWord); } catch (FaultException <PlayerNotPlayingTheGameFault> fault) { Console.WriteLine(fault.Detail.Reason); return; } if (!gameOver) { Console.WriteLine("Nope, try again..."); } } Console.WriteLine("You WON!!!"); } } }