Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 07-26-2005, 07:09 AM   #1
Solid State Member
 
Yado8's Avatar
 
Join Date: May 2005
Posts: 7
Send a message via MSN to Yado8
Default help with program :)

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!
__________________

Yado8 is offline   Reply With Quote
Old 07-26-2005, 07:10 AM   #2
Solid State Member
 
Yado8's Avatar
 
Join Date: May 2005
Posts: 7
Send a message via MSN to Yado8
Default Re: help with program :)

oops - here r the includes:

#include <iostream.h>
#include <conio.h>
#include <dos.h>
__________________

Yado8 is offline   Reply With Quote
Old 07-26-2005, 10:06 AM   #3
Solid State Member
 
Yado8's Avatar
 
Join Date: May 2005
Posts: 7
Send a message via MSN to Yado8
Default Re: help with program :)

anyone??? plz?
Yado8 is offline   Reply With Quote
Old 07-26-2005, 10:29 AM   #4
Fully Optimized
 
UK31337's Avatar
 
Join Date: Feb 2005
Posts: 2,776
Default

What is this supposed to be?

I couldn't get it to compile.
__________________
Master of common sense. If you don't like it, stop reading.
UK31337 is offline   Reply With Quote
Old 07-26-2005, 10:33 AM   #5
Solid State Member
 
Yado8's Avatar
 
Join Date: May 2005
Posts: 7
Send a message via MSN to Yado8
Default Re: help with program :)

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(); )...
Yado8 is offline   Reply With Quote
Old 07-26-2005, 10:33 AM   #6
Daemon Poster
 
Tulsileaf's Avatar
 
Join Date: Jul 2004
Posts: 1,249
Default Re: help with program :)

I'm sorry, I'm too busy to read through your program. May be you can get some help from this site:
http://www.cpp-home.com/
__________________

__________________
(|141 73g ()7 (|33|/| 11143s| |_| z1|-|7 (|43s| |/|4> |_| |-|0|1
Tulsileaf is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 08:54 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0