[Kde-games-devel] Re: Kplayer and game logic

cantabile cantabile.03 at wanadoo.fr
Mon Sep 1 22:19:12 CEST 2003


Hum, I think I understand better the classes objectives this time :
KPlayer defines a player - anything being a player, be it a net player,
a local player, a computer, whatever. And KGameIO defines the way this
player interacts with the game - mouse for example or game logic for the
'puter.

So, all I need to do is create an inherited class from KGAMEIO and
overwrite/overload needed methods, if any, and I'm OK.
Am  I right ?

Actually, this is good C++ logic : providing common interface for
various players/situations. Good job, indeed!

I'll try to correct my program tomorrow or Wednesday and send results
(and probably new questions) here.

Thx again Andreas.


Le lun 01/09/2003 à 04:41, Andreas Beckermann a écrit :
> On Monday 01 September 2003 03:57, cantabile wrote:
> > Hi, Andreas
> >
> > Here are the lines where I create and instantiate the players.
> >
> > void KMatchesDoc::initPlayers()
> > {
> >         MatchesPlayer *player;
> >         player=(MatchesPlayer *)createPlayer(1, KGameIO::MouseIO,
> > false);
> >         player->setUserId(1);
> >         player->setName(i18n("You"));
> >         addPlayer(player);
> >
> >         ComputerPlayer *computer;
> >         computer=(ComputerPlayer *)createPlayer(2, KGameIO::ComputerIO,
> > false);
> 
> Isn't ComputerPlayer a KGameIO? Then this won't work, as createPlayer() 
> returns a KPlayer*. Replace these lines by 
> KPlayer* computer = createPlayer(2, KGameIO::ComputerIO);
> 
> But I believe you don't need the rtti of createPlayer() anyway, sou you could 
> use any random number instead of 2, but this depends on your implementation. 
> 
> >         player->setUserId(2);
> >         player->setName(i18n("Computer"));
> >         addPlayer(computer);
> 
> If ComputerPlayer is not a KPlayer, then this won't work. As described above - 
> use a KPlayer* instead of a ComputerPlayer*.
> 
> > KPlayer *KMatchesDoc::createPlayer(int rtti,int io,bool isvirtual)
> > {
> >         KPlayer *player;
> >         switch(rtti) {
> >         case 1:
> >                 player=(KPlayer *)new MatchesPlayer();
> >                 break;
> >         case 2:
> >                 player=(KPlayer *)new ComputerPlayer();
> >                 break;
> >         }
> >         if (!isvirtual) {
> >                 createIO(player,(KGameIO::IOMode)io);
> >         }
> >         return player;
> > }
> 
> Looks fine for me, assuming ComputerPlayer and MatchesPlayer are both derived 
> from KPlayer. But you may probably want to use a single class, instead of two 
> different classes for the players.
> 
> > void KMatchesDoc::createIO(KPlayer *player,KGameIO::IOMode io)
> [...]
> Looks fine.
> 
> > My players are :
> >
> > MatchesPlayer(): KPlayer(); //human (public inheritance)
> > ComputerPlayer(): KGameIO(); // computer (public inheritance)
> 
> I think you got me wrong (please re-read my previous mail - I already told you 
> what is going wrong).
> 
> A KPlayer should be used to store the data of a player. Think of it as your 
> actual player.
> A KGameIO should be used to control the input/output of your player only. 
> Think of it as the "brain" of your player.
> 
> A KPlayer has a name, has the money (assuming your game uses money), ...
> A KGameIO does not have a name. It always belongs to exactly one KPlayer 
> object, which provides all these.
> 
> > Human rtti returns 1 and computer 2.
> 
> Usually you won't need the KPlayer::rtti(), as you'll use the same class for 
> all players. Only your KGameIO::rtti()'s will differ.
> 
> > Is there something wrong in this ?
> 
> Yes, you should use
> MyPlayer : public KPlayer
> instead of MatchesPlayer and ComputerPlayer
> and also
> ComputerPlayerIO : public KGameIO
> 
> You use a KGameMouseIO if you create a human player and you use 
> ComputerPlayerIO if you create a computer player.
> 
> > BTW, isn't there something strange in "player=(KPlayer *)new
> > ComputerPlayer();" since ComputerPlayer inherits from KGameIO ?
> 
> As said im my previous mail - it is _definitely_, 100%, *absolutely* wrong. It 
> must crash sooner or later.
> 
> > Thanks for your patient help, Andeas.
> > Cheers.
> 
> CU
> Andi
> _______________________________________________
> kde-games-devel mailing list
> kde-games-devel at mail.kde.org
> http://mail.kde.org/mailman/listinfo/kde-games-devel



More information about the kde-games-devel mailing list