Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ch.cleverbytes.job;
- import java.util.ArrayList;
- import javax.swing.JOptionPane;
- public class Gui
- {
- private Object[] buttons = new Object[] { "red", "green", "orange", "blue", "purple", "yellow" };
- /**
- *
- * @param game Aktuelles Spiel an dem weiter geraten werden soll.
- * @return Der geratene Farbcode des Spielers.
- */
- public ArrayList<String> getGuess(Game game)
- {
- int guess = 0;
- ArrayList<String> reList = new ArrayList<>();
- for (int i = 1; i <= Game.NUMBER_OF_PINS; i++)
- {
- try
- {
- guess = auswahl("Color Guess " + i + " of " + Game.NUMBER_OF_PINS, "Guess", buttons);
- reList.add((String) buttons[guess]);
- } catch (Exception ex)
- {
- ausgabeText(ex.getMessage(), "Exception", 1);
- i--;
- }
- }
- return reList;
- }
- /**
- * Zeigt dem Spieler die Statistiken des Spiels und dass er das Spiel erfolgreich beendet hat
- * @param game Aktuelles Spiel welches erfolgreich beendet wurde.
- * @return Ob der Spieler noch ein Spiel spielen mοΏ½chte.
- */
- public boolean showFinish(Game game)
- {
- Object[] btns = new Object[] {"yes", "no"};
- int weiter = auswahl("You Won!" + System.getProperty("line.separator") + "Do you like to play again?", "Congratulations!", btns);
- if(weiter == 0)
- return true;
- return false;
- }
- private int auswahl(String hinweis, String title, Object[] buttons)
- {
- int selection = JOptionPane.showOptionDialog(null, hinweis, title, JOptionPane.YES_NO_OPTION,
- JOptionPane.PLAIN_MESSAGE, null, buttons, null);
- return selection;
- }
- private void ausgabeText(String hinweis, String title, int type)
- {
- JOptionPane.showMessageDialog(null, hinweis, title, type);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement