Git Product home page Git Product logo

basic-terminal-tetris's Introduction

TETRIS : Behind The Scenes

Introduction:

Explore the classic joy of Tetris with my C-coded implementation!
Discover the magic behind the falling blocks, intricate code, and timeless gaming experience.
Let's bring the nostalgia to life! ๐Ÿš€

a

Rough Explanation:

First, let's imagine the gameboard and its tetrimnoes as matrices:
a After that, we can easily imagine how the code of the tetrominoes would be:

/*This Struct is used to save information about the tetromino*/
typedef struct {
    char **boyut;
    int en;        
    int boy;      
    int x;          
    int y;         
    int tmp_en;
} Parca;

/*get a tetromino*/
Parca eldeParca;

/*define matrices for each tetromino*/
const Parca parcalar[PARCALAR] = {
    {(char *[]){(char[]){1,1,0},(char[]){1,1,0}}, 2, 2},                       
    {(char *[]){(char[]){1,0,0}}, 1, 1},                                      
    {(char *[]){(char[]){1,1,0},(char[]){0,1,1},(char[]){0,0,0}}, 3, 2},     
    {(char *[]){(char[]){1,1,1},(char[]){0,1,0},(char[]){0,0,0}}, 3, 2},    
    {(char *[]){(char[]){1,1,1},(char[]){0,0,0},(char[]){0,0,0}}, 3, 1},   
    {(char *[]){(char[]){1,1,1},(char[]){1,0,0},(char[]){0,0,0}}, 3, 2},  
};

So, how much easy it is to check the full rows and overwrite the above ones?
graph2

void skorlama( int r, int c, char oyun[r][c])
{
 int i, j, sum, count=0;
 for(i=0 ; i<r ; i++){
  sum = 0;
  for(j=0 ; j<c ; j++) {
   sum+=oyun[i][j];
  }
  if(sum == c ){
   count++;
   int l, k;
   for(k = i;k >=1;k--)
    for(l=0 ; l<c ; l++)
     oyun[k][l]=oyun[k-1][l];
   for(l=0 ; l<c ; l++)
    oyun[k][l]=0;
  }
 }
 skor += 100*count*i;
}

Last bu not least, we should print or render the board and the tetromino. As always, while 0s indicates empty areas 1s will indicate full ones.
However, The tetromino that the player contols should be displayed in a different way so we print it as a buffer. a

oid printleme( int r, int c, char oyun[r][c])
{
 char Buffer[r][c];
 int i, j;
    
    for ( i = 0; i < r; i++)
    {
        for ( j = 0; j < c; j++)
        {
            Buffer[i][j] = 0;
        }
    }
    
 for(i = 0; i < eldeParca.en ;i++){
  for(j = 0; j < eldeParca.en ; j++){
   if(eldeParca.boyut[i][j])
    Buffer[eldeParca.x+i][eldeParca.y+j] = eldeParca.boyut[i][j];
  }
 }
.
.
.
/*check main.c for the full code.*/

basic-terminal-tetris's People

Contributors

ahmedzeer avatar

Watchers

 avatar

basic-terminal-tetris's Issues

Rename.

Rename all Turkish variables and functions to the convenient equivalents in English.
Furthermore, don't forget to edit codes in README.md so both files can be consistent.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.