lundi 13 mai 2019

Problem regarding dice app // Make app reroll two more dice on a 6

Hello there people of Stack. i'm currently doing an assignment where i am to create an dice game with the following conditons.

Sorry for the formatting and my bad english.

-Unlimited 6 sided dice.

  • Ask the user how many dice they would like to roll Min 1. Max. 4

-if any dice roll 6 it shall not be counted to the max sum, instead it shall be re-rolled with two new dices. and repeat if one of the new dices roll 6.

-when all dice are rolled show total sum

-The player is asked if they would like to replay or exit the program.

the problem i face is the following. i cant make it so the six is removed from the list and two new dice are rolled instead.

i've tried to look around here on the site to figure it out, and i have exhausted google. maybe the solution is obvious but i cant figure it out.

"" OKEY so i solved the crashing of the foreach loop by adding dice.tolist()) so my only issue remaing is removing the 6

Console.Write(" ++how many dice 1- 4 ++: "); bool input = int.TryParse(Console.ReadLine(), out int antal);

                if (input && antal < 5)
                {
                    for (int i = 0; i < antal; i++)
                    {
                        dice.Add(RandomNumber.GenerateRandom(1, 7));


                    }
                    Console.Clear();
                    Console.WriteLine("++dice rolled: ++");
                    foreach (int die in dice)
                    {
                        Console.WriteLine("\t" +  "dice:" + " " +  die);
                        System.Threading.Thread.Sleep(1000);
                        if (die == 6)
                        {
                            Console.WriteLine("SIX! rerolling 2 new");
                            for (int i = 0; i < 2; i++)
                            {
                             dice.Add(RandomNumber.GenerateRandom(1, 7));
                               Console.WriteLine("\t" + "new" + " " + i);
                                {

                                }

                            }
                        }


                     }
                    Console.WriteLine();
                    Console.WriteLine();


                    Console.WriteLine("Summan av dina tärningsslag är {0}", dice.Sum(x => Convert.ToInt32(x)));
                    Console.WriteLine("Vill du slå igen?. Tryck N för att avsluta programmet, eller tryck på annan valfri knapp för att börja om");
                    dice.Clear();
                    string Ifexit = Console.ReadLine().ToLower();
                    if (Ifexit == "n")
                    {
                        Environment.Exit(0);

so i want it to remove the six from the total sum and instead roll 2 new dices and and add to the total sum in lien of the 6.




Aucun commentaire:

Enregistrer un commentaire