From 332f87b19e4cb97cf201ecc6d6c89e4b499211e8 Mon Sep 17 00:00:00 2001 From: "benjamin.sitbon" <benjamin.sibon@etu.hesge.ch> Date: Mon, 24 May 2021 17:59:34 +0200 Subject: [PATCH] =?UTF-8?q?rajout=20de=20l'interdiction=20de=20recommencer?= =?UTF-8?q?=20la=20partie=20lorsque=20toutes=20les=20roues=20son=20d=C3=A9?= =?UTF-8?q?j=C3=A0=20active?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- display.c | 7 ------- one_armed_bandit.c | 12 +++++++++++- one_armed_bandit.h | 5 ++++- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/display.c b/display.c index 94371c5..7272bbd 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 a66b782..ca4bf73 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 13e36f0..ca932cf 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 -- GitLab