Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
MLOD Mini Projet
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yoann Bordin
MLOD Mini Projet
Commits
1d27412a
Commit
1d27412a
authored
Nov 01, 2020
by
Yoann Bordin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug fixes
parent
69fbf0f9
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
89 additions
and
39 deletions
+89
-39
settings.json
.vscode/settings.json
+5
-0
tetris-graph.c
tetris-graph.c
+16
-14
tetris-graph.h
tetris-graph.h
+2
-2
tetris-main.c
tetris-main.c
+8
-5
tetris-main.exe
tetris-main.exe
+0
-0
tetris-struct.c
tetris-struct.c
+52
-16
tetris-struct.h
tetris-struct.h
+6
-2
No files found.
.vscode/settings.json
0 → 100644
View file @
1d27412a
{
"files.associations"
:
{
"*.m"
:
"c"
}
}
\ No newline at end of file
tetris-graph.c
View file @
1d27412a
...
@@ -13,30 +13,32 @@ void InitDisplay(){
...
@@ -13,30 +13,32 @@ void InitDisplay(){
DrawLine
(
BORDER_GAP
,
BORDER_GAP
,
BORDER_GAP
,
posY
,
RAYWHITE
);
DrawLine
(
BORDER_GAP
,
BORDER_GAP
,
BORDER_GAP
,
posY
,
RAYWHITE
);
DrawLine
(
BORDER_GAP
,
posY
,
posX
,
posY
,
RAYWHITE
);
DrawLine
(
BORDER_GAP
,
posY
,
posX
,
posY
,
RAYWHITE
);
DrawLine
(
posX
,
posY
,
posX
,
BORDER_GAP
,
RAYWHITE
);
DrawLine
(
posX
+
1
,
posY
,
posX
+
1
,
BORDER_GAP
,
RAYWHITE
);
}
}
void
drawSquare
(
Square
sq
){
void
drawSquare
(
int
x
,
int
y
,
Color
color
){
if
(
sq
!=
NULL
){
DrawRectangle
(
BORDER_GAP
+
x
*
SQUARE_SIZE
,
DrawRectangle
(
BORDER_GAP
+
sq
->
posX
*
SQUARE_SIZE
,
BORDER_GAP
+
y
*
SQUARE_SIZE
,
BORDER_GAP
+
sq
->
posY
*
SQUARE_SIZE
,
SQUARE_SIZE
,
SQUARE_SIZE
,
SQUARE_SIZE
,
SQUARE_SIZE
,
color
);
sq
->
color
);
}
}
}
void
drawPiece
(
Piece
p
){
void
drawPiece
(
Piece
p
){
for
(
int
i
=
0
;
i
<
p
.
size
;
i
++
){
for
(
int
i
=
0
;
i
<
p
.
size
;
i
++
){
drawSquare
(
p
.
squares
[
i
]);
drawSquare
(
p
.
squares
[
i
]
->
posX
,
p
.
squares
[
i
]
->
posY
,
p
.
squares
[
i
]
->
color
);
}
}
}
}
void
displayGrid
(
Grid
g
){
void
drawGrid
(
Grid
g
){
for
(
int
i
=
0
;
i
<
g
.
width
;
i
++
){
for
(
int
x
=
0
;
x
<
g
.
width
;
x
++
){
for
(
int
j
=
0
;
j
<
g
.
height
;
j
++
){
for
(
int
y
=
0
;
y
<
g
.
height
;
y
++
){
drawSquare
(
g
.
grid
[
i
][
j
]);
if
(
g
.
grid
[
x
][
y
]
!=
NULL
){
drawSquare
(
x
,
y
,
g
.
grid
[
x
][
y
]
->
color
);
}
//drawSquare(g.grid[x][y]);
}
}
}
}
}
}
...
...
tetris-graph.h
View file @
1d27412a
...
@@ -12,8 +12,8 @@
...
@@ -12,8 +12,8 @@
void
InitDisplay
();
void
InitDisplay
();
void
InitGame
();
void
InitGame
();
void
drawSquare
(
Square
sq
);
void
drawSquare
(
int
x
,
int
y
,
Color
color
);
void
drawPiece
(
Piece
p
);
void
drawPiece
(
Piece
p
);
void
d
isplay
Grid
(
Grid
g
);
void
d
raw
Grid
(
Grid
g
);
void
gameInstructions
(
Grid
grid
,
Piece
*
pList
);
void
gameInstructions
(
Grid
grid
,
Piece
*
pList
);
\ No newline at end of file
tetris-main.c
View file @
1d27412a
...
@@ -37,8 +37,12 @@ int main(void){
...
@@ -37,8 +37,12 @@ int main(void){
}
}
// Déplacements saisis au clavier
// Déplacements saisis au clavier
if
(
IsKeyPressed
(
KEY_LEFT
))
movePieceHztl
(
p
,
-
1
);
if
(
IsKeyPressed
(
KEY_LEFT
)
&&
canMoveHztl
(
grid
,
p
,
-
1
)){
if
(
IsKeyPressed
(
KEY_RIGHT
))
movePieceHztl
(
p
,
1
);
movePieceHztl
(
p
,
-
1
);
}
if
(
IsKeyPressed
(
KEY_RIGHT
)
&&
canMoveHztl
(
grid
,
p
,
1
)){
movePieceHztl
(
p
,
1
);
}
if
(
IsKeyPressed
(
KEY_A
))
rotatePiece
(
p
,
false
);
if
(
IsKeyPressed
(
KEY_A
))
rotatePiece
(
p
,
false
);
if
(
IsKeyPressed
(
KEY_Z
))
rotatePiece
(
p
,
true
);
if
(
IsKeyPressed
(
KEY_Z
))
rotatePiece
(
p
,
true
);
...
@@ -52,16 +56,15 @@ int main(void){
...
@@ -52,16 +56,15 @@ int main(void){
isFixed
=
true
;
isFixed
=
true
;
removeLinesIfCompleted
(
grid
);
removeLinesIfCompleted
(
grid
);
}
}
}
}
drawPiece
(
p
);
drawPiece
(
p
);
drawGrid
(
grid
);
displayGrid
(
grid
);
displayGrid
(
grid
);
frameCounter
++
;
frameCounter
++
;
EndDrawing
();
EndDrawing
();
}
}
...
...
tetris-main.exe
View file @
1d27412a
No preview for this file type
tetris-struct.c
View file @
1d27412a
...
@@ -279,6 +279,18 @@ void movePieceVert(Piece piece, int shift){
...
@@ -279,6 +279,18 @@ void movePieceVert(Piece piece, int shift){
DrawText
(
text3
,
450
,
20
,
20
,
RED
);
DrawText
(
text3
,
450
,
20
,
20
,
RED
);
}
}
bool
canMoveHztl
(
Grid
g
,
Piece
p
,
int
moveNum
){
for
(
int
i
=
0
;
i
<
p
.
size
;
i
++
){
int
x
=
p
.
squares
[
i
]
->
posX
+
moveNum
;
int
y
=
p
.
squares
[
i
]
->
posY
;
if
(
x
<
0
||
x
>=
g
.
width
||
g
.
grid
[
x
][
y
]
!=
NULL
){
return
false
;
}
}
return
true
;
}
void
moveSquareHztl
(
Square
sq
,
int
shift
){
void
moveSquareHztl
(
Square
sq
,
int
shift
){
sq
->
posX
+=
shift
;
sq
->
posX
+=
shift
;
}
}
...
@@ -289,29 +301,53 @@ void movePieceHztl(Piece p, int shift){
...
@@ -289,29 +301,53 @@ void movePieceHztl(Piece p, int shift){
}
}
}
}
void
removeLine
(
Grid
g
,
int
lineIndex
){
void
removeLinesIfCompleted
(
Grid
grid
){
int
i
=
lineIndex
;
bool
isLineCompleted
;
while
(
i
>
0
){
i
--
;
int
y
=
0
;
while
(
y
<
grid
.
height
){
isLineCompleted
=
true
;
for
(
int
x
=
0
;
x
<
grid
.
width
;
x
++
){
if
(
grid
.
grid
[
x
][
y
]
==
NULL
){
isLineCompleted
=
false
;
}
}
for
(
int
j
=
0
;
j
<
g
.
width
;
j
++
){
if
(
isLineCompleted
){
g
.
grid
[
j
][
i
+
1
]
=
g
.
grid
[
j
][
i
];
int
lineToRemove
=
y
;
//free
for
(
int
x
=
0
;
x
<
grid
.
width
;
x
++
){
free
(
grid
.
grid
[
x
][
lineToRemove
]);
}
//shift
for
(
int
x
=
0
;
x
<
grid
.
width
;
x
++
){
for
(
int
i
=
lineToRemove
;
i
>
0
;
i
--
){
grid
.
grid
[
x
][
i
]
=
grid
.
grid
[
x
][
i
-
1
];
}
}
//initTop
for
(
int
x
=
0
;
x
<
grid
.
width
;
x
++
){
grid
.
grid
[
x
][
0
]
=
malloc
(
sizeof
(
square_s
));
grid
.
grid
[
x
][
0
]
=
NULL
;
}
}
}
for
(
int
k
=
0
;
k
<
g
.
width
;
k
++
)
{
else
{
g
.
grid
[
k
][
0
]
=
NULL
;
y
++
;
}
}
}
}
}
}
void
removeLinesIfCompleted
(
Grid
grid
){
void
displayColumn
(
Square
*
line
,
int
index
,
int
height
){
for
(
int
k
=
0
;
k
<
grid
.
height
;
k
++
){
for
(
int
y
=
0
;
y
<
height
;
y
++
){
int
j
=
0
;
if
(
line
[
y
]
!=
NULL
){
while
(
j
<
grid
.
width
&&
grid
.
grid
[
j
][
k
]
!=
NULL
){
DrawText
(
"1"
,
500
+
30
*
index
,
20
+
30
*
y
,
20
,
RAYWHITE
);
j
++
;
}
}
if
(
j
==
grid
.
width
){
}
removeLine
(
grid
,
k
);
}
}
void
displayGrid
(
Grid
g
){
for
(
int
x
=
0
;
x
<
g
.
width
;
x
++
){
displayColumn
(
g
.
grid
[
x
],
x
,
g
.
height
);
}
}
}
}
\ No newline at end of file
tetris-struct.h
View file @
1d27412a
...
@@ -61,8 +61,12 @@ void displayPieceList(Piece* pList, int size);
...
@@ -61,8 +61,12 @@ void displayPieceList(Piece* pList, int size);
void
moveSquareVert
(
Square
sq
,
int
shift
);
void
moveSquareVert
(
Square
sq
,
int
shift
);
void
movePieceVert
(
Piece
piece
,
int
shift
);
void
movePieceVert
(
Piece
piece
,
int
shift
);
bool
canMoveHztl
(
Grid
g
,
Piece
p
,
int
moveNum
);
void
moveSquareHztl
(
Square
sq
,
int
shift
);
void
moveSquareHztl
(
Square
sq
,
int
shift
);
void
movePieceHztl
(
Piece
p
,
int
shift
);
void
movePieceHztl
(
Piece
p
,
int
shift
);
void
removeLine
(
Grid
g
,
int
lineIndex
);
void
removeLinesIfCompleted
(
Grid
grid
);
void
removeLinesIfCompleted
(
Grid
grid
);
\ No newline at end of file
void
displayColumn
(
Square
*
line
,
int
index
,
int
height
);
void
displayGrid
(
Grid
g
);
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment