Exemple #1
0
void select_puzzle(int puzzle_num){
	switch(puzzle_num){
		case 0:
			init_puzzle(valid_puzzle0);
			break;
			
		case 1:
			init_puzzle(invalid_puzzle0);
			break;
			
		default:
			init_puzzle(empty_puzzle);
	}
		
}
Exemple #2
0
void
draw_puzzle(ModeInfo * mi)
{
	puzzlestruct *pp;

	if (puzzles == NULL)
		return;
	pp = &puzzles[MI_SCREEN(mi)];
	if (pp->fixbuff == NULL)
		return;

	MI_IS_DRAWN(mi) = True;
	pp->painted = False;
	if (pp->movingBox) {
		if (moveboxdelta(mi)) {
			wrapupmovedelta(mi);
			wrapupmove(mi);
			pp->movingBox = False;
			if (pp->moves++ > 2 * MI_COUNT(mi))
				init_puzzle(mi);
		}
	} else {
		if (setupmove(mi)) {
			setupmovedelta(mi);
			pp->movingBox = True;
		}
	}
}
Exemple #3
0
void main(void) 
{
    struct puzzleStruct puzzle;
    struct buttonStruct buttons;
    bool result = true;
    //init code here
    setup_int();
    init_puzzle(&puzzle);
    init_buttons(&buttons);
    init_inputs();

    //Enter main loop
    for(;;) {
        //Draw GUI
        build_gui(&puzzle);
        //Handle USB
        update_puzzle(&puzzle,&buttons);
        //Set output
        set_output(&puzzle);
        //Check inputs
        update_buttons(&buttons);
        //Read result
        result = check_result(&puzzle);
    }
}
Exemple #4
0
int main(int ac, char **av) {
	char cmd_line[MAX_CHARS+1] ;
	op_result status ;

	/*
	 * Parse the command arguments.
	 * If this returns, initialize the puzzle.
	 * Then
	 *   - configure the board from the command
	 *     line puzzle file,
	 *   - close the file,
	 *   - print the initial board
	 */
	parse_args(ac, av) ;
	init_puzzle() ;
	configure( puzzle_file() ) ;
	fclose( puzzle_file() ) ;
	print_puzzle() ;

	/*
	 * Command loop.
	 * Read a line and use the first character to decide
	 * what command to execute (or report an error).
	 */
	printf("command: ");

	while(read_line(cmd_line, MAX_CHARS) != EOF ) {
		if(cmd_line[CMD_INDEX] == 'q') {		// quit
			break ;
		} else if (cmd_line[CMD_INDEX] == 'p') {	// print the board
			print_puzzle() ;
		} else if (cmd_line[CMD_INDEX] == 'a') {	// add a digit
			int r, c, d ;
			r = cmd_line[ROW_INDEX] - '0' ;
			c = cmd_line[COL_INDEX] - '0' ;
			d = cmd_line[DIGIT_INDEX] - '0' ;

			status = add_digit(r, c, d) ;
			if( status != OP_OK ) {
				print_error(status) ;
			}
		} else if (cmd_line[CMD_INDEX] == 'e') {	// erase a digit
			int r, c ;
			r = cmd_line[ROW_INDEX] - '0' ;
			c = cmd_line[COL_INDEX] - '0' ;

			status = erase_digit(r, c) ;
			if( status != OP_OK ) {
				print_error(status) ;
			}
		} else {				// error
			printf("Unknown command %s\n", cmd_line) ;
		}
	
	printf("command: ") ;
	}

	return 0 ;
}