Question: How can I fix my code so it loops through people and prints the information about the person after each round and about who won

How can I fix my code so it loops through people and prints the information about the person after each round and about who won at the end?

My code so far: class Program { public static int number { get; set; } public static int number2 { get; set; }

static void Main(string[] args) { People person; Game game;

do { Console.WriteLine(" How many numbers do you want to match?"); var input = Console.ReadLine(); number = int.Parse(input); game = new Game(number); } while (number < 2);

do { Console.WriteLine(" How many people will be playing?"); var input2 = Console.ReadLine(); number2 = int.Parse(input2); for (int i = 0; i < number2; i++) { person = new People("Person" + i); game.AddPeople(person); } } while (number2 < 2);

game.Start(); game.Next();

for (int i = 0; i < 6; i++) { game.Play(); Console.WriteLine($" {game.OnTurn.Name} "); game.Play(); Console.WriteLine("Your lucky numbers are: "); for (int j = 0; j < number - 1; j++) { Console.WriteLine(game.nums[j]); } Console.WriteLine($"Your points are: {game.OnTurn.Points} "); Console.WriteLine(" Continue... (enter)"); Console.Read();

} } game.IsFinished = true;

Console.WriteLine($" Who won: {game.Result()}! ");

Console.WriteLine($"Your game: {game.OnTurn.Archive}"); } } }

class People {

public string Name { get; set; }

public int Points { get; set; } public List Archive { get; set; }

public People(ShowResult Archive) { this.Archive = new List(); }

public People(string Name) { this.Name = Name; } } }

class Game { public List nums { get; set; } public List Peoplee = new List(); public People OnTurn { get; private set; }

private bool isFinished;

public bool IsFinished { get { return isFinished; } set { isFinished = true;

} } public Game(int number) { nums = new List(number); for (int i=0;i < number; i++)

{ var instance = new Game(6); nums.Add(instance); } }

public void AddPerson(People person) { if (!IsFinished) Peoplee.Add(person);

public void Start() IsFinished = false; OnTurn = Pleoplee[0];

public void Play() { while (!IsFinished) { GetNums(); PersonalArchive(); ParcialResult(); Next(); }

}

public void GetNums() {

for (int i = 0; i < nums.Count; i++) nums[i].RandNum(); }

public void ParcialResult() {

for (int i = 0; i < nums.Count; i++) { for (int j = 0; j < j + 1; j++) { if (nums[i] == nums[i + 1] && nums[i].Equals(nums[i].Maximum)) { OnTurn.Points = nums.Count * nums[i].Maximum * 10; } else if (nums[i] == nums[i + 1] && !(nums[i].Equals(nums[i].Maximum))) { OnTurn.Points = nums.Count * nums[i].LessThanMaximum * 5; } else { OnTurn.Points = 0; } } }

}

public void PersonalArchive() { for (int i = 0; i < nums.Count; i++) { if (nums[i] == nums[i + 1] && nums[i].Equals(nums[i].Maximum)) { OnTurn.Archive.Add(ShowResult.Great); } else if (nums[i] == nums[i + 1] && !(nums[i].Equals(nums[i].Maximum))) { OnTurn.Archive.Add(ShowResult.Good); } else { OnTurn.Archive.Add(ShowResult.Awful); } } }

public void Next() { for (int i = 0; i < Peoplee.Count; i++) { OnTurn = Peoplee[i]; }

}

public People Result() { for (int i = 0; i < Peoplee.Count; i++) { if (Peoplee[i].Points > Peoplee[i + 1].Points) { return Peoplee[i]; } else { return null; } } return null;

}

} }

class LuckyNumbers {

public int Maximum { get; set; } public int LessThanMaximum { get; private set; }

public LuckyNumbers(int maximum) { this.Maximum = 6; } public void RandNum() { Random random = new Random(); LessThanMaximum = random.Next(1, Maximum + 1); } } }

enum ShowResult { Great,

Good,

Awful } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!