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)