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));
        }
Ejemplo n.º 2
0
 public Suggestion From(SuggestionData data) => Suggestion.From(data);
Ejemplo n.º 3
0
 internal static Suggestion From(SuggestionData data) => data == null ? null : new Suggestion(data);
Ejemplo n.º 4
0
 protected Suggestion(SuggestionData data)
 {
     this.data = data;
 }
Ejemplo n.º 5
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)
                    {
                    }
                }
            }
        }