9 private int m_nrofblocks;
13 public int m_nrofpacs;
14 public int[] m_pacMenX;
15 public int[] m_pacMenY;
16 public int[] m_directions;
17 public int[] m_pacOriX;
18 public int[] m_pacOriY;
19 public int[] m_leftLives;
20 public int[] m_leftLevels;
23 public int m_paccount;
24 public int m_deathcount;
27 public int m_nrofghosts;
28 public int[] m_ghostsX;
29 public int[] m_ghostsY;
30 public int[] m_ghostdirections;
31 public int[] m_targets;
32 public int m_ghostcount;
33 public int m_failghostcount;
38 public Map(int nrofpacs, int nrofghosts) {
39 //System.printString("step 1\n");
40 this.m_nrofblocks = 15;
41 this.m_map = new int[this.m_nrofblocks*this.m_nrofblocks];
43 this.m_nrofpacs = nrofpacs;
44 this.m_pacMenX = new int[this.m_nrofpacs];
45 this.m_pacMenY = new int[this.m_nrofpacs];
46 this.m_directions = new int[this.m_nrofpacs];
47 this.m_pacOriX = new int[this.m_nrofpacs];
48 this.m_pacOriY = new int[this.m_nrofpacs];
49 this.m_leftLives = new int[this.m_nrofpacs];
50 this.m_leftLevels = new int[this.m_nrofpacs];
51 this.m_desX = new int[this.m_nrofpacs];
52 this.m_desY = new int[this.m_nrofpacs];
54 this.m_deathcount = 0;
56 this.m_nrofghosts = nrofghosts;
57 this.m_ghostsX = new int[this.m_nrofghosts];
58 this.m_ghostsY = new int[this.m_nrofghosts];
59 this.m_ghostdirections = new int[this.m_nrofghosts];
60 this.m_targets = new int[this.m_nrofghosts];
61 this.m_ghostcount = 0;
62 this.m_failghostcount = 0;
64 this.m_r = new Random();
66 for(int i = 0; i < this.m_nrofblocks*this.m_nrofblocks; i++) {
70 //System.printString("step 2\n");
71 for(int i = 0; i < this.m_nrofpacs; i++) {
72 this.m_pacMenX[i] = this.m_pacMenY[i] = -1;
73 this.m_directions[i] = 0;
74 this.m_pacOriX[i] = this.m_pacOriY[i] = -1;
75 this.m_leftLives[i] = this.m_leftLevels[i] = 0;
76 this.m_desX[i] = this.m_desY[i] = -1;
78 //System.printString("step 3\n");
79 for(int i = 0; i < this.m_nrofghosts; i++) {
80 this.m_ghostsX[i] = this.m_ghostsY[i] = -1;
81 this.m_targets[i] = -1;
83 //System.printString("step 4\n");
89 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;
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++]=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;
91 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;
92 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;
93 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;
94 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;
95 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;
96 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;
97 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;
98 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;
99 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;
100 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;
101 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;
102 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;
103 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
106 public void placePacman(Pacman t) {
107 this.m_pacMenX[t.m_index] = t.m_locX;
108 this.m_pacMenY[t.m_index] = t.m_locY;
112 public void placeGhost(Ghost t) {
113 this.m_ghostsX[t.m_index] = t.m_locX;
114 this.m_ghostsY[t.m_index] = t.m_locY;
118 public boolean check(Pacman t) {
119 boolean death = false;
121 while((!death) && (i < this.m_ghostsX.length)) {
122 if((t.m_locX == this.m_ghostsX[i]) && (t.m_locY == this.m_ghostsY[i])) {
126 //System.printString("Pacman " + t.m_index + " caught! " + t.m_leftLives + "\n");
130 if((!death) && (t.m_locX == t.m_tx) && (t.m_locY == t.m_ty)) {
131 // reach the destination
132 //System.printString("Hit destination!\n");
136 //System.printString("Pacman " + t.m_index + " hit, upgrade! " + t.m_leftLevels + "\n");
140 // pacman has no more lives or no more levels
143 this.m_pacMenX[t.m_index] = -1;
144 this.m_pacMenY[t.m_index] = -1;
147 this.m_leftLives[t.m_index]--;
148 } else if(t.m_success) {
149 this.m_leftLevels[t.m_index]--;
152 this.m_pacMenX[t.m_index] = t.m_locX;
153 this.m_pacMenY[t.m_index] = t.m_locY;
154 this.m_directions[t.m_index] = 0;
155 //System.printString("Pacman " + t.m_index + " reset: (" + t.m_locX + ", " + t.m_locY + ")\n");
161 public boolean isfinish() {
162 return this.m_nrofpacs == 0;
165 public Vector getNeighbours(int index) {
166 Vector neighbours = new Vector();
167 int tmp = this.m_map[index];
168 int locX = index % this.m_nrofblocks;
169 int locY = index / this.m_nrofblocks;
170 if((int)(tmp & 1) == 0) {
173 neighbours.addElement(new Integer(locY * this.m_nrofblocks + this.m_nrofblocks - 1));
175 neighbours.addElement(new Integer(index - 1));
178 if((int)(tmp & 2) == 0) {
181 neighbours.addElement(new Integer((this.m_nrofblocks - 1) * this.m_nrofblocks + locX));
183 neighbours.addElement(new Integer((locY - 1) * this.m_nrofblocks + locX));
186 if((int)(tmp & 4) == 0) {
188 if(locX == this.m_nrofblocks - 1) {
189 neighbours.addElement(new Integer(locY * this.m_nrofblocks));
191 neighbours.addElement(new Integer(index + 1));
194 if((int)(tmp & 8) == 0) {
196 if(locY == this.m_nrofblocks - 1) {
197 neighbours.addElement(new Integer(locX));
199 neighbours.addElement(new Integer((locY + 1) * this.m_nrofblocks + locX));