1 task startup(StartupObject s{initialstate}) {
2 //System.printString("Task startup\n");
6 Map map = new Map(nrofpacs, nrofghosts){init};
7 taskexit(s{!initialstate});
10 task initMap(Map map{init}) {
11 //System.printString("Task initMap\n");
17 for(i = 0; i < map.m_nrofghosts; i++) {
18 Ghost ghost = new Ghost(7, 7, map){move};
20 map.placeGhost(ghost);
27 for(i = 0; i < map.m_nrofpacs; i++) {
29 tmpx = map.m_r.nextInt() % 14;
32 tmpy = map.m_r.nextInt() % 14;
34 Pacman pacman = new Pacman(5, 7, map){move};
35 //Pacman pacman = new Pacman(tmpx, tmpy, map){move};
36 //System.printString("Pacman: (" + tmpx + ", " + tmpy + ")\n");
37 pacman.setTarget(tx*(i/2), ty*(i%2));
39 map.placePacman(pacman);
40 map.m_desX[i] = tx*(i/2);
41 map.m_desY[i] = ty*(i%2);
42 map.m_pacOriX[i] = pacman.m_locX;
43 map.m_pacOriY[i] = pacman.m_locY;
44 map.m_leftLives[i] = map.m_leftLevels[i] = 60;
45 pacman.m_leftLives = pacman.m_leftLevels = 60;
51 taskexit(map{!init, updateGhost});
54 task moveGhost(Ghost g{move}) {
55 //System.printString("Task moveGhost\n");
59 taskexit(g{!move, update});
62 task movePacman(Pacman p{move}) {
63 //System.printString("Task movePacman\n");
67 taskexit(p{!move, update});
70 task updateGhost(Map map{updateGhost}, /*optional*/ Ghost g{update}) {
71 //System.printString("Task updateGhost\n");
73 //System.printString("Ghost: " + g.m_index + "\n");
75 //if(isavailable(g)) {
78 //System.printString("place Ghost\n");
83 if(map.m_ghostcount == map.m_nrofghosts) {
84 //map.m_nrofghosts -= map.m_failghostcount;
86 map.m_failghostcount = 0;
87 /*for(int i = 0; i < map.m_ghostsX.length; i++) {
88 System.printString("(" + map.m_ghostsX[i] + "," + map.m_ghostsY[i] + ") ");
90 System.printString("\n");*/
91 taskexit(map{updatePac, !updateGhost}, g{!update});
96 task updatePac(Map map{updatePac}, /*optional*/ Pacman p{update}) {
97 //System.printString("Task updatePac\n");
99 //if(isavailable(p)) {
102 //System.printString("Pacman " + p.m_index + ": (" + map.m_pacMenX[p.m_index] + "," + map.m_pacMenY[p.m_index] + ")\n");
103 boolean death = map.check(p);
109 boolean finish = map.m_paccount == map.m_nrofpacs;
112 map.m_nrofpacs -= map.m_deathcount;
113 //System.printString(map.m_nrofpacs + " pacmen left. \n");
115 taskexit(map{finish, !updatePac}, p{!update, !move});
117 taskexit(map{next, !updatePac}, p{!update, !move});
120 taskexit(p{!move, !update});
124 task next(Map map{next}) {
125 //System.printString("Task next\n");
128 for(i = 0; i < map.m_nrofghosts; i++) {
129 Ghost ghost = new Ghost(map.m_ghostsX[i], map.m_ghostsY[i], map){move};
131 ghost.m_direction = map.m_ghostdirections[i];
133 for(i = 0; i < map.m_pacMenX.length; i++) {
134 if(map.m_pacMenX[i] != -1) {
136 //System.printString("new Pacman\n");
137 Pacman pacman = new Pacman(map.m_pacMenX[i], map.m_pacMenY[i], map){move};
138 pacman.setTarget(map.m_desX[i], map.m_desY[i]);
140 pacman.m_direction = map.m_directions[i];
141 pacman.m_oriLocX = map.m_pacOriX[i];
142 pacman.m_oriLocY = map.m_pacOriY[i];
143 pacman.m_leftLives = map.m_leftLives[i];
144 pacman.m_leftLevels = map.m_leftLevels[i];
149 map.m_deathcount = 0;
151 taskexit(map{!next, updateGhost});
154 task finish(Map map{finish}) {
155 //System.printString("Task Finish\n");
156 taskexit(map{!finish});