public void displayAccusedList(Accusation accusation, ArrayList seenKeywords, Person person) { foreach (Transform child in peopleInCurrentLineup.transform) { Destroy(child.gameObject); } currentAccusables = accusation.filteredChoices(seenKeywords); for (int i = 0; i < currentAccusables.Count; i++) { Transform sourcePerson = peopleInLineup.transform.GetChild(((AccusationChoice)currentAccusables[i]).personId); Transform displayedPerson = GameObject.Instantiate(sourcePerson); displayedPerson.parent = peopleInCurrentLineup.transform; Vector3 newPosition = sourcePerson.localPosition; newPosition.x = i * spaceBetweenPeople; displayedPerson.localPosition = newPosition; displayedPerson.localScale = sourcePerson.localScale; } peopleInCurrentLineup.transform.localPosition = new Vector3(); changeAccusationText((AccusationChoice)currentAccusables[0], seenKeywords, person.personName); playerTalking(); }
public IHttpActionResult MakeAccusation([FromBody] Accusation accusation) { AuthResult auth = authorizeAndVerifyGameStart(); if (auth.result != null) { return(auth.result); } var game = auth.game.getGame(); var player = auth.player; if (!isPlayerTurn(game, player)) { return(Unauthorized()); } bool isCorrect = game.makeAccusation(player.Name, accusation); AccusationData data = new AccusationData { accusation = accusation, playerName = player.Name, accusationCorrect = isCorrect }; var cmd = new Command { command = CommandType.AccusationMade, data = new CommandData { accusationData = data } }; CommandInterface.SetCommandForEveryone(auth.game, cmd); return(Created("", data)); }
// returns 'null' if no other player can disprove public async Task <DisproveData> MakeSuggestionAsync(Accusation accusation) { var json = Json.toJson(accusation); var response = client.PostAsync("/suggest", new CluelessJsonContent(json)).Result; if (response.IsSuccessStatusCode) { var data = Json.fromJson <SuggestionData>(response); if (data.disprovingPlayer == null) { return(null); } // Else, wait for disprove command var disproveResponse = await WaitForCommandAsync(); if (disproveResponse.command == CommandType.DisproveResult) { return(disproveResponse.data.disproveData); } else { return(null); } } return(null); }
private void selectCurrentAccusation() { foreach (Accusation accusation in accusations) { if (accusation.timeState == gameManager.timeState) { currentAccusation = accusation; break; } } }
// returns 'null' on network failure, otherwise returns 'true' if // accusation was correct or 'false' if accusation was incorrect public AccusationData MakeAccusation(Accusation accusation) { var json = Json.toJson(accusation); var response = client.PostAsync("/accuse", new CluelessJsonContent(json)).Result; if (response.IsSuccessStatusCode) { return(Json.fromJson <AccusationData>(response)); } return(null); }
public IHttpActionResult MakeSuggestion([FromBody] Accusation accusation) { AuthResult auth = authorizeAndVerifyGameStart(); if (auth.result != null) { return(auth.result); } // TODO: validate accusationData data var game = auth.game.getGame(); var player = auth.player; if (!isPlayerTurn(game, player)) { return(Unauthorized()); } Command command = new Command(); command.command = CommandType.SuggestionMade; SuggestionData data = new SuggestionData { playerName = player.Name, accusation = accusation }; var cmdData = new CommandData { suggestData = data }; var disprovingPlayer = game.makeSuggestion(player.Name, accusation); if (disprovingPlayer != null) { data.disprovingPlayer = disprovingPlayer.name; var disproveCmd = new Command { command = CommandType.DisproveSuggestion, data = cmdData }; CommandInterface.SetCommandForPlayer(disprovingPlayer.name, disproveCmd); var waitCmd = new Command { command = CommandType.Wait }; CommandInterface.SetCommandForPlayer(player.Name, waitCmd); } command.data = cmdData; CommandInterface.SetCommandForEveryone(auth.game, command); return(Created("", data)); }
public bool DeleteEntity(Accusation entity) { return(base.DeleteEntity <Accusation>(entity)); }
public bool UpdateEntity(Accusation entity) { return(base.UpdateEntity <Accusation>(entity)); }
public bool CreateEntity(Accusation entity) { return(base.CreateEntity <Accusation>(entity)); }
public void TestCreateJoinAndStartGame() { // CluelessServerConnection is not designed for async, so async verifications are // being commented out CluelessServerConnection connect = CluelessServerConnection.getConnection( "localhost", 50351); // Host actions Assert.IsTrue(connect.registerAsPlayer("Harry Potter")); { // Success var lobbies = connect.Lobbies.GetLobbies(); Assert.IsNotNull(lobbies); var lobby = connect.Lobbies.CreateLobby(); Assert.IsNotNull(lobby); lobbies = connect.Lobbies.GetLobbies(); Assert.IsNotNull(lobbies); Assert.AreNotEqual(0, lobbies.Count); // Harry is host, he is already in game Assert.IsFalse(connect.Lobbies.JoinLobby(lobby)); } // Other player actions // Task<bool> ronWaitForGame = null; Assert.IsTrue(connect.registerAsPlayer("Ron Weasley")); { // Success var lobbies = connect.Lobbies.GetLobbies(); var lobby = lobbies[lobbies.Count - 1]; // Ron is not host, he can join Assert.IsTrue(connect.Lobbies.JoinLobby(lobby)); connect.registerToGame(lobby); // registerToGame makes it so 'lobby' isn't needed // as a parameter for further API calls // This function is a blocking call if game has not started. // The client should call this to wait for the game to begin. // There currently isn't a way to cancel a wait. Ryan can // implement that later if desired // if (!connect.Lobbies.WaitForGameStart()) // throw new Exception("Unsuccessful Wait for game start"); // Ron cannot start game because he is not the host Assert.IsFalse(connect.Lobbies.StartGame()); // ronWaitForGame = connect.Lobbies.WaitForGameStartAsync(); // Assert.IsFalse(ronWaitForGame.IsCompleted); } // Have a third person join // Task<bool> hermioneWaitForGame = null; Assert.IsTrue(connect.registerAsPlayer("Hermione")); { // Success var lobbies = connect.Lobbies.GetLobbies(); var lobby = lobbies[lobbies.Count - 1]; Assert.IsTrue(connect.Lobbies.JoinLobby(lobby)); connect.registerToGame(lobby); // hermioneWaitForGame = connect.Lobbies.WaitForGameStartAsync(); // Assert.IsFalse(hermioneWaitForGame.IsCompleted); } // Host can start game Assert.IsTrue(connect.registerAsPlayer("Harry Potter")); { Assert.IsTrue(connect.Lobbies.StartGame()); // Allow call to be sent to Hermione and Ron // Thread.Sleep(3100); // Assert.IsTrue(ronWaitForGame.IsCompleted); // response has come back // Assert.IsTrue(ronWaitForGame.Result); // game has started // Assert.IsTrue(hermioneWaitForGame.IsCompleted); // Assert.IsTrue(hermioneWaitForGame.Result); } // other players 'WaitForGameStart()' will now return true Assert.IsTrue(connect.registerAsPlayer("Ron Weasley")); { Assert.IsTrue(connect.Lobbies.WaitForGameStart()); } Assert.IsTrue(connect.registerAsPlayer("Hermione")); { Assert.IsTrue(connect.Lobbies.WaitForGameStart()); } // Play the game now // Get cards String[] players = { "Harry Potter", "Ron Weasley", "Hermione" }; List <Card> previousPlayersCards = null; Command lastSeenCommand = null; foreach (var playerName in players) { // verify that each player has a hand of cards Assert.IsTrue(connect.registerAsPlayer(playerName)); if (!playerName.Equals("Harry Potter")) // Harry will get message 'Take Turn' { // WaitForCommand should return immediately and not wait here Command command = connect.Gameplay.WaitForCommand(); Assert.AreEqual(CommandType.GameStart, command.command); lastSeenCommand = command; // remove last seen command so that hermione won't block connect.Gameplay.TestOnlySetLastSeenCommand(null); } var cards = connect.Gameplay.GetPlayerHand(); Assert.IsNotNull(cards); Assert.AreNotEqual(0, cards.Count); //// Make sure each hand is unique Assert.AreNotEqual(previousPlayersCards, cards); previousPlayersCards = cards; } // The async code doesn't work with a ClientController task that is // intended for a single process // Task<Command> ronWaitForCommand, hermioneWaitForCommand; // take turn Assert.IsTrue(connect.registerAsPlayer("Harry Potter")); { // Get game state to verify correct information Game game = connect.Gameplay.GetState(); Assert.IsNotNull(game); Command command = connect.Gameplay.WaitForCommand(); Assert.AreEqual(CommandType.TakeTurn, command.command); { // Restore Ron & Hermione's last seen command, since they've seen it, // the request for a command should block connect.Gameplay.TestOnlySetLastSeenCommand(lastSeenCommand); /* * Assert.IsTrue(connect.registerAsPlayer("Ron Weasley")); * ronWaitForCommand = connect.Gameplay.WaitForCommandAsync(); * * Assert.IsTrue(connect.registerAsPlayer("Hermione")); * hermioneWaitForCommand = connect.Gameplay.WaitForCommandAsync(); * * Assert.IsFalse(ronWaitForCommand.IsCompleted); * Assert.IsFalse(hermioneWaitForCommand.IsCompleted); */ } // Harry's starting spot is Scarlet's: new Location(0,3,"Hallway") var expectedMoveData = new MoveData { playerName = "Harry Potter", location = new Location(0, 2, "Hallway") }; Assert.IsTrue(connect.registerAsPlayer(expectedMoveData.playerName)); bool successful = connect.Gameplay.MovePlayerTo(expectedMoveData.location); Assert.IsTrue(successful); // Make sure that Ron & Hermione received message { /* * Thread.Sleep(3100); * Assert.IsTrue(ronWaitForCommand.IsCompleted); * Assert.IsTrue(hermioneWaitForCommand.IsCompleted); * * Command cmd = ronWaitForCommand.Result; */ connect.Gameplay.TestOnlySetLastSeenCommand(lastSeenCommand); Assert.IsTrue(connect.registerAsPlayer("Ron Weasley")); Command cmd = connect.Gameplay.WaitForCommand(); connect.Gameplay.TestOnlySetLastSeenCommand(lastSeenCommand); Assert.IsTrue(connect.registerAsPlayer("Hermione")); Command cmd2 = connect.Gameplay.WaitForCommand(); // Ron & Hermione received the same command Assert.AreEqual(cmd, cmd2); // This is the expected command data Assert.AreEqual(CommandType.MovePlayer, cmd.command); Assert.IsNotNull(cmd.data.moveData); Assert.AreEqual(expectedMoveData, cmd.data.moveData); lastSeenCommand = cmd; } Assert.IsTrue(connect.registerAsPlayer("Harry Potter")); // This blocks // DisproveData result = connect.Gameplay.MakeSuggestion(new Accusation(Room.Ballroom, Suspect.Mustard, Weapon.Pipe)); // if null, no one could disprove // Otherwise, result.card is the proof, and result.playerName is the owner of 'card' // This is called by the 'other' player, not by Harry // successful = connect.Gameplay.DisproveSuggestion(new Card(Weapon.Pipe)); Accusation accusation = new Accusation(Room.Ballroom, Suspect.Mustard, Weapon.Pipe); AccusationData data = connect.Gameplay.MakeAccusation(accusation); Assert.IsNotNull(data); Assert.AreEqual(accusation, data.accusation); Assert.IsFalse(data.accusationCorrect); successful = connect.Gameplay.EndTurn(); Assert.IsTrue(successful); Accusation solution = connect.Gameplay.GetSolution(); Assert.IsNull(solution); // game is not finished. Solution not available until then // it is now Ron's turn Assert.IsTrue(connect.registerAsPlayer("Ron Weasley")); Command finalCmd = connect.Gameplay.WaitForCommand(); Assert.IsNotNull(finalCmd); Assert.AreEqual(CommandType.TakeTurn, finalCmd.command); successful = connect.Gameplay.EndTurn(); Assert.IsTrue(successful); // Hermione's turn Assert.IsTrue(connect.registerAsPlayer("Hermione")); finalCmd = connect.Gameplay.WaitForCommand(); Assert.IsNotNull(finalCmd); Assert.AreEqual(CommandType.TakeTurn, finalCmd.command); successful = connect.Gameplay.EndTurn(); Assert.IsTrue(successful); // Harry's turn again Assert.IsTrue(connect.registerAsPlayer("Harry Potter")); finalCmd = connect.Gameplay.WaitForCommand(); Assert.IsNotNull(finalCmd); Assert.AreEqual(CommandType.TakeTurn, finalCmd.command); } }
public AccusationModel(Accusation accusation) { // TODO }
void CalculateRect() { guiAccusationList.Clear(); TitleLabel = new Rect(0, 0, screenX, 30); SaveBtn = new Rect(screenX - 155, 5, 150, 30); ScrollViewRect = new Rect(0, TitleLabel.height + 5, screenX, screenY - TitleLabel.height - 5); ScrollViewArea = new Rect(0, 0, screenX - 20, 0); Rect prevAccusationGroup = new Rect(5, 0, screenX - 25, 0); for (int i = 0; i < xmlAccusations.Count; i++) { Accusation accusation = (Accusation)xmlAccusations[i]; GUIAccusation guiAccusation = new GUIAccusation(); guiAccusation.timeState = (int)accusation.timeState; Rect accusationGroupRect = new Rect(prevAccusationGroup.x, prevAccusationGroup.y + prevAccusationGroup.height, prevAccusationGroup.width, 0); guiAccusation.AccusationGroup = accusationGroupRect; guiAccusation.AccusationBG = new Rect(0, 0, guiAccusation.AccusationGroup.width, guiAccusation.AccusationGroup.height); guiAccusation.AccusationTitle = new Rect(5, 5, 300, 30); guiAccusation.TimeStampLabel = new Rect(guiAccusation.AccusationTitle.x + guiAccusation.AccusationTitle.width, guiAccusation.AccusationTitle.y, 150, 20); guiAccusation.TimeStampInput = new Rect(guiAccusation.TimeStampLabel.x + guiAccusation.TimeStampLabel.width, guiAccusation.AccusationTitle.y, 150, 20); guiAccusation.TransitionStatement = GenerateStatement(accusation.transitionStatement, guiAccusation.AccusationTitle, guiAccusation.AccusationGroup, "Transition Statement"); Rect prevRect = guiAccusation.TransitionStatement.StatementGroupRect; ScrollViewArea.height += guiAccusation.AccusationTitle.height; ScrollViewArea.height += guiAccusation.TransitionStatement.StatementGroupRect.height; accusationGroupRect.height += guiAccusation.AccusationTitle.height; accusationGroupRect.height += guiAccusation.TransitionStatement.StatementGroupRect.height; for (int j = 0; j < accusation.choices.Count; j++) { AccusationChoice accusationChoice = (AccusationChoice)accusation.choices[j]; GUIAccusationChoice guiAccusationChoice = new GUIAccusationChoice(); guiAccusationChoice.personID = accusationChoice.personId; guiAccusationChoice.defenderID = accusationChoice.defenderId; Rect accusationChoiceGroup = new Rect(20, prevRect.y + prevRect.height + 10, guiAccusation.AccusationGroup.width - 40, 0); guiAccusationChoice.accusationChoiceGroup = accusationChoiceGroup; guiAccusationChoice.choiceTitle = new Rect(5, 5, 150, 30); guiAccusationChoice.AddEnablingKeyword = new Rect(accusationChoiceGroup.width - 155, guiAccusationChoice.choiceTitle.y / 2.0f, 150, 30); guiAccusationChoice.PersonIDLabel = new Rect(guiAccusationChoice.choiceTitle.x + guiAccusationChoice.choiceTitle.width, guiAccusationChoice.choiceTitle.y, 120, 20); guiAccusationChoice.PersonIDInput = new Rect(guiAccusationChoice.PersonIDLabel.x + guiAccusationChoice.PersonIDLabel.width, guiAccusationChoice.PersonIDLabel.y, 150, 20); //ScrollViewArea.height += 10; accusationGroupRect.height += guiAccusationChoice.choiceTitle.height; guiAccusationChoice.DefenderIDLabel = new Rect(guiAccusationChoice.PersonIDInput.x + guiAccusationChoice.PersonIDInput.width + 40, guiAccusationChoice.PersonIDInput.y, 120, 20); guiAccusationChoice.DefenderIDInput = new Rect(guiAccusationChoice.DefenderIDLabel.x + guiAccusationChoice.DefenderIDLabel.width, guiAccusationChoice.DefenderIDLabel.y, 150, 20); Rect tmpPrevRect = guiAccusationChoice.DefenderIDInput; for (int k = 0; k < accusationChoice.enablingKeywords.Count; k++) { guiAccusationChoice.enablingKeywords.Add(((Keyword)accusationChoice.enablingKeywords[k]).text); Rect enablingKeywordLabelRect = new Rect(10, guiAccusationChoice.DefenderIDLabel.y + guiAccusationChoice.DefenderIDLabel.height + k * 25 + 10, 180, 20); Rect enablingKeywordInputRect = new Rect(enablingKeywordLabelRect.x + enablingKeywordLabelRect.width, enablingKeywordLabelRect.y, guiAccusationChoice.accusationChoiceGroup.width - enablingKeywordLabelRect.x - enablingKeywordLabelRect.width - 5 - 30, enablingKeywordLabelRect.height); Rect deleteEnablingKeyword = new Rect(enablingKeywordInputRect.x + enablingKeywordInputRect.width + 5, enablingKeywordInputRect.y, 20, 20); //ScrollViewArea.height += enablingKeywordLabelRect.height + k * 25 + 10; accusationChoiceGroup.height += enablingKeywordLabelRect.height + k * 25 + 10; guiAccusationChoice.EnablingKeywordsLabel.Add(enablingKeywordLabelRect); guiAccusationChoice.EnablingKeywordsInput.Add(enablingKeywordInputRect); guiAccusationChoice.DeleteEnablingKeyword.Add(deleteEnablingKeyword); tmpPrevRect = enablingKeywordLabelRect; } guiAccusationChoice.InvestigatorIntutionTitle = new Rect(10, tmpPrevRect.y + tmpPrevRect.height + 10, 200, 20); tmpPrevRect = guiAccusationChoice.InvestigatorIntutionTitle; guiAccusationChoice.AddInvstigatorIntution = new Rect(accusationChoiceGroup.width - 155, guiAccusationChoice.InvestigatorIntutionTitle.y - 5, 150, 30); //ScrollViewArea.height += guiAccusationChoice.InvestigatorIntutionTitle.height + 10; accusationChoiceGroup.height += guiAccusationChoice.InvestigatorIntutionTitle.height + 10; for (int k = 0; k < accusationChoice.investigatorIntuitions.Count; k++) { Statement investigatorIntution = (Statement)accusationChoice.investigatorIntuitions[k]; tmpPrevRect.height += 10; GUIStatement guiInvestigatorIntution = GenerateStatement(investigatorIntution, tmpPrevRect, guiAccusationChoice.accusationChoiceGroup, "Investigator Intuitions"); tmpPrevRect = guiInvestigatorIntution.StatementGroupRect; //ScrollViewArea.height += guiInvestigatorIntution.StatementGroupRect.height; accusationChoiceGroup.height += guiInvestigatorIntution.StatementGroupRect.height; guiAccusationChoice.investigatorIntution.Add(guiInvestigatorIntution); } accusationChoiceGroup.height += 5; guiAccusationChoice.AccusationStatementTitle = new Rect(10, tmpPrevRect.y + tmpPrevRect.height, 200, 30); tmpPrevRect = guiAccusationChoice.AccusationStatementTitle; guiAccusationChoice.AddAccusationStatement = new Rect(accusationChoiceGroup.width - 155, guiAccusationChoice.AccusationStatementTitle.y + 3, 150, 30); //ScrollViewArea.height += guiAccusationChoice.AccusationStatementTitle.height; accusationChoiceGroup.height += guiAccusationChoice.AccusationStatementTitle.height; for (int k = 0; k < accusationChoice.statementPairs.Count; k++) { Question question = (Question)accusationChoice.statementPairs[k]; GUIAccusationStatementPair accusationStatementPair = new GUIAccusationStatementPair(); Rect accusationStatementGroup = new Rect(tmpPrevRect.x, tmpPrevRect.y + tmpPrevRect.height + 5, guiAccusationChoice.accusationChoiceGroup.width - tmpPrevRect.x - tmpPrevRect.x, 0); accusationStatementPair.titleRect = new Rect(10, 0, 150, 40); accusationStatementGroup.height += accusationStatementPair.titleRect.x + accusationStatementPair.titleRect.height; accusationStatementPair.DeleteStatementPair = new Rect(accusationStatementGroup.width - 155, 5, 150, 30); Rect offsetRect = accusationStatementPair.titleRect; accusationStatementPair.question = GenerateStatement(question.question, offsetRect, accusationStatementGroup, "AccusationStatement"); accusationStatementGroup.height += accusationStatementPair.question.StatementGroupRect.height; //ScrollViewArea.height += accusationStatementPair.question.StatementGroupRect.height; Rect questionTmpRect = new Rect(accusationStatementPair.question.StatementGroupRect); questionTmpRect.height += 5; accusationStatementPair.answer = GenerateStatement(question.answer, questionTmpRect, accusationStatementGroup, "ResultStatement"); accusationStatementGroup.height += accusationStatementPair.answer.StatementGroupRect.height; //ScrollViewArea.height += accusationStatementPair.answer.StatementGroupRect.height; guiAccusationChoice.accusationStatement.Add(accusationStatementPair); Rect accusationStatementBG = new Rect(0, 0, accusationStatementGroup.width, accusationStatementGroup.height); accusationStatementPair.AccusationStatementGroup = accusationStatementGroup; accusationStatementPair.AccusationStatementBGRect = accusationStatementBG; tmpPrevRect = accusationStatementGroup; //ScrollViewArea.height += accusationStatementPair.titleRect.height + 5; accusationChoiceGroup.height += accusationStatementPair.AccusationStatementGroup.height; } accusationChoiceGroup.height += 35; guiAccusationChoice.accusationChoiceGroup = accusationChoiceGroup; guiAccusationChoice.accusationChoiceBG = new Rect(0, 0, guiAccusationChoice.accusationChoiceGroup.width, guiAccusationChoice.accusationChoiceGroup.height); accusationGroupRect.height += guiAccusationChoice.accusationChoiceGroup.height; //accusationGroupRect.y = i * accusationGroupRect.height; prevRect = guiAccusationChoice.accusationChoiceGroup; guiAccusation.AccusationChoice.Add(guiAccusationChoice); } accusationGroupRect.height -= 200; guiAccusation.AccusationGroup = accusationGroupRect; guiAccusation.AccusationBG = new Rect(0, 0, guiAccusation.AccusationGroup.width, guiAccusation.AccusationGroup.height); ScrollViewArea.height += accusationGroupRect.height - 150; prevAccusationGroup.height += guiAccusation.AccusationGroup.height + 10; guiAccusationList.Add(guiAccusation); } ScrollViewArea.height += 20; }
public void displayTimeUpForAccusation(Accusation accusation, Person transitionPerson) { personPortrait.sprite = transitionPerson.portrait; dialogText.text = accusation.transitionStatement.transitionStatementText(); personTalking(); }