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_pacOriX;
\r
14 public int[] m_pacOriY;
\r
15 public int[] m_leftLives;
\r
16 public int[] m_leftLevels;
\r
17 public int[] m_desX;
\r
18 public int[] m_desY;
\r
19 public int m_paccount;
\r
20 public int m_deathcount;
\r
22 // ghosts information
\r
23 public int m_nrofghosts;
\r
24 public int[] m_ghostsX;
\r
25 public int[] m_ghostsY;
\r
26 public int[] m_ghostdirections;
\r
27 public int[] m_targets;
\r
28 public int m_ghostcount;
\r
33 public Map(int nrofpacs, int nrofghosts) {
\r
34 //System.printString("step 1\n");
\r
35 this.m_nrofblocks = 15;
\r
36 this.m_map = new int[this.m_nrofblocks*this.m_nrofblocks];
\r
38 this.m_nrofpacs = nrofpacs;
\r
39 this.m_pacMenX = new int[this.m_nrofpacs];
\r
40 this.m_pacMenY = new int[this.m_nrofpacs];
\r
41 this.m_directions = new int[this.m_nrofpacs];
\r
42 this.m_pacOriX = new int[this.m_nrofpacs];
\r
43 this.m_pacOriY = new int[this.m_nrofpacs];
\r
44 this.m_leftLives = new int[this.m_nrofpacs];
\r
45 this.m_leftLevels = new int[this.m_nrofpacs];
\r
46 this.m_desX = new int[this.m_nrofpacs];
\r
47 this.m_desY = new int[this.m_nrofpacs];
\r
48 this.m_paccount = 0;
\r
49 this.m_deathcount = 0;
\r
51 this.m_nrofghosts = nrofghosts;
\r
52 this.m_ghostsX = new int[this.m_nrofghosts];
\r
53 this.m_ghostsY = new int[this.m_nrofghosts];
\r
54 this.m_ghostdirections = new int[this.m_nrofghosts];
\r
55 this.m_targets = new int[this.m_nrofghosts];
\r
56 this.m_ghostcount = 0;
\r
58 this.m_ghosts = new Ghost[this.m_nrofghosts];
\r
59 this.m_pacmen = new Pacman[this.m_nrofpacs];
\r
61 this.m_r = new Random();
\r
63 for(int i = 0; i < this.m_nrofblocks*this.m_nrofblocks; i++) {
\r
67 //System.printString("step 2\n");
\r
68 for(int i = 0; i < this.m_nrofpacs; i++) {
\r
69 this.m_pacMenX[i] = this.m_pacMenY[i] = -1;
\r
70 this.m_directions[i] = 0;
\r
71 this.m_pacOriX[i] = this.m_pacOriY[i] = -1;
\r
72 this.m_leftLives[i] = this.m_leftLevels[i] = 0;
\r
73 this.m_desX[i] = this.m_desY[i] = -1;
\r
74 this.m_pacmen[i] = null;
\r
76 //System.printString("step 3\n");
\r
77 for(int i = 0; i < this.m_nrofghosts; i++) {
\r
78 this.m_ghostsX[i] = this.m_ghostsY[i] = -1;
\r
79 this.m_targets[i] = -1;
\r
80 this.m_ghosts[i] = null;
\r
82 //System.printString("step 4\n");
\r
85 public void init() {
\r
86 // initilize the maze
\r
88 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
89 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
90 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
91 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
92 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
93 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
94 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
95 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
96 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
97 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
98 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
99 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
100 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
101 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
102 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
105 public void placePacman(Pacman t) {
\r
106 this.m_pacMenX[t.m_index] = t.m_locX;
\r
107 this.m_pacMenY[t.m_index] = t.m_locY;
\r
111 public void placeGhost(Ghost t) {
\r
112 this.m_ghostsX[t.m_index] = t.m_locX;
\r
113 this.m_ghostsY[t.m_index] = t.m_locY;
\r
114 this.m_ghostcount++;
\r
117 public boolean check(Pacman t) {
\r
118 boolean death = false;
\r
120 while((!death) && (i < this.m_ghostsX.length)) {
\r
121 if((t.m_locX == this.m_ghostsX[i]) && (t.m_locY == this.m_ghostsY[i])) {
\r
125 //System.printString("Pacman " + t.m_index + " caught! " + t.m_leftLives + "\n");
\r
129 if((!death) && (t.m_locX == t.m_tx) && (t.m_locY == t.m_ty)) {
\r
130 // reach the destination
\r
131 //System.printString("Hit destination!\n");
\r
133 t.m_success = true;
\r
135 //System.printString("Pacman " + t.m_index + " hit, upgrade! " + t.m_leftLevels + "\n");
\r
139 // pacman has no more lives or no more levels
\r
141 this.m_deathcount++;
\r
142 this.m_pacMenX[t.m_index] = -1;
\r
143 this.m_pacMenY[t.m_index] = -1;
\r
146 this.m_leftLives[t.m_index]--;
\r
147 } else if(t.m_success) {
\r
148 this.m_leftLevels[t.m_index]--;
\r
151 this.m_pacMenX[t.m_index] = t.m_locX;
\r
152 this.m_pacMenY[t.m_index] = t.m_locY;
\r
153 this.m_directions[t.m_index] = 0;
\r
154 //System.printString("Pacman " + t.m_index + " reset: (" + t.m_locX + ", " + t.m_locY + ")\n");
\r
160 public boolean isfinish() {
\r
161 return this.m_nrofpacs == 0;
\r
164 public Vector getNeighbours(int index) {
\r
165 Vector neighbours = new Vector();
\r
166 int tmp = this.m_map[index];
\r
167 int locX = index % this.m_nrofblocks;
\r
168 int locY = index / this.m_nrofblocks;
\r
169 if((int)(tmp & 1) == 0) {
\r
172 neighbours.addElement(new Integer(locY * this.m_nrofblocks + this.m_nrofblocks - 1));
\r
174 neighbours.addElement(new Integer(index - 1));
\r
177 if((int)(tmp & 2) == 0) {
\r
180 neighbours.addElement(new Integer((this.m_nrofblocks - 1) * this.m_nrofblocks + locX));
\r
182 neighbours.addElement(new Integer((locY - 1) * this.m_nrofblocks + locX));
\r
185 if((int)(tmp & 4) == 0) {
\r
187 if(locX == this.m_nrofblocks - 1) {
\r
188 neighbours.addElement(new Integer(locY * this.m_nrofblocks));
\r
190 neighbours.addElement(new Integer(index + 1));
\r
193 if((int)(tmp & 8) == 0) {
\r
195 if(locY == this.m_nrofblocks - 1) {
\r
196 neighbours.addElement(new Integer(locX));
\r
198 neighbours.addElement(new Integer((locY + 1) * this.m_nrofblocks + locX));
\r