【问题标题】:Display win and loss for a little game显示小游戏的输赢
【发布时间】:2021-04-26 09:43:57
【问题描述】:

我试图让每个玩家显示“每个玩家在每次计数时都赢了和输了,所以他们可以看到他们赢了和输了的人

类似的东西:

玩家 A

游戏:游戏状态
1:赢

2:赢

3:赢

4 : 丢失

5 : 丢失

6:赢

玩家 B

游戏:状态 1:丢失

2 : 丢失

3 : 丢失

4:赢

5:赢

6 : 丢失

请帮我解决这个问题

class Guess
{

   
    public int GuessedNumber { get; set; }
   
    List<int> PlayerA = new List<int>();
    List<int> PlayerB = new List<int>();
    int countA = 0;
    int countB = 0;
    int count = 0;

    public void  Guu()
    {
        Random rand = new Random();
        GuessedNumber = rand.Next(1,7);
    }

    


    public int input { get; set; }
    
    public void FirstDisplay(string Active_Player)
    {
        Console.WriteLine($"{Active_Player}: Guess the number that i am thinking about");
        input = Convert.ToInt32(Console.ReadLine());
        count++;
    }
    public void CompareNumbers(List<int> PlayerA, List<int> PlayerB, ref string Active_Player)
    {
        if (Active_Player == "A")
        {
            if (input == GuessedNumber)
            {
                Console.WriteLine($"Correct, i was thinking of {GuessedNumber} my turn");
                PlayerA.Add(1);
                PlayerB.Add(0);
                countA++;
            }
            else
            {
                Console.WriteLine($"Wrong, i was thinking of {GuessedNumber} try again");
                PlayerB.Add(1);
                PlayerA.Add(0);
                countB++;
            }
        }
        else if (Active_Player == "B")
        {
            if (input == GuessedNumber)
            {
                Console.WriteLine($"Correct, i was thinking of {GuessedNumber} try again");
                PlayerA.Add(0);
                PlayerB.Add(1);
                countB++;
            }
            else
            {
                Console.WriteLine($"Wrong, i was thinking of {GuessedNumber} try again");
                PlayerB.Add(0);
                PlayerA.Add(1);
                countA++;
            }

        }

    }
    public void Display()
    {
        Console.WriteLine("This is the result of the game");
        Console.WriteLine($"Number of Game Played is: {count++}");
        if (countA > countB)
        {
            Console.WriteLine("Winner: A");
        }
        else if (countA < countB)
        {
            Console.WriteLine("Winner: B");
        }
        else
        {
            Console.WriteLine("Draw");
        }

        Console.WriteLine($"Player A has {countA++} point");
        Console.WriteLine($"Player B has {countB++} point ");

       

       

    }
}


class Program
{



    static void Main(string[] args)
    {
        List<int> PlayerA = new List<int>();
        List<int> PlayerB = new List<int>();
      string  Active_Player = "A";
        int count = 0;
        Guess guess = new Guess();
        string choice;
        do
        {
            guess.Guu();
            guess.FirstDisplay(Active_Player);
            guess.CompareNumbers( PlayerA,  PlayerB, ref Active_Player);
            count++;
            Console.WriteLine("Do you want to continue, Yes or No?");
             choice = Console.ReadLine().ToLower();

        }
        while(choice == "yes");
        guess.Display();

    }





}

}

【问题讨论】:

    标签: c# asp.net loops asp.net-mvc-3 c#-4.0


    【解决方案1】:

    你不能使用List&lt;int&gt; PlayerAList&lt;int&gt; PlayerB吗?

    Console.WriteLine("PlayerA Games Status");
    for ( int i = 0; i < PlayerA.Count; ++i )
    {
        Console.Write( $"{i}: " );
        if ( PlayerA[i] == 0) Console.WriteLine( "Loss" );
        else Console.WriteLine( "Win" );
    }
    

    PlayerB 执行相同操作。

    【讨论】:

      猜你喜欢
      • 2020-07-25
      • 2023-04-10
      • 2014-07-14
      • 2012-01-13
      • 1970-01-01
      • 2022-12-16
      • 1970-01-01
      • 1970-01-01
      • 2017-02-16
      相关资源
      最近更新 更多