Nov 26, 2009

Tetris Sourcode - Making Tetris with C/C++

free web hosting
Open Discussion > MODERATED AREA > Computers > Programming Languages > C/C++ Programming

Tetris Sourcode - Making Tetris with C/C++

.hack//GU
Please help me, I have an assignment to make a tetris-like game in C/C++.
Anyone could help me with the source code?

I've thought the algorithm to make a 2-D matrix, but in the end all I can make is only the one I've attached.

So, please anyone who knows how to make this one to help me.
Thank you in advance. sad.gif

(Attachment: Tetris2.TXT should be Tetris2.CPP to edit in C++)

Comment/Reply (w/o sign-up)

osknockout
Woah. I couldn't even compile that one. (Probably because I don't have the identical headers to yours, I'm sure I even have a copy of dos.h) Mind commenting through the file? I mean, I'm probably one of the last people who should say this, but it's really necessary sometimes. Especially when you're talking to a public who has no clue what useX is used for or why it equals 41 instead of 42 biggrin.gif

So yeah, please comment through it. Otherwise it'd take us a lot longer than it should to find a problem and you'd get less people to help you.

Comment/Reply (w/o sign-up)

.hack//GU
QUOTE(osknockout @ Apr 4 2007, 12:03 AM) *
Woah. I couldn't even compile that one. (Probably because I don't have the identical headers to yours, I'm sure I even have a copy of dos.h) Mind commenting through the file? I mean, I'm probably one of the last people who should say this, but it's really necessary sometimes. Especially when you're talking to a public who has no clue what useX is used for or why it equals 41 instead of 42 biggrin.gif

So yeah, please comment through it. Otherwise it'd take us a lot longer than it should to find a problem and you'd get less people to help you.


Well, I thought my code itself is a failure. I'll take another glimpse through the codes tonight. Anyway, I've acquired some tetris code but all of it are in graphics.h. Anyone know where I can get tetris code without graphics.h?

 

 

 


Comment/Reply (w/o sign-up)

alex7h3pr0gr4m3r
I made a tetris game! It was part of a spoof i made of DOS in c++ feel free to use my source if you can find the tetris sourcecode inside the OS.

I looked through the file and found some lines of code that start with //START PONG and // END PONG so i think all the code is there. This should be all of it:

CODE
//START PONG
void linecall(int line,int computerlocal,int plrlocal,int ballx,int bally)
{
    int loopvar;
    if(computerlocal+3>=line&&computerlocal<=line)
{
    cout << "|";
    }else{
        cout << " ";
    }
if(bally==line)
{
loopvar=1;
while(loopvar<ballx)
{
    cout << " ";
    loopvar++;
}
cout << "O";
while(loopvar<40)
{
    cout << " ";
    loopvar++;
}
}else{
    cout << "                                        ";
}
if(plrlocal+3>=line&&plrlocal<=line)
{
    cout << "|";
}
cout << "\n";
}
void playpong(int diff)
{
system("cls");
//10 rows
//paddles 4
//40 cols
//dwnleft-1
//dwnright-2
//upleft-3
//upright-4
int computerlocal=1;
int plrlocal=1;
int ballx=20;
int bally=5;
int balldir=1;
int gamerun=1;
int loopvar;

while(gamerun==1)
{
//linecall
    loopvar=1;
    while(loopvar<=10)
    {
linecall(loopvar,computerlocal,plrlocal,ballx,bally);
loopvar++;
    }
    if(ballx>=41||ballx<=0)
    {
        if(ballx>=41)
        {
        gamerun=0;
        cout << "You Lost!\n";
        }else{
        gamerun=0;
        cout << "You Won!\n";
        }
    }else{
        //computer ai
        if((balldir==1)||(balldir==3))
        {
        if(((rand()%diff)*20)>(rand()%50))
        {
        if(computerlocal+2<bally)
        {
            computerlocal++;
        }
        if(computerlocal+2>bally)
        {
            computerlocal--;
        }
        }
        }
        if(computerlocal<1)
        {
            computerlocal=1;
        }
        if(computerlocal>7)
        {
            computerlocal=7;
        }
    //move ball
        if(ballx==40&&plrlocal+3>=bally&&plrlocal<=bally)
        {
            if(balldir==2)
            {
                balldir=1;
            }
            if(balldir==4)
            {
                balldir=3;
            }
        }
        if(ballx==1&&computerlocal+3>=bally&&computerlocal<=bally)
        {
            if(balldir==3)
            {
                balldir=4;
            }
            if(balldir==1)
            {
                balldir=2;
            }
        }
    if(bally==0)
    {
        if(balldir==3)
        {
            balldir=1;
        }
        if(balldir==4)
        {
            balldir=2;
        }
    }
    if(bally==10)
    {
        if(balldir==1)
        {
            balldir=3;
        }
        if(balldir==2)
        {
            balldir=4;
        }
    }
    if(balldir==1)
    {
        bally++;
        ballx--;
    }
    if(balldir==2)
    {
        bally++;
        ballx++;
    }
    if(balldir==3)
    {
        bally--;
        ballx--;
    }
    if(balldir==4)
    {
        bally--;
        ballx++;
    }
clock_t endwait;
endwait = clock () + .02 * CLK_TCK;
while (clock() < endwait) {}
    //key listen
    int ch;
    if(kbhit())
    {
  ch = getch();
   if ( ch == 0 || ch == 224 )
  {
    ch = 256 + getch();
  }
  if(ch==328)
  {
      plrlocal--;
  }
   if(ch==336)
  {
      plrlocal++;
  }
  if(ch==27)
  {
system("cls");
cout << "Pong game ended.\n";
gamerun=0;
  }
  if(gamerun==1)
  {
     system("cls");
  }
    }else{
            clock_t endwait;
endwait = clock () + .02 * CLK_TCK;
while (clock() < endwait) {}
system("cls");
    }
        if(plrlocal<1)
        {
            plrlocal=1;
        }
        if(plrlocal>7)
        {
            plrlocal=7;
        }
}
}
}
//END PONG


But this code might need the rest of the program to work.. I don't know, its been ages since ive looked at it. Good luck

Comment/Reply (w/o sign-up)

alex7h3pr0gr4m3r
Um... My bad... I totaly confused tetris with pong there for a second... Wow... Sorry. Well if you want the code for a pong game, there it is... hehe

Comment/Reply (w/o sign-up)

Blessed
what C++ compyler / program are you guż using

i whant to learn how to make some litle app and stuff.

can you guy's give me some links biggrin.gifbiggrin.gif

Comment/Reply (w/o sign-up)

bin1011111
if ur using windows i'd go with http://www.bloodshed.net/devcpp.html, ive been using it for years and have no complaints

Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : Tetris Sourcode Making Tetris Cc


    Looking for tetris, sourcode, making, tetris, c, c,

Searching Video's for tetris, sourcode, making, tetris, c, c,
See Also,
advertisement


Tetris Sourcode - Making Tetris with C/C++

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com