Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package slotmachine;
- import java.net.URL;
- import java.util.Random;
- import java.util.ResourceBundle;
- import javafx.event.ActionEvent;
- import javafx.fxml.FXML;
- import javafx.fxml.Initializable;
- import javafx.scene.control.*;
- import javafx.scene.image.Image;
- import javafx.scene.image.ImageView;
- /**
- *
- * @author Nick
- */
- public class FXMLDocumentController implements Initializable {
- @FXML
- private Label spinWin;
- @FXML
- private Label totalWin;
- @FXML
- private TextField textBox;
- @FXML
- private ImageView left;
- @FXML
- private ImageView right;
- @FXML
- private ImageView middle;
- private Random rand = new Random();
- private String[] diceImages = {"file:/C:/Users/Nicolas/Documents/_JAVA/Source%20Code/chapter%2014/Images/Fruit%20Symbols/Apple.png",
- "file:/C:/Users/Nicolas/Documents/_JAVA/Source%20Code/chapter%2014/Images/Fruit%20Symbols/Banana.png",
- "file:/C:/Users/Nicolas/Documents/_JAVA/Source%20Code/chapter%2014/Images/Fruit%20Symbols/Cherries.png",
- "file:/C:/Users/Nicolas/Documents/_JAVA/Source%20Code/chapter%2014/Images/Fruit%20Symbols/Grapes.png",
- "file:/C:/Users/Nicolas/Documents/_JAVA/Source%20Code/chapter%2014/Images/Fruit%20Symbols/Lemon.png",
- "file:/C:/Users/Nicolas/Documents/_JAVA/Source%20Code/chapter%2014/Images/Fruit%20Symbols/Lime.png",
- "file:/C:/Users/Nicolas/Documents/_JAVA/Source%20Code/chapter%2014/Images/Fruit%20Symbols/Orange.png",
- "file:/C:/Users/Nicolas/Documents/_JAVA/Source%20Code/chapter%2014/Images/Fruit%20Symbols/Pear.png",
- "file:/C:/Users/Nicolas/Documents/_JAVA/Source%20Code/chapter%2014/Images/Fruit%20Symbols/Strawberry.png",
- "file:/C:/Users/Nicolas/Documents/_JAVA/Source%20Code/chapter%2014/Images/Fruit%20Symbols/Watermelon.png"};
- private int[] game = new int[3];
- private int total = 0;
- @FXML
- private void handleButtonAction(ActionEvent event) {
- spin();
- payout();
- }
- @FXML
- private void instaWin(ActionEvent event) {
- left.setImage(new Image(diceImages[0]));
- middle.setImage(new Image(diceImages[0]));
- right.setImage(new Image(diceImages[0]));
- payout();
- }
- public void spin() {
- game[0] = rand.nextInt(10);
- game[1] = rand.nextInt(10);
- game[2] = rand.nextInt(10);
- left.setImage(new Image(diceImages[game[0]]));
- middle.setImage(new Image(diceImages[game[1]]));
- right.setImage(new Image(diceImages[game[2]]));
- }
- public void payout() {
- int payout = 0;
- if (game[0] == game[1] && game[1] == game[2])
- payout = Integer.parseInt(textBox.getText()) * 3;
- else if (game[0] == game[1] || game[0] == game[2] || game[1] == game[2])
- payout = Integer.parseInt(textBox.getText()) * 2;
- total += payout;
- spinWin.setText(Integer.toString(payout));
- totalWin.setText(Integer.toString(total));
- }
- @Override
- public void initialize(URL url, ResourceBundle rb) {
- // TODO
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement