PDA

View Full Version : need help in C++ tron game


bluebird1234
08-30-2010, 10:21 AM
I facing the problem with how to run two snake together.i need someone help me to solve the problem.thx
my problem is how to make the both snake move together.?
this is my code


#include <iostream>
#include "colortext.hpp"

using namespace std;

void snake()
{
int x =10;
int y =10;
gotoxy(x,y);
cout<<"@";
int move =3;
char key;

do
{ Sleep(100);
if (kbhit())
{
key=getch();
{
if (key == 'w')
move=1; //up
else if (key == 'a')
move=2; //left
else if (key == 'd')
move =3; //right
else if (key =='s')
move= 4; //down
}

}
switch(move)
{
case 1: y--; break;
case 2: x--; break;
case 3: x++; break;
case 4: y++; break;
}
gotoxy(x,y);
cout<<"@";
}while (key !=27);
}

void snake2()
{
int a =20;
int b =20;
gotoxy(a,b);
cout<<"#";
int move =3;
char key;

do
{ Sleep(100);
if (kbhit())
{
key=getch();
{
if (key == 'i')
move=1; //up
else if (key == 'j')
move=2; //left
else if (key == 'l')
move =3; //right
else if (key =='k')
move= 4; //down
}

}
switch(move)
{
case 1: b--; break;
case 2: a--; break;
case 3: a++; break;
case 4: b++; break;
}
gotoxy(a,b);
cout<<"#";
}while (key !=27);
}


int main ()
{
system("MODE CON: COLS=80 LINES=25");

snake();
snake2();

return 0;
}