Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How can I fix this code? It's not looping through the person each round and it's not giving me any result. Here is my code:

How can I fix this code? It's not looping through the person each round and it's not giving me any result.

Here is my code:

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(" Lucky Numbers: "); var input = Console.ReadLine(); number = int.Parse(input); game = new Game(number); } while (number < 2);

do { Console.WriteLine(" Playing: "); var input2 = Console.ReadLine(); number2 = int.Parse(input2); for (int i = 0; i < number2; i++) { person = new People("Person" + i); game.AddPerson(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 inst = new LuckyNumbers(6); nums.Add(inst); } }

public void AddPerson(People person) { if (!IsFinished) Peoplee.Add(person); else throw new Exception(); }

public void Start() { IsFinished = false; OnTurn = Peoplee[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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions