diff --git a/display.c b/display.c index 94371c5bdb44960d2373dbcc54b212abeb538bc9..7272bbddf766f68536dc59f970b74142f40f0f0b 100644 --- a/display.c +++ b/display.c @@ -10,9 +10,6 @@ SDL_Window* init_display(){ int one_arm_width, one_arm_height; SDL_Window *window; - // ------------------------- - // Graphic initialization - // ------------------------- assert(SDL_Init(SDL_INIT_VIDEO) == 0); get_image_file_size("./one_armed_bandit.png", &one_arm_width, &one_arm_height); assert((window = SDL_CreateWindow("one_armed_bandit", SDL_WINDOWPOS_UNDEFINED, @@ -33,16 +30,12 @@ SDL_Window* init_display(){ } void display_wheel(int pixel,int offset){ - // ------------------------- - // example of board display: - // ------------------------- SDL_Rect src_rect, dst_rect=object_rect; dst_rect.h=object_height*1.5; // display 1.5 object on screen for a wheel src_rect=dst_rect; src_rect.x=0; // src_rect.y is positionned here on the 2nd object of objects.png - //85 + index*104 + 1 src_rect.y= offset; dst_rect.x= pixel; dst_rect.y=410-object_height/2; // setup the coord. of the icon in the global renderer diff --git a/one_armed_bandit.c b/one_armed_bandit.c index a66b782597663b628c29e4ab3e93baa0aa059fe5..ca4bf7364d6e429f7ef9b3588020fed6eaf0d779 100644 --- a/one_armed_bandit.c +++ b/one_armed_bandit.c @@ -27,6 +27,16 @@ int how_many_points(machine mas){ return count; } +int stopped_wheels(machine mas){ + int res = 0; + for(int i = 0; i<WHEEL_NB; i++){ + if(mas.wheels[i].speed == 0){ + res+=1; + } + } + return res; +} + int main() { @@ -88,7 +98,7 @@ int main() break; case SDLK_s: wait_key_release(); - if(mas.player_wallet > 0){ + if(mas.player_wallet > 0 && stopped_wheels(mas) > 0){ paid = false; mas.player_wallet -= 1; mas.machine_wallet += 1; diff --git a/one_armed_bandit.h b/one_armed_bandit.h index 13e36f0ec75c0c83ad83fa2d09798797c80e15fe..ca932cf73e8d025cd46e7c6e0783079f6c4bd5e9 100644 --- a/one_armed_bandit.h +++ b/one_armed_bandit.h @@ -19,5 +19,8 @@ \#/ */ -int how_many_points(machine mas); + // returns the score based on the positionning of the wheels +int how_many_points(machine mas); + +int stopped_wheels(machine mas); \ No newline at end of file