Insights Blog
-- Browse All Articles --
Physics Articles
Physics Tutorials
Physics Guides
Physics FAQ
Math Articles
Math Tutorials
Math Guides
Math FAQ
Education Articles
Education Guides
Bio/Chem Articles
Technology Guides
Computer Science Tutorials
Forums
Intro Physics Homework Help
Advanced Physics Homework Help
Precalculus Homework Help
Calculus Homework Help
Bio/Chem Homework Help
Engineering Homework Help
Trending
Featured Threads
Log in
Register
What's new
Search
Search
Search titles only
By:
Intro Physics Homework Help
Advanced Physics Homework Help
Precalculus Homework Help
Calculus Homework Help
Bio/Chem Homework Help
Engineering Homework Help
Menu
Log in
Register
Navigation
More options
Contact us
Close Menu
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Forums
Homework Help
Engineering and Comp Sci Homework Help
Master Mind - computer game programming in C#
Reply to thread
Message
[QUOTE="Veronica_Oles, post: 5465846, member: 591621"] [h2]Homework Statement [/h2] Create this website: In this game, there are four different coloured blocks (red, green, blue, and yellow). The computer hides three different coloured blocks from the user. The user then tries to guess the colours and the order of the blocks. After guessing the colour of the three hidden blocks, the computer displays: [LIST] [*]how many of the colours are correct and [*]how many of the colours are in the right position. [/LIST] Based on this information, the user can make another guess and so on until the user has determined the correct order and colour of the blocks. [h2]Homework Equations[/h2][h2]The Attempt at a Solution[/h2] String ret; [B] ret = RandomNumbers(); int intUserGuess1 = 0;// This variable will be used to store the first guess of the user inputted into the console int intUserGuess2 = 0;// This variable will be used to store the second guess of the user inputted into the console int intUserGuess3 = 0;// This variable will be used to store the third guess of the user inputted into the console int intBlock1 = int.Parse(ret.Substring(0, 1)); int intBlock2 = int.Parse(ret.Substring(1, 1)); int intBlock3 = int.Parse(ret.Substring(2, 1)); int intPlayGames = 1; int intGames = 0; Console.WriteLine("Welcome to the game where you choose three colours and attempt to match them with the console's numbers! Enjoy!"); while (intPlayGames == 1) { intGames++; Console.WriteLine("Please enter Guess Code Number 1 [1-Red, 2-Blue, 3-Green, 4-Yellow]: "); intUserGuess1 = int.Parse(Console.ReadLine());// This will accept the users first guess and store it under the variable intUserGuess1 Console.WriteLine("Please enter Guess Code Number 2 [1-Red, 2-Blue, 3-Green, 4-Yellow]: "); intUserGuess2 = int.Parse(Console.ReadLine());// This will accept the users second guess and store it under the variable intUserGuess2 Console.WriteLine("Please enter Guess Code Number 3 [1-Red, 2-Blue, 3-Green, 4-Yellow]: "); intUserGuess3 = int.Parse(Console.ReadLine());// This will accept the users third guess and store it under the variable intUserGuess3 Console.WriteLine("You have guessed " + checkCorrectColour(intBlock1, intBlock2, intBlock3, intUserGuess1, intUserGuess2, intUserGuess3).ToString() + " colours correctly."); Console.WriteLine("You have guessed " + checkColoursPosition(intBlock1, intBlock2, intBlock3, intUserGuess1, intUserGuess2, intUserGuess3).ToString() + " colours in the correct position."); Console.WriteLine(); Console.WriteLine("Play Again [1] Yes [2] No: "); intPlayGames = int.Parse(Console.ReadLine()); if (intPlayGames == 2) { intPlayGames = 0; } Console.WriteLine(); } Console.WriteLine("Bye! Thank you for playing!"); Console.ReadKey();// Keeps console window open } static int checkCorrectColour(int a, int b, int c, int b1, int b2, int b3)// This is a new method by the name of checkCorrectColour { int num = 0;// This variable will be used to store the number if (b1 == a || b1 == b || b1 == c) { num++; } if (b2 == a || b2 == b || b2 == c) { num++; } if (b3 == a || b3 == b || b3 == c) { num++; } return num;// This will return the number to the main method } static int checkColoursPosition(int a, int b, int c, int b1, int b2, int b3) { int num = 0; if (b1 == a) { num++; } if (b2 == b) { num++; } if (b3 == c) { num++; } return num;// This will return the number to the main method } static String RandomNumbers() { String result = ""; Random r = new Random(); int n1, n2, n3; Boolean flag = true; Boolean flag1 = true; n1 = r.Next(1, 5); result = n1.ToString(); n2 = r.Next(1, 5); while (flag == true) { if (n2 == n1) { n2 = r.Next(1, 5); flag = true; } else { flag = false; result = result + n2.ToString(); } } n3 = r.Next(1, 5); while (flag1 == true) { if (n3 == n1 || n3 == n2) { n3 = r.Next(1, 5); flag1 = true; } else { flag1 = false; result = result + n3.ToString(); } } return result;// This will return the result to the main method } } } Cannot find what is wrong with my program and I do not know where to fit in a statement that tells the winner if they have won. This program is in c#. [/B] [/QUOTE]
Insert quotes…
Post reply
Forums
Homework Help
Engineering and Comp Sci Homework Help
Master Mind - computer game programming in C#
Back
Top