SHARE
TWEET

Untitled

a guest Jun 17th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package rst;
  2.  
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5. import java.util.Scanner;
  6. import javax.swing.Action;
  7. import javax.swing.ImageIcon;
  8. import javax.swing.JButton;
  9. import javax.swing.JFrame;
  10. import javax.swing.JLabel;
  11.  
  12. import javax.swing.JOptionPane;
  13. import javax.swing.JPanel;
  14. import static rst.Rst.show;
  15.  
  16. public class Rst {
  17.  
  18.     public static void main(String[] args) {
  19.         welcomingmethod();
  20.         Scanner input = new Scanner(System.in);
  21.         boolean jim = false;
  22.         String puzzle[] = {"p", "r", "i", "n", "c", "e"};
  23.         String display[] = {"_", "_", "_", "_", "_", "_"};
  24.         String[] players = createPlayers(input);
  25.         int[] scores = new int[players.length];
  26.         int currentPlayer = 0;
  27.  
  28.         while (!checkWin(puzzle, display)) {
  29.             if (currentPlayer >= players.length) {
  30.                 currentPlayer = 0;
  31.             }
  32. //            System.out.println("test");
  33.  
  34.             if (guess(puzzle, display, players[currentPlayer])) {
  35.                 show(display);
  36.                 scores[currentPlayer] += 10;
  37.                 System.out.println("Correct!");
  38.             } else {
  39.                 System.out.println("Incorrect!");
  40.                 currentPlayer++;
  41.  
  42.             }
  43.         }
  44.  
  45.         printScores(players, scores);
  46.  
  47.     }
  48.  
  49.     public static void printScores(String[] players, int[] scores) {
  50.         for (int i = 0; i < players.length; i++) {
  51.             System.out.println(players[i] + ": " + scores[i]);
  52.         }
  53.     }
  54.  
  55.     public static void show(String[] display) {
  56.         for (int i = 0; i < display.length; i++) {
  57.             System.out.print(display[i] + " ");
  58.         }
  59.         System.out.println("");
  60.     }
  61.  
  62.     public static boolean guess(String[] puzzle, String[] display, String player) {
  63.         String guess = JOptionPane.showInputDialog(player + ": Guess a letter in the puzzle");
  64.  
  65.         boolean correct = false;
  66.         for (int i = 0; i < puzzle.length; i++) {
  67.             if (puzzle[i].equals(guess)) {
  68.                 display[i] = guess;
  69.                 correct = true;
  70.             }
  71.         }
  72.         return correct;
  73.  
  74.     }
  75.  
  76.     public static boolean checkWin(String[] puzzle, String[] display) {
  77.         for (int i = 0; i < puzzle.length; i++) {
  78.             if (!puzzle[i].equals(display[i])) {
  79.                 return false;
  80.             }
  81.         }
  82.         return true;
  83.     }
  84.  
  85.     public static String[] createPlayers(Scanner input) {
  86.         System.out.print("How many people are playing?: ");
  87.         String[] players = new String[input.nextInt()];
  88.         input.nextLine();// advance scanner to next line
  89.  
  90.         for (int i = 0; i < players.length; i++) {
  91.             System.out.print("Enter player " + (i + 1) + " name: ");
  92.             players[i] = input.nextLine();
  93.         }
  94.  
  95.         return players;
  96.     }
  97.  
  98.     private static void welcomingmethod() {
  99.         JFrame frame = new JFrame("Wheel of fortune");
  100.         frame.setVisible(true);
  101.         frame.setSize(500, 600);
  102.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  103.  
  104.         JLabel label = new JLabel("Welcome ");
  105.         JPanel panel = new JPanel();
  106.         frame.add(panel);
  107.         panel.add(label);
  108.  
  109.         JButton button = new JButton("Press");
  110.         panel.add(button);
  111.         button.addActionListener(new Action());
  112.     }
  113.     static class Action implements ActionListener {
  114.  
  115.         public void actionPerformed(ActionEvent e) {
  116.             JFrame frame2 = new JFrame("You win");
  117.             frame2.setVisible(true);
  118.             frame2.setSize(1000, 1000);
  119.             JLabel winimage = new JLabel();
  120.             winimage.setIcon(new ImageIcon("images/popart_car_red.png"));
  121.             winimage.setBounds((1300), (240), winimage.getPreferredSize().width, winimage.getPreferredSize().height);
  122.  
  123.             frame2.add(winimage);
  124.  
  125.         }
  126.     }
  127. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top