Advertisement
Aspirior

Klasse Gui

Mar 5th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.67 KB | None | 0 0
  1. package ch.cleverbytes.job;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import javax.swing.JOptionPane;
  6.  
  7. public class Gui
  8. {
  9.     private Object[] buttons = new Object[] { "red", "green", "orange", "blue", "purple", "yellow" };
  10.  
  11.     /**
  12.      *
  13.      * @param game Aktuelles Spiel an dem weiter geraten werden soll.
  14.      * @return Der geratene Farbcode des Spielers.
  15.      */
  16.     public ArrayList<String> getGuess(Game game)
  17.     {
  18.         int guess = 0;
  19.         ArrayList<String> reList = new ArrayList<>();
  20.         for (int i = 1; i <= Game.NUMBER_OF_PINS; i++)
  21.         {
  22.             try
  23.             {
  24.                 guess = auswahl("Color Guess " + i + " of " + Game.NUMBER_OF_PINS, "Guess", buttons);
  25.                 reList.add((String) buttons[guess]);
  26.             } catch (Exception ex)
  27.             {
  28.                 ausgabeText(ex.getMessage(), "Exception", 1);
  29.                 i--;
  30.             }
  31.         }
  32.         return reList;
  33.     }
  34.  
  35.     /**
  36.      * Zeigt dem Spieler die Statistiken des Spiels und dass er das Spiel erfolgreich beendet hat
  37.      * @param game Aktuelles Spiel welches erfolgreich beendet wurde.
  38.      * @return Ob der Spieler noch ein Spiel spielen mοΏ½chte.
  39.      */
  40.     public boolean showFinish(Game game)
  41.     {
  42.         Object[]  btns = new Object[] {"yes", "no"};
  43.         int weiter = auswahl("You Won!" + System.getProperty("line.separator") + "Do you like to play again?", "Congratulations!", btns);
  44.         if(weiter == 0)
  45.             return true;
  46.         return false;
  47.     }
  48.  
  49.     private int auswahl(String hinweis, String title, Object[] buttons)
  50.     {
  51.         int selection = JOptionPane.showOptionDialog(null, hinweis, title, JOptionPane.YES_NO_OPTION,
  52.                 JOptionPane.PLAIN_MESSAGE, null, buttons, null);
  53.         return selection;
  54.     }
  55.  
  56.     private void ausgabeText(String hinweis, String title, int type)
  57.     {
  58.         JOptionPane.showMessageDialog(null, hinweis, title, type);
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement