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

1    /** 
2     * @(#)GameObject.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 com.evelopers.unimod.runtime.ControlledObject; 
10   import com.evelopers.unimod.runtime.context.StateMachineContext; 
11    
12   import ru.ifmo.knim.main.GamePlay; 
13   import ru.ifmo.knim.main.MoveResult; 
14   import ru.ifmo.knim.screens.*; 
15    
16   /** 
17    * This is the class that controls the game process 
18    * @author Anthony Yakovlev 
19    */ 
20   public class GameObject implements ControlledObject { 
21        
22       /** 
23        * Determines, whether the player has wone or not 
24        */ 
25       boolean hasPlayerWon = false; 
26    
27       /** 
28       *@unimod.action.descr reset game 
29       */ 
30       public void z1(StateMachineContext context) { 
31           GameScreen.getScreen().restartIface(); 
32       } 
33    
34       /** 
35       *@unimod.action.descr is move correct? 
36       */ 
37       public boolean x1(StateMachineContext context) { 
38            
39           // get param 
40           Object input = context.getEventContext().getParameter("Move"); 
41            
42           // test input 
43           int [] move = (int []) input; 
44           MoveResult result = MoveResult.getMoveResult(move); 
45           if (result == null) { 
46               return false; 
47           } else { 
48               return result.nTaken <= GamePlay.getGamePlay().getGameInfo().getFishInLine(result.takenFrom); 
49           } 
50       } 
51    
52       /** 
53       *@unimod.action.descr display move 
54       */ 
55       public void z2(StateMachineContext context) { 
56           // understands different kinds of input 
57           // get param 
58           Object input = context.getEventContext().getParameter("Move"); 
59           if (input != null) { 
60               GameScreen.getScreen().takeStones( 
61                       MoveResult.getMoveResult( (int []) input ) 
62               ); 
63           } else { 
64               input = context.getEventContext().getParameter("AIMove"); 
65               MoveResult move = (MoveResult) input; 
66               GameScreen.getScreen().takeStones(move); 
67               GameScreen.getScreen().updateStatus(move); 
68               move.isGameOver = false; 
69               GamePlay.getGamePlay().resendMove(move); 
70           } 
71            
72       } 
73    
74       /** 
75       *@unimod.action.descr is game finished? 
76       */ 
77       public boolean x2(StateMachineContext context) { 
78           return GamePlay.getGamePlay().getGameInfo().isGameover(); 
79       } 
80    
81       /** 
82       *@unimod.action.descr player won 
83       */ 
84       public void z3(StateMachineContext context) { 
85           hasPlayerWon = GamePlay.getGamePlay().getGameInfo().isGameover(); 
86       } 
87    
88       /** 
89       *@unimod.action.descr has the player won? 
90       */ 
91       public boolean x3(StateMachineContext context) { 
92           return hasPlayerWon; 
93       } 
94   } 
95