Results 1 to 10 of 10
Thread: ArrayList of Integer Arrays
- 03-15-2012, 05:57 PM #1
Member
- Join Date
- Mar 2012
- Location
- Lisburn Northern Ireland
- Posts
- 15
- Rep Power
- 0
ArrayList of Integer Arrays
Hi,
I am hoping 4 some direction please....
I have java "coursework" to complete, produce a MasterMind code breaking game. OOP text based random number guessing game (4 code length).
Current Game Progression
1. Loop scanner int "guess" into int [] "guessCode"
2. Convert int [] "guessCode" into new String[] "textGuess" is example "Black, Blue, Green, Red" = send int [] "guessCode" to "OutPutDisplay" Class.
3. Display int [] "guessCode" and String[] "textGuess = Display Method in "OutPutDisplay" Class.
4. Validate int [] "guessCode" by creating new char[] "feedBack" Array is example "X, B, W, W" = send int [] "guessCode" to "BlackValidation" and then "WhiteValidation" Classes.
5. Sort char[] "feedBack" Array is example "B, W, W, X" = char[] "feedBack" sort Method in "FeedBack" Class.
6. Display char[] "feedBack" = send Array to "OutPutDisplay" Class
6a.
7. Guess again if "gameLoop" < "MAX_GUESSES"
I wish to display the following at 6a with each failed guess prior to another guess if (gameLoop > 0).
First Guess ("First") from String []
1, 2, 3, 4 (User Guess) (Integers[]) entered in "Game" Class
Black, Blue, Green, Red (Converted Text Code) (String[]) created in "OutPutDisplay" Class from passed guessCode []
B, W, W, X (FeedBack) (Char[]) created in "FeedBack" Class in 2 passes from BlackValidation and WhiteValidation Classes
Second Guess.........So on until (gameLoop == numberHistory.size())
I have the game running fine but I wish to add History to each completed guess as above. I have a GameHistory Class were I send the users guess to be added to the ArrayList "numberHistory" from the Game Class as shown below. I then want to send each Int array in a loop while less than size() to the "DisplayOutPut" Class for display after each completed incorrect guess. I have no idea how to retrieve each array from the ArrayList to send from "GameHistory" Class to "OutPutDisplay" Class, or if I should collect all three Arrays int [] "guessCode", String[] "textGuess and char[] "feedBack" in seperate ArrayLists , or 1 Oject ArrayList containing the three Arrays or just reprocess int [] "guessCode" to generate the other 2 Arrays again.
I have been looking at this so long I cant get it. I have no idea how to "SSCCE" this as this is the first java oop program I have written with multiple classes.
Cheers
Pete
Link to java files
MasterMind folder .java files
Java Code:public class Game private int gameLoop = 0; private int[] guessCode = new int[CODE_SIZE]; Private GameHistory aNewHistory = new GameHistory public void add2History(int[] guessCode, int gameLoop) { /// Send Message to Class "GameHistory" // Method "addNumberHistory()" aNewHistory.addNumberHistory(guessCode, gameLoop); // Pass "guessCode" Array and "gameLoop" Integer } // End of add2History() Method public class GameHistory private ArrayList <int []> numberHistory = new ArrayList <int []> (); public void addNumberHistory(int[] numberCode, int gameLoop) { // Add "numberCode" Array to "guessHistory" ArrayList // @ "gameLoop" Index Position numberHistory.add(gameLoop, numberCode); } // End of addNumberHistory() Method public class OutPutDisplay public void displaygameHistory(int[] numberCode, int gameLoop) { // Display Feed Back Message System.out.println("\n**************************************************"); System.out.print("** Guess" ); // Run displayUserNumberCode() Method displayUserNumberCode(numberCode); // Pass "numberCode" Array // Run userCodeColourConverter() Method userCodeColourConverter(numberCode); // Pass "numberCode" Array } // End of displaygameHistory() MethodLast edited by KevinWorkman; 03-15-2012 at 07:23 PM. Reason: fixed code tags
- 03-15-2012, 06:09 PM #2
Re: ArrayList of Integer Arrays
That is not how you use the code tags- they're square brackets, not < >.
If you want help, you should provide an SSCCE that demonstrates the problem without any extra pieces such as game logic. Nobody wants to download a .rar from a third party site. Make it easy for people to help you!
I'm still not sure what your actual question is. Are you getting errors? Some strange behavior? Something else?How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 03-15-2012, 07:11 PM #3
Member
- Join Date
- Mar 2012
- Location
- Lisburn Northern Ireland
- Posts
- 15
- Rep Power
- 0
Re: ArrayList of Integer Arrays
I have Amended myself in the hope I am clearer
Cheers
Pete
- 03-15-2012, 07:25 PM #4
Re: ArrayList of Integer Arrays
I fixed your code tags for you. But I didn't mean that you should just link to something other than a .rar, I meant that all code you want us to look at should be posted in the form of an SSCCE. It should be easy for us to copy and paste the code into an editor so that we can see the problem ourselves.
Sorry, but I'm still not sure what your actual question is. You've listed some requirements and some code, but I'm not sure where you're stuck? Are you getting an error? Strange behavior? Something else? Have you narrowed the problem down at all?How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 03-15-2012, 07:33 PM #5
Member
- Join Date
- Mar 2012
- Location
- Lisburn Northern Ireland
- Posts
- 15
- Rep Power
- 0
Re: ArrayList of Integer Arrays
I have no idea how to continue.... No errors as nothing really to compile.
I add int [] "guessCode" Array to ArrayList "numberHistory" in a loop up to 12 times = game over. If user guess is incorrect I want to display all previous guesses in the display format above but I dont know how to get the int [] "guessCode" Array out of the ArrayList "numberHistory" to send to other Classes for processing.
I also dont know if I should collect String[] "textGuess and char[] "feedBack" Arrays in seperate ArrayLists , or 1 Oject ArrayList containing all three Arrays or just reprocess int [] "guessCode" through other Class Methods to generate the other 2 Arrays again.
I will try agin later if I am still confusing.
Cheers
Pete
- 03-15-2012, 07:38 PM #6
Re: ArrayList of Integer Arrays
The best I can tell you is to break your problem up into smaller pieces. Each piece roughly translates to a single method that might take a parameter and might return a value. For example, one method would prompt the user for input and then convert that input to the appropriate data type and return it. That's one piece. Get that piece working perfectly before you move onto the next piece. The next piece might take a data type and do some kind of calculation with it- get that piece working perfectly, and then try to use the first piece to feed into the second piece (so the first piece would take user input and return a data type, which you could then pass into the second piece to perform the calculation). Repeat that process until you've finished your program. And when you get stuck, you can post just that single piece instead of your whole program, which will make it easier for us to help you. Good luck!
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 03-15-2012, 10:40 PM #7
Member
- Join Date
- Mar 2012
- Location
- Lisburn Northern Ireland
- Posts
- 15
- Rep Power
- 0
Re: ArrayList of Integer Arrays
I have the game working as is,
1. I dont know how to get the "guessCode" int[] Arrays out of the ArrayList so I can send them to another class for either display or further processing?
2. I dont know if I should collect all three Arrays and if so should they be seperate ArrayLists or a single ArrayList containing all three Arrays Int[], String[] and char[]. I have methods in other classes that I can send the userGuess int[] Array to Convert to create a new String[] Array which describes the colours in text and also create and organise the FeedBack char[] Array.
This is displayed 4x
**************************************************
** Guess Number Two
** Guess First Position
**************************************************
** Enter: '1' = Black, '2' = Blue, '3' = Green **
** '4' = Red, '5' = Yellow and '6' = White **
**************************************************
** Or: '9' = QUIT **
**************************************************
Guess the Secret Code:
Then this
**************************************************
**************** USERS CODE GUESS ****************
**************************************************
** User Number Code is: 1, 2, 3, 4 **
**************************************************
** User Text Code is: Black, Blue, Green, Red
**************************************************
Then this
**************************************************
** Colour/s MisMatch, FeedBack Hint, B, W, X, X
**************************************************
Then This
**************************************************
****************** WRONG GUESS *******************
**************************************************
****************** GUESS AGAIN *******************
**************************************************
NEW DISPLAY BETWEEN
First Guess
1, 2, 3, 4
Black, Blue, Green, Red
B, W, W, X
Second Guess
4, 3, 2, 1
Red, Black, Blue, Green
B, W, W, X
Third Guess and so on....
NEW DISPLAY BETWEEN
Then back to guessing again
**************************************************
** Guess Number Two
** Guess First Position
**************************************************
** Enter: '1' = Black, '2' = Blue, '3' = Green **
** '4' = Red, '5' = Yellow and '6' = White **
**************************************************
** Or: '9' = QUIT **
**************************************************
Guess the Secret Code:
Cheers
PeteLast edited by PeteW44; 03-15-2012 at 10:52 PM.
- 03-16-2012, 04:07 PM #8
Member
- Join Date
- Mar 2012
- Location
- Lisburn Northern Ireland
- Posts
- 15
- Rep Power
- 0
Re: ArrayList of Integer Arrays
As I am unable to articulate my issue I have attempted to write code from my GuessHistroy Class. I intend to call this method after every guess so I can give a quick refresh of the users previous guesses, I have add methods adding the int [] "guessCode" Array to ArrayList "numberHistory" and the char[] "feedBack" Array to ArrayList "feedBackHistory" I am just going to regenerate the String[] "textGuess" Array reusing its display method.
As you can notice I highlighted in red the issue I think! I want to pass the Arrays stored in the ArrayLists onto another Method in another Class for display. I dont know how to say "get the Array from this ArrayList in the position "gameLoop" and send in on please, thankyou. Ohhh and also do this again until its done as many times as the ArrayLists are long".
Sorry for being so SO but I am not understanding java ArrayLists and how to get the added Arrays OUT and Passed on. I would be most appreciative of some assistance as I am pickled, so far this coursework has taken many many days working 10am til 4am.
Cheers
Pete
Java Code:public void displayHistory(int guessPosition) { // Method Variables int historyLoop = 0; if (guessPosition > 1) { // Loop WHILE // Loop While "historyLoop" is Less Than "numberHistory" Array Size while (historyLoop < numberHistory.size()) { // Set "numberCode" and "feedBack" arrays from ArrayLists int[] numberCode = numberHistory.get(guessPosition); char[] feedBack = feedBackHistory.get(guessPosition); aNewDisplayHistory.displayGameHistory(numberCode, feedBack, historyLoop); // Add 1 to "historyLoop" historyLoop++; } // End of While Loop } // End of If Statement } // End of getNumberHistory() MethodLast edited by PeteW44; 03-17-2012 at 09:26 AM.
- 03-17-2012, 09:26 AM #9
Member
- Join Date
- Mar 2012
- Location
- Lisburn Northern Ireland
- Posts
- 15
- Rep Power
- 0
Re: ArrayList of Integer Arrays
Can anybody understand what the problem is I am totally beat on this I thought maybe I was close to an explanation.
Cheers
Pete
- 03-22-2012, 06:26 AM #10
Member
- Join Date
- Mar 2012
- Location
- Lisburn Northern Ireland
- Posts
- 15
- Rep Power
- 0
Similar Threads
-
Adding integer to arraylist
By powerpravin in forum New To JavaReplies: 2Last Post: 04-03-2011, 07:21 AM -
Java Heap Space : ArrayList<Integer>
By Ms.Ranjan in forum Advanced JavaReplies: 7Last Post: 03-16-2011, 08:22 AM -
Copy a List<Integer> to an ArrayList
By Nosrettap in forum New To JavaReplies: 3Last Post: 01-16-2011, 07:05 PM -
arraylist to integer array
By monika in forum Advanced JavaReplies: 3Last Post: 04-26-2010, 09:09 PM -
Arraylist with arrays?
By Dieter in forum Advanced JavaReplies: 13Last Post: 09-19-2009, 11:10 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks