Ejemplo n.º 1
0
struct coord player_select_square()
{
	struct coord c, dc;
	int k;

	c.x = player.x;
	c.y = player.y;

	do {
		main_move(c.x, c.y);
		display_refresh();

		k = display_getch();

		dc = key_to_direction(k);

		c.x += dc.x;
		c.y += dc.y;

	} while(k != '.');

	return c;
}
Ejemplo n.º 2
0
/* This is the entry-point for the game! */
void c_start(void) {
    /* TODO:  You will need to initialize various subsystems here.  This
     *        would include the interrupt handling mechanism, and the various
     *        systems that use interrupts.  Once this is done, you can call
     *        enable_interrupts() to start interrupt handling, and go on to
     *        do whatever else you decide to do!
     */

    seed_rand_with_time();
    init_interrupts();
    init_keyboard();
    init_timer();
    enable_interrupts();

    int board[BOARD_SIZE][BOARD_SIZE] = { };
    animation_descriptor descriptor = { };
    initialize(board);
    int high_score = current_score(board);
    init_video(high_score);
    draw_board(board);
    
    /* Loop forever, so that we don't fall back into the bootloader code. */
    while (1) {
        if (!isemptyqueue()) {
            key k = dequeue();
            if (k == enter_key) {
                for (int *b = *board; b < *board + BOARD_SIZE * BOARD_SIZE; b++) *b = 0;
                initialize(board);
                init_video(high_score);
                draw_board(board);
                continue;
            } else {
                shift_direction direction = key_to_direction(k);

                // Setup animation
                copy_board(board, descriptor.board);
                descriptor.direction = direction;

                // Only add a box if the pieces actually move
                if (shift(board, direction, descriptor.offsets)) {
                    add_random_box(board);
                    int score = current_score(board);
                    if (score > high_score) high_score = score;
                    init_video(high_score);
                }
            }
            
            int num_frames = frame_count(descriptor.direction);
            int incr = get_axis(descriptor.direction) == horizontal_axis ? 12 : 2;
            int frame = 0;
            while (frame <= num_frames) {
                draw_board_frame(descriptor, frame);
                sleep(30);

                if (frame == num_frames) break;
                else frame = min(frame + incr, num_frames);
            }
            draw_board(board);
            
            if (!move_available(board)) {
                draw_failure_message();
            }
        }
    }
}
Ejemplo n.º 3
0
Archivo: main.c Proyecto: davel/lartem
int main(int argc, char *argv[])
{
	int k;
	struct coord c;
	unsigned int i;
	unsigned char turn_taken = 1, running = 0;

	seed_rng();

	display_init();

	if(player_init() == -1) return 0;

	level_init(&levels[0], 8);
	player_set_level(&levels[0]);

	while(1) {
		main_clear();
		player_see();
		player_status();

		turn_taken = 0;

		if(!running) k = display_getch();

		msg_clear();

		switch(k) {
		case '8':
		case '9':
		case '6':
		case '3':
		case '2':
		case '1':
		case '4':
		case '7':
		case KEY_UP:
		case KEY_DOWN:
		case KEY_LEFT:
		case KEY_RIGHT:
			c = key_to_direction(k);
			if(!player_move(c.x, c.y)) running = 0;
			turn_taken = 1;
			break;
		case 'c':
			c = key_to_direction(ask_key("In which direction?"));
			msg_clear();
			player_close(c.x, c.y);
			turn_taken = 1;
			break;
		case 'o':
			c = key_to_direction(ask_key("In which direction?"));
			msg_clear();
			player_open(c.x, c.y);
			turn_taken = 1;
			break;
		case 'k':
			c = key_to_direction(ask_key("In which direction?"));
			msg_clear();
			player_kick(c.x, c.y);
			turn_taken = 1;
			break;
		case 'g':
		case 'G':
			k = ask_key("In which direction?");
			c = key_to_direction(k);
			if((c.x || c.y) && player_move(c.x, c.y)) running = 1;
			turn_taken = 1;
			break;
		case ':':
			player_look();
			break;
		case ';':
			msg_printf("Pick an object...");
			c = player_select_square();
			msg_clear();
			player_remote_look(c.x, c.y);
			break;
		case '.':
			turn_taken = 1;
			break;
		}


		if(turn_taken) {
			if(player_poll()) running = 0;

			for(i = 0; i < levels[0].nmonst; i++)
				if(monster_poll(levels[0].monsters[i]))
					running = 0;
		}
	}

	return 0;
}