public async Task <GameMoveResult> PlayGameAsync(string InstanceID, string Move) { var gmr = new GameMoveResult(); var JOptions = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var url = GetUri("https", ApiHost, _playGamePath, "InstanceID=" + InstanceID + "&Move=" + Move).ToString(); var _result = await _client.PostAsJsonAsync <GameMoveResult>(url, gmr, JOptions); var _moveResult = await _result.Content.ReadFromJsonAsync <GameMoveResult>(JOptions); return(_moveResult); }
public void TestSampleGameFailure() { OnVictoryFlag = false; OnFailureFlag = false; GameMove _solution = new GameMove( ColorSelection.FindColorSwatchByColorName("Blue"), ColorSelection.FindColorSwatchByColorName("Orange"), ColorSelection.FindColorSwatchByColorName("Red"), ColorSelection.FindColorSwatchByColorName("White")); GameMove _guess = new GameMove( ColorSelection.FindColorSwatchByColorName("Blue"), ColorSelection.FindColorSwatchByColorName("Blue"), ColorSelection.FindColorSwatchByColorName("Blue"), ColorSelection.FindColorSwatchByColorName("Blue")); var game = GameEngine.CreateSampleGame(_solution); game.OnVictory += (s, e) => OnVictoryFlag = true; game.OnFailure += (s, e) => OnFailureFlag = true; GameMoveResult result = new GameMoveResult(); for (int i = 0; i < Game.MAX_MOVES_ALLOWED; i++) { result = game.RecordGuess(_guess); } // just test the last one Assert.AreEqual<int>(1, result.NumberOfReds, "Reds"); Assert.AreEqual<int>(0, result.NumberOfWhites, "Whites"); Assert.AreEqual<int>(3, result.NumberOfEmpties, "Empties"); Assert.IsFalse(result.IsSolved, "Solved"); Assert.IsFalse(OnVictoryFlag, "OnVictory"); Assert.IsTrue(OnFailureFlag, "OnFailure"); }
private static Tuple <bool, GameMoveResult, PlayAdventure, CommandState> Helper_DidPlayerMove(PlayAdventure p, GameMoveResult gmr, CommandState cs) { cs.Message = ""; if (p.Player.PlayerDead == false) { var movecommands = new List <string> { "go", "nor", "sou", "eas", "wes", "up", "down", "n", "s", "e", "w", "u", "d" }; if (movecommands.Contains(cs.Command)) { List <string> ml; if (cs.Command == "go") { ml = new List <string> { "north", "south", "east", "west", "up", "down" }; if (ml.Contains(cs.Modifier)) { cs.Valid = true; } else { cs.Valid = false; } } // if the command is a short move convert to word // shortcut for moves ml = new List <string> { "nor", "sou", "eas", "wes", "up", "down", "n", "s", "e", "w", "u", "d" }; if (ml.Contains(cs.Command)) { cs = Parse_ConvertShortMove(cs.Command); } if (cs.Valid == true) { (p, cs) = Action_MovePlayer(p, cs); // update the gmr with the new room details gmr.RoomName = Object_GetRoom(p.Rooms, p.Player.Room).Name; gmr.RoomMessage = Object_GetRoom(p.Rooms, p.Player.Room).Desc; gmr.PlayerName = p.Player.Name; gmr.ItemsMessage = GetRoomItemsList(p.Player.Room, p.Items, true); return(new Tuple <bool, GameMoveResult, PlayAdventure, CommandState>(true, gmr, p, cs)); } else if (cs.Valid == false) { cs.Message = "Wrong Way!"; } } } else { cs.Message = GetFunMessage(p.Messages, "DeadMove".Trim(), cs.Modifier); } return(new Tuple <bool, GameMoveResult, PlayAdventure, CommandState>(false, gmr, p, cs)); }
public void SaveLastMove(GameMoveResult gameMoveResult) { LastMove = gameMoveResult; }
public static Boolean PlayAdventure() { string instanceID; string move; bool error; string errormsg = ""; var _httpClient = new System.Net.Http.HttpClient(); var _client = new swaggerClient(_httpClient) { BaseUrl = ApiUrl }; move = ""; try { DisplayIntro(); Console.WriteLine(); SetColor(ConsoleColor.Yellow); Console.WriteLine("cquit = quit game and capi = Display API endpoint"); SetColor(ConsoleColor.Green); Console.WriteLine(""); // default to game 1 until I we have selection system // Gets the first game and sets up the game gmr = _client.Adventure3Async(1).GetAwaiter().GetResult(); instanceID = gmr.InstanceID; error = false; } catch (Exception e) { // oops! Looks like we had a problem starting the game. SetColor(ConsoleColor.Red); errormsg = "Error: Can not create new game (" + ApiUrl + ")"; Console.WriteLine(errormsg); Console.WriteLine(e.ToString()); SetColor(ConsoleColor.Green); return(false); } while (move != "cquit") { switch (move) { case "capi": Console.WriteLine(); SetColor(ConsoleColor.Yellow); Console.WriteLine("Api:" + ApiUrl); SetColor(ConsoleColor.Green); Console.WriteLine(); move = ""; break; default: Console.WriteLine(); SetColor(ConsoleColor.Yellow); Console.Write(gmr.RoomName); Console.WriteLine(); SetColor(ConsoleColor.Green); Console.WriteLine(gmr.RoomMessage); SetColor(ConsoleColor.DarkCyan); Console.WriteLine(gmr.ItemsMessage); Console.WriteLine(); SetColor(ConsoleColor.White); Console.Write("What now?"); SetColor(ConsoleColor.Green); Console.Write(" >"); SetColor(ConsoleColor.Green); if (error == true) { Console.WriteLine(); SetColor(ConsoleColor.Red); Console.WriteLine("Client Error:"); Console.WriteLine(errormsg); SetColor(ConsoleColor.Green); Console.WriteLine(); } move = Console.ReadLine(); try { // once the game is setup by calling the get that returns the first gmr you then // just pass the game move with the instance id gmr = _client.Adventure2Async(instanceID, move).GetAwaiter().GetResult(); } catch (Exception) { error = true; SetColor(ConsoleColor.Red); errormsg = "Error: Can not Process Move - Possible Timeout. Try move again or LOOK."; gmr.RoomMessage = errormsg; // report the error ro the user; SetColor(ConsoleColor.Green); } break; } } if (error) { Console.WriteLine(errormsg); } return(error); }