diff --git a/one_armed_bandit.c b/one_armed_bandit.c index 07155b8eb28aecc815adf347f8719f7546bd7e53..f8a8e3731ea4a631f0a0f6b055967837ea0e4368 100644 --- a/one_armed_bandit.c +++ b/one_armed_bandit.c @@ -19,7 +19,7 @@ int main() { - + int wheel_turn = 0; pthread_t threads[4]; machine mas; @@ -59,6 +59,7 @@ int main() break; case SDLK_SPACE: wait_key_release(); + stop_wheel(&mas.wheels[wheel_turn]); break; case SDLK_s: wait_key_release(); diff --git a/wheel.c b/wheel.c index 465fce06208c3812ec09714aa54da053bf0d003e..35169063aa4fe34d56c108ef38c2d035af5fac52 100644 --- a/wheel.c +++ b/wheel.c @@ -22,10 +22,7 @@ void *wheel_func(void *param){ printf("\nwheel_func"); wheel* id = (wheel *) (param); - while(1){ - // for(double a = 0; a<8.0; a +=0.1){ - - // wheel_spin(a,id.current_px,id.speed); + while(id->speed > 0){ wheel_spin_1_tick(id); wait_until(wheel_delay_ms(*id)); } @@ -42,13 +39,13 @@ int wheel_spin_1_tick(wheel* this){ int wheel_delay_ms(wheel this){ if (this.speed) { return this.speed * 2; - } return 2; + } } -int stop_wheel(wheel this){ - while (this.current_px % 128 != 32) { // 32 is the offset to center the item +int stop_wheel(wheel* this){ + while (this->current_px % 128 != 32) { // 32 is the offset to center the item wheel_spin_1_tick(&this); - wait_until(wheel_delay_ms(this)); + wait_until(wheel_delay_ms(*this)); } - this.speed = 0; + this->speed = 0; } diff --git a/wheel.h b/wheel.h index bfa751e3257a20bcc571daab9c9df5d0a2cd7aea..f66b13ec1b462e534989f97e8359dfae8ccc7a15 100644 --- a/wheel.h +++ b/wheel.h @@ -15,7 +15,7 @@ int get_current_px(); void *wheel_func(void *param); int wheel_spin_1_tick(wheel* this); int wheel_delay_ms(wheel this); -int stop_wheel(wheel this); +int stop_wheel(wheel* this); #endif