显示小游戏的输赢

Posted

技术标签:

【中文标题】显示小游戏的输赢【英文标题】: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();

    






【问题讨论】:

【参考方案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 执行相同操作。

【讨论】:

以上是关于显示小游戏的输赢的主要内容,如果未能解决你的问题,请参考以下文章

如何在用户在 jQuery 浏览器中输赢游戏时安排音频播放

[教你做小游戏] 《五子棋》怎么判断输赢?你能5分钟交出代码吗?

微信小程序游戏开发│石头剪刀布游戏(附源码)

C语言小游戏:扫雷实现

面向对象编程思想-中介者模式

c语言——五子棋游戏