package JRPG;
/**
*
* @author Ccc
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class GameFrame extends JFrame implements ActionListener{
private Game g1;
private JButton player,com,restart,showcards,exit,Sound;
public JButton[] pick= new JButton[5];
private JLabel title,playlbl,comlbl,cardspick;
private JPanel north,center,South,cardsp,East,West,insidenorth1,insidenorth2,total;
private ImageIcon playeric,comIc,soic;
ImageIcon[] aicardic=new ImageIcon[5];
private String Name;
private JTextArea result;
private JTextField playername;
private JMenuBar bar;
private JMenu menu,customize;
private JRadioButton red,green,black,gray,blue;
ImageIcon[] images= new ImageIcon[5];
public void actionPerformed(ActionEvent e){
if (e.getSource()==pick[0]){
pick[0].setEnabled(false);
int[] a=g1.pickingCard();
int[] b=g1.setAICards();
String msg=g1.getWin(a[0],b[0]);
JOptionPane.showMessageDialog(null, msg, "input", JOptionPane.INFORMATION_MESSAGE);
}
else if (e.getSource()==pick[1]){
pick[1].setEnabled(false);
int[] a=g1.pickingCard();
int[] b=g1.setAICards();
g1.setDrawn(a[1],true);
String msg1=g1.getWin(a[1],b[1]);
aicardic=g1.getAiCardImage();
com.setIcon(aicardic[1]);
JOptionPane.showMessageDialog(null, msg1, "input", JOptionPane.INFORMATION_MESSAGE);
}
else if (e.getSource()==pick[2]){
pick[2].setEnabled(false);
int[] a=g1.pickingCard();
int[] b=g1.setAICards();
g1.setDrawn(a[2],true);
String msg2=g1.getWin(a[2],b[2]);
aicardic=g1.getAiCardImage();
com.setIcon(aicardic[2]);
JOptionPane.showMessageDialog(null, msg2, "input", JOptionPane.INFORMATION_MESSAGE);
}
else if (e.getSource()==pick[3]){
pick[3].setEnabled(false);
int[] a=g1.pickingCard();
int[] b=g1.setAICards();
g1.setDrawn(a[3],true);
String msg3=g1.getWin(a[3],b[3]);
aicardic=g1.getAiCardImage();
com.setIcon(aicardic[3]);
JOptionPane.showMessageDialog(null, msg3, "input", JOptionPane.INFORMATION_MESSAGE);
}
else if (e.getSource()==pick[4]){
pick[4].setEnabled(false);
int[] a=g1.pickingCard();
int[] b=g1.setAICards();
g1.setDrawn(a[4],true);
String msg4=g1.getWin(a[4],b[4]);
aicardic=g1.getAiCardImage();
com.setIcon(aicardic[4]);
JOptionPane.showMessageDialog(null, msg4, "input", JOptionPane.INFORMATION_MESSAGE);
}
else if (e.getSource()==exit){
JOptionPane.showMessageDialog(null, "Thank you for using this program!!", "input", JOptionPane.INFORMATION_MESSAGE);
dispose();
System.exit(0);
}
else if (e.getSource()==restart){
g1=new Game();
aicardic=g1.getAiCardImage();
images=g1.getGameImages();
pick[0].setEnabled(true);
pick[1].setEnabled(true);
pick[2].setEnabled(true);
pick[3].setEnabled(true);
pick[4].setEnabled(true);
pick[0].setIcon(images[0]);
pick[1].setIcon(images[1]);
pick[2].setIcon(images[2]);
pick[3].setIcon(images[3]);
pick[4].setIcon(images[4]);
}
else if (e.getSource()==showcards){
}
else if (e.getSource()==red){
north.setBackground(Color.RED);
South.setBackground(Color.RED);
East.setBackground(Color.RED);
West.setBackground(Color.RED);
center.setBackground(Color.RED);
}
else if (e.getSource()==green){
north.setBackground(Color.GREEN);
South.setBackground(Color.GREEN);
East.setBackground(Color.GREEN);
West.setBackground(Color.GREEN);
center.setBackground(Color.GREEN);
}
else if (e.getSource()==blue){
north.setBackground(Color.BLUE);
South.setBackground(Color.BLUE);
East.setBackground(Color.BLUE);
West.setBackground(Color.BLUE);
center.setBackground(Color.BLUE);
}
else if (e.getSource()==black){
north.setBackground(Color.BLACK);
South.setBackground(Color.BLACK);
East.setBackground(Color.BLACK);
West.setBackground(Color.BLACK);
center.setBackground(Color.BLACK);
}
else if (e.getSource()==gray){
north.setBackground(Color.LIGHT_GRAY);
South.setBackground(Color.LIGHT_GRAY);
East.setBackground(Color.LIGHT_GRAY);
West.setBackground(Color.LIGHT_GRAY);
center.setBackground(Color.LIGHT_GRAY);
}
}
public void setNorth(){
Name = JOptionPane.showInputDialog(null, "Enter Name:", "input", JOptionPane.QUESTION_MESSAGE);
north = new JPanel(new BorderLayout());
insidenorth1 = new JPanel();
insidenorth2 = new JPanel();
title = new JLabel("Card Game");
title.setFont(new Font("Arial",1,40));
title.setForeground(Color.red);
playername =new JTextField(Name,8);
playername.disable();
comlbl = new JLabel("Computer:");
playlbl = new JLabel("Player:");
insidenorth1.add(title,BorderLayout.CENTER);
insidenorth2.add(playlbl);
insidenorth2.add(playername);
north.add(comlbl,BorderLayout.EAST);
north.add(insidenorth1,BorderLayout.NORTH);
north.add(insidenorth2,BorderLayout.WEST);
add(north,BorderLayout.NORTH);
}
public void setWest(){
West = new JPanel();
playeric= new ImageIcon("Images/Mark.jpg");
player = new JButton(playeric);
West.add(player);
//West.setBackground(Color.GREEN);
add(West,BorderLayout.WEST);
}
public void setEast(){
East = new JPanel();
insidenorth1 = new JPanel();
comIc= new ImageIcon("Images/cardback.png");
com = new JButton(comIc);
East.add(com);
add(East,BorderLayout.EAST);
}
public void setCenter(){
center = new JPanel();
comIc= new ImageIcon();
pick[0] = new JButton(images[0]);
pick[1] = new JButton(images[1]);
pick[2] = new JButton(images[2]);
pick[3] = new JButton(images[3]);
pick[4] = new JButton(images[4]);
cardspick = new JLabel("pick your cards:");
cardsp = new JPanel();
result =new JTextArea("Number of times "+Name+ " Won:"+g1.getPlayerScore()+"\n"
+ "Number of times the computer won:"+g1.getComScore()+"\n"
+ "Number of times that were draw:"+g1.getDraw()+"\n");
result.disable();
result.setForeground(Color.BLACK);
result.setFont(new Font("sansserif", Font.BOLD, 14));
soic = new ImageIcon("sound");
center.add(cardspick);
pick[0].addActionListener(this);
pick[1].addActionListener(this);
pick[2].addActionListener(this);
pick[3].addActionListener(this);
pick[4].addActionListener(this);
cardsp.add(pick[0]);
cardsp.add(pick[1]);
cardsp.add(pick[2]);
cardsp.add(pick[3]);
cardsp.add(pick[4]);
center.add(cardsp);
center.add(result);
add(center,BorderLayout.CENTER);
}
public void setSouth(/*int com,int play,int draw*/){
South = new JPanel();
soic = new ImageIcon("onmedia.png");
Sound= new JButton (soic);
Sound.setForeground(Color.green);
Sound.setBackground(Color.BLACK);
Sound.addActionListener(this);
restart = new JButton("restart");
restart.setForeground(Color.green);
restart.setBackground(Color.BLACK);
showcards = new JButton("show cards");
showcards.setForeground(Color.green);
showcards.setBackground(Color.BLACK);
showcards.addActionListener(this);
exit = new JButton("exit");
exit.addActionListener(this);
exit.setForeground(Color.green);
exit.setBackground(Color.BLACK);
restart.addActionListener(this);
//adding into west panel
South.add(Sound);
South.add(restart);
South.add(showcards);
South.add(exit);
add(South,BorderLayout.SOUTH);
}
public void addMenu(){
bar = new JMenuBar();
menu = new JMenu("Menu");
customize = new JMenu("Customize");
bar.add(menu);
bar.add(customize);
JMenuItem newAction = new JMenuItem("New");
JMenuItem muteAction = new JMenuItem("Mute");
JMenuItem exitAction = new JMenuItem("Exit");
menu.add(newAction);
menu.add(muteAction);
menu.add(exitAction);
ButtonGroup btg= new ButtonGroup();
red= new JRadioButton("set background to Red");
blue= new JRadioButton("set background to Blue");
green= new JRadioButton("set background to Green");
black= new JRadioButton("set background to Black");
gray= new JRadioButton("set background to Gray");
btg.add(red);
btg.add(blue);
btg.add(green);
btg.add(black);
btg.add(gray);
gray.setSelected(true);
customize.add(red);
customize.add(blue);
customize.add(green);
customize.add(black);
customize.add(gray);
red.addActionListener(this);
blue.addActionListener(this);
black.addActionListener(this);
gray.addActionListener(this);
green.addActionListener(this);
setJMenuBar(bar);
}
public void setFrame(){
setNorth();
setCenter();
setSouth();
setWest();
setEast();
title.setBackground(Color.LIGHT_GRAY);
north.setBackground(Color.LIGHT_GRAY);
South.setBackground(Color.LIGHT_GRAY);
East.setBackground(Color.LIGHT_GRAY);
West.setBackground(Color.LIGHT_GRAY);
center.setBackground(Color.LIGHT_GRAY);
addMenu();
}
public GameFrame(){
g1=new Game();
aicardic=g1.getAiCardImage();
images=g1.getGameImages();
setFrame();
}
}