import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class Game extends JFrame implements ActionListener{
Container con = getContentPane();
ImageIcon begin = new ImageIcon("wall.png");
ImageIcon p1 = new ImageIcon("slot1.jpg");
ImageIcon p2 = new ImageIcon("slot2.png");
ImageIcon p3 = new ImageIcon("slot3.png");
int score =50000;
JButton slot1 = new JButton("",begin);
JButton slot2 = new JButton("",begin);
JButton slot3= new JButton("",begin);
JButton spin= new JButton("spin");
Game(){
con.setBackground(Color.black);
setLayout(null);
setBounds(200, 10, 200, 400);
setVisible(true);
setTitle("Slot Machine");
setResizable(false);
con.add(slot1);
con.add(slot2);
con.add(slot3);
con.add(spin);
slot1.setBounds(10,50, 50, 50);
slot2.setBounds(60,50, 50, 50);
slot3.setBounds(110,50, 50, 50);
spin.setBounds(50,150, 60, 50);
spin.addActionListener(this);
}
public static void main(String[] args) {
new Game();
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==spin){
Random ran = new Random();
int Rslot1 = ran.nextInt(3);
int Rslot2 = ran.nextInt(3);
int Rslot3 = ran.nextInt(3);
ImageIcon pp1 = null;
ImageIcon pp2 = null;
ImageIcon pp3 = null;
if(Rslot1==1){
pp1 = p1;
}
if(Rslot1==2){
pp1 = p2;
}if(Rslot1==3){
pp1 = p3;
}
if(Rslot2==1){
pp2 = p1;
}
if(Rslot2==2){
pp2 = p2;
}if(Rslot2==3){
pp2 = p3;
}
if(Rslot3==1){
pp3 = p1;
}
if(Rslot3==2){
pp3 = p2;
}if(Rslot3==3){
pp3 = p3;
}
con.remove(slot1);
con.remove(slot2);
con.remove(slot3);
repaint();
slot1 = new JButton("",pp1);
slot2 = new JButton("",pp2);
slot3= new JButton("",pp3);
con.add(slot1);
con.add(slot2);
con.add(slot3);
slot1.setBounds(10,50, 50, 50);
slot2.setBounds(60,50, 50, 50);
slot3.setBounds(110,50, 50, 50);
if(score<=0){
JOptionPane.showMessageDialog(null, "หมดตูด");
System.exit(0);
}
if(Rslot1 == Rslot2 && Rslot2 == Rslot3){
score = score+10000;
JOptionPane.showMessageDialog(null, "Jacpot"+score);
}
else{
score = score-10000;
JOptionPane.showMessageDialog(null, "สมน้ำหน้า"+score);
}
}
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น