예제 #1
0
void* tram_ep(void *arg){
    task_context_t * ctx = arg;
	int start = rand() % 4;
	int stop = rand() % 3;
	ctx->posX = from_to[start][0][0];
	ctx->posY = from_to[start][0][1];
	while (!place_at(ctx->posX, ctx->posY)) {
		sleep(1);
	}
    int destX = from_to[start][stop+1][0];
    int destY = from_to[start][stop+1][1];
    //printf("going from %d %d to %d %d\n", ctx->posX, ctx->posY, destX, destY);
    while (destX != ctx->posX || destY != ctx->posY) {
        if (destX > ctx->posX && ctx->posY == TRAM_LANE_BOTTOM) {
            try_move(ctx, +1, 0);
        } else if (destX < ctx->posX && ctx->posY == TRAM_LANE_TOP) {
            try_move(ctx, -1, 0);
        } else if (destY > ctx->posY && ctx->posX == TRAM_LANE_LEFT) {
            try_move(ctx, 0, 1);
        } else if (destY < ctx->posY && ctx->posX == TRAM_LANE_RIGHT) {
            try_move(ctx, 0, -1);
        }
        sleep(1);
    }
    
    remove_from(ctx->posX, ctx->posY);
	ctx->alive = 0;
	return NULL;
}
예제 #2
0
int
try_to_cough(short row, short col, object *obj)
{
    if ((row < MIN_ROW) || (row > (ROGUE_LINES - 2)) || (col < 0)
	|| (col > (ROGUE_COLUMNS - 1))) {
	return 0;
    }
    if ((!(dungeon[row][col] & (OBJECT | STAIRS | TRAP))) &&
	(dungeon[row][col] & (TUNNEL | FLOOR | DOOR))) {
	place_at(obj, row, col);
	if (((row != rogue.row) || (col != rogue.col)) &&
	    (!(dungeon[row][col] & MONSTER))) {
	    mvaddch_rogue(row, col, get_dungeon_char(row, col));
	}
	return 1;
    }
    return 0;
}