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!!!"); } } }
/// <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); } } } }
/// <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!!!"); } } }