Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void actionPerformed(ActionEvent event)
- {
- boolean playerWin = model.hasWon(Model.PLAYER) == true;
- boolean compWin = model.hasWon(Model.COMPUTER) == true;
- //check if game is over
- if(this.isFinished() != true)
- {
- try {
- getView().setSlot(this.getModel().drop(Integer.parseInt(event.getActionCommand()), Model.PLAYER), Integer.parseInt(event.getActionCommand()), Model.PLAYER);
- } catch (Exception e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- if(this.isFinished() == true)
- {
- this.setFinished(finished);
- }
- if (model.isFilled(Integer.parseInt(event.getActionCommand())) == true)
- { // if player made correct move (aka it wasn't in a full column) then -> AI turn || if not -> player retry
- try {
- getView().setSlot(this.getModel().drop(Integer.parseInt(event.getActionCommand()), Model.PLAYER), Integer.parseInt(event.getActionCommand()), Model.PLAYER);
- } catch (Exception e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- if(playerWin)
- {
- System.out.print("You have won");
- this.setFinished(finished);
- }
- else{ //AI turn code
- model.move();
- }
- if(compWin)
- {
- System.out.print("You have lost");
- this.setFinished(finished);
- }
- if(model.isFilled() && playerWin != true && compWin != true)
- {
- System.out.print("It is a tie");
- this.setFinished(finished);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement