Skip to content

Commit

Permalink
GUI updates
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoernuhlig committed Jan 3, 2017
1 parent 2027ac4 commit a90c17a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
Expand Up @@ -33,6 +33,7 @@ public void newGame(Gameview theView, Game theGame) {
theView.addMenuListener(new MenuListener());
theView.addHintListener(new HintListener());
theView.addSizeListener(new SizeListener());
theView.addHoboListener(new HoboListener());

gameview.setPlayerTyp(theGame.getPlayerBlack(), theGame.getPlayerWhite());
updateGameBoard();
Expand Down Expand Up @@ -90,11 +91,12 @@ public void actionPerformed(ActionEvent e) {
}
}
}

class MenuListener implements ActionListener {

public void actionPerformed(ActionEvent e) {

//TODO BJOERN write a line that starts a new game. the restart() method does throw a nullPointer

try {
// todo refactor? look not quite efficient
/*
Expand Down Expand Up @@ -230,6 +232,8 @@ public void actionPerformed(ActionEvent e) {
}

}

// TODO if no Move Avail hint throws java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
class HintListener implements ActionListener {

public void actionPerformed(ActionEvent e) {
Expand All @@ -248,6 +252,7 @@ public void actionPerformed(ActionEvent e) {
}
}
}

class SizeListener implements ComponentListener {

public void componentResized(ComponentEvent e) {
Expand All @@ -264,6 +269,19 @@ public void componentHidden(ComponentEvent e) {
}
}

class HoboListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
try {
if (e.getSource() == gameview.getGoHobo())
theGame.activateHobeMode();
theGame.getLastHobeModeType();
updateGameBoard();
} catch (NumberFormatException ex) {
gameview.displayErrorMessage("Ups! Something is wrong?!");
}
}
}

/**
* Update the Gameview with the current Board Infos
*
Expand All @@ -278,7 +296,7 @@ public void updateGameBoard() {
gameview.updateBoardPlayerPoints(Color.BLACK, theGame.countPlayerPoints(Color.BLACK));
gameview.updateBoardPlayerPoints(Color.WHITE, theGame.countPlayerPoints(Color.WHITE));

// show which player is
// show which players turn it is
gameview.updateCurrentPlayer(theGame.getCurrentPlayer().getColor().toString());
}

Expand Down
13 changes: 12 additions & 1 deletion src/main/java/de/htw_berlin/HoboOthello/GUI/Gameview.java
Expand Up @@ -32,6 +32,7 @@ public class Gameview extends JFrame {

private JButton[][] fieldView;
private JButton showHint;
private JButton goHobo;

private JMenuItem[] toogleMenu;
private JMenu gameMenu;
Expand Down Expand Up @@ -123,8 +124,10 @@ public Gameview(int boardSize) {
*/
actionPanel = new JPanel();
//actionPanel.setBorder(BorderFactory.createEtchedBorder()); // a frame around the panel
showHint = new JButton("hint");
showHint = new JButton(" Hint? ");
goHobo = new JButton ("Go Hobo");
actionPanel.add(showHint);
actionPanel.add(goHobo);

/*
* the score panel to display the actual score
Expand Down Expand Up @@ -227,6 +230,10 @@ public void addSizeListener(ComponentListener listenerForReSize) {
this.getContentPane().addComponentListener(listenerForReSize);
}

public void addHoboListener(ActionListener listenerForGoHobo) {
this.goHobo.addActionListener(listenerForGoHobo);
}


/**
* Getter for the board to check which Button was clicked
Expand All @@ -249,6 +256,10 @@ public JButton getShowHint() {
return showHint;
}

public JButton getGoHobo() {
return goHobo;
}


/**
* error message to display errors
Expand Down

0 comments on commit a90c17a

Please sign in to comment.