main part of the code
More...
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "main.h"
#include "sdl.h"
#include "debugging.h"
#include "events.h"
#include "load_graphics.h"
|
|
#define | HEIGHT 18 |
| |
|
#define | WIDTH 12 |
| |
|
#define | BLK_SIZE 32 |
| |
|
#define | SCREEN_HEIGHT BLK_SIZE * HEIGHT |
| |
|
#define | SCREEN_WIDTH BLK_SIZE * WIDTH |
| |
|
#define | TTM_WIDTH 4 |
| |
|
|
int | setBackColor (SDL_Renderer *renderer, SDL_Color color) |
| |
| int | canPrint (char mat[TTM_WIDTH][TTM_WIDTH], int row, int col) |
| | Determines ability to print tetrimino. More...
|
| |
| int | rotateCur (void) |
| | rotate current tetrimino More...
|
| |
| int | wholeLine (int row) |
| | determines if line is whole More...
|
| |
| int | randTtm (void) |
| | change current tetrimino to a random tetrimino More...
|
| |
| int | printTtm (char mat[TTM_WIDTH][TTM_WIDTH], int row, int col) |
| | put a tetrimino in the board More...
|
| |
|
void | downTtm (void) |
| | down current tetrimino from 1 row
|
| |
|
void | fullDownTtm (void) |
| | down current tetrimino at the bottom
|
| |
| void | moveTtm (int direction) |
| | move current tetrimino to left or right More...
|
| |
| void | removeLine (int row) |
| | Removes blocks from line and down the above ones. More...
|
| |
| void | refreshScreen (void) |
| | refresh screen More...
|
| |
|
void | game (void) |
| | the place that contains game loop
|
| |
|
int | init (SDL_Window *window) |
| |
|
int | main (int argc, char *argv[]) |
| |
|
| char | ITtm [][TTM_WIDTH] |
| |
| char | LTtm [][TTM_WIDTH] |
| |
| char | JTtm [][TTM_WIDTH] |
| |
| char | TTtm [][TTM_WIDTH] |
| |
| char | OTtm [][TTM_WIDTH] |
| |
| char | ZTtm [][TTM_WIDTH] |
| |
| char | STtm [][TTM_WIDTH] |
| |
|
SDL_Color | white = { 255, 255, 255, 255 } |
| |
|
SDL_Color | black = { 0, 0, 0, 0 } |
| |
|
struct ttm | curTtm |
| |
|
char | board [HEIGHT][WIDTH] = { 0 } |
| |
|
long | score = 0 |
| |
|
SDL_Texture * | BLK |
| |
|
SDL_Renderer * | renderer |
| |
main part of the code
"ttm" is an abbreviation for "tetrimino".
◆ canPrint()
| int canPrint |
( |
char |
mat[TTM_WIDTH][TTM_WIDTH], |
|
|
int |
row, |
|
|
int |
col |
|
) |
| |
Determines ability to print tetrimino.
- Parameters
-
| mat | The matrix of the tetrimino |
| [in] | row | The row of the tetrimino |
| [in] | col | The column of the tetrimino |
- Returns
- 1 if able to print, 0 otherwise.
◆ moveTtm()
| void moveTtm |
( |
int |
direction | ) |
|
move current tetrimino to left or right
- Parameters
-
| [in] | direction | The direction |
◆ printTtm()
| int printTtm |
( |
char |
mat[TTM_WIDTH][TTM_WIDTH], |
|
|
int |
row, |
|
|
int |
col |
|
) |
| |
put a tetrimino in the board
- Parameters
-
| [in] | mat | The matrix of the ttm |
| [in] | row | The row in board |
| [in] | col | The col in board |
- Returns
- 1 if it's not possible to print the ttm, 0 else
◆ randTtm()
change current tetrimino to a random tetrimino
- Returns
- 0 if current tetrimino successfully changed, 1 otherwise
◆ refreshScreen()
| void refreshScreen |
( |
void |
| ) |
|
refresh screen
remove everything from screen, refresh with content of board matrix, put current tetrimino at right place
◆ removeLine()
| void removeLine |
( |
int |
row | ) |
|
Removes blocks from line and down the above ones.
- Parameters
-
◆ rotateCur()
rotate current tetrimino
- Returns
- 0 if current tetrimino successfully rotated, 1 otherwise
◆ wholeLine()
determines if line is whole
- Parameters
-
| [in] | row | The line in the board |
- Returns
- 1 if the line is whole, 0 otherwise
◆ ITtm
Initial value:= {
{ 0, 0, 1, 0 },
{ 0, 0, 1, 0 },
{ 0, 0, 1, 0 },
{ 0, 0, 1, 0 }
}
◆ JTtm
Initial value:= {
{ 0, 0, 0, 0 },
{ 0, 0, 1, 0 },
{ 0, 0, 1, 0 },
{ 0, 1, 1, 0 }
}
◆ LTtm
Initial value:= {
{ 0, 0, 0, 0 },
{ 0, 1, 0, 0 },
{ 0, 1, 0, 0 },
{ 0, 1, 1, 0 }
}
◆ OTtm
Initial value:= {
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
{ 0, 1, 1, 0 },
{ 0, 1, 1, 0 }
}
◆ STtm
Initial value:= {
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
{ 0, 1, 1, 0 },
{ 1, 1, 0, 0 }
}
◆ TTtm
Initial value:= {
{ 0, 0, 0, 0 },
{ 0, 1, 1, 1 },
{ 0, 0, 1, 0 },
{ 0, 0, 0, 0 }
}
◆ ZTtm
Initial value:= {
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
{ 0, 1, 1, 0 },
{ 0, 0, 1, 1 }
}