예제 #1
0
        public void Judge(IPlayer player1, IPlayer player2)
        {
            bool finished = false;

            while (!finished)
            {
                RSPType p1 = player1.ChoiceRSP();
                RSPType p2 = player2.ChoiceRSP();

                Console.WriteLine($"じゃんけん結果:\n\t{player1.GetName()}\t: {p1}\n\t{player2.GetName()}\t: {p2}");

                // あいこ
                if (p1 == p2)
                {
                    Console.WriteLine("あいこです");
                    continue;
                }
                // p1の勝ち
                if (Compare(p1, p2))
                {
                    Console.WriteLine($"{player1.GetName()}の勝ちです");
                    finished = true;
                }
                // p2の勝ち
                if (Compare(p2, p1))
                {
                    Console.WriteLine($"{player2.GetName()}の勝ちです");
                    finished = true;
                }
            }
        }
예제 #2
0
 /// <summary>
 /// pから見た、出した手の比較結果を得る
 /// </summary>
 /// <param name="p"></param>
 /// <param name="opponent">相手が出した手</param>
 /// <returns></returns>
 private static bool Compare(RSPType p, RSPType opponent)
 {
     return((p == RSPType.パー && opponent == RSPType.グー) ||
            (p == RSPType.グー && opponent == RSPType.チョキ) ||
            (p == RSPType.チョキ && opponent == RSPType.パー));
 }