Results 1 to 4 of 4
Thread: Mastermind Java Code
- 11-03-2011, 05:13 PM #1
Member
- Join Date
- Nov 2011
- Posts
- 4
- Rep Power
- 0
Mastermind Java Code
I need a code for mastermind which allows the user to guess 4 letters from a-f, the player has 10 turns. It will tell the player if they get exact letter and position matches and partial matches for correct letter and wrong position. Here's what I have so far, but doesnt seem right. Need to use private String generateSecretCode(). THANKS!
Java Code:import java.util.ArrayList; import java.util.Arrays; public class Assignment5Code { /**Jim Petersen * 11/3/11 * The purpose of this program is to create a game called Mastermind using arrays. * @param args */ private String generateSecretCode() { char[] correctCode = {'a', 'e', 'b', 'd' }; ArrayList<String> varName = Arrays.asList(new String[] { "A", "B", "C", "D", "E", "F" } ); String firstLetter = lettersList.remove((int)(Math.random() * 6)); String secongLetter = lettersList.remove((int)(Math.random() * 5)); String thirdLetter = lettersList.remove((int)(Math.random() * 4)); String fourthLetter = lettersList.remove((int)(Math.random() * 3)); String secretCode = firstLetter + secondLetter + thirdLetter + fourthLetter; return secretCode; } private String getGuess() { } private int getExactMatches(String secretCode, String guess) {} public void start() { int numberOfTurns = 0; System.out.println("You have a maximum of 10 chances to correctly guess a sequence of four non-repeating letters ranging from a to f."); String secretCode = generateSecretCode(); varName.get(1); System.out.println("Enter four different letters, seperated by a space"); String guess = getGuess(); String exactMatches = getExactMatches(secretCode, guess); String partialMatches = getPartialMatches(secretCode, guess); System.out.println("Exact (correct letter and position): " + exactMatches); System.out.println("Partial (correct letter, incorrect position): " + partialMatches); numberOfTurns--; if (numberOfTurns == 0) { System.out.println("You lost. The correct code was: " + secretCode); if(exactMatches > 3) { System.out.println("You won!") numberOfTurns *= 0; } }Last edited by Norm; 11-03-2011 at 06:04 PM. Reason: added code tags
- 11-03-2011, 06:04 PM #2
Re: Mastermind Java Code
Does it work the way you want it to? If not, please explain what the problem is.but doesnt seem right
What is the above line of code supposed to do?numberOfTurns *= 0;Last edited by Norm; 11-03-2011 at 06:08 PM.
- 11-03-2011, 07:36 PM #3
Member
- Join Date
- Nov 2011
- Posts
- 4
- Rep Power
- 0
Re: Mastermind Java Code
Figured it out myself. I'm good.
- 11-03-2011, 07:40 PM #4
Similar Threads
-
Mastermind game problem
By TheQuad in forum New To JavaReplies: 1Last Post: 04-16-2011, 05:29 PM -
problem mastermind
By Alexander_003 in forum AWT / SwingReplies: 4Last Post: 03-16-2011, 05:08 PM -
Mastermind!
By MishkaRX in forum New To JavaReplies: 11Last Post: 12-14-2010, 01:39 PM -
MasterMind Problem!!
By papinhio in forum New To JavaReplies: 4Last Post: 07-09-2010, 03:51 PM -
how to make mastermind game
By javabeginer in forum New To JavaReplies: 10Last Post: 04-14-2009, 02:11 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks