Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need a GUI memory game with images. You can use what ever images you like spor

ID: 3559025 • Letter: I

Question

I need a GUI memory game with images. You can use what ever images you like sports teams pictures of planets I dont care. It just needs to:

-have 12 cards on the window

-an image on the back of the card

-the images need to be randomly placed

-click one it flips over to display the image

-click another and it flips over if the cards images match it clears the cards if not it flips them back over

-the game ends when all the cards have been matched

it must be written in java

I have been trying to write this for hours and cant seem to get it right so im giving up and just asking for it thanks for the help and getting rid of my headache

Explanation / Answer

import java.awt.event.*;

import java.awt.*;

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},

        };

        boolean[][] revealed = new boolean[4][3];

        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 + " ";

        }

        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;

            }

        }

    }

}

import java.io.File;

import java.io.IOException;

import javax.imageio.ImageIO;

import javax.swing.*;

public class FindingMemo{

         public static void main(String[] args){

              Memo memo = new Memo();

            JFrame frame = new JFrame("Finding Memo");

            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            frame.getContentPane().add(memo);

            frame.pack();

            frame.setLocationRelativeTo(null);

            frame.setVisible(true);

                  

         }

}       

class Memo extends JPanel implements ActionListener{

    JLabel label;

    JRadioButton yes,no;

    ButtonGroup radioGroup;

    public Memo(){

     label=new JLabel("Would You Like to Play?");

         radioGroup=new ButtonGroup();

         yes=new JRadioButton("Yes", true);

         no=new JRadioButton("No", false);

         yes.addActionListener(this);

         no.addActionListener(this);

         radioGroup.add(yes);

         radioGroup.add(no);

         label.setBounds(430,250,150,50);

         yes.setBounds(380,300,180,20);

         no.setBounds(560,300,200,20);

         add(label);

         add(yes);

         add(no);

    }

     

     

        public void actionPerformed(ActionEvent e){

                    if(e.getSource()==yes){

                        JOptionPane.showMessageDialog(null,"Welcome to Finding Memo!");

                         

                             

                                  

                                             

                    }else {

                        JOptionPane.showMessageDialog(null,"Thanks for Visiting Memo!");

                        System.exit(0);

                    }

        }

         

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote