[Kde-games-devel] Re: Kplayer and game logic
Andreas Beckermann
b_mann at gmx.de
Mon Sep 1 02:47:04 CEST 2003
On Sunday 31 August 2003 22:58, cantabile wrote:
> Hi again,
> I'm on my way to create a computer player. The inherited class is called
> ComputerPlayer (I'm quite creative for class names :) ) and constructs
> like this:
>
> ComputerPlayer():KGameIO(){};
>
> When I try and create this player
Note that this is not a player, but a player IO only! You will still need a
KPlayer, which the IO operates on.
> in an initPlayers() method, calling a
> createIO method I get a program crash with this code :
[...]
>
> Here are the lines where I create a computer player
[...]
Which exactly is line 107 where the crash happens?
Also it seems to me that you call createIO() from your KGame::createPlayer()
implementation. I don't think this is necessary. Usually you will add players
like this:
MyPlayer* player = new MyPlayer;
player->setName(i18n("Me"));
KGameMouseIO* io = new KGameMouseIO(...);
connect(io, SIGNAL(...), this, SLOT(...)); // connect mouseevent
player->addGameIO(io);
mKGame->addPlayer(player);
This is of course an example for adding a local (human) player. A computer
player would be the same, but you replace KGameMouseIO by a different IO.
KGame::createPlayer() will get called when starting a network game - it
creates the non-local players on other clients. They should not contain a IO
(as you cannot control a non-local player).
> I noticed, though, that I must cast(1) computer to KPlayer* because
You cast a KGameIO derived class to KPlayer? This must crash as soon as KGame
tries to access this "KPlayer".
> addPlayer(KGameIO*) isn't available. Would it be the soure of my problem
> here ? Is there another way to add this specific player?
See above - you usually first create the KPlayer (-derived) class, and then
add you gameIO there.
> Thanks.
CU
Andi
More information about the kde-games-devel
mailing list