Results 1 to 2 of 2
- 12-02-2009, 10:19 AM #1
Member
- Join Date
- Sep 2009
- Posts
- 4
- Rep Power
- 0
Memory card game using JOption... Need help flipping cards...more info inside, thanks
Here is what I have at the moment, I was able to create two arrays 4x4 , ones a boolean and the other is a normal one called "board". I got to the level where I was able to shuffle the numbers randomly and I've tested it. There is 2 lines of code that shows where I tested two different coordinates. The project I'm working on asks to create a 4 x 4 to match numbers with each other, if correct the two numbers should remain revealed as you continue to play and if the two numbers are not the same to flip once more. I got some commented out code, not sure if thats any good. Thanks and let me know if further details needed.
Thanks!Java Code:import javax.swing.JOptionPane; import java.util.Random; public class MemoryGame { public static void main(String[] args) { int[][] board = { {1, 1, 2, 2}, {3, 3, 4, 4}, {5, 5, 6, 6}, {7, 7, 8, 8} }; boolean[][] revealed = new boolean[4][4]; String input; int row; int col; showBoard(board, revealed); shuffleBoard(board); //this is just to test the my board for right now revealed[2][2] = true; revealed[3][1] = true; // input = JOptionPane.showInputDialog("Enter the row"); // row = Integer.parseInt(input); // input = JOptionPane.showInputDialog("Enter the col"); // col = Integer.parseInt(input); // row -= 1; // col -= 1; // // board[row][col] = 'B'; // // for (int i = 0; i < board.length; i++) { // for (int j = 0; j < board[i].length; j++) { // if (row != i) { // if (row - i == j - col || row - i == col - j) { // board[i][j] = 'x'; // } // } // } // } showBoard(board, revealed); System.exit(0); } public static void showBoard(int[][] b, boolean[][] revealed) { String theBoard = ""; for (int i = 0; i < b.length; i++) { for (int j = 0; j < b[i].length; j++) { if (revealed[i][j] == true) { theBoard = theBoard + " " + b[i][j] + " "; } else { theBoard = theBoard + " X "; } } theBoard = theBoard + "\n"; } JOptionPane.showMessageDialog(null, theBoard); } public static void shuffleBoard(int[][] b) { Random randomNumbers = new Random(); for (int i = 0; i < b.length; i++) { for (int j = 0; j < b[i].length; j++) { // Shuffling code goes here int x = randomNumbers.nextInt(4); int y = randomNumbers.nextInt(4); int old = b[x][y]; b[x][y] = b[i][j]; b[i][j] = old; } } } }Last edited by moe123; 12-02-2009 at 10:22 AM.
- 12-02-2009, 03:39 PM #2
Member
- Join Date
- Dec 2009
- Posts
- 1
- Rep Power
- 0
Similar Threads
-
Have been stuck up coding the GUI for Memory Card Game
By Galore in forum New To JavaReplies: 44Last Post: 10-19-2009, 08:07 PM -
flipping memory cards if they are not matched...
By yanipao in forum New To JavaReplies: 8Last Post: 10-18-2009, 02:25 AM -
Creating a Card Game in Java
By Natrix in forum New To JavaReplies: 1Last Post: 05-05-2009, 05:55 PM -
card game Rummy
By javafox in forum New To JavaReplies: 4Last Post: 03-14-2009, 03:53 PM -
A Online Card Game
By GonzaloP in forum NetworkingReplies: 0Last Post: 12-28-2008, 06:37 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks