/** * Attempt to move the player as instructed * * @param dungeon A pointer to the dungeon * @param move The move to make * * @return RESULT_WIN if the player has won the game * RESULT_DIE if the player has died in the game * INVALID_MOVE if the move is invalid * else 0 */ int makeMove(Dungeon* dungeon, char move) { Object *player; int result=0; int len; if(!dungeon->moveList) { dungeon->moveList = malloc(EXTEND_MOVE*4+1); bzero(dungeon->moveList, EXTEND_MOVE*4+1); } len = cgc_strlen(dungeon->moveList); sprintf(&dungeon->moveList[len], "!H", (unsigned char) move); if(!(player = getObjectById(dungeon->start, PLAYER_NUM))) _terminate(OBJECT_NOT_FOUND_ERROR); if(move == dungeon->moveTypes.left) { player->direction->x = 0; if((result = moveLeft(dungeon, player))) return result; if((result = moveEnemies(dungeon, player->moves))) return result; sendCurrentDungeonView(dungeon->start); if((result = checkFloor(dungeon, player))) return result; } else if(move == dungeon->moveTypes.right) { player->direction->x = 0; if((result = moveRight(dungeon, player))) return result; if((result = moveEnemies(dungeon, player->moves))) return result; sendCurrentDungeonView(dungeon->start); if((result = checkFloor(dungeon, player))) return result; } else if(move == dungeon->moveTypes.jump) return jump(dungeon, player); else if (move == dungeon->moveTypes.jumpleft) return jumpLeft(dungeon, player); else if (move == dungeon->moveTypes.jumpright) return jumpRight(dungeon, player); else if (move == dungeon->moveTypes.wait) { addMove(dungeon, player, dungeon->moveTypes.wait); if((result = moveEnemies(dungeon, player->moves))) return result; sendCurrentDungeonView(dungeon->start); return 0; } else return INVALID_MOVE; return 0; }
/** * Move zombie one space * * @param dungeon A pointer to the dungeon * @param zombie A pointer to the zombie * @param moveNum The number of moves the player has made * * @return RESULT_DIE if the player has died in the game * else 0 */ int moveZombie(Dungeon* dungeon, Object* zombie, unsigned int moveNum) { int result=0; if(zombie->moves == moveNum) return 0; if(zombie->direction->x == DIR_LEFT) { if((result = moveLeft(dungeon, zombie))) return result; if((result = checkFloor(dungeon, zombie))) return result; } else if(zombie->direction->x == DIR_RIGHT) { if((result = moveRight(dungeon, zombie))) return result; if((result = checkFloor(dungeon, zombie))) return result; } zombie->moves++; return 0; }
/** * Attempt to jump JUMP_HEIGHT spaces up and return to starting position * NOTE: If there are not JUMP_HEIGHT spaces, player will stay at the highest * point until JUMP_HEIGHT moves upward have been made. The player will * then move down until the floor is reached. * * @param dungeon A pointer to the dungeon * @param dungeon A pointer to the object to move * * @return RESULT_WIN if the player has won the game * RESULT_DIE if the player has died in the game * else 0 */ int jump(Dungeon* dungeon, Object* object) { int result=0; object->direction->x = 0; object->direction->y = DIR_UP; for(int up=1; up<=JUMP_HEIGHT; up++) { if(object->id == PLAYER_NUM) addMove(dungeon, object, dungeon->moveTypes.jump); if((result = moveUp(dungeon, object))) return result; if((result = moveEnemies(dungeon, object->moves))) return result; sendCurrentDungeonView(dungeon->start); } object->direction->y = DIR_DOWN; if((result = checkFloor(dungeon, object))) return result; return 0; }
/** * Attempt to jump JUMP_HEIGHT spaces up and to the left * NOTE: If there are not JUMP_HEIGHT spaces, player will stay at the highest * point until JUMP_HEIGHT moves upward have been made. The player will * then move down until the floor is reached. Player will move left a * space for each move up and down unless a wall or floor is hit. * * @param dungeon A pointer to the dungeon * @param dungeon A pointer to the object to move * * @return RESULT_WIN if the player has won the game * RESULT_DIE if the player has died in the game * else 0 */ int jumpRight(Dungeon* dungeon, Object* object) { int result=0; object->direction->y = DIR_UP; object->direction->x = DIR_RIGHT; for(int up=1; up<=JUMP_HEIGHT; up++) { if((result = moveUp(dungeon, object))) return result; if((result = moveRight(dungeon, object))) return result; if((result = moveEnemies(dungeon, object->moves))) return result; sendCurrentDungeonView(dungeon->start); } object->direction->y = DIR_DOWN; if((result = checkFloor(dungeon, object))) return result; object->direction->x = 0; return 0; }
void Tp1Simulation1::checkEndOfSimulation() { checkFloor(); checkNet(); }