F:\java\knim-game\sources\ru\ifmo\knim\controlled\InterfaceManipulator.java

1    /** 
2     * @(#)InterfaceManipulator.java 
3     *  
4     *  Copyright Anthony Yakovlev <yakovlev@rain.ifmo.ru> and Michail Lukin <michail@users.msn.com> 
5     */ 
6     
7    package ru.ifmo.knim.controlled; 
8     
9    import javax.swing.*; 
10    
11   import ru.ifmo.knim.main.MoveResult; 
12    
13   import com.evelopers.unimod.runtime.ControlledObject; 
14   import com.evelopers.unimod.runtime.context.StateMachineContext; 
15    
16   /** 
17    * Class that controls the interface 
18    * @author Anthony Yakovlev 
19    */ 
20   public class InterfaceManipulator implements ControlledObject { 
21       /** 
22       *@unimod.action.descr “wrong move” message 
23       */ 
24       public void z1(StateMachineContext context) { 
25           JOptionPane.showMessageDialog(null, "Wrong move!"); 
26       } 
27    
28       /** 
29       *@unimod.action.descr does the player want to continue game after he lost? 
30       */ 
31       public boolean x1(StateMachineContext context) { 
32           // fake by AY 
33           MoveResult move = (MoveResult) context.getEventContext().getParameter("AIMove"); 
34           if (move.isGameOver) { 
35               return false; 
36           } 
37           return JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(null, "Play once more?", "Computer is the winner", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); 
38       } 
39        
40       /** 
41       *@unimod.action.descr does the player want to continue game after he won? 
42       */ 
43       public boolean x2(StateMachineContext context) { 
44           // fake by AY 
45           MoveResult move = (MoveResult) context.getEventContext().getParameter("AIMove"); 
46           if (!move.isGameOver) { 
47               return false; 
48           } 
49           return JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(null, "Play once more?", "You are the winner!", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); 
50       } 
51    
52       /** 
53       *@unimod.action.descr “About” message 
54       */ 
55       public void z2(StateMachineContext context) { 
56           JOptionPane.showMessageDialog(null,  
57                   "Classical Nim game\n" + 
58                   "Anthony Yakovlev & Michail Lukin \n", 
59                   "About", 
60                   JOptionPane.INFORMATION_MESSAGE 
61           );               
62       } 
63   } 
64