KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > innig > macker > example > modularity > game > impl > AbstractGame


1 package net.innig.macker.example.modularity.game.impl;
2
3 import net.innig.macker.example.modularity.game.*;
4 import net.innig.macker.example.modularity.player.*;
5 import java.util.*;
6
7 public abstract class AbstractGame
8     implements Game
9     {
10     public AbstractGame()
11         {
12         player = new Player[2];
13         score = new int[2];
14         prevMove = new Move[2];
15         }
16     
17     public void setPlayer(int playerNum, Player player)
18         { this.player[playerNum] = player; }
19     
20     public Player getPlayer(int playerNum)
21         { return player[playerNum]; }
22     
23     public int getScore(int playerNum)
24         { return score[playerNum]; }
25     
26     public Move getPreviousMove(int playerNum)
27         { return prevMove[playerNum]; }
28     
29     public void move()
30         {
31         Move move0 = player[0].nextMove(getLegalMoves(), prevMove[1]);
32         Move move1 = player[1].nextMove(getLegalMoves(), prevMove[0]);
33         prevMove[0] = move0;
34         prevMove[1] = move1;
35         score[0] += move0.getScoreFor(move1);
36         score[1] += move1.getScoreFor(move0);
37         }
38
39     private Player[] player;
40     private int[] score;
41     private Move[] prevMove;
42     }
43
Popular Tags