9 private int m_nrofblocks;
11 public Node[] m_mapNodes;
14 public int m_nrofpacs;
15 public int[] m_pacMenX;
16 public int[] m_pacMenY;
17 public int[] m_directions;
20 public int m_paccount;
21 public int m_deathcount;
24 public int m_nrofghosts;
25 public int[] m_ghostsX;
26 public int[] m_ghostsY;
27 public int[] m_ghostdirections;
28 public int[] m_targets;
29 public int m_ghostcount;
30 public int m_failghostcount;
35 public Map(int nrofpacs, int nrofghosts) {
36 //System.printString("step 1\n");
37 this.m_nrofblocks = 15;
38 this.m_map = new int[this.m_nrofblocks*this.m_nrofblocks];
39 this.m_mapNodes = new Node[this.m_nrofblocks*this.m_nrofblocks];
41 this.m_nrofpacs = nrofpacs;
42 this.m_pacMenX = new int[this.m_nrofpacs];
43 this.m_pacMenY = new int[this.m_nrofpacs];
44 this.m_directions = new int[this.m_nrofpacs];
45 this.m_desX = new int[this.m_nrofpacs];
46 this.m_desY = new int[this.m_nrofpacs];
48 this.m_deathcount = 0;
50 this.m_nrofghosts = nrofghosts;
51 this.m_ghostsX = new int[this.m_nrofghosts];
52 this.m_ghostsY = new int[this.m_nrofghosts];
53 this.m_ghostdirections = new int[this.m_nrofghosts];
54 this.m_targets = new int[this.m_nrofghosts];
55 this.m_ghostcount = 0;
56 this.m_failghostcount = 0;
58 this.m_r = new Random();
60 for(int i = 0; i < this.m_nrofblocks*this.m_nrofblocks; i++) {
62 this.m_mapNodes[i] = new Node(i%this.m_nrofblocks, i/this.m_nrofblocks, i);
65 //System.printString("step 2\n");
66 for(int i = 0; i < this.m_nrofpacs; i++) {
67 this.m_pacMenX[i] = this.m_pacMenY[i] = -1;
68 this.m_desX[i] = this.m_desY[i] = -1;
70 //System.printString("step 3\n");
71 for(int i = 0; i < this.m_nrofghosts; i++) {
72 this.m_ghostsX[i] = this.m_ghostsY[i] = -1;
73 this.m_targets[i] = -1;
75 //System.printString("step 4\n");
81 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;
82 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;
83 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;
84 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;
85 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;
86 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;
87 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;
88 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;
89 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;
90 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;
91 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;
92 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;
93 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;
94 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;
95 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
97 // initilize the graph of the maze
98 for(i = 0; i < this.m_nrofblocks*this.m_nrofblocks; i++) {
99 int tmp = this.m_map[i];
100 Node tmpNode = this.m_mapNodes[i];
101 int locX = tmpNode.getXLoc();
102 int locY = tmpNode.getYLoc();
103 if((int)(tmp & 1) == 0) {
106 tmpNode.addNeighbour(this.m_mapNodes[locY * this.m_nrofblocks + this.m_nrofblocks - 1]);
108 tmpNode.addNeighbour(this.m_mapNodes[i - 1]);
111 if((int)(tmp & 2) == 0) {
114 tmpNode.addNeighbour(this.m_mapNodes[(this.m_nrofblocks - 1) * this.m_nrofblocks + locX]);
116 tmpNode.addNeighbour(this.m_mapNodes[(locY - 1) * this.m_nrofblocks + locX]);
119 if((int)(tmp & 4) == 0) {
121 if(locX == this.m_nrofblocks - 1) {
122 tmpNode.addNeighbour(this.m_mapNodes[locY * this.m_nrofblocks]);
124 tmpNode.addNeighbour(this.m_mapNodes[i + 1]);
127 if((int)(tmp & 8) == 0) {
129 if(locY == this.m_nrofblocks - 1) {
130 tmpNode.addNeighbour(this.m_mapNodes[locX]);
132 tmpNode.addNeighbour(this.m_mapNodes[(locY + 1) * this.m_nrofblocks + locX]);
138 public void placePacman(Pacman t) {
139 this.m_pacMenX[t.m_index] = t.m_locX;
140 this.m_pacMenY[t.m_index] = t.m_locY;
144 public void placeGhost(Ghost t) {
145 this.m_ghostsX[t.m_index] = t.m_locX;
146 this.m_ghostsY[t.m_index] = t.m_locY;
150 public boolean check(Pacman t) {
151 boolean death = false;
153 while((!death) && (i < this.m_ghostsX.length)) {
154 if((t.m_locX == this.m_ghostsX[i]) && (t.m_locY == this.m_ghostsY[i])) {
159 if((!death) && (t.m_locX == t.m_tx) && (t.m_locY == t.m_ty)) {
160 // reach the destination
161 //System.printString("Hit destination!\n");
165 // pacman caught by ghost
166 // set pacman as death
169 //this.m_map[t.y * this.m_nrofblocks + t.x - 1] -= 16;
171 this.m_pacMenX[t.m_index] = -1;
172 this.m_pacMenY[t.m_index] = -1;
177 public boolean isfinish() {
178 return this.m_nrofpacs == 0;