Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 KB | None | 0 0
  1.     public void actionPerformed(ActionEvent event)
  2.     {
  3.         boolean playerWin = model.hasWon(Model.PLAYER) == true;
  4.         boolean compWin = model.hasWon(Model.COMPUTER) == true;
  5.         //check if game is over
  6.        
  7.         if(this.isFinished() != true)
  8.         {
  9.             try {
  10.                 getView().setSlot(this.getModel().drop(Integer.parseInt(event.getActionCommand()), Model.PLAYER), Integer.parseInt(event.getActionCommand()), Model.PLAYER);
  11.             } catch (Exception e1) {
  12.                 // TODO Auto-generated catch block
  13.                 e1.printStackTrace();
  14.             }
  15.             if(this.isFinished() == true)
  16.             {
  17.                 this.setFinished(finished);
  18.             }
  19.            
  20.             if (model.isFilled(Integer.parseInt(event.getActionCommand())) == true)
  21.             { // if player made correct move (aka it wasn't in a full column) then -> AI turn || if not -> player retry
  22.                 try {
  23.                     getView().setSlot(this.getModel().drop(Integer.parseInt(event.getActionCommand()), Model.PLAYER), Integer.parseInt(event.getActionCommand()), Model.PLAYER);
  24.                 } catch (Exception e1) {
  25.                     // TODO Auto-generated catch block
  26.                     e1.printStackTrace();                  
  27.                 }
  28.             }
  29.             if(playerWin)
  30.             {
  31.                 System.out.print("You have won");
  32.                 this.setFinished(finished);
  33.             }
  34.             else{ //AI turn code
  35.                 model.move();
  36.             }
  37.             if(compWin)
  38.             {
  39.                 System.out.print("You have lost");
  40.                 this.setFinished(finished);
  41.             }
  42.             if(model.isFilled() && playerWin != true && compWin != true)
  43.             {
  44.                 System.out.print("It is a tie");
  45.                 this.setFinished(finished);
  46.             }
  47.         }
  48.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement