Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Bandit_Manchot
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
benjamin.sitbon
Bandit_Manchot
Commits
6948091f
Commit
6948091f
authored
4 years ago
by
benjamin.sitbon
Browse files
Options
Downloads
Patches
Plain Diff
opörationnel
parent
b2bdd29a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
display.c
+6
-1
6 additions, 1 deletion
display.c
game.c
+4
-2
4 additions, 2 deletions
game.c
game.h
+1
-1
1 addition, 1 deletion
game.h
one_armed_bandit.c
+36
-6
36 additions, 6 deletions
one_armed_bandit.c
utilities.c
+1
-1
1 addition, 1 deletion
utilities.c
wheel.c
+2
-2
2 additions, 2 deletions
wheel.c
with
50 additions
and
13 deletions
display.c
+
6
−
1
View file @
6948091f
...
...
@@ -64,7 +64,12 @@ void *display_func(void *param){
SDL_Rect
coin_rect_pos
=
{
700
,
1020
,
coin_rect
.
w
,
coin_rect
.
h
};
SDL_RenderCopy
(
renderer
,
coin_texture
,
NULL
,
&
coin_rect_pos
);
for
(
int
i
=
0
;
i
<
4
;
i
++
){
for
(
int
i
=
0
;
i
<
mas
->
machine_wallet
;
i
++
){
SDL_Rect
coin_rect_pos
=
{
700
,
1010
-
10
*
i
,
coin_rect
.
w
,
coin_rect
.
h
};
SDL_RenderCopy
(
renderer
,
coin_texture
,
NULL
,
&
coin_rect_pos
);
}
for
(
int
i
=
0
;
i
<
mas
->
player_wallet
;
i
++
){
SDL_Rect
coin_rect_pos
=
{
700
,
400
-
10
*
i
,
coin_rect
.
w
,
coin_rect
.
h
};
SDL_RenderCopy
(
renderer
,
coin_texture
,
NULL
,
&
coin_rect_pos
);
}
...
...
This diff is collapsed.
Click to expand it.
game.c
+
4
−
2
View file @
6948091f
...
...
@@ -23,8 +23,10 @@ wheel create_wheel(int pixel,int speed){
}
void
new_machine
(
machine
*
mas
,
int
nb_wheels
){
void
new_machine
(
machine
*
mas
,
int
nb_wheels
,
int
player
,
int
machine
){
for
(
int
i
=
0
;
i
<
nb_wheels
;
i
++
)
{
mas
->
wheels
[
i
]
=
create_wheel
(
96
,
nb_wheels
-
i
);
mas
->
wheels
[
i
]
=
create_wheel
(
96
,
0
);
mas
->
player_wallet
=
player
;
mas
->
machine_wallet
=
machine
;
}
}
This diff is collapsed.
Click to expand it.
game.h
+
1
−
1
View file @
6948091f
...
...
@@ -21,6 +21,6 @@ int insert_coin();
int
set_wheel_speed
(
int
index
);
int
next_wheel
();
wheel
create_wheel
(
int
pixel
,
int
speed
);
void
new_machine
(
machine
*
mas
,
int
nb_wheels
);
void
new_machine
(
machine
*
mas
,
int
nb_wheels
,
int
player
,
int
machine
);
#endif
This diff is collapsed.
Click to expand it.
one_armed_bandit.c
+
36
−
6
View file @
6948091f
...
...
@@ -17,13 +17,26 @@
int
how_many_points
(
machine
mas
){
int
count
=
0
;
int
bubble
=
mas
.
wheels
[
0
].
current_px
;
for
(
int
i
=
0
;
i
<
WHEEL_NB
;
i
++
){
if
(
bubble
==
mas
.
wheels
[
i
].
current_px
)
count
+=
1
;
}
if
(
mas
.
wheels
[
1
].
current_px
==
mas
.
wheels
[
2
].
current_px
)
count
+=
1
;
return
count
;
}
int
main
()
{
int
wheel_turn
=
0
;
int
wheel_turn
=
4
;
bool
paid
=
false
;
pthread_t
threads
[
4
];
machine
mas
;
new_machine
(
&
mas
,
3
);
new_machine
(
&
mas
,
3
,
10
,
30
);
for
(
int
i
=
0
;
i
<
3
;
i
++
){
run_thread
(
&
threads
[
i
],
wheel_func
,
&
mas
.
wheels
[
i
]);
...
...
@@ -59,16 +72,33 @@ int main()
break
;
case
SDLK_SPACE
:
wait_key_release
();
if
(
wheel_turn
<
3
){
if
(
wheel_turn
<
WHEEL_NB
){
stop_wheel
(
&
mas
.
wheels
[
wheel_turn
]);
wheel_turn
+=
1
;
}
if
(
wheel_turn
==
WHEEL_NB
&&
paid
==
false
){
paid
=
true
;
int
howmany
=
how_many_points
(
mas
);
if
(
howmany
==
2
){
mas
.
player_wallet
+=
2
;
mas
.
machine_wallet
-=
2
;
}
else
if
(
howmany
>
2
){
mas
.
player_wallet
+=
mas
.
machine_wallet
/
2
;
mas
.
machine_wallet
-=
mas
.
machine_wallet
/
2
;
}
}
break
;
case
SDLK_s
:
wait_key_release
();
if
(
mas
.
player_wallet
>
0
){
paid
=
false
;
mas
.
player_wallet
-=
1
;
mas
.
machine_wallet
+=
1
;
wheel_turn
=
0
;
for
(
int
i
=
0
;
i
<
3
;
i
++
){
mas
.
wheels
[
i
].
speed
=
3
-
i
;
for
(
int
i
=
0
;
i
<
WHEEL_NB
;
i
++
){
mas
.
wheels
[
i
].
speed
=
WHEEL_NB
-
i
;
}
}
break
;
}
...
...
This diff is collapsed.
Click to expand it.
utilities.c
+
1
−
1
View file @
6948091f
...
...
@@ -64,7 +64,7 @@ void wait_key_release()
if
(
SDL_PollEvent
(
&
event
))
{
if
(
event
.
type
==
SDL_KEYUP
)
{
printf
(
"key released
\n
"
);
//
printf("key released\n");
break
;
}
}
...
...
This diff is collapsed.
Click to expand it.
wheel.c
+
2
−
2
View file @
6948091f
...
...
@@ -38,8 +38,8 @@ int wheel_delay_ms(wheel this){
}
int
stop_wheel
(
wheel
*
this
){
while
(
this
->
current_px
%
128
!=
128
-
32
)
{
// 32 is the offset to center the item
wheel_spin_1_tick
(
this
);
while
(
this
->
current_px
%
128
!=
96
)
{
// 32 is the offset to center the item
//
wheel_spin_1_tick(this);
wait_until
(
wheel_delay_ms
(
*
this
));
}
this
->
speed
=
0
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment