コード例 #1
0
 public void Setup()
 {
     rpsPlayer = Substitute.For <IRPSPlayer>();
     rpsPlayer.GetReady(Arg.Any <int>(), Arg.Any <int>()).Returns(Constants.GameSuccessfullySetup);
     rpsPlayer.MakeMove().Returns(Move.Rock);
     rpsPlayer.Result(Arg.Any <Outcome>()).Returns(Constants.OverallWin);
     gameController = new GameController(rpsPlayer);
 }
コード例 #2
0
ファイル: DataAI.cs プロジェクト: Aggrathon/rps_tournament
 public void memorizeOpponentHistory(IRPSPlayer opponent)
 {
     var store = TournamentState.instance.Matches;
     var oppChoices = store.Select(m =>
     {
         return opponent == m.playerOne
             ? m.playerOneChoices as IEnumerable<Match.RPS>
             : m.playerTwoChoices as IEnumerable<Match.RPS>;
     }).Aggregate((a, b) => a.Concat(b)).ToList();
     opponentHistory = oppChoices;
 }
コード例 #3
0
ファイル: Match.cs プロジェクト: Aggrathon/rps_tournament
    /// <summary>
    /// This creates a match and starts it immediately
    /// </summary>
    /// <param name="player1"></param>
    /// <param name="player2"></param>
    /// <param name="callback">The function called when the match is over</param>
    public Match(IRPSPlayer player1, IRPSPlayer player2, MatchEnded callback)
    {
        this.player1 = player1;
        this.player2 = player2;

        playerOneHealth = player1.health;
        playerTwoHealth = player2.health;

        player1Choices = new LinkedList<RPS>();
        player2Choices = new LinkedList<RPS>();

        this.callback = callback;

        player1.startMatch(this);
        player2.startMatch(this);

        newRound();
    }
コード例 #4
0
        public void PlayGame(IRPSPlayer p1, IRPSPlayer p2)
        {
            Choices p1Choice = p1.GetChoice();
            Choices p2Choice = p2.GetChoice();

            if (p1Choice == p2Choice)
            {
                Console.WriteLine($"{p1.Name} and {p2.Name} have tied");
            }
            else if (p1Choice == Choices.Rock && p2Choice == Choices.Scissors ||
                     p1Choice == Choices.Scissors && p2Choice == Choices.Paper ||
                     p1Choice == Choices.Paper && p2Choice == Choices.Rock)
            {
                Console.WriteLine($"{p1.Name} has defeated {p2.Name}!");
            }
            else
            {
                Console.WriteLine($"{p2.Name} has defeated {p1.Name}!");
            }
        }
コード例 #5
0
        public void PlayGame(IRPSPlayer p1, IRPSPlayer p2)
        {
            RPSChoice p1Choice = p1.GetChoice();
            RPSChoice p2Choice = p2.GetChoice();

            if (p1Choice == p2Choice)
            {
                ConsoleOutput.TieMessage(p1, p2);
            }
            else if (p1Choice == RPSChoice.Rock && p2Choice == RPSChoice.Scissors ||
                     p1Choice == RPSChoice.Paper && p2Choice == RPSChoice.Rock ||
                     p1Choice == RPSChoice.Scissors && p2Choice == RPSChoice.Paper)
            {
                ConsoleOutput.P1WinMessage(p1);
            }
            //else if(p2Choice == RPSChoice.Nuke)
            //{
            //    ConsoleOutput.P1NukedMessage(p1);
            //}
            else
            {
                ConsoleOutput.P2WinMessage(p2);
            }
        }
コード例 #6
0
 public GameController(IRPSPlayer rpsPlayer)
 {
     this.rpsPlayer = rpsPlayer;
 }
コード例 #7
0
 public Arena(IRPSPlayer player)
 {
     _player = player;
 }
コード例 #8
0
 internal static void P2WinMessage(IRPSPlayer p2)
 {
     Console.WriteLine($"Congrats {p2.PlayerName} you have won!");
 }
コード例 #9
0
 internal static void TieMessage(IRPSPlayer p1, IRPSPlayer p2)
 {
     Console.WriteLine($"{p1.PlayerName} and {p2.PlayerName} have tied.");
 }
コード例 #10
0
ファイル: Match.cs プロジェクト: Aggrathon/rps_tournament
 /// <summary>
 /// Use this to inform the match that the player has finished ending the match (calls the callback method when both players are ready)
 /// </summary>
 /// <param name="player"></param>
 public void setPlayerFinished(IRPSPlayer player)
 {
     if(player1HasFinished && player2HasFinished)
     {
         return;
     }
     if (player == player1)
     {
         player1HasFinished = true;
         if (player2HasFinished)
         {
             matchHasEnded = true;
             callback.BeginInvoke(this, null, null);
         }
     }
     else if (player == player2)
     {
         player2HasFinished = true;
         if (player1HasFinished)
         {
             matchHasEnded = true;
             callback.BeginInvoke(this, null, null);
         }
     }
 }
コード例 #11
0
ファイル: Match.cs プロジェクト: Aggrathon/rps_tournament
 /// <summary>
 /// Sets the choice of the player for this round (next round begins when both players have selected their choice)
 /// </summary>
 /// <param name="player"></param>
 /// <param name="choice"></param>
 public void setPlayerChoice(IRPSPlayer player, RPS choice)
 {
     if(matchHasEnded)
     {
         return;
     }
     if(player == player1)
     {
         player1Choice = choice;
         player1HasPlayed = true;
         if(player2HasPlayed)
         {
             endRound();
         }
     }
     else if(player == player2)
     {
         player2Choice = choice;
         player2HasPlayed = true;
         if (player1HasPlayed)
         {
             endRound();
         }
     }
 }
コード例 #12
0
ファイル: Match.cs プロジェクト: Aggrathon/rps_tournament
 /// <summary>
 /// Returns the other player
 /// </summary>
 /// <param name="player"></param>
 /// <returns></returns>
 public IRPSPlayer getOtherPlayer(IRPSPlayer player)
 {
     return (player == player2 ? player1 : player2);
 }
コード例 #13
0
ファイル: Match.cs プロジェクト: Aggrathon/rps_tournament
 /// <summary>
 /// Get the last choice of the player
 /// </summary>
 /// <param name="player"></param>
 /// <returns></returns>
 public RPS getLastChoicePlayer(IRPSPlayer player)
 {
     LinkedList<RPS> list = (player1 == player ? player1Choices : player2Choices);
     if (list.Count > 0)
     {
         return list.Last.Value;
     }
     else
     {
         return RPS.UNDEFINED;
     }
 }
コード例 #14
0
ファイル: Match.cs プロジェクト: Aggrathon/rps_tournament
 /// <summary>
 /// Get the last choice of the other player
 /// </summary>
 /// <param name="player"></param>
 /// <returns></returns>
 public RPS getLastChoiceOther(IRPSPlayer player)
 {
     return getLastChoicePlayer(getOtherPlayer(player));
 }
コード例 #15
0
ファイル: Match.cs プロジェクト: Aggrathon/rps_tournament
 /// <summary>
 /// Returns the health of the player
 /// </summary>
 /// <param name="player"></param>
 /// <returns></returns>
 public int getHealthPlayer(IRPSPlayer player)
 {
     return (player == player1 ? playerOneHealth : playerTwoHealth);
 }
コード例 #16
0
 public GameFlow(IRPSPlayer player)
 {
     _player = player;
 }