hello,
i have a code of the game called 'TRON' in c++
an example of the same game in c++ here http://www.mediafire.com/?vnkslb3x0qbd3q0
((i tried to upload it here but it says invalid every time))
i can't understand some partss of the code so please geys help me understanding the code
#include <conio.h>
# include <windows.h>
for two lines, is it for this code?
double speed = 200; //this decreasing a bit only every loop
now, the most dificult part for me
COORD posP1, posP2, bonus;//COORD is a variable with X and Y attribute
bool show_bonus = false, exit = false;//show bonus to show only 1 bonus at the same time, exit is to exit from game when we press ESC + ENTER
unsigned char ch1, ch2;
int dp1 = 0, dp2 = 0, dp1_old, dp2_old; //dp = direction of player, old_dp is used when the player stops(taking bonus) and continues(to continue which direction)
bonus.X = -1; //X position of bonus
bonus.Y = -1; //Y position of bonus
textcolor(3);
drawRect(0,3,79,46,'+'); //draws rectangle
for (int i = 0; i < 79; i++){
track[i][0] = 'w'; //assigns that rectangle as wall
track[i][1] = 'w';
track[i][2] = 'w';
track[i][3] = 'w';
track[i][49] = 'w';
}
for (int i = 0; i < 49; i++){
track[0][i] = 'w';
track[79][i] = 'w';
}
posP1.X = 15 + rand() % 35; //position of player 1
posP1.Y = 10 + rand() % 25;
do
posP2.X = 15 + rand() % 35;
while(posP1.X == posP2.X); //until position player 1 is not equal player 2
do
posP2.Y = 10 + rand() % 25;
while(posP1.Y == posP2.Y);//until position player 1 is not equal player 2
dp1 = 1 + rand() % 4; //rand() % X means = random number between 0-X
dp2 = 1 + rand() % 4;
while (true){
if (show_bonus == false){ //if there is no bonus showing, try to show (not certain) there is probability...
bonus.X = rand();
if (bonus.X % 29 == 0){
bonus.X = 1 + rand() % 78;
bonus.Y = 4 + rand() % 48;
if (track[bonus.X][bonus.Y] == ' '){
track[bonus.X][bonus.Y] = '?';
gotoxy(bonus.X,bonus.Y);
cout << "?";
show_bonus = true;
}
}
}
can you please explain to me by lines
see the lase code here
if (dp1 < 5){
if (track[posP1.X][posP1.Y] == '1'){ //checking for collision
gotoxy(25,1);
cout << "Player 1 hit himself ";
explode(posP1.X, posP1.Y, 'x');
Sleep(1000);
gotoxy(25,2);
cout << "Press Enter to Continue... ";
getEnter();
return;
}else if (track[posP1.X][posP1.Y] == '2'){
gotoxy(25,1);
cout << "Player 1 hit Player 2";
explode(posP1.X, posP1.Y, 'x');
Sleep(1000);
gotoxy(25,2);
cout << "Press Enter to Continue... ";
getEnter();
return;
}else if (track[posP1.X][posP1.Y] == 'w'){ //w = wall
gotoxy(25,1);
cout << "Player 1 hit Wall";
explode(posP1.X, posP1.Y, 'x');
Sleep(1000);
gotoxy(25,2);
cout << "Press Enter to Continue... ";
getEnter();
return;
}else if (track[posP1.X][posP1.Y] == '?'){
gotoxy(25,1);
cout << "Player 1 found BONUS..!! ";
dp1_old = dp1;
dp1 = 25;
track[posP1.X][posP1.Y] = '1';
show_bonus = false;
}else{
track[posP1.X][posP1.Y] = '1';
}
}
i can't understand
if (track[posP1.X][posP1.Y] == '1')
why is it '1'? and in the second time is '2' and then 'w'
and here,
explode(posP1.X, posP1.Y, 'x');
what this code do?
waiting for you geys :)