public IHttpActionResult DisproveSuggestion([FromBody] Card card)
        {
            AuthResult auth = authorizeAndVerifyGameStart();

            if (auth.result != null)
            {
                return(auth.result);
            }

            // TODO: authorize call from correct player

            DisproveData result = new DisproveData();

            result.card             = card;
            result.card             = new Card(Weapon.Pipe);
            result.disprovingPlayer = auth.player.Name;
            var cmdData = new CommandData {
                disproveData = result
            };

            // remove player's need to disprove suggestion
            CommandInterface.SetCommandForPlayer(result.disprovingPlayer, null);

            // set command for current player's turn
            var playerName = auth.game.getGame().getPlayerTurn().name;
            var resultCmd  = new Command {
                command = CommandType.DisproveResult, data = cmdData
            };

            CommandInterface.SetCommandForPlayer(playerName, resultCmd);

            return(Created("", ""));
        }
Beispiel #2
0
        // End of the functions used to interact

        //Start of the list of event handlers that take data from the client


        private async void WaitForCommand()
        {
            while (true)
            {
                var incCommand = await connect.Gameplay.WaitForCommandAsync();

                if (incCommand.command == CommandType.MovePlayer)
                {
                    MoveData data = incCommand.data.moveData;
                    List <Model.Game.Player> players = connect.Gameplay.GetState().getPlayers();

                    foreach (Model.Game.Player player in players)
                    {
                        if (player.name == data.playerName)
                        {
                            //this isn't ideal, I'm clearing that one person off the board
                            //then adding them to their new spot
                            foreach (Room room in Board)
                            {
                                RemovePersonFromRoom(player.character.ToString(), room);
                            }
                            AddPersonToRoom(player.character.ToString(), Board[player.location.x, player.location.y]);
                        }
                    }
                }
                else if (incCommand.command == CommandType.TakeTurn)
                {
                    MessageBox.Show("It's your turn");
                    TurnEnabled = true;
                    RaisePropertyChangedEvent("TurnEnabled");
                    break;
                }
                else if (incCommand.command == CommandType.AccusationMade)
                {
                    AccusationData data = incCommand.data.accusationData;
                    bool           accusationWasCorrect = data.accusationCorrect;

                    string accusationMessage = (accusationWasCorrect) ?
                                               "The accusation was correct." : "The accusation was incorrect.";

                    //TODO: Add logic for when this is received
                    MessageBoxResult result = MessageBox.Show(data.playerName + " has accused " + data.accusation.suspect +
                                                              " of killing the victim using the " + data.accusation.weapon +
                                                              " in the " + data.accusation.room + ". " + accusationMessage,
                                                              "Accusation Received", MessageBoxButton.YesNo);
                    if (accusationWasCorrect)
                    {
                        // TODO: further end game process?
                        break;
                    }
                }
                else if (incCommand.command == CommandType.DisproveResult)
                {
                    DisproveData data = incCommand.data.disproveData;

                    MessageBox.Show("The suggestion was disproven by " + data.disprovingPlayer + " by revealing " + data.card.cardValue);
                    break; // This is the active player
                }
                else if (incCommand.command == CommandType.SuggestionMade)
                {
                    SuggestionData data = incCommand.data.suggestData;
                    string         disprovePlayerName = data.disprovingPlayer;

                    string disproveMessage = (disprovePlayerName == null) ?
                                             "No one can disprove." : disprovePlayerName + " can disprove the suggestion.";
                    MessageBoxResult result = MessageBox.Show(data.playerName + " has suggested that " + data.accusation.suspect +
                                                              " killed the victim using the " + data.accusation.weapon +
                                                              " in the " + data.accusation.room + ". " + disproveMessage,
                                                              "Suggestion Received", MessageBoxButton.YesNo);
                }
                else if (incCommand.command == CommandType.DisproveSuggestion)
                {
                    SuggestionData data = incCommand.data.suggestData;
                    //TODO: Add logic for when this is received
                    MessageBoxResult result = MessageBox.Show(data.playerName + "Has suggested that " + data.accusation.suspect +
                                                              " killed the victim using the " + data.accusation.weapon +
                                                              " in the " + data.accusation.room + ". Choose how to disprove this.",
                                                              "Suggestion Received", MessageBoxButton.YesNo);
                    //If the user says they can disprove the suggestion, enable the disprove button and combobox
                    //Added a call to tell the client to stop what it's doing until it receives the disprove info
                    //May not be the best idea, but I'm open to suggestions
                    if (result == MessageBoxResult.Yes)
                    {
                        //If the user says they can disprove the suggestion, enable the disprove button and combobox
                        //Added a call to tell the client to stop what it's doing until it receives the disprove info
                        //May not be the best idea, but I'm open to suggestions
                        if (result == MessageBoxResult.Yes)
                        {
                            DisproveEnabled = true;
                            RaisePropertyChangedEvent("DisproveEnabled");
                            break;
                        }
                        else
                        {
                            DisproveEnabled = false;
                            RaisePropertyChangedEvent("DisproveEnabled");
                        }
                    }
                    else if (incCommand.command == CommandType.TurnEnd)
                    {
                        //TODO: Add logic for when this is received
                    }
                    else if (incCommand.command == CommandType.Wait)
                    {
                        // Ryan: No logic neccessary. Wait is used by WaitForCommand()
                        // to keep waiting for command
                    }
                    else if (incCommand.command == CommandType.GameStart)
                    {
                    }
                }
            }
        }