Mail Archives: djgpp/2000/05/28/12:15:28
From: | joel_hansell AT my-deja DOT com
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Array of home-made class, C++ game
|
Date: | Sun, 28 May 2000 15:54:49 GMT
|
Organization: | Deja.com - Before you buy.
|
Lines: | 88
|
Message-ID: | <8grfga$h00$1@nnrp2.deja.com>
|
NNTP-Posting-Host: | iw8.deja.com
|
X-Trace: | nnrp2.deja.com 959529289 17408 10.12.1.135 (28 May 2000 15:54:50 GMT)
|
X-Complaints-To: | usenet AT deja DOT com
|
NNTP-Posting-Date: | 28 May 2000 15:54:50 GMT
|
X-Article-Creation-Date: | Sun May 28 09:52:24 2000 GMT
|
X-Http-User-Agent: | Mozilla/4.0 (compatible; MSIE 5.0; Windows 98)
|
X-Http-Proxy: | 1.0 Telia:80 (Squid/2.2.STABLE4), 1.0 x66.deja.com:80 (Squid/1.1.22) for client 194.18.3.17, 194.18.2.243
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
In C++ class, I'm supposed to write a simple
slalom game. I'm trying to do this in an
expandable fasion, so I can add new levels,
players and such easily. I use a struct "Port"
for each gate the skier has to pass, and the
object "Game" stores the levels as an array of
such Ports. However, I don't think I'm doing this
quite right, since I keep getting a GFP when I
run it. It compiles ok under djgpp 2.03 (dos),
but at runtime I get the following:
Program exit code 255 (0x00ff)
Call frame traceback:
0x00001019 ???
stderr:
Exiting due to signal SIGSEGV
GPF at eip=00001019, error=2800
and then lots of assembly code. If it would be
helpful, I can post the whole of it.
I believe the problem lies in the "array of
Port". My teacher has so far been unable to
explain to us the use of pointers, so I guess
there should be some *'s and stuff in there...
I've isolated the troublesome code down to this:
#include <stdlib.h>
#include <time.h>
struct Port {
public:
int x, y, width;
};
class Game {
private:
int gameOver;
Port level[]; /* array of Ports, should this
be "Port* level[]" or even "Port[] level"?
Perhaps I must define the size of the array, like
"Port* level[5]"? /*
public:
Game();
void setup();
};
Game::Game() {
gameOver=0;
for (int i=0; i<5; i++) {
level[i].x=0;
level[i].y=0;
level[i].width=0;
}
}
void Game::setup() {
srand(time(NULL));
for (int i=0; i<5; i++) { /*Randomizes
the locations of the Ports, and places them 20
pixels below the last one*/
level[i].x=150+(random() % 200);
level[i].y=20+i*20;
level[i].width=30;
}
}
int main()
{
Game newgame;
newgame.setup();
return 0;
}
Could someone please tell me what would be the
proper way of declaring
the Port array?
--
--
Joel Hansell
http://home.bip.net/jolter
Sent via Deja.com http://www.deja.com/
Before you buy.
- Raw text -