Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            string[] answer = CreateAnswer();

            Game game = new Game(answer, 4);
            bool won  = false;

            for (int turns = game.guesses; turns > 0; turns--)
            {
                Console.WriteLine("You have {0} tries left!", turns);
                Console.WriteLine("Choose four letters: ");
                string letters = Console.ReadLine();
                //reads the chosen letters as a string letters
                Ball[] balls = new Ball[4];
                for (int i = 0; i < 4; i++)
                //checks each one of the balls
                {
                    balls[i] = new Ball(letters[i].ToString());
                    //each of the 4 balls created in the array are assigned to a string of one letter
                    //the letters come from string the user typed in and entered to the string letters
                }
                Row row = new Row(balls);
                //makes a new Row called row where we pass in the users' balls, all now in their own separate strings
                game.rows.Add(row);
                //add the row of the new balls we created to the list of rows in the game

                //checks if the correct answer has been guessed every turn
                if (game.Score(row) == "4 - 0")
                {
                    Console.WriteLine("You win!");
                    won = true;
                    break;
                }
                else
                {
                    Console.WriteLine(game.Score(row));
                }
                //tells me the score (red and white respectively) for that particular turn
            }
            if (won == false)
            {
                Console.WriteLine("Out of turns!");
            }
        }
Ejemplo n.º 2
0
        public static void Main()
        {
            // initialize won to false so won will be false if user runs out of turns or set to true if user wins
            bool won = false;

            System.Console.WriteLine("How many tries would you like to guess correct answer?");
            // convert user input to an int
            int userTurns = Convert.ToInt32(Console.ReadLine());

            // call function CreateAnswer and set return value to a string array called answer
            string[] answer = CreateAnswer();

            // code to print out random answer for debugging purposes

            // foreach(var i in answer)
            // {
            //     System.Console.WriteLine(i);
            // }

            // instantiate a new game and pass in computer generated answer and number of turns user has selected
            Game game = new Game(answer, userTurns);

            // loop through game logic for user selected number of turns or until user wins and loop is broken
            for (int turns = userTurns; turns > 0; turns--)
            {
                Console.WriteLine($"You have {turns} tries left");
                Console.WriteLine("Choose any combination of the four letters a,b,c, or d: ");
                string letters = Console.ReadLine();
                // instantiate a new array of type ball that has a length of 4
                Ball[] balls = new Ball[4];
                // populate the array with balls(letters) chosen by the user
                for (int i = 0; i < 4; i++)
                {
                    balls[i] = new Ball(letters[i].ToString());
                }
                // create a new row by passing in the balls array
                Row row = new Row(balls);
                // add row to the rows list in game
                game.AddRow(row);
                // output the row of balls(letters) chosen and the score for that row
                Console.WriteLine(game.Rows);
                if (game.Score(row) == "4 - 0")
                {
                    won = true;
                    System.Console.WriteLine("You Won!");
                    break;
                }
            }
            // ran out of turns - lost the game
            if (won == false)
            {
                Console.WriteLine("Out Of Turns");
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            bool   win        = false;
            string pegLetters = "abcdefgh";
            string answer     = "";
            Random random     = new Random();

            for (int i = 0; i < 4; i++)
            {
                int index = random.Next(0, 8);
                answer += pegLetters[index];
            }
            Console.WriteLine(answer);
            Game game = new Game(answer);

            for (int turns = 0; turns < 10; turns++)
            {
                Console.Write("Choose four letters: ");
                string letters = Console.ReadLine();
                Peg[]  pegs    = new Peg[4];
                for (int i = 0; i < pegs.Length; i++)
                {
                    pegs[i] = new Peg(letters[i]);
                }
                Row row1 = new Row(pegs);
                game.AddRow(row1);
                foreach (string row in game.Rows)
                {
                    if (row != null)
                    {
                        Console.WriteLine(row);
                    }
                    else
                    {
                        break;
                    }
                }
                if (game.Score(row1)[0] == 4)
                {
                    Console.WriteLine("You win!");
                    win = true;
                    break;
                }
            }
            if (!win)
            {
                Console.WriteLine("No more turns");
            }
        }