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

USE JAVAFX, AND memory game is images matching game, not puzzle game. an example

ID: 3713245 • Letter: U

Question

USE JAVAFX, AND memory game is images matching game, not puzzle game.

an example would be like this: (go to this website)

http://dkmgames.com/Memory/pairsrun.php

READ THE PROBLEM AND DON'T ANSWER WITH JFrame.

General Description: "Memory" or "Concentration" is a popular game played by young children. The object of the game is to take turns flipping over pairs of cards and keeping track of how many same pairs each user has found. The winner is the person who made the most matches. An example of this game can be seen here where the objective is to match a country with its flag (a variation on the classic game.) You will implement a single player version of this game this week. Requirements Your program must place all files in a package called hws Your program must use Object Oriented Design in its implementation. Your program must use JavaFX for the GUI, no console input /output is allowed. Programs which utilize the console will receive no credit. Your program must offer the user a choice of different game board sizes from the following: 4 x4,6x6, and 10 x 10. come up with your own.) Your program must offer the user a choice of three different image themes, i.e. food, animals, colors (don't use these o You will want to find small images to use for each theme. o Please choose themes that are school appropriate. Your program must time the user and report how long it took them to find all matches, once all matches have been found ° You do not need to display a ticking clock, as this may need to use the animation libraries we have yet to cover, but if you can figure out a way you are more than welcome to do this. Your prNJrarn musi b: able in play?( ar in irm boginning in end vnih nt>

Explanation / Answer

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.*;

import java.util.Random;

public class MemoryApp extends JFrame {

static String Pics[] = {"beaver.JPG", "dawgs.jfif",

"ducks.jfif", "forky.jfif",

"trees.jfif", "utes.jfif"};

static JButton buttons[];

ImageIcon closedIcon;

int numButtons;

ImageIcon icons[];

int firstClick, secondClick, clickNumber;

Timer myTimer;

int openImages;

public MemoryApp() {

// Set the title.

setTitle("Memory Game");

// Specify an action for the close button.

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// Create a BorderLayout manager.

getContentPane().setLayout(new GridLayout(2, Pics.length));

closedIcon = new ImageIcon("p12.jfif");

numButtons = Pics.length * 2;

buttons = new JButton[numButtons];

icons = new ImageIcon[numButtons];

for (int i = 0, j = 0; i < Pics.length; i++) {

icons[j] = new ImageIcon(Pics[i]);

buttons[j] = new JButton("");

buttons[j].addActionListener(new MemoryApp.ImageButtonListener());

buttons[j].setIcon(closedIcon);

getContentPane().add(buttons[j++]);

icons[j] = icons[j - 1];

buttons[j] = new JButton("");

buttons[j].addActionListener(new MemoryApp.ImageButtonListener());

buttons[j].setIcon(closedIcon);

getContentPane().add(buttons[j++]);

}

// randomize icons

Random generator = new Random();

for(int i=0 ; i<numButtons; i++)

{

int j = generator.nextInt(numButtons);

ImageIcon temp = icons[i];

icons[i] = icons[j];

icons[j] = temp;

}   

// Pack and display the window.

pack();

setVisible(true);

validate();

myTimer = new Timer(1000, new TimerListener());

}

private class TimerListener implements ActionListener {

public void actionPerformed(ActionEvent e) {

myTimer.stop();

buttons[firstClick].setIcon(closedIcon);

buttons[secondClick].setIcon(closedIcon);

}

}

private class ImageButtonListener implements ActionListener {

public void actionPerformed(ActionEvent e) {

for (int i = 0; i < numButtons; i++) {

if (e.getSource() == buttons[i]) {

buttons[i].setIcon(icons[i]);

}

}

}

}

public static void main(String[] args) {

MemoryApp mem = new MemoryApp();

mem.setSize(450,300);

mem.setVisible(true);

mem.setLocation(450, 220);

}

}