help with program :)

Yado8

Solid State Member
Messages
7
hi,
I'm starting to learn c++ so I tryed to creat a ping-pong game - you know....

and for some reasen I have problem with the levels counter! I tryed to do if question that every time that the "score" can dvide with 100 the lelel will go one up...

here is the code:

#define X 78
#define Y 35
#define BALL *
#define MADKA 3
#define MADKA_LENGTH 12
#define COLORT YELLOW
#define C_BG BLACK
#define C_T YELLOW
#define STATUS_L 40
#define STATUSB_C GREEN
#define STATUST_C BLUE
#define C_MADKA YELLOW
#define C_GOVER BLUE
#define CT_GOVER MAGENTA
#define ADD_POINTS 10
#define LOOSE_POINTS 100


int x= X /2;
int y= Y /2;
int tx=1;
int ty=1;
int direction;
int madka=(X+MADKA_LENGTH)/2;
int score =0;
int level =1;

const int pause_length = 500000;
const int speed = 15;

void gvul();
bool onMadka();
void kbd();
void Another_game();
void status();
void srawStatusline();
void draw_madka();
void loose();
void moves();
void drawball();
void delay1();
void initscr();
void drawmadka();
void init();


void gvul()
{
if (madka+MADKA_LENGTH+1>=X)
madka -=1;
else if (madka < 2) {
madka +=1;
direction = 0;
} else
madka += direction;
}


bool onMadka ()
{
return (x>madka && x<madka+MADKA_LENGTH+1);
}

void kbd()
{
if (!(kbhit())) return;
switch (getch())
{
case '\0': switch (getch())
{
case 75: direction = -1; //left button
break;
case 77: direction = 1; //right button
break;
case 80: direction = 0; //down button
}
}
}

void Another_game()
{
char ch;

window(10, Y/2-2, X-10, Y/2+2);
textbackground(C_GOVER);
textcolor(CT_GOVER);
clrscr();
gotoxy (19,2);
cprintf (" G a m e O v e r !\n");
gotoxy( 18,4);
cprintf ("Do u want another game?\n");
clreol();
do
ch = getch();
while (ch != 'n' && ch != 'N' &&
ch != 'y' && ch != 'Y');
switch (ch)
{
case 'N':
case 'x':
case 'X':
case 'n': exit(1);
break;
case 'Y':
case 'y': init ();
break;
default : break;
}
}
void status()
{
if (onMadka() && y == Y-1)
score += ADD_POINTS;
if (score % 100 == 0)
level++;

if (score<0)
score =0;
gotoxy(1, STATUS_L);
cprintf("score: %04d | level: %04d |Yair :)", score, level);
clreol();
}

void drawStatusline()
{
gotoxy(1, STATUS_L);
clreol();
textcolor (STATUST_C);
textbackground (STATUSB_C);
status();
}

void draw_madka ()
{
gotoxy (madka, Y);
for (int i=0; i<MADKA_LENGTH; i++)
cprintf(MADKA);
//gvul ();
}

void loose()
{
if (y == Y && onMadka())
ty *=(-1);
else if (y == Y && !onMadka())
{
score -= LOOSE_POINTS;
Another_game();
}
}

/*
void move_madka_left()
{
gotoxy(madka-1,Y);
textcolor(COLORT);
cprintf(MADKA);
gotoxy(madka+MADKA_LENGTH,Y);
cprintf(" ");
}


void move_madka_right()
{
gotoxy(madka+MADKA_LENGTH+1,Y);
textcolor(COLORT);
cprintf(MADKA);
gotoxy(madka+1,Y);
cprintf(" ");
}*/

void moves()
{
loose(); //bottom
if (x == 1) // left
tx *=(-1);
if (x == X) // right
tx *=(-1);
if (y == 1) // top
ty *=(-1);
}


void drawball()
{
gotoxy (x,y);
cprintf(" ");
x +=tx;
y +=ty;
gotoxy (x,y);
textcolor (C_T);
cprintf(BALL);

/*
screen_grid[x][y]= ' ';
x +=tx;
y +=ty;
screen_grid[x][y] = 'O'; */
}


void delay1()
{
for (int i=0; i<(speed*pause_length); i++) int j = 1+i;
}

void initScr() {
textcolor(C_T);
textbackground(C_BG);
clrscr();
_directvideo = true;
_setcursortype(_NOCURSOR);
draw_madka();
drawball();
drawStatusline();
}

void drawMadka ()
{ textcolor(C_MADKA);
textbackground(C_BG);
gotoxy(1,Y);
for (int i=0; i<=X; i++)
if (i>= madka && i<=madka+MADKA_LENGTH)
cprintf (MADKA);
else
cprintf (" ");

}

void init() {
window(1,1,80,STATUS_L);
x= X /2;
y= Y /2;
tx=1;
ty=1;
direction = 0;
madka=(X+MADKA_LENGTH)/2;
initScr();
_setcursortype(_NOCURSOR);
}

void main()
{
init();
while (direction == 0)
kbd();
while (1)
{
gvul();
madka += direction;
drawMadka();
/*
switch (direction)
{
case 1: move_madka_right();
break;
case -1: move_madka_left();
break;
default:
break;
} */
kbd();
delay1 ();
drawball ();
moves ();
drawStatusline();

}

}

I realy need this help.... thnx!
 
oops - here r the includes:

#include <iostream.h>
#include <conio.h>
#include <dos.h>
 
aaa right - you can compile it only with the borland c++ any other compiler dont have this functions in there includes... it's also a big problem (like - gotoxy(); )...
 
Back
Top Bottom