3 private int m_nrofblocks;
\r
5 public Ghost[] m_ghosts;
\r
6 public Pacman[] m_pacmen;
\r
8 // pacmen information
\r
9 public int m_nrofpacs;
\r
10 public int[] m_pacMenX;
\r
11 public int[] m_pacMenY;
\r
12 public int[] m_directions;
\r
13 public int[] m_desX;
\r
14 public int[] m_desY;
\r
15 public int m_paccount;
\r
16 public int m_deathcount;
\r
18 // ghosts information
\r
19 public int m_nrofghosts;
\r
20 public int[] m_ghostsX;
\r
21 public int[] m_ghostsY;
\r
22 public int[] m_ghostdirections;
\r
23 public int[] m_targets;
\r
24 public int m_ghostcount;
\r
29 public Map(int nrofpacs, int nrofghosts) {
\r
30 //System.printString("step 1\n");
\r
31 this.m_nrofblocks = 15;
\r
32 this.m_map = new int[this.m_nrofblocks*this.m_nrofblocks];
\r
34 this.m_nrofpacs = nrofpacs;
\r
35 this.m_pacMenX = new int[this.m_nrofpacs];
\r
36 this.m_pacMenY = new int[this.m_nrofpacs];
\r
37 this.m_directions = new int[this.m_nrofpacs];
\r
38 this.m_desX = new int[this.m_nrofpacs];
\r
39 this.m_desY = new int[this.m_nrofpacs];
\r
40 this.m_paccount = 0;
\r
41 this.m_deathcount = 0;
\r
43 this.m_nrofghosts = nrofghosts;
\r
44 this.m_ghostsX = new int[this.m_nrofghosts];
\r
45 this.m_ghostsY = new int[this.m_nrofghosts];
\r
46 this.m_ghostdirections = new int[this.m_nrofghosts];
\r
47 this.m_targets = new int[this.m_nrofghosts];
\r
48 this.m_ghostcount = 0;
\r
50 this.m_ghosts = new Ghost[this.m_nrofghosts];
\r
51 this.m_pacmen = new Pacman[this.m_nrofpacs];
\r
53 this.m_r = new Random();
\r
55 for(int i = 0; i < this.m_nrofblocks*this.m_nrofblocks; i++) {
\r
59 //System.printString("step 2\n");
\r
60 for(int i = 0; i < this.m_nrofpacs; i++) {
\r
61 this.m_pacMenX[i] = this.m_pacMenY[i] = -1;
\r
62 this.m_desX[i] = this.m_desY[i] = -1;
\r
63 this.m_pacmen[i] = null;
\r
65 //System.printString("step 3\n");
\r
66 for(int i = 0; i < this.m_nrofghosts; i++) {
\r
67 this.m_ghostsX[i] = this.m_ghostsY[i] = -1;
\r
68 this.m_targets[i] = -1;
\r
69 this.m_ghosts[i] = null;
\r
71 //System.printString("step 4\n");
\r
74 public void init() {
\r
75 // initilize the maze
\r
77 this.m_map[i++]=3;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=6;this.m_map[i++]=9;this.m_map[i++]=12;this.m_map[i++]=3;this.m_map[i++]=10;this.m_map[i++]=6;this.m_map[i++]=9;this.m_map[i++]=12;this.m_map[i++]=3;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=6;
\r
78 this.m_map[i++]=5;this.m_map[i++]=11;this.m_map[i++]=14;this.m_map[i++]=1;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=4;this.m_map[i++]=15;this.m_map[i++]=1;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=4;this.m_map[i++]=11;this.m_map[i++]=14;this.m_map[i++]=5;
\r
79 this.m_map[i++]=1;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=4;this.m_map[i++]=11;this.m_map[i++]=6;this.m_map[i++]=1;this.m_map[i++]=10;this.m_map[i++]=4;this.m_map[i++]=3;this.m_map[i++]=14;this.m_map[i++]=1;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=4;
\r
80 this.m_map[i++]=5;this.m_map[i++]=3;this.m_map[i++]=6;this.m_map[i++]=9;this.m_map[i++]=6;this.m_map[i++]=5;this.m_map[i++]=5;this.m_map[i++]=7;this.m_map[i++]=5;this.m_map[i++]=5;this.m_map[i++]=3;this.m_map[i++]=12;this.m_map[i++]=3;this.m_map[i++]=6;this.m_map[i++]=5;
\r
81 this.m_map[i++]=5;this.m_map[i++]=9;this.m_map[i++]=8;this.m_map[i++]=14;this.m_map[i++]=5;this.m_map[i++]=13;this.m_map[i++]=5;this.m_map[i++]=5;this.m_map[i++]=5;this.m_map[i++]=13;this.m_map[i++]=5;this.m_map[i++]=11;this.m_map[i++]=8;this.m_map[i++]=12;this.m_map[i++]=5;
\r
82 this.m_map[i++]=9;this.m_map[i++]=2;this.m_map[i++]=10;this.m_map[i++]=2;this.m_map[i++]=8;this.m_map[i++]=2;this.m_map[i++]=12;this.m_map[i++]=5;this.m_map[i++]=9;this.m_map[i++]=2;this.m_map[i++]=8;this.m_map[i++]=2;this.m_map[i++]=10;this.m_map[i++]=2;this.m_map[i++]=12;
\r
83 this.m_map[i++]=6;this.m_map[i++]=5;this.m_map[i++]=7;this.m_map[i++]=5;this.m_map[i++]=7;this.m_map[i++]=5;this.m_map[i++]=11;this.m_map[i++]=8;this.m_map[i++]=14;this.m_map[i++]=5;this.m_map[i++]=7;this.m_map[i++]=5;this.m_map[i++]=7;this.m_map[i++]=5;this.m_map[i++]=3;
\r
84 this.m_map[i++]=4;this.m_map[i++]=5;this.m_map[i++]=5;this.m_map[i++]=5;this.m_map[i++]=5;this.m_map[i++]=5;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=5;this.m_map[i++]=5;this.m_map[i++]=5;this.m_map[i++]=5;this.m_map[i++]=5;this.m_map[i++]=1;
\r
85 this.m_map[i++]=12;this.m_map[i++]=5;this.m_map[i++]=13;this.m_map[i++]=5;this.m_map[i++]=13;this.m_map[i++]=5;this.m_map[i++]=11;this.m_map[i++]=10;this.m_map[i++]=14;this.m_map[i++]=5;this.m_map[i++]=13;this.m_map[i++]=5;this.m_map[i++]=13;this.m_map[i++]=5;this.m_map[i++]=9;
\r
86 this.m_map[i++]=3;this.m_map[i++]=8;this.m_map[i++]=10;this.m_map[i++]=8;this.m_map[i++]=10;this.m_map[i++]=0;this.m_map[i++]=10;this.m_map[i++]=2;this.m_map[i++]=10;this.m_map[i++]=0;this.m_map[i++]=10;this.m_map[i++]=8;this.m_map[i++]=10;this.m_map[i++]=8;this.m_map[i++]=6;
\r
87 this.m_map[i++]=5;this.m_map[i++]=3;this.m_map[i++]=2;this.m_map[i++]=2;this.m_map[i++]=6;this.m_map[i++]=5;this.m_map[i++]=15;this.m_map[i++]=5;this.m_map[i++]=15;this.m_map[i++]=5;this.m_map[i++]=3;this.m_map[i++]=2;this.m_map[i++]=2;this.m_map[i++]=6;this.m_map[i++]=5;
\r
88 this.m_map[i++]=5;this.m_map[i++]=9;this.m_map[i++]=8;this.m_map[i++]=8;this.m_map[i++]=4;this.m_map[i++]=1;this.m_map[i++]=10;this.m_map[i++]=8;this.m_map[i++]=10;this.m_map[i++]=4;this.m_map[i++]=1;this.m_map[i++]=8;this.m_map[i++]=8;this.m_map[i++]=12;this.m_map[i++]=5;
\r
89 this.m_map[i++]=1;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=6;this.m_map[i++]=13;this.m_map[i++]=5;this.m_map[i++]=11;this.m_map[i++]=2;this.m_map[i++]=14;this.m_map[i++]=5;this.m_map[i++]=13;this.m_map[i++]=3;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=4;
\r
90 this.m_map[i++]=5;this.m_map[i++]=11;this.m_map[i++]=14;this.m_map[i++]=1;this.m_map[i++]=10;this.m_map[i++]=8;this.m_map[i++]=6;this.m_map[i++]=13;this.m_map[i++]=3;this.m_map[i++]=8;this.m_map[i++]=10;this.m_map[i++]=4;this.m_map[i++]=11;this.m_map[i++]=14;this.m_map[i++]=5;
\r
91 this.m_map[i++]=9;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=12;this.m_map[i++]=3;this.m_map[i++]=6;this.m_map[i++]=9;this.m_map[i++]=10;this.m_map[i++]=12;this.m_map[i++]=3;this.m_map[i++]=6;this.m_map[i++]=9;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=12; // 15*15
\r
94 public void placePacman(Pacman t) {
\r
95 this.m_pacMenX[t.m_index] = t.m_locX;
\r
96 this.m_pacMenY[t.m_index] = t.m_locY;
\r
100 public void placeGhost(Ghost t) {
\r
101 this.m_ghostsX[t.m_index] = t.m_locX;
\r
102 this.m_ghostsY[t.m_index] = t.m_locY;
\r
103 this.m_ghostcount++;
\r
106 public boolean check(Pacman t) {
\r
107 boolean death = false;
\r
109 while((!death) && (i < this.m_ghostsX.length)) {
\r
110 if((t.m_locX == this.m_ghostsX[i]) && (t.m_locY == this.m_ghostsY[i])) {
\r
115 if((!death) && (t.m_locX == t.m_tx) && (t.m_locY == t.m_ty)) {
\r
116 // reach the destination
\r
117 //System.printString("Hit destination!\n");
\r
121 // pacman caught by ghost
\r
122 // set pacman as death
\r
125 //this.m_map[t.y * this.m_nrofblocks + t.x - 1] -= 16;
\r
126 this.m_deathcount++;
\r
127 this.m_pacMenX[t.m_index] = -1;
\r
128 this.m_pacMenY[t.m_index] = -1;
\r
133 public boolean isfinish() {
\r
134 return this.m_nrofpacs == 0;
\r
137 public Vector getNeighbours(int index) {
\r
138 Vector neighbours = new Vector();
\r
139 int tmp = this.m_map[index];
\r
140 int locX = index % this.m_nrofblocks;
\r
141 int locY = index / this.m_nrofblocks;
\r
142 if((int)(tmp & 1) == 0) {
\r
145 neighbours.addElement(new Integer(locY * this.m_nrofblocks + this.m_nrofblocks - 1));
\r
147 neighbours.addElement(new Integer(index - 1));
\r
150 if((int)(tmp & 2) == 0) {
\r
153 neighbours.addElement(new Integer((this.m_nrofblocks - 1) * this.m_nrofblocks + locX));
\r
155 neighbours.addElement(new Integer((locY - 1) * this.m_nrofblocks + locX));
\r
158 if((int)(tmp & 4) == 0) {
\r
160 if(locX == this.m_nrofblocks - 1) {
\r
161 neighbours.addElement(new Integer(locY * this.m_nrofblocks));
\r
163 neighbours.addElement(new Integer(index + 1));
\r
166 if((int)(tmp & 8) == 0) {
\r
168 if(locY == this.m_nrofblocks - 1) {
\r
169 neighbours.addElement(new Integer(locX));
\r
171 neighbours.addElement(new Integer((locY + 1) * this.m_nrofblocks + locX));
\r