示例#1
0
void check_win(){

        if (flags == 0){
            for(i = 0; i < rows; i++){
                for (j = 0; j < columns; j++){
                    //all flags have bombs
                    if (button_arr[i][j].flag == 1 && button_arr[i][j].value != -1) return;
                    //all bombs have flags
                    if (button_arr[i][j].flag != 1 && button_arr[i][j].value == -1) return;
                }
            }
        } else {
            for(i = 0; i < rows; i++){
            for (j = 0; j < columns; j++){
                //all the hidden ones are bombs
                if (button_arr[i][j].state == 0 && button_arr[i][j].value != -1) return;
            }
        }
        }
      
        cli();
        _delay_ms(500);
        display_color(BLACK, GREEN);
        clear_screen();
        display_string_xy("CONGRATULATIONS! YOU WON! :D\n", 40, 100);
        display_string_xy("Press center to restart", 60, 130);
        display_string_xy("Hold < to return to menu", 56, 150);
        finish_game();
        sei();
}
示例#2
0
void draw_flag(uint16_t x, uint16_t y){

    if(button_arr[x][y].flag == 1){
         display_string_xy("!", lefts[x][y] + button_width/5*2 + 3, tops[x][y] + button_width/5*2);
    } else if (button_arr[x][y].flag == 2){
         display_string_xy("?", lefts[x][y] + button_width/5*2, tops[x][y] + button_width/5*2);
    }
}
示例#3
0
/*
 * Set up the required initial conditions for a match, and switch to playing state
 */
void start_game()
{
	/* Seed the RNG */
	srand(TCNT1);

	/* Load in the sprites */
	reticule_SPR = reticule(0);

	/* Generate and draw a level */
	clear_screen();
	free((void*) level_map);
	level_map = generate_flat(WIDTH, 129);	
	if(level_map != NULL)
		draw_level(level_map, SILVER, 0, WIDTH - 1);
	
	/* Set up the players in the field */
	playersX = malloc(players * sizeof(int16_t));
	playersY = malloc(players * sizeof(int16_t));
	players_HP = malloc(players * sizeof(uint8_t));
	if(playersX == NULL || playersY == NULL || players_HP == NULL)
	{
		display_string("Out of memory error!");
		return;
	}
	uint8_t i;
	for(i = 0; i < players; i++)
	{
		playersX[i] = (i + 1) * WIDTH / (players + 1);
		playersY[i] = 120;
		players_HP[i] = MAX_PLAYER_HP;

		free_sprite(player_SPR);
		player_SPR = botleft(i);
		fill_sprite(player_SPR, playersX[i], playersY[i], HEIGHT_NO_UI, WIDTH);
	}

	/* Pick a random player to ... go last
	 * First call to start_turn will cycle to next player. Poor sod. */
	current_player = rand() % players;

	reticuleX = (playersX[current_player] + (RETICULE_DISTANCE * ml_cos(position))/100);
	reticuleY = (playersY[current_player] + (RETICULE_DISTANCE * ml_sin(position))/100);

	/* Initialise movement variables */
	direction = 0;
	launch_speed = 0;

	/* Draw the UI */
	display_string_xy("POWER:", POWER_LABEL_X, POWER_LABEL_Y);
	fill_rectangle(power_outline, WHITE);
	fill_rectangle(power_empty, BLACK);
	display_string_xy("WIND:", WIND_LABEL_X, WIND_LABEL_Y);
	fill_rectangle(wind_outline, WHITE);
	fill_rectangle(wind_empty, BLACK);

	/* Start the first player's turn */
	start_turn();
}
示例#4
0
void draw_button_content(uint16_t x, uint16_t y){
    
    char disp[20];
    if (button_arr[x][y].value == -1){
        sprintf(disp, "x");  
        display_string_xy(disp, lefts[x][y] + button_width/5*2 + 2, tops[x][y] + button_width/5*2 + 2);
    } else {
         sprintf(disp, "%d", button_arr[x][y].value);  
         display_string_xy(disp, lefts[x][y] + button_width/5*2, tops[x][y] + button_width/5*2);
    }

}
示例#5
0
void switch_button_flag(){
    button b;
     int e = get_selected_button(&b);
     if (e != 0){
        uint16_t x = b.posx;
        uint16_t y = b.posy;
        
        if (!button_arr[x][y].state) {
            int before = button_arr[x][y].flag;
            button_arr[x][y].flag = (button_arr[x][y].flag + 1) % 3;
            button_col = BLUE;
            draw_button_background(x,y);
            display_color(BLACK,button_col);  
            draw_flag(x,y);
            
            if (button_arr[x][y].flag == 1){
                
                    --flags;
                    char disp[20];
                    display_color(BLACK, def_button_col);
                    sprintf(disp, "== %d ==", flags);         
                    display_string_xy(disp, LCDHEIGHT/2 + 25, 13);
                
            } else {
                if (flags < maxflags && before == 1) {
                    ++flags;
                    char disp[20];
                    display_color(BLACK, def_button_col);
                    sprintf(disp, "== %d ==", flags);         
                    display_string_xy(disp, LCDHEIGHT/2 + 25, 13);
                }
                
            }
            check_win();

        }
     }
}
示例#6
0
void reveal_button(){

     button b;
     int e = get_selected_button(&b);
     if (e != 0){
        char disp[20];

        uint16_t x = b.posx;
        uint16_t y = b.posy;
        button_arr[x][y].state = 1;
        if (button_arr[x][y].flag == 1){
            if (flags < maxflags) {
                button_arr[x][y].flag = 0;
                ++flags;
                char disp[20];
                display_color(BLACK, def_button_col);
                sprintf(disp, "== %d ==", flags);         
                display_string_xy(disp, LCDHEIGHT/2 + 25, 13);
            }
        }

        if (b.value == -1){
            cli();
            button_col = RED;
            draw_button_background(x, y);
            display_color(BLACK,button_col);
            draw_button_content(x, y);
            draw_grid_lines(x,y);

            _delay_ms(1000);
            clear_screen();
            display_string_xy("GAME OVER :(\n", 110, 100);
            display_string_xy("Press center to restart", 60, 130);
            display_string_xy("Hold < to return to menu", 56, 150);
            finish_game();
            sei();
            return;
        } else {
            button_col = DIM_GRAY;
            draw_button_background(x, y);
            char n = b.value;
            if (n > 0){
                switch(n) {
                    case 1 :
                        display_color(BLUE,button_col);
                    break;
                    case 2 :
                        display_color(DARK_GREEN,button_col);
                    break;
                    case 3 :
                        display_color(RED, button_col);
                    break;
                    case 4:
                        display_color(PURPLE, button_col);
                    break;
                    default :
                        display_color(PURPLE,button_col);  
                }
                draw_button_content(x, y);
            }
            draw_grid_lines(x,y);
            check_neighbours(x,y);
            check_win();
        }
        
     }
     
}