Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Maze_Game
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlAmeri Rawan
Maze_Game
Commits
68575b6e
Commit
68575b6e
authored
3 years ago
by
IKHRICHI Soumaya
Browse files
Options
Downloads
Patches
Plain Diff
modification dans le trap.c fait avec Rawan
parent
6313ccdd
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
main
+0
-0
0 additions, 0 deletions
main
main.c
+5
-4
5 additions, 4 deletions
main.c
trap.c
+89
-39
89 additions, 39 deletions
trap.c
trap.h
+22
-2
22 additions, 2 deletions
trap.h
with
116 additions
and
45 deletions
main
+
0
−
0
View file @
68575b6e
No preview for this file type
This diff is collapsed.
Click to expand it.
main.c
+
5
−
4
View file @
68575b6e
...
@@ -3,10 +3,10 @@
...
@@ -3,10 +3,10 @@
int
main
()
int
main
()
{
{
trap_t
trap1
=
{
"
t
he capital of
france"
,
"paris
"
};
trap_t
trap1
=
{
"
T
he capital of
Yemen"
,
"Sanaa"
,
"Riyadh"
,
"Aden
"
};
trap_t
trap2
=
{
"light bulb inventor"
,
"tesla"
};
//
trap_t trap2= {"light bulb inventor","tesla"};
trap_t
trap3
=
{
"the origine of the frensh language"
,
"latin"
};
//
trap_t trap3={"the origine of the frensh language","latin"};
trap_t
trap4
=
{
"Who won the world cup in 2006"
,
"italy"
};
//
trap_t trap4={"Who won the world cup in 2006","italy"};
int
nbl
=
0
,
nbc
=
0
,
i
=
0
;
int
nbl
=
0
,
nbc
=
0
,
i
=
0
;
char
**
map
=
lire_map
(
"ressources/maze_map.txt"
);
//lire le fichier
char
**
map
=
lire_map
(
"ressources/maze_map.txt"
);
//lire le fichier
taille_map
(
"ressources/maze_map.txt"
,
&
nbl
,
&
nbc
);
taille_map
(
"ressources/maze_map.txt"
,
&
nbl
,
&
nbc
);
...
@@ -18,6 +18,7 @@ int main()
...
@@ -18,6 +18,7 @@ int main()
init_sdl
(
&
fenetre
,
&
ecran
,
SCREENW
,
SCREENH
);
init_sdl
(
&
fenetre
,
&
ecran
,
SCREENW
,
SCREENH
);
// Charger l’images
// Charger l’images
apply_texture
(
walls
,
ecran
);
apply_texture
(
walls
,
ecran
);
FontPosition_t
fontPos
=
initFontPosition
();
SDL_Event
event
;
SDL_Event
event
;
// Boucle principale
// Boucle principale
while
(
!
player
->
gameover
){
while
(
!
player
->
gameover
){
...
...
This diff is collapsed.
Click to expand it.
trap.c
+
89
−
39
View file @
68575b6e
#include
"trap.h"
#include
"trap.h"
trap_t
*
init_trap
(
trap_t
trap1
,
trap_t
trap2
,
trap_t
trap3
,
trap_t
trap4
){
FontPosition_t
initFontPosition
(){
FontPosition_t
fontPos
;
for
(
int
i
=
0
;
i
<
4
;
i
++
){
fontPos
.
position
[
i
].
h
=
TRAPHT
;
fontPos
.
position
[
i
].
w
=
TRAPWT
;
if
(
i
==
0
){
fontPos
.
position
[
i
].
x
=
60
;
fontPos
.
position
[
i
].
y
=
30
;
}
else
{
fontPos
.
position
[
i
].
x
=
60
;
fontPos
.
position
[
i
].
y
=
30
+
fontPos
.
position
[
i
].
y
;
}
}
//fontPos.font= TTF_OpenFont("ressources/arial.ttf",20);
return
fontPos
;
}
SDL_Texture
*
createText
(
SDL_Renderer
*
renderer
,
TTF_Font
*
font
,
const
char
*
text
,
SDL_Color
color
,
SDL_Rect
*
position
){
SDL_Surface
*
text_img
=
TTF_RenderText_Solid
(
font
,
text
,
color
);
SDL_Texture
*
text_tex
=
SDL_CreateTextureFromSurface
(
renderer
,
text_img
);
position
->
x
=
60
;
position
->
y
=
30
;
position
->
w
=
text_img
->
w
;
position
->
h
=
text_img
->
h
;
SDL_FreeSurface
(
text_img
);
return
text_tex
;
}
/*
void initialiser_text_surf(FontPosition_t fontPos,SDL_Renderer* renderer,trap_t trap){
SDL_Color color_question={255,255,255,255};
SDL_Color color_answer={255,0,255,0};
fontPos.textSurfQ = TTF_RenderText_Solid(fontPos.font,trap.question,color_question);
fontPos.textTextureQ= SDL_CreateTextureFromSurface(renderer,fontPos.textSurfQ);
for (int i = 0; i < 3; i++)
{
fontPos.textSurfR[i] = TTF_RenderText_Solid(fontPos.font,trap.answers[i],color_answer);
fontPos.textTextureR[i]= SDL_CreateTextureFromSurface(renderer,fontPos.textSurfR[i]);
}
}*/
trap_t
*
init_trap
(
trap_t
trap1
,
trap_t
trap2
,
trap_t
trap3
){
trap_t
*
traps
=
malloc
(
4
*
sizeof
(
trap_t
));
trap_t
*
traps
=
malloc
(
4
*
sizeof
(
trap_t
));
traps
[
0
]
=
trap1
;
traps
[
0
]
=
trap1
;
traps
[
1
]
=
trap2
;
traps
[
1
]
=
trap2
;
traps
[
2
]
=
trap3
;
traps
[
2
]
=
trap3
;
traps
[
3
]
=
trap4
;
return
traps
;
return
traps
;
}
}
void
showTrap
(
trap_t
trap
,
player_t
*
player
,
SDL_Event
*
event
){
void
showTrap
(
trap_t
trap
,
player_t
*
player
,
SDL_Event
*
event
){
int
px
=
0
,
py
=
0
;
//int px=fontPos.position[j+1].x,py=fontPos.position[j+1].y;
//SDL_Surface* textSurfQ;
SDL_Init
(
SDL_INIT_VIDEO
);
SDL_Init
(
SDL_INIT_VIDEO
);
SDL_Window
*
fenetre
1
=
SDL_CreateWindow
(
"Trap"
,
SDL_WINDOWPOS_UNDEFINED
,
SDL_WINDOWPOS_UNDEFINED
,
400
,
600
,
SDL_WINDOW_OPENGL
);
SDL_Window
*
fenetre
=
SDL_CreateWindow
(
"Trap"
,
SDL_WINDOWPOS_UNDEFINED
,
SDL_WINDOWPOS_UNDEFINED
,
400
,
600
,
SDL_WINDOW_OPENGL
);
SDL_Renderer
*
renderer
1
=
SDL_CreateRenderer
(
fenetre
1
,
-
1
,
0
);
SDL_Renderer
*
renderer
=
SDL_CreateRenderer
(
fenetre
,
-
1
,
0
);
TTF_Init
();
TTF_Init
();
TTF_Font
*
font
=
TTF_OpenFont
(
"ressources/arial.ttf"
,
2
0
);
TTF_Font
*
font
=
TTF_OpenFont
(
"ressources/arial.ttf"
,
2
4
);
SDL_Color
color
=
{
255
,
255
,
255
,
255
};
SDL_Color
color
=
{
255
,
255
,
255
,
255
};
SDL_Surface
*
textSurf
;
SDL_Rect
*
position
;
textSurf
=
TTF_RenderText_Solid
(
font
,
trap
.
question
,
color
);
SDL_Rect
*
position1
;
SDL_Texture
*
textTexture
=
SDL_CreateTextureFromSurface
(
renderer1
,
textSurf
);
SDL_Rect
*
position2
;
SDL_Rect
textRect
=
{
30
,
30
,
textSurf
->
w
,
textSurf
->
h
};
//textSurfQ = TTF_RenderText_Solid(font,trap.question,color);
SDL_FreeSurface
(
textSurf
);
SDL_Texture
*
textTextureQ
=
createText
(
renderer
,
font
,
trap
.
question
,
color
,
position
);
TTF_CloseFont
(
font
);
SDL_Texture
*
textTextureR
=
createText
(
renderer
,
font
,
trap
.
answers
,
color
,
position1
);
SDL_Texture
*
textTextureR1
=
createText
(
renderer
,
font
,
trap
.
answers
,
color
,
position2
);
//SDL_FreeSurface(textSurfQ);
//textSurfQ = TTF_RenderText_Solid(font,trap.answers,color);
//SDL_Texture* textTextureR= SDL_CreateTextureFromSurface(renderer,textSurfQ);
//SDL_FreeSurface(textSurfQ);
TTF_CloseFont
(
font
);
bool
end
=
false
;
bool
end
=
false
;
const
char
*
reponse_j
;
const
char
*
r
;
//SDL_SetRenderDrawColor(renderer1,0,0,225,225);
while
(
!
end
){
while
(
!
end
){
// apply_text(renderer1,0,0,100,200,trap.question,font);
while
(
SDL_PollEvent
(
event
))
while
(
SDL_PollEvent
(
event
))
{
{
if
(
event
->
type
==
SDL_QUIT
){
if
(
event
->
type
==
SDL_QUIT
){
end
=
true
;
end
=
true
;
}
}
if
(
event
->
type
==
SDL
_KEYDOWN
){
if
(
event
->
key
.
keysym
.
sym
==
SDL
K_ESCAPE
){
//si on appui sur la touche Echap, on quitte le jeu.
if
(
event
->
key
.
keysym
.
sym
==
SDLK_ESCAPE
){
//si on appui sur la touche Echap, on quitte le jeu.
end
=
true
;
end
=
true
;
}
}
if
(
event
->
type
==
SDL_MOUSEBUTTONDOWN
){
if
(
event
->
key
.
keysym
.
sym
==
SDLK_KP_ENTER
){
if
(
event
->
button
.
state
==
SDL_PRESSED
){
if
(
strcmp
(
reponse_j
,
trap
.
answer
)
==
0
){
if
(
((
event
->
button
.
x
>=
px
)
&&
(
event
->
button
.
x
<=
(
px
+
TRAPWT
)))
&&
((
event
->
button
.
y
>=
py
)
&&
(
event
->
button
.
y
<=
(
py
+
TRAPHT
)))
){
player
->
score
+=
1
0
;
player
->
score
+=
5
0
;
end
=
true
;
end
=
true
;
}
else
{
}
else
{
player
->
lives
--
;
player
->
lives
--
;
}
}
}
}
else
{
r
=
SDL_GetKeyName
(
event
->
key
.
keysym
.
sym
);
reponse_j
+=*
r
;
textSurf
=
TTF_RenderText_Solid
(
font
,
reponse_j
,
color
);
}
}
}
}
}
SDL_RenderCopy
(
renderer
,
textTextureQ
,
NULL
,
position
);
SDL_RenderCopy
(
renderer1
,
textTexture
,
NULL
,
&
textRect
);
SDL_RenderCopy
(
renderer
,
textTextureR
,
NULL
,
position1
);
SDL_RenderPresent
(
renderer1
);
SDL_RenderCopy
(
renderer
,
textTextureR
,
NULL
,
position2
);
SDL_UpdateWindowSurface
(
fenetre1
);
SDL_RenderPresent
(
renderer
);
SDL_UpdateWindowSurface
(
fenetre
);
}
}
SDL_DestroyTexture
(
textTextureQ
);
SDL_DestroyTexture
(
textTextureR
);
SDL_DestroyTexture
(
textTextureR1
);
// Quitter SDL
// Quitter SDL
SDL_DestroyRenderer
(
renderer
1
);
SDL_DestroyRenderer
(
renderer
);
SDL_DestroyWindow
(
fenetre
1
);
SDL_DestroyWindow
(
fenetre
);
SDL_Quit
();
SDL_Quit
();
TTF_Quit
();
TTF_Quit
();
}
}
\ No newline at end of file
void
clean_trap
(
trap_t
*
trap
){
free
(
trap
);
}
/*
void clean_FontPosition(FontPosition_t fontPos){
SDL_FreeSurface(fontPos.textSurfQ);
SDL_DestroyTexture(fontPos.textTextureQ);
SDL_FreeSurface(fontPos.textSurfR);
SDL_DestroyTexture(fontPos.textTextureR[i]);
TTF_CloseFont(fontPos.font);
}*/
This diff is collapsed.
Click to expand it.
trap.h
+
22
−
2
View file @
68575b6e
...
@@ -3,13 +3,33 @@
...
@@ -3,13 +3,33 @@
#include
"graphics.h"
#include
"graphics.h"
#include
"sdl2-ttf-light.h"
#include
"sdl2-ttf-light.h"
#define TRAPHT 60
#define TRAPWT 120
typedef
struct
trap_s
{
typedef
struct
trap_s
{
const
char
*
question
;
const
char
*
question
;
const
char
*
answer
;
const
char
*
answers
;
const
char
*
answers1
;
const
char
*
answers2
;
}
trap_t
;
}
trap_t
;
trap_t
*
init_trap
(
trap_t
trap1
,
trap_t
trap2
,
trap_t
trap3
,
trap_t
trap4
);
typedef
struct
FontPosition_s
{
SDL_Rect
position
[
4
];
/*
SDL_Surface* textSurfQ;
SDL_Surface* textSurfR[3];
SDL_Texture* textTextureQ;
SDL_Texture* textTextureR[3];
TTF_Font* font;*/
}
FontPosition_t
;
FontPosition_t
initFontPosition
();
void
initialiser_text_surf
(
FontPosition_t
fontPos
,
SDL_Renderer
*
renderer
,
trap_t
trap
);
SDL_Texture
*
createText
(
SDL_Renderer
*
renderer
,
TTF_Font
*
font
,
const
char
*
text
,
SDL_Color
color
,
SDL_Rect
*
position
);
trap_t
*
init_trap
(
trap_t
trap1
,
trap_t
trap2
,
trap_t
trap3
);
void
showTrap
(
trap_t
trap
,
player_t
*
player
,
SDL_Event
*
event
);
void
showTrap
(
trap_t
trap
,
player_t
*
player
,
SDL_Event
*
event
);
void
clean_trap
(
trap_t
*
trap
);
void
clean_FontPosition
(
FontPosition_t
fontPos
);
//void check_Trap(player_t* player,trap_t trap,char** map,int* i,walls_t* walls);
//void check_Trap(player_t* player,trap_t trap,char** map,int* i,walls_t* walls);
#endif
#endif
\ No newline at end of file
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