import java.io.*;
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.sound.midi.*;
/**
*
* @author *********
* @version *********
*/
public class memGame extends JFrame
{
MyButton gmButtons[] = new MyButton[16];
// Image files
ImageIcon img1 = new ImageIcon("C:\\Documents and Settings\\My Documents\\My eBooks\\CS340\\MemoryGame\\1UPmushCard.gif");
ImageIcon img2 = new ImageIcon("C:\\Documents and Settings\\My Documents\\My eBooks\\CS340\\MemoryGame\\cloudCard.gif");
ImageIcon img3 = new ImageIcon("C:\\Documents and Settings\\My Documents\\My eBooks\\CS340\\MemoryGame\\flowerCard.gif");
ImageIcon img4 = new ImageIcon("C:\\Documents and Settings\\My Documents\\My eBooks\\CS340\\MemoryGame\\goombaCard.gif");
ImageIcon img5 = new ImageIcon("C:\\Documents and Settings\\My Documents\\My eBooks\\CS340\\MemoryGame\\luigiCard.gif");
ImageIcon img6 = new ImageIcon("C:\\Documents and Settings\\My Documents\\My eBooks\\CS340\\MemoryGame\\marioCard.gif");
ImageIcon img7 = new ImageIcon("C:\\Documents and Settings\\My Documents\\My eBooks\\CS340\\MemoryGame\\mushRegCard.gif");
ImageIcon img8 = new ImageIcon("C:\\Documents and Settings\\My Documents\\My eBooks\\CS340\\MemoryGame\\starCard.gif");
ImageIcon guess = new ImageIcon("C:\\Documents and Settings\\My Documents\\My eBooks\\CS340\\MemoryGame\\unTurnedCard.gif");
ImageIcon vals[] = new ImageIcon[16];
/*Sound files
File songA = new File("C:\\Documents and Settings\\My Documents\\My eBooks\\CS340\\SoundsfromMario\\charSel.mid");
File songB = new File("C:\\Documents and Settings\\My Documents\\My eBooks\\CS340\\SoundsfromMario\\hammerinAway.mid");
File songC = new File("C:\\Documents and Settings\\My Documents\\My eBooks\\CS340\\SoundsfromMario\\memGameMain.mid");
boolean soundOn;
*/
int turnNumber = 0;
boolean Game;
/** Creates a new instance of memGame */
public memGame()
{
super("Mario Memory Game");
randomize();
Container win = getContentPane();
JPanel mp2 = new JPanel();
JLabel turnCount = new JLabel("Number of Turns: ");
JPanel mp = new JPanel();
/* Setting up the background music for game
JButton playSound = new JButton("Music On");
JButton stopSound = new JButton("Music Off");
playSound.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
soundOn = true;
setSound(songA,soundOn);
}
});
stopSound.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
soundOn = false;
setSound(songB,soundOn);
}
});
*/
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
setSize(400,550);
win.setLayout(new BorderLayout());
mp.setLayout(new GridLayout(4,4,8,8));
mp.setBackground(Color.darkGray);
win.add(mp,BorderLayout.CENTER);
makeMenu();
mp2.setLayout(new FlowLayout());
//mp2.add(playSound);
//mp2.add(stopSound);
mp2.add(turnCount);
win.add(mp2,BorderLayout.SOUTH);
//randomize();
for(int i=0; i < gmButtons.length; i++)
{
gmButtons[i] = new MyButton(i);
mp.add(gmButtons[i]);
gmButtons[i].setIcon(guess);
gmButtons[i].addActionListener(gmButtons[i]);
}
}
public void makeMenu()
{
JMenuBar menuBar = new JMenuBar();
JMenu gMenu = new JMenu("Game");
JMenu gMenu2 = new JMenu("Extra");
//JMenu gMenu3 = new JMenu("Music");
JMenuItem newG = new JMenuItem("New Game");
newG.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
turnNumber = 0;
randomize();
for(int i=0; i < gmButtons.length; i++)
{
gmButtons[i].setIcon(guess);
}
}
});
JMenuItem quit = new JMenuItem("Quit Game");
quit.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.out.println("Exit command executed...");
System.exit(0);
}
});
JMenuItem help = new JMenuItem("Help");
help.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JOptionPane helpMe = new JOptionPane();
helpMe.showMessageDialog(memGame.this,"Object of the Game:\nTry to use memory " +
"and some guessing to match each card with " +
"its partner.\nThe lower the number of turns the " +
"better you are at the memory Game!\n" +
"\nMenu Features:\n" +
"Selecting \"New Game\" from the menu starts over\n" +
"Quit of course Quits the current game window.", "Mario Memory Game Help",3);
}
});
JMenuItem about = new JMenuItem("About");
about.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JOptionPane abt = new JOptionPane();
abt.showMessageDialog(memGame.this,"Title: Mario Memory Game\n" +
"Author: \n" +
"Class: \n" +
"\nMario is a registered TradeMark of " +
"the Nintendo Corporation\n" +
"This product intended for personal use only!\n" +
"\nAny reproduction or distribution of this product " +
"for monetary\nor commercial use is strictly " +
"prohibited, due to the nature of content", "About The Author",1);
}
});
/*Song menu
JCheckBoxMenuItem song1 = new JCheckBoxMenuItem("Song 1");
song1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(soundOn == true)
{
setSound(songA,soundOn);
}
}
});
JCheckBoxMenuItem song2 = new JCheckBoxMenuItem("Song 2");
song2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(soundOn == true)
{
setSound(songB,soundOn);
}
}
});
JCheckBoxMenuItem song3 = new JCheckBoxMenuItem("Song 3");
song3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(soundOn == true)
{
setSound(songC,soundOn);
}
}
});
gMenu3.add(song1);
gMenu3.add(song2);
gMenu3.add(song3);
*/
gMenu.add(newG);
gMenu.add(quit);
gMenu2.add(help);
gMenu2.add(about);
menuBar.add(gMenu);
menuBar.add(gMenu2);
//menuBar.add(gMenu3);
setJMenuBar(menuBar);
}
public void randomize()
{
int j = 0;
ImageIcon temp;
vals[0] = img1;
vals[1] = img1;
vals[2] = img2;
vals[3] = img2;
vals[4] = img3;
vals[5] = img3;
vals[6] = img4;
vals[7] = img4;
vals[8] = img5;
vals[9] = img5;
vals[10] = img6;
vals[11] = img6;
vals[12] = img7;
vals[13] = img7;
vals[14] = img8;
vals[15] = img8;
for(int i = 0 ; i < 16; i++)
{
j = (int)Math.floor(Math.random() * 16);
temp = vals[i];
vals[i] = vals[j];
vals[j] = temp;
}
}
public ImageIcon[] getVals()
{
return vals;
}
}