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);
25 for(i = 0; i < map.m_nrofpacs; i++) {
26 Pacman pacman = new Pacman(5, 7, map){move};
27 pacman.setTarget(tx*(i/2), ty*(i%2));
29 map.placePacman(pacman);
30 map.m_desX[i] = tx*(i/2);
31 map.m_desY[i] = ty*(i%2);
37 taskexit(map{!init, updateGhost});
40 task moveGhost(Ghost g{move}) {
41 //System.printString("Task moveGhost\n");
45 taskexit(g{!move, update});
48 task movePacman(Pacman p{move}) {
49 //System.printString("Task movePacman\n");
53 taskexit(p{!move, update});
56 task updateGhost(Map map{updateGhost}, /*optional*/ Ghost g{update}) {
57 //System.printString("Task updateGhost\n");
59 //if(isavailable(g)) {
66 if(map.m_ghostcount == map.m_nrofghosts) {
67 //map.m_nrofghosts -= map.m_failghostcount;
69 map.m_failghostcount = 0;
70 /*for(int i = 0; i < map.m_ghostsX.length; i++) {
71 System.printString("(" + map.m_ghostsX[i] + "," + map.m_ghostsY[i] + ") ");
73 System.printString("\n");*/
74 taskexit(map{updatePac, !updateGhost}, g{!update});
79 task updatePac(Map map{updatePac}, /*optional*/ Pacman p{update}) {
80 //System.printString("Task updatePac\n");
82 //if(isavailable(p)) {
85 //System.printString("Pacman " + p.m_index + ": (" + map.m_pacMenX[p.m_index] + "," + map.m_pacMenY[p.m_index] + ")\n");
86 boolean death = map.check(p);
88 System.printString("Pacman " + p.m_index + " caught!\n");
95 boolean finish = map.m_paccount == map.m_nrofpacs;
98 map.m_nrofpacs -= map.m_deathcount;
99 //System.printString(map.m_nrofpacs + " pacmen left. \n");
101 taskexit(map{finish, !updatePac}, p{!update, !move});
103 taskexit(map{next, !updatePac}, p{!update, !move});
106 taskexit(p{!move, !update});
110 task next(Map map{next}) {
111 //System.printString("Task next\n");
114 for(i = 0; i < map.m_nrofghosts; i++) {
115 Ghost ghost = new Ghost(map.m_ghostsX[i], map.m_ghostsY[i], map){move};
117 ghost.m_direction = map.m_ghostdirections[i];
119 for(i = 0; i < map.m_pacMenX.length; i++) {
120 if(map.m_pacMenX[i] != -1) {
122 //System.printString("new Pacman\n");
123 Pacman pacman = new Pacman(map.m_pacMenX[i], map.m_pacMenY[i], map){move};
124 pacman.setTarget(map.m_desX[i], map.m_desY[i]);
126 pacman.m_direction = map.m_directions[i];
131 map.m_deathcount = 0;
133 taskexit(map{!next, updateGhost});
136 task finish(Map map{finish}) {
137 System.printString("Task Finish\n");
138 taskexit(map{!finish});