newlearn
02-04-2004, 10:19 AM
بسم الله الرحمن الرحيم
السلام عليكم ورحمة الله وبركاته
اخوتي ....اردت عمل هذا البرنامج-اللعبة-ولكن نقص خبرتي ومعرفتي بلغة الجافا حالت دون قيامي بالبرنامج
توضيح عمل اللعبة
Write a Java program to play a game called Mastermind. In this game, the computer selects a three-digit number in which all three digits are distinct. The task of the player is to keep making guesses until she/he guesses all three digits in the proper order. Each time the player makes a guess, the computer tells the player:
-How many hits the player had (one hit means getting one digit in its correct position), and
-How many matches the player had (one match means getting one correct digit in the wrong position)
example,,, if the computer's number was 586 and the player guessed 856, the computer would respond with
1 hit
2 matches
After the player guesses the correct sequence of digits, the program should display the total number of guesses made, and then give the player the option to play again.
Your program should be developed by using the following methods:
1-generateCode: This function uses the random number generator to generate three distinct digits in the range 0 - 9, and stores them in the array for the computer's secret code.
2-getGuess: This function reads in the player's guess as a String, converts the three characters to integers, and stores them in the guess array. The function should check if the 3-didgit number contains 3 distinct digits, otherwise the user has to input the number again.
3-compare: This function compares the computer's generated numbers with the player's guess, and calculates the number of hits and matches. Then it should return true if the user scored 3 hits.
4-printResults: This function displays the number of hits and matches for a given guess.
ولكم جزيل الشكر .....
السلام عليكم ورحمة الله وبركاته
اخوتي ....اردت عمل هذا البرنامج-اللعبة-ولكن نقص خبرتي ومعرفتي بلغة الجافا حالت دون قيامي بالبرنامج
توضيح عمل اللعبة
Write a Java program to play a game called Mastermind. In this game, the computer selects a three-digit number in which all three digits are distinct. The task of the player is to keep making guesses until she/he guesses all three digits in the proper order. Each time the player makes a guess, the computer tells the player:
-How many hits the player had (one hit means getting one digit in its correct position), and
-How many matches the player had (one match means getting one correct digit in the wrong position)
example,,, if the computer's number was 586 and the player guessed 856, the computer would respond with
1 hit
2 matches
After the player guesses the correct sequence of digits, the program should display the total number of guesses made, and then give the player the option to play again.
Your program should be developed by using the following methods:
1-generateCode: This function uses the random number generator to generate three distinct digits in the range 0 - 9, and stores them in the array for the computer's secret code.
2-getGuess: This function reads in the player's guess as a String, converts the three characters to integers, and stores them in the guess array. The function should check if the 3-didgit number contains 3 distinct digits, otherwise the user has to input the number again.
3-compare: This function compares the computer's generated numbers with the player's guess, and calculates the number of hits and matches. Then it should return true if the user scored 3 hits.
4-printResults: This function displays the number of hits and matches for a given guess.
ولكم جزيل الشكر .....