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
6e78304a
Commit
6e78304a
authored
Oct 30, 2020
by
Yoann Bordin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Edited struct, added functions
parent
76f29de8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
124 additions
and
39 deletions
+124
-39
tetris-main.c
tetris-main.c
+26
-0
tetris-struct.c
tetris-struct.c
+71
-20
tetris-struct.h
tetris-struct.h
+27
-19
No files found.
tetris-main.c
View file @
6e78304a
#include "tetris-struct.h"
#include "tetris-struct.h"
#include "raylib.h"
#include <stdio.h>
int
main
(){
int
main
(){
const
int
screenWidth
=
1280
;
const
int
screenHeight
=
720
;
InitWindow
(
screenWidth
,
screenHeight
,
"Tetris"
);
SetTargetFPS
(
60
);
while
(
!
WindowShouldClose
()){
BeginDrawing
();
ClearBackground
(
RAYWHITE
);
EndDrawing
();
}
CloseWindow
();
Grid
grid
=
gridInit
();
while
(
!
gameOver
(
grid
)){
Piece
piece
=
pieceInit
();
while
(
canMove
(
piece
,
grid
)){
move
(
piece
);
}
addPieceToGrid
(
piece
,
grid
);
}
}
}
\ No newline at end of file
tetris-struct.c
View file @
6e78304a
...
@@ -4,43 +4,94 @@
...
@@ -4,43 +4,94 @@
Grid
gridInit
(){
Grid
gridInit
(){
Grid
g
;
Grid
g
;
g
.
matrix
=
calloc
(
g
.
width
,
sizeof
(
Square
*
));
g
.
grid
=
calloc
(
g
.
width
,
sizeof
(
Square
*
));
for
(
int
i
=
0
;
i
<
g
.
width
;
i
++
){
for
(
int
i
=
0
;
i
<
g
.
width
;
i
++
){
g
.
matrix
[
i
]
=
calloc
(
g
.
height
,
sizeof
(
Square
));
g
.
grid
[
i
]
=
calloc
(
g
.
height
,
sizeof
(
Square
));
}
}
return
g
;
}
g
.
matrix
=
squareMatrixInit
(
g
.
matrix
,
g
.
width
,
g
.
height
);
Piece
pieceInit
(){
Piece
p
;
p
.
squares
=
calloc
(
p
.
size
,
sizeof
(
Square
));
return
g
;
return
p
;
}
bool
gameOver
(
Grid
grid
){
return
height
(
grid
)
==
grid
.
height
;
}
int
height
(
Grid
g
){
int
height
=
0
;
int
height_p
;
for
(
int
i
=
0
;
i
<
g
.
width
;
i
++
){
height_p
=
heightColumn
(
g
.
grid
[
i
],
g
.
height
);
if
(
height_p
>
height
){
height
=
height_p
;
}
}
}
}
Square
squareInit
(
){
int
heightColumn
(
Square
*
column
,
int
size
){
Square
sq
;
int
height
=
0
;
sq
.
isFilled
=
false
;
int
y
;
return
sq
;
for
(
int
i
=
0
;
i
<
size
;
i
++
){
if
(
column
[
i
]
!=
NULL
){
y
=
column
[
i
]
->
position
[
1
];
if
(
y
+
1
>
height
){
height
=
y
+
1
;
}
}
}
return
height
;
}
}
Square
**
squareMatrixInit
(
Square
**
matrix
,
int
width
,
int
height
){
bool
canMove
(
Piece
piece
,
Grid
grid
){
for
(
int
i
=
0
;
i
<
width
;
i
++
){
int
x
,
y
;
for
(
int
j
=
0
;
j
<
height
;
j
++
){
matrix
[
i
][
j
]
=
squareInit
();
for
(
int
i
=
0
;
i
<
piece
.
size
;
i
++
){
if
(
!
canMoveSquare
(
piece
.
squares
[
i
],
grid
)){
return
false
;
}
}
}
}
return
matrix
;
return
true
;
}
}
Piece
pieceInit
(){
bool
canMoveSquare
(
Square
sq
,
Grid
g
){
Piece
p
;
int
x
=
sq
->
position
[
0
];
p
.
matrix
=
calloc
(
p
.
size
,
sizeof
(
Square
*
));
int
y
=
sq
->
position
[
1
];
return
(
y
!=
0
||
y
==
heightColumn
(
g
.
grid
[
x
],
g
.
height
));
}
for
(
int
i
=
0
;
i
<
p
.
size
;
i
++
){
void
move
(
Piece
piece
){
p
.
matrix
[
i
]
=
calloc
(
p
.
size
,
sizeof
(
Square
));
for
(
int
i
=
0
;
i
<
piece
.
size
;
i
++
){
moveSquare
(
piece
.
squares
[
i
]);
}
}
}
p
.
matrix
=
squareMatrixInit
(
p
.
matrix
,
p
.
size
,
p
.
size
);
void
moveSquare
(
Square
sq
){
sq
->
position
[
1
]
--
;
}
return
p
;
void
addPieceToGrid
(
Piece
piece
,
Grid
grid
){
for
(
int
i
=
0
;
i
<
piece
.
size
;
i
++
){
addSquareToGrid
(
piece
.
squares
[
i
],
grid
);
}
}
}
void
addSquareToGrid
(
Square
sq
,
Grid
g
){
int
x
=
sq
->
position
[
0
];
int
y
=
sq
->
position
[
1
];
g
.
grid
[
x
][
y
]
=
sq
;
}
\ No newline at end of file
tetris-struct.h
View file @
6e78304a
#include <stdbool.h>
#include <stdbool.h>
typedef
struct
Square
{
typedef
struct
square_s
{
int
size
;
int
*
position
;
bool
isFilled
;
int
coordSize
;
}
Square
;
int
color
;
typedef
struct
Grid
}
square_s
;
{
typedef
square_s
*
Square
;
int
height
=
20
;
int
width
=
10
;
Square
**
matrix
;
typedef
struct
Grid
{
}
G
rid
;
Square
**
g
rid
;
typedef
struct
Piece
int
width
;
{
int
height
;
int
size
=
4
;
}
Grid
;
Square
**
matrix
;
typedef
struct
Piece
{
Square
*
squares
;
int
size
;
}
Piece
;
}
Piece
;
Grid
gridInit
();
Grid
gridInit
();
Square
squareInit
();
Grid
initSquares
(
Grid
g
);
Square
**
squareMatrixInit
(
Square
**
matrix
,
int
width
,
int
height
);
Piece
pieceInit
();
Piece
pieceInit
();
void
down
();
bool
gameOver
(
Grid
grid
);
void
move
();
int
height
(
Grid
g
);
void
rotate
();
int
heightColumn
(
Square
*
column
,
int
size
);
\ No newline at end of file
bool
canMove
(
Piece
piece
,
Grid
grid
);
bool
canMoveSquare
(
Square
sq
,
Grid
g
);
void
move
(
Piece
piece
);
void
moveSquare
(
Square
sq
);
void
addPieceToGrid
(
Piece
piece
,
Grid
grid
);
void
addSquareToGrid
(
Square
sq
,
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