static void Main(string[] args) { Game game = new Game(new string[] { "a", "b", "c", "d" }); for (int turns = 10; turns > 0; turns--) { Console.WriteLine($"You have {turns} tries left"); Console.WriteLine("Choose four letters: "); string letters = Console.ReadLine(); Ball[] balls = new Ball[4]; for (int i = 0; i < 4; i++) { balls[i] = new Ball(letters[i].ToString()); } Row row = new Row(balls); game.AddRow(row); Console.WriteLine(game.Rows); if (row.balls[0].Letter == "a" && row.balls[1].Letter == "b" && row.balls[2].Letter == "c" && row.balls[3].Letter == "d") { Console.WriteLine("You won."); break; } } Console.WriteLine("Out Of Turns"); }
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"); } }
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"); } }
static void Main(string[] args) { Game game = new Game(new string[] { "a", "b", "c", "d" }); for (int turns = 0; turns < 10; turns++) { Console.WriteLine("Choose four letters: "); string letters = Console.ReadLine(); string[] lettersSplit = letters.Split(','); Ball[] balls = new Ball[4]; for (int i = 0; i < 4; i++) { balls[i] = new Ball(lettersSplit[i]); } Row row = new Row(balls); game.AddRow(row); Console.WriteLine(game.Rows); } Console.WriteLine("Out Of Turns"); }
static void Main(string[] args) { int numTries = 0; getTries(ref numTries); Game game = new Game(generateRandomCode(), numTries); for (int turns = game.numTries; turns > 0; turns--) { Console.WriteLine($"You have {turns} tries left"); Console.WriteLine("Choose four letters: "); string letters = Console.ReadLine(); Ball[] balls = new Ball[4]; for (int i = 0; i < 4; i++) { balls[i] = new Ball(letters[i].ToString()); } Row row = new Row(balls); game.AddRow(row); Console.WriteLine(game.Rows); } Console.WriteLine("Out Of Turns"); }