Esempio n. 1
0
 /// <summary>
 /// Send a game step to the server.
 /// </summary>
 /// <param name="step">The step that was performed in the game.</param>
 public void GameStep(YachtStep step)
 {
     proxy.GameStepAsync(gameID, playerID, step.ScoreLine, step.Score, step.PlayerIndex, step.StepNumber);
 }
Esempio n. 2
0
        /// <summary>
        /// Write the selected score to the score table and move to the next player.
        /// Checks if the game is over and raises the GameOver event as well.
        /// </summary>
        public void FinishTurn()
        {
            // Check if a score was selected
            if (SelectedScore != null)
            {
                if (type == GameTypes.Offline)
                {
                    State.Players[State.CurrentPlayer].ScoreCard[(int)SelectedScore - 1] =
                        CombinationScore((YachtCombination)SelectedScore, currentDice);

                    // Accumulate the total score
                    State.Players[State.CurrentPlayer].TotalScore +=
                        State.Players[State.CurrentPlayer].ScoreCard[(int)SelectedScore - 1];

                    // Move to the next player
                    State.CurrentPlayer = (State.CurrentPlayer + 1) % players.Length;

                    // Accumulate the numbers of turns
                    State.StepsMade++;

                    // Check if all players play 12 turns (so all players have a full score card)
                    if (State.StepsMade == 12 * players.Length)
                    {
                        // Check who the winner is
                        State.CurrentPlayer = HighesPlayerScore();
                        WinnerPlayer        = players[State.CurrentPlayer];

                        IsGameOver = true;

                        if (WinnerPlayer is HumanPlayer)
                        {
                            AudioManager.PlaySound("Winner");
                        }
                        else
                        {
                            AudioManager.PlaySound("Loss");
                        }
                    }
                    else
                    {
                        AudioManager.PlaySoundRandom("TurnChange", 2);
                    }
                }
                else
                {
                    // The server manages the game state, so simply send the move over
                    YachtStep currentMove = new YachtStep((int)SelectedScore - 1,
                                                          CombinationScore((YachtCombination)SelectedScore, currentDice), State.CurrentPlayer,
                                                          State.StepsMade);

                    State.CurrentPlayer = (State.CurrentPlayer + 1) % State.Players.Count;

                    NetworkManager.Instance.GameStep(currentMove);
                }

                // Clear the selected score
                SelectedScore = null;

                message = null;
            }
        }