如何解决显示小游戏的输赢
我试图让每个玩家都显示“每个玩家在每次计数时都赢和输,所以他们可以看到他们赢和输的人
比如:
玩家 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();
}
}
}
解决方法
你不能使用 List<int> PlayerA
和 List<int> 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
执行相同的操作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。