tetris  final beta
A tetris implementation in C
Classes | Macros | Functions | Variables
main.c File Reference

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"
Include dependency graph for main.c:

Classes

struct  ttm
 structure for tetriminos More...
 

Macros

#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
 

Functions

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[])
 

Variables

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
 

Detailed Description

main part of the code

"ttm" is an abbreviation for "tetrimino".

Function Documentation

◆ canPrint()

int canPrint ( char  mat[TTM_WIDTH][TTM_WIDTH],
int  row,
int  col 
)

Determines ability to print tetrimino.

Parameters
matThe matrix of the tetrimino
[in]rowThe row of the tetrimino
[in]colThe 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]directionThe direction

◆ printTtm()

int printTtm ( char  mat[TTM_WIDTH][TTM_WIDTH],
int  row,
int  col 
)

put a tetrimino in the board

Parameters
[in]matThe matrix of the ttm
[in]rowThe row in board
[in]colThe col in board
Returns
1 if it's not possible to print the ttm, 0 else

◆ randTtm()

int randTtm ( void  )

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
[in]rowThe line

◆ rotateCur()

int rotateCur ( void  )

rotate current tetrimino

Returns
0 if current tetrimino successfully rotated, 1 otherwise

◆ wholeLine()

int wholeLine ( int  row)

determines if line is whole

Parameters
[in]rowThe line in the board
Returns
1 if the line is whole, 0 otherwise

Variable Documentation

◆ ITtm

char ITtm[][TTM_WIDTH]
Initial value:
= {
{ 0, 0, 1, 0 },
{ 0, 0, 1, 0 },
{ 0, 0, 1, 0 },
{ 0, 0, 1, 0 }
}

◆ JTtm

char JTtm[][TTM_WIDTH]
Initial value:
= {
{ 0, 0, 0, 0 },
{ 0, 0, 1, 0 },
{ 0, 0, 1, 0 },
{ 0, 1, 1, 0 }
}

◆ LTtm

char LTtm[][TTM_WIDTH]
Initial value:
= {
{ 0, 0, 0, 0 },
{ 0, 1, 0, 0 },
{ 0, 1, 0, 0 },
{ 0, 1, 1, 0 }
}

◆ OTtm

char OTtm[][TTM_WIDTH]
Initial value:
= {
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
{ 0, 1, 1, 0 },
{ 0, 1, 1, 0 }
}

◆ STtm

char STtm[][TTM_WIDTH]
Initial value:
= {
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
{ 0, 1, 1, 0 },
{ 1, 1, 0, 0 }
}

◆ TTtm

char TTtm[][TTM_WIDTH]
Initial value:
= {
{ 0, 0, 0, 0 },
{ 0, 1, 1, 1 },
{ 0, 0, 1, 0 },
{ 0, 0, 0, 0 }
}

◆ ZTtm

char ZTtm[][TTM_WIDTH]
Initial value:
= {
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
{ 0, 1, 1, 0 },
{ 0, 0, 1, 1 }
}