Beispiel #1
0
	public void PlayerSelectedTarget(int x,int y)
	{
		m_TargetLoc[m_CurrentPlayer.getNumOfSelectedTargets()-1] = new Location(x,y);
		m_GameWindow.updateActionConsole(m_CurrentPlayer.getName() + ":  Selected Target...\n\t" +
										 m_CurrentPlayer.getName() + ": Has " + (5 - m_CurrentPlayer.getNumOfSelectedTargets()) + " Left");
		System.out.println(m_CurrentPlayer.getNumOfSelectedTargets() + " num of targets");
	}
  public void drawVictory(Graphics g) {
    g.setColor(new Color(0, 0, 0, 200));
    g.fillRect(195, 220, 410, 110);
    g.setColor(new Color(255, 255, 255, 200));
    g.fillRect(200, 225, 400, 100);
    g.setColor(new Color(0, 0, 0, 200));
    g.setFont(new Font("Bell MT", Font.BOLD, 20));
    FontMetrics metrics = g.getFontMetrics(new Font("Bell MT", Font.BOLD, 20));
    int hgt = metrics.getHeight();

    String initialMessage;
    String followupMessage;

    if (nextWindow) {
      initialMessage = "You have gotten stronger.";
      followupMessage = player.getName() + " is now level " + player.getLevel() + "!";
    } else {
      initialMessage = "You survived!";
      followupMessage = "You and your allies gain " + totalExperience + " experience!";
    }

    // Hgt = 26
    int adv = metrics.stringWidth(initialMessage);
    g.drawString(initialMessage, getWidth() / 2 - adv / 2, 234 + hgt);
    adv = metrics.stringWidth(followupMessage);
    g.drawString(followupMessage, getWidth() / 2 - adv / 2, 269 + hgt);
  }
Beispiel #3
0
  private void final_scores(Match m) {
    int numPlayers = 0;
    int playerTotal = 0;
    int gameNum = 0, maxGameNum = 0;
    Player p;

    // Create window
    final JFrame f = new JFrame();
    JPanel titles = new JPanel();
    titles.setLayout(new BorderLayout());
    JLabel maintitle = new JLabel("Yahtzee World!");
    maintitle.setFont(new Font("SansSerif", Font.ITALIC, 24));
    JLabel instr = new JLabel("Final Scores (total of game scores).");
    instr.setFont(new Font("SansSerif", Font.PLAIN, 16));
    titles.add(maintitle, "North");
    titles.add(instr, "South");

    JPanel names = new JPanel();
    JLabel l[] = new JLabel[Match.MAXPLAYERS];
    final JTextField t[] = new JTextField[Match.MAXPLAYERS];

    numPlayers = m.getNumPlayers();
    names.setLayout(new GridLayout(numPlayers, 2));
    for (int playerNum = 0; playerNum < numPlayers; playerNum++) {
      p = m.getPlayer(playerNum);
      playerTotal = 0;
      l[playerNum] = new JLabel(p.getName());
      t[playerNum] = new JTextField(20);
      names.add(l[playerNum]);
      names.add(t[playerNum]);
      maxGameNum = (m.getGameNum() >= Match.MAXGAMES) ? (Match.MAXGAMES - 1) : m.getGameNum();
      for (gameNum = 0; gameNum <= maxGameNum; gameNum++) {
        playerTotal += p.getScoreCell(gameNum, CellCodes.GRANDTOTAL);
      }
      t[playerNum].setText(String.valueOf(playerTotal));
    }

    JButton quit = new JButton("Quit");
    quit.addActionListener(
        new ActionListener() {
          // This method is called when the user clicks the JButton
          public void actionPerformed(ActionEvent e) {
            System.exit(0);
          }
        });
    f.add(titles, "North");
    f.add(names, "Center");
    f.add(quit, "South");
    f.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    f.pack();
    f.setVisible(true);
    f.setResizable(false);
  }
Beispiel #4
0
  public void saveFile() {
    try {
      cardFormatter = new Formatter(currentFile);
    } catch (Exception e) {
      System.out.print("That File doesn't exist");
    }
    cardFormatter.format("%s%n", currentPlayer.getName());
    cardFormatter.format("%d%n", currentPlayer.getTotalCardsOwned());
    cardFormatter.format("%d%n", currentPlayer.getNumberOfCardsInDeck());
    cardFormatter.format("%d%n", currentPlayer.getWins());
    cardFormatter.format("%d%n", currentPlayer.getLosses());
    cardFormatter.format("%d%n", currentPlayer.getMoney());

    Card[] deck = currentPlayer.getDeck();

    for (int count = 0; count < deck.length; count++) {
      cardFormatter.format("%d%n", deck[count].getCardIndex());
      cardFormatter.format("%b%n", deck[count].getInDeck());
    }
    cardFormatter.close();
  }
Beispiel #5
0
 // Observers////////////////////////////////////////////////////////////////////////////
 public String getCustomNames(int number) {
   String[] names =
       new String[] {player1.getName(), player2.getName(), player3.getName(), player4.getName()};
   return names[number];
 }
Beispiel #6
0
  public void createLayout() {
    top = new JPanel();
    wModel.panel.add(top, BorderLayout.NORTH);
    top.setLayout(new BorderLayout(0, 0));

    bottom = new JPanel();
    wModel.panel.add(bottom, BorderLayout.SOUTH);
    bottom.setLayout(new BorderLayout(0, 0));

    center = new JPanel();
    wModel.panel.add(center, BorderLayout.CENTER);
    center.setLayout(new BorderLayout(0, 0));

    // Spielfeld
    gameField = new JPanel();
    gameField.setPreferredSize(new Dimension(550, 800));
    wModel.panel.add(gameField, BorderLayout.WEST);
    gameField.setLayout(new GridLayout(4, 4, 5, 5));

    /**
     * *********************************************************** Sidebar
     * ************************************************************
     */
    dates = new JPanel();
    dates.setLayout(new BorderLayout());
    JLabel background = new JLabel(new ImageIcon("../gfx/datesBack.png"));
    dates.add(background);

    GridBagLayoutModel gblModel = new GridBagLayoutModel();
    GridBagLayout gbl = new GridBagLayout();
    background.setLayout(gbl);

    l1 = new JLabel(new ImageIcon("../gfx/spieler1.png"));
    points1 = new JLabel(new ImageIcon("../gfx/punkte.png"));
    points1Num = new JLabel("0");
    l2 = new JLabel(new ImageIcon("../gfx/spieler2.png"));
    points2 = new JLabel(new ImageIcon("../gfx/punkte.png"));
    points2Num = new JLabel("0");

    JLabel namePlayer1 = new JLabel(player1.getName());
    JLabel namePlayer2 = new JLabel(player2.getName());

    JButton end = new JButton("Beenden");

    gblModel.addComponent(background, gbl, l1, 0, 2, 1, 1, 1.0, 0.5);
    gblModel.addComponent(background, gbl, namePlayer1, 1, 2, 1, 1, 1.0, 0.5);
    gblModel.addComponent(background, gbl, points1, 0, 3, 1, 1, 1.0, 0.2);
    gblModel.addComponent(background, gbl, points1Num, 1, 3, 1, 1, 1.0, 0.2);
    gblModel.addComponent(background, gbl, l2, 0, 4, 1, 1, 1.0, 1.0);
    gblModel.addComponent(background, gbl, namePlayer2, 1, 4, 1, 1, 1.0, 1.0);
    gblModel.addComponent(background, gbl, points2, 0, 5, 1, 1, 1.0, 0.2);
    gblModel.addComponent(background, gbl, points2Num, 1, 5, 1, 1, 1.0, 0.2);
    gblModel.addComponent(background, gbl, end, 1, 6, 1, 1, 0.0, 0.2);

    wModel.panel.add(dates, BorderLayout.EAST);

    end.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            System.exit(0);
          }
        });
  }