2 problems with my slot machine program

2 problems with my slot machine program

Page 1 of 1

8 Replies - 3360 Views - Last Post: 19 March 2009 - 05:37 AM Rate Topic: -----

#1 AZBOY2000  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 06-December 08

2 problems with my slot machine program

Posted 10 December 2008 - 07:39 AM

hi all

my problems are as followed:

1. im trying to add in some hold buttons but im not sure how to go about it i think i need to do someting with the timers but im not sure

2. the other problem i have is that when you click on the bye button i want it to display a message to say do you want to add the coins to your existing total or cash out but im not sure how to display a message box with those options

thanks for any help
Adam

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: 2 problems with my slot machine program

#2 markhazlett9  Icon User is offline

  • Coding is a lifestyle
  • member icon

Reputation: 60
  • View blog
  • Posts: 1,666
  • Joined: 12-July 08

Re: 2 problems with my slot machine program

Posted 10 December 2008 - 09:08 AM

View PostAZBOY2000, on 10 Dec, 2008 - 06:39 AM, said:

hi all

my problems are as followed:

1. im trying to add in some hold buttons but im not sure how to go about it i think i need to do someting with the timers but im not sure

2. the other problem i have is that when you click on the bye button i want it to display a message to say do you want to add the coins to your existing total or cash out but im not sure how to display a message box with those options

thanks for any help
Adam



There is a way to hold off on your commands for coming through. Take a look at the sun API for swing. As to your second question... you will have to create a new JFrame and only make it visible at certain times. This would allow you to customize the buttons on the frame... cheers :^:
Was This Post Helpful? 0
  • +
  • -

#3 AZBOY2000  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 06-December 08

Re: 2 problems with my slot machine program

Posted 10 December 2008 - 10:48 AM

There is a way to hold off on your commands for coming through. Take a look at the sun API for swing. As to your second question... you will have to create a new JFrame and only make it visible at certain times. This would allow you to customize the buttons on the frame... cheers :^:
[/quote]
ok i understand the hold button stuff, but i still dont know how to do the option stuff could you please give an example
thanks adam
Was This Post Helpful? 0
  • +
  • -

#4 markhazlett9  Icon User is offline

  • Coding is a lifestyle
  • member icon

Reputation: 60
  • View blog
  • Posts: 1,666
  • Joined: 12-July 08

Re: 2 problems with my slot machine program

Posted 10 December 2008 - 11:06 AM

What exactly do you mean by options? I'm just not too sure what you mean
Was This Post Helpful? 0
  • +
  • -

#5 AZBOY2000  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 06-December 08

Re: 2 problems with my slot machine program

Posted 10 December 2008 - 12:58 PM

View Postmarkhazlett9, on 10 Dec, 2008 - 10:06 AM, said:

What exactly do you mean by options? I'm just not too sure what you mean

basicly when you click bye i want it to display a message box which has two buttons on one that adds coins to the current total the other to display a message box that says collect your winnings
Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8329
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: 2 problems with my slot machine program

Posted 10 December 2008 - 07:54 PM

Please post your code. We do not like to download attachements for 2 reasons
- first this site has been attack in the past by a virus in an attachment
- secondif we have a solution for you, there is a non pedagogic approach of having other DIC to download your problem to see the offered solution

BTW I make my living by programming slot machines in C++ so I really know what I am talking about (must be a lot easier in Java.. I wish we can do so but our target boards only have a few K of memory)
Was This Post Helpful? 0
  • +
  • -

#7 AZBOY2000  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 06-December 08

Re: 2 problems with my slot machine program

Posted 11 December 2008 - 03:12 AM

View Postpbl, on 10 Dec, 2008 - 06:54 PM, said:

Please post your code. We do not like to download attachements for 2 reasons
- first this site has been attack in the past by a virus in an attachment
- secondif we have a solution for you, there is a non pedagogic approach of having other DIC to download your problem to see the offered solution

BTW I make my living by programming slot machines in C++ so I really know what I am talking about (must be a lot easier in Java.. I wish we can do so but our target boards only have a few K of memory)


ok sorry didnt know about the attachment thing so here is the code
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import java.util.*;
import javax.swing.*;
import javax.swing.Timer;

public class TheElectronicBandit extends JFrame implements ActionListener{
	//list all the variables in the project
	private JButton btnAddcoin, btnSpin, btnBye, panelLeft, panelMiddle, panelRight, btnHold1, btnHold2, btnHold3;
	private JLabel lblCoins;
	private JTextField txtCoin, txtWinnings;
	private int num1, num2, num3, num4, winnings =0;
	private Random random;
	private Icon iconPic1, iconPic2, iconPic3, iconPic4, iconPic5, iconPic6, iconPic7, iconPic8;
	private Timer timer1, timer2, timer3;
	private int Apple = 0, Rberry = 0, Lemon = 0, Bberry = 0, Bar = 0, Seven = 0, Melon = 0, Pineapple = 0, counter;

	public static void main(String[] args)
	{
		TheElectronicBandit TheElectronicBandit = new TheElectronicBandit();
	}
	
	public TheElectronicBandit()
		//definitions of all the variables
		{
		timer1 = new Timer(200, this);
		timer2 = new Timer(200, this);
		timer3 = new Timer(200, this);
		JOptionPane.showMessageDialog(null,"Hello and welcome to the One Armed Bandit!!");
		num1 = 0;
		random = new Random();
		Apple =0;Rberry=0;Lemon=0;Bberry=0;Bar=0;Seven=0;Melon=0;Pineapple = 0;counter=0;
		setLayout(new FlowLayout());
		lblCoins = new JLabel("Coins Inserted");
		txtCoin = new JTextField(3);
		txtCoin.setFont(new Font("TimesRoman", Font.BOLD, 16));
		txtCoin.setBackground(Color.cyan);
		txtCoin.setForeground(Color.red);
		txtCoin.setText(num1 + " ");
		txtWinnings = new JTextField(25);
		txtWinnings.setFont(new Font("TimesRoman", Font.BOLD, 16));
		btnAddcoin = new JButton("Insert Coins");
		btnSpin = new JButton("Play");
		btnBye = new JButton("Bye!!");
		btnHold1 = new JButton("Hold");
		btnHold2 = new JButton("Hold");
		btnHold3 = new JButton("Hold");
		panelLeft = new JButton();
		panelLeft.setBackground(Color.cyan);
		panelLeft.setPreferredSize(new Dimension(100, 100));
		panelMiddle = new JButton();
		panelMiddle.setBackground(Color.cyan);
		panelMiddle.setPreferredSize(new Dimension(100, 100));
		panelRight = new JButton();
		panelRight.setBackground(Color.cyan);
		panelRight.setPreferredSize(new Dimension(100, 100));
		
		setBackground(Color.cyan);
		setLayout(new FlowLayout());
		  
		// adds the controls to the form
		add(lblCoins);
		add(txtCoin);
		add(btnAddcoin);
		add(btnSpin);
		add(panelLeft);
		add(panelMiddle);
		add(panelRight);
		add(btnHold1);
		add(btnHold2);
		add(btnHold3);
		add(txtWinnings);
		add(btnBye);

		btnAddcoin.addActionListener(this);
		btnSpin.addActionListener(this);
		btnBye.addActionListener(this);
		//all the images and where they are and what they are called in the bin folder
		iconPic1 = new ImageIcon("bin/iconPic1.png");
		iconPic2 = new ImageIcon("bin/iconPic2.png");
		iconPic3 = new ImageIcon("bin/iconPic3.png");
		iconPic4 = new ImageIcon("bin/iconPic4.png");
		iconPic5 = new ImageIcon("bin/iconPic5.png");
		iconPic6 = new ImageIcon("bin/iconPic6.png");
		iconPic7 = new ImageIcon("bin/iconPic7.png");
		iconPic8 = new ImageIcon("bin/iconPic8.png");

		setTitle("The Electronic Bandit");
		setSize(350, 300);
		setVisible(true);
		}
	
	public void actionPerformed(ActionEvent event){
		//once the add coin button is selected it adds 100 coins from the current total and changes the colour of the text black
		if (event.getSource()== btnAddcoin){
			txtCoin.setForeground(Color.BLACK);
			num1 = num1 + 100;
			txtCoin.setText(num1 + " ");
		}
		//once the spin button is selected it takes 20 coins from the current total and changes the colour of the text red
		if (event.getSource()== btnSpin){
			txtCoin.setForeground(Color.red);
			num1 = num1 - 20;
			txtCoin.setText(num1 + " ");
		}
		//once the coins equal five hundred it turns off the add coins button
		if (num1 >= 500){
			btnAddcoin.setEnabled(false);
		}
		//once the coins equal zero it turns on the add coins button
		if (num1 <= 0){
			btnAddcoin.setEnabled(true);

		}
		//once the coins equal five hundred it turns the spin button on
		if (num1 >= 500){
			btnSpin.setEnabled(true);
		}
		//once the coins equal zero it turns the spin button off 
		if (num1 == 0){
			btnSpin.setEnabled(false);
		}
		//assigns each timer to a specific case system 
		if (event.getSource()== timer1){
			setIcon1();
		}
		//assigns each timer to a specific case system 
		if (event.getSource()== timer2){
			setIcon2();
		}
		//assigns each timer to a specific case system 
		if (event.getSource()== timer3){
			setIcon3();
		}
		if (event.getSource()== btnBye){
			JOptionPane.showMessageDialog(null,"You Have Won " + winnings + "coins, Do you want to cash in your winnings or add them to your current coins!");
			System.exit(0);
		}
		//starts all the timers and sets the counter to zero	
		if (event.getSource()== btnSpin){
			counter = 0;
			timer1.start();
			timer2.start();
			timer3.start();
			
		}
		}
		public void stopTimer(){
			//stops all three timers at once
			timer1.stop();
			timer2.stop();
			timer3.stop();
			//checks the images that appears and assigns winnings to be displayed in the right text box
			if (num1 == num2){
						winnings = winnings + 50;
						txtWinnings.setText("You Have Won " + winnings);
			}
			if (num1 == num3){
				  winnings = winnings + 50;
				  txtWinnings.setText("You Have Won " + winnings);
			}
			if (num2 == num3){
						winnings = winnings + 50;
						txtWinnings.setText("You Have Won " + winnings);
			}
			if (num1 == num2 && num2 == num3){
					  winnings = winnings + 100;
					  txtWinnings.setText("You Have Won The Jackpot  " + winnings);
			}
			}
		private void setIcon1(){	
			//spins the pictures randomly and also increases the counter
			num2 = random.nextInt(8);
			switch (num2){
			case 1:
				panelLeft.setIcon(iconPic1);
				Apple = Apple +1;
				counter =  counter + 1;
				break;
			case 2:
				panelLeft.setIcon(iconPic2);
				Rberry = Rberry + 1;
				counter =  counter + 1;
				break;
			case 3:
				panelLeft.setIcon(iconPic3);
				Lemon= Lemon +1;
				counter =  counter + 1;
				break;
			case 4:
				panelLeft.setIcon(iconPic4);
				Bberry = Bberry +1;
				counter =  counter + 1;
				break;
			case 5:
				panelLeft.setIcon(iconPic5);
				Bar = Bar +1;
				counter =  counter + 1;
				break;
			case 6:
				panelLeft.setIcon(iconPic6);
				Seven = Seven +1;
				counter =  counter + 1;
				break;
			case 7:
				panelLeft.setIcon(iconPic7);
				Melon = Melon +1;
				counter =  counter + 1;
				break;
			case 8:
				panelLeft.setIcon(iconPic8);
				Pineapple = Pineapple +1;
				counter =  counter + 1;
				break;
		}
		}
			
			 private void setIcon2(){
			//spins the pictures randomly and also increases the counter
			num3 = random.nextInt(8);
			switch (num3){
			case 1:
				panelMiddle.setIcon(iconPic1);
				Apple = Apple +1;
				counter =  counter + 1;
				break;
			case 2:
				panelMiddle.setIcon(iconPic2);
				Rberry = Rberry + 1;
				counter =  counter + 1;
				break;
			case 3:
				panelMiddle.setIcon(iconPic3);
				Lemon= Lemon +1;
				counter =  counter + 1;
				break;
			case 4:
				panelMiddle.setIcon(iconPic4);
				Bberry = Bberry +1;
				counter =  counter + 1;
				break;
			case 5:
				panelMiddle.setIcon(iconPic5);
				Bar = Bar +1;
				counter =  counter + 1;
				break;
			case 6:
				panelMiddle.setIcon(iconPic6);
				Seven = Seven +1;
				counter =  counter + 1;
				break;
			case 7:
				panelLeft.setIcon(iconPic7);
				Melon = Melon +1;
				counter =  counter + 1;
				break;
			case 8:
				panelLeft.setIcon(iconPic8);
				Pineapple = Pineapple +1;
				counter =  counter + 1;
				break;
		}
		}
		
			 private void setIcon3(){
			//spins the pictures randomly and also increases the counter
			num4 = random.nextInt(8);
			switch (num4){
			case 1:
				panelRight.setIcon(iconPic1);
				Apple = Apple +1;
				counter =  counter + 1;
				break;
			case 2:
				panelRight.setIcon(iconPic2);
				Rberry = Rberry + 1;
				counter =  counter + 1;
				break;
			case 3:
				panelRight.setIcon(iconPic3);
				Lemon= Lemon +1;
				counter =  counter + 1;
				break;
			case 4:
				panelRight.setIcon(iconPic4);
				Bberry = Bberry +1;
				counter =  counter + 1;
				break;
			case 5:
				panelRight.setIcon(iconPic5);
				Bar = Bar +1;
				counter =  counter + 1;
				break;
			case 6:
				panelRight.setIcon(iconPic6);
				Seven = Seven +1;
				counter =  counter + 1;
				break;
			case 7:
				panelLeft.setIcon(iconPic7);
				Melon = Melon +1;
				counter =  counter + 1;
				break;
			case 8:
				panelLeft.setIcon(iconPic8);
				Pineapple = Pineapple +1;
				counter =  counter + 1;
				break;
		}
		//stops all timers once the counter reaches 20
	   	if (counter >20)
			stopTimer();
	}
	}


Was This Post Helpful? 0
  • +
  • -

#8 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8329
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: 2 problems with my slot machine program

Posted 11 December 2008 - 08:13 PM

You do not have actionListener on your Hold button

And you should learn how to use arrays
Here is your code revisited with arrays.... I do not garanty that it works but worth a try

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.Timer;

public class TheElectronicBandit extends JFrame implements ActionListener{
	//list all the variables in the project
	private JButton btnAddcoin, btnSpin, btnBye;
	private JButton[] panel = new JButton[3];
	private JButton[] btnHold = new JButton[3];
	private int counter = 0;
	private JLabel lblCoins;
	private JTextField txtCoin, txtWinnings;
	private int[] num = new int[3];
	private int cash = 0;
	private int winnings =0;
	private Random random;
	private Icon[] iconPic = new Icon[8];
	private Timer[] timer = new Timer[3];
	private int[] fruit = new int[8];

	public static void main(String[] args)
	{
		new TheElectronicBandit();
	}

	public TheElectronicBandit()
	//definitions of all the variables
	{
		JOptionPane.showMessageDialog(null,"Hello and welcome to the One Armed Bandit!!");
	
		random = new Random();
	
		setLayout(new FlowLayout());
		lblCoins = new JLabel("Coins Inserted");
		txtCoin = new JTextField(3);
		txtCoin.setFont(new Font("TimesRoman", Font.BOLD, 16));
		txtCoin.setBackground(Color.cyan);
		txtCoin.setForeground(Color.red);
		txtCoin.setText(num[0] + " ");
		txtWinnings = new JTextField(25);
		txtWinnings.setFont(new Font("TimesRoman", Font.BOLD, 16));
		btnAddcoin = new JButton("Insert Coins");
		btnSpin = new JButton("Play");
		btnBye = new JButton("Bye!!");
		add(lblCoins);
		add(txtCoin);
		add(btnAddcoin);
		add(btnSpin);

		for(int i = 0; i < 3; i++) {
			btnHold[i] = new JButton("Hold");
			btnHold[i].addActionListener(this);
			panel[i] = new JButton();
			panel[i].setBackground(Color.cyan);
			panel[i].setPreferredSize(new Dimension(100, 100));
			add(panel[i]);
		}
		

		setLayout(new FlowLayout());

		// adds the controls to the form
		for(int i = 0; i < 3; i++)
			add(btnHold[i]);
		add(txtWinnings);
		add(btnBye);

		btnAddcoin.addActionListener(this);
		btnSpin.addActionListener(this);
		btnBye.addActionListener(this);
		//all the images and where they are and what they are called in the bin folder
		for(int i = 0; i < iconPic.length; i++) {
			String str = "bin/iconPic" + (i+1) + ".png";
			iconPic[i] = new ImageIcon(str);
			fruit[i] = 0;
		}


		for(int i = 0; i < timer.length; i++) {
			timer[i] = new Timer(200, this);
			timer[i].addActionListener(this);
		}

		setTitle("The Electronic Bandit");
		setSize(350, 300);
		setVisible(true);
	}

	public void actionPerformed(ActionEvent event){
		for(int i = 0; i < 3; i++) {
			if(event.getSource() == btnHold[i]) {
				timer[i].stop();
				setIcon(i);
				return;
			}
		}
		//once the add coin button is selected it adds 100 coins from the current total and changes the colour of the text black
		if (event.getSource()== btnAddcoin){
			txtCoin.setForeground(Color.BLACK);
			cash = cash + 100;
			txtCoin.setText(cash + " ");
			return;
		}
		//once the spin button is selected it takes 20 coins from the current total and changes the colour of the text red
		if (event.getSource()== btnSpin){
			txtCoin.setForeground(Color.red);
			cash = cash - 20;
			txtCoin.setText(cash + " ");
			for(int i = 0; i < 3; i++)
				timer[i].start();

			return;
		}
		//once the coins equal five hundred it turns off the add coins button
		if (cash >= 500){
			btnAddcoin.setEnabled(false);
		}
		//once the coins equal zero it turns on the add coins button
		if (cash <= 0){
			btnAddcoin.setEnabled(true);

		}
		//once the coins equal five hundred it turns the spin button on
		if (cash >= 500){
			btnSpin.setEnabled(true);
		}
		//once the coins equal zero it turns the spin button off 
		if (cash == 0){
			btnSpin.setEnabled(false);
		}
		//assigns each timer to a specific case system
		for(int i = 0; i < 3; i++) {
		  if(event.getSource() == timer[i]) {
			  setIcon(i);
		  }
		}
		if (event.getSource()== btnBye){
			JOptionPane.showMessageDialog(null,"You Have Won " + winnings + "coins, Do you want to cash in your winnings or add them to your current coins!");
			System.exit(0);
		}
		//starts all the timers and sets the counter to zero	
		if (event.getSource()== btnSpin){
			counter = 0;
			for(int i = 0; i < 3; i++)
				timer[i].start();

		}
	}
	public void stopTimer(){
		//stops all three timers at once
		for(int i = 0; i < 3; i++)
			timer[i].stop();

		int winnings = 0;
		//checks the images that appears and assigns winnings to be displayed in the right text box
		if (num[0] == num[1]){
			winnings = winnings + 50;
			txtWinnings.setText("You Have Won " + winnings);
		}
		if (num[1] == num[2]){
			winnings = winnings + 50;
			txtWinnings.setText("You Have Won " + winnings);
		}
		if (num[0] == num[1] && num[1] == num[2]){
			winnings = winnings + 100;
			txtWinnings.setText("You Have Won The Jackpot  " + winnings);
		}
		cash += winnings;
	}
	
	private void setIcon(int i) {
		num[i] = random.nextInt(8);
		panel[i].setIcon(iconPic[num[i]]);
		fruit[i]++;
		counter++;
		if(i == 2) {
			stopTimer();
		}
	}

}


This post has been edited by pbl: 11 December 2008 - 10:30 PM

Was This Post Helpful? 0
  • +
  • -

#9 dkheartsag  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 18-February 09

Re: 2 problems with my slot machine program

Posted 19 March 2009 - 05:37 AM

View Postpbl, on 11 Dec, 2008 - 07:13 PM, said:

You do not have actionListener on your Hold button

And you should learn how to use arrays
Here is your code revisited with arrays.... I do not garanty that it works but worth a try

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.Timer;

public class TheElectronicBandit extends JFrame implements ActionListener{
	//list all the variables in the project
	private JButton btnAddcoin, btnSpin, btnBye;
	private JButton[] panel = new JButton[3];
	private JButton[] btnHold = new JButton[3];
	private int counter = 0;
	private JLabel lblCoins;
	private JTextField txtCoin, txtWinnings;
	private int[] num = new int[3];
	private int cash = 0;
	private int winnings =0;
	private Random random;
	private Icon[] iconPic = new Icon[8];
	private Timer[] timer = new Timer[3];
	private int[] fruit = new int[8];

	public static void main(String[] args)
	{
		new TheElectronicBandit();
	}

	public TheElectronicBandit()
	//definitions of all the variables
	{
		JOptionPane.showMessageDialog(null,"Hello and welcome to the One Armed Bandit!!");
	
		random = new Random();
	
		setLayout(new FlowLayout());
		lblCoins = new JLabel("Coins Inserted");
		txtCoin = new JTextField(3);
		txtCoin.setFont(new Font("TimesRoman", Font.BOLD, 16));
		txtCoin.setBackground(Color.cyan);
		txtCoin.setForeground(Color.red);
		txtCoin.setText(num[0] + " ");
		txtWinnings = new JTextField(25);
		txtWinnings.setFont(new Font("TimesRoman", Font.BOLD, 16));
		btnAddcoin = new JButton("Insert Coins");
		btnSpin = new JButton("Play");
		btnBye = new JButton("Bye!!");
		add(lblCoins);
		add(txtCoin);
		add(btnAddcoin);
		add(btnSpin);

		for(int i = 0; i < 3; i++) {
			btnHold[i] = new JButton("Hold");
			btnHold[i].addActionListener(this);
			panel[i] = new JButton();
			panel[i].setBackground(Color.cyan);
			panel[i].setPreferredSize(new Dimension(100, 100));
			add(panel[i]);
		}
		

		setLayout(new FlowLayout());

		// adds the controls to the form
		for(int i = 0; i < 3; i++)
			add(btnHold[i]);
		add(txtWinnings);
		add(btnBye);

		btnAddcoin.addActionListener(this);
		btnSpin.addActionListener(this);
		btnBye.addActionListener(this);
		//all the images and where they are and what they are called in the bin folder
		for(int i = 0; i < iconPic.length; i++) {
			String str = "bin/iconPic" + (i+1) + ".png";
			iconPic[i] = new ImageIcon(str);
			fruit[i] = 0;
		}


		for(int i = 0; i < timer.length; i++) {
			timer[i] = new Timer(200, this);
			timer[i].addActionListener(this);
		}

		setTitle("The Electronic Bandit");
		setSize(350, 300);
		setVisible(true);
	}

	public void actionPerformed(ActionEvent event){
		for(int i = 0; i < 3; i++) {
			if(event.getSource() == btnHold[i]) {
				timer[i].stop();
				setIcon(i);
				return;
			}
		}
		//once the add coin button is selected it adds 100 coins from the current total and changes the colour of the text black
		if (event.getSource()== btnAddcoin){
			txtCoin.setForeground(Color.BLACK);
			cash = cash + 100;
			txtCoin.setText(cash + " ");
			return;
		}
		//once the spin button is selected it takes 20 coins from the current total and changes the colour of the text red
		if (event.getSource()== btnSpin){
			txtCoin.setForeground(Color.red);
			cash = cash - 20;
			txtCoin.setText(cash + " ");
			for(int i = 0; i < 3; i++)
				timer[i].start();

			return;
		}
		//once the coins equal five hundred it turns off the add coins button
		if (cash >= 500){
			btnAddcoin.setEnabled(false);
		}
		//once the coins equal zero it turns on the add coins button
		if (cash <= 0){
			btnAddcoin.setEnabled(true);

		}
		//once the coins equal five hundred it turns the spin button on
		if (cash >= 500){
			btnSpin.setEnabled(true);
		}
		//once the coins equal zero it turns the spin button off 
		if (cash == 0){
			btnSpin.setEnabled(false);
		}
		//assigns each timer to a specific case system
		for(int i = 0; i < 3; i++) {
		  if(event.getSource() == timer[i]) {
			  setIcon(i);
		  }
		}
		if (event.getSource()== btnBye){
			JOptionPane.showMessageDialog(null,"You Have Won " + winnings + "coins, Do you want to cash in your winnings or add them to your current coins!");
			System.exit(0);
		}
		//starts all the timers and sets the counter to zero	
		if (event.getSource()== btnSpin){
			counter = 0;
			for(int i = 0; i < 3; i++)
				timer[i].start();

		}
	}
	public void stopTimer(){
		//stops all three timers at once
		for(int i = 0; i < 3; i++)
			timer[i].stop();

		int winnings = 0;
		//checks the images that appears and assigns winnings to be displayed in the right text box
		if (num[0] == num[1]){
			winnings = winnings + 50;
			txtWinnings.setText("You Have Won " + winnings);
		}
		if (num[1] == num[2]){
			winnings = winnings + 50;
			txtWinnings.setText("You Have Won " + winnings);
		}
		if (num[0] == num[1] && num[1] == num[2]){
			winnings = winnings + 100;
			txtWinnings.setText("You Have Won The Jackpot  " + winnings);
		}
		cash += winnings;
	}
	
	private void setIcon(int i) {
		num[i] = random.nextInt(8);
		panel[i].setIcon(iconPic[num[i]]);
		fruit[i]++;
		counter++;
		if(i == 2) {
			stopTimer();
		}
	}

}


Hii ,
this slot game is not considering the weight of images at the time of scoring , i want to know if different image have different weight then how can code or what edition should be done ???
weight is like following

1st image 2nd image 3rd image 4th image 5th image
xxx- 2 point 5 point 5 point 10 point 15 point

xx - 1 point 2 point 8

x - 1point 1 point 1 point
how it can be impediment code ???
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1