delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/26/04:51:52

Message-ID: <c=GB%a=_%p=Indigo_Active_Vi%l=CRIANLARICH-970326094400Z-522@crianlarich.Indigo>
From: Robert Humphris <r DOT humphris AT indigo-avs DOT com>
To: "'djgpp AT delorie DOT com'" <djgpp AT delorie DOT com>,
"'Lee Simons'"
<lee AT dialin DOT co DOT uk>
Subject: RE: C++ Class Help
Date: Wed, 26 Mar 1997 09:44:00 -0000
Encoding: 51 TEXT

You wrote:
>
>I'm writing a football game, and as in real life football there are lots of
>players.
>I'm going to create and object array of a class Player.  This class will
>hold information about the players, such as skill, speed etc.  It will also
>hold the players position in xyz space and it's personal functions, for
>telling the program what its skill is, shooting, passing, and player AI.
>
>I want to declare the array, like so:
>
>Player data[1000]; // 1000 players in data array =)
>
>But, the problem is, I don't want to use loads of functions to set the
>player's data. Like:
>
>data[0].SetSkill(100);
>data[0].SetSpeed(99);
>
>etc..
>
>I would like to be able to do a:
>
>data[0](100, 99)

Well the answer is something along the lines of this
class player : public footballObject
{
protected:
	BYTE nSkill, nSpeed;
public:
	player();
	~player();

	void setStats( BYTE skill, BYTE speed );
};

you would then instanciate the array thus:

void main()
{
   player paData[1000];

   ...

  paData[i].setStats( 100, 90 );

}

does that help at all?
>

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019