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

Andreas Beckermann b_mann at gmx.de
Wed Aug 27 20:17:12 CEST 2003


On Monday 25 August 2003 14:45, cantabile wrote:
> Hello again, dearest list (and precious too!),
>
> My problem today is with KPlayer logic.
>
> I'm trying to program a little 'matches' game program. The players can
> select as many matches in one single row as then wish to, but they loose
> if they're left with one match.
> The selection works ok, so far. I just switch the sprite frame in case
> it is selected, and the match is thus grayed.
>
> The problems :
>
>> I want to add a computer player, and I didn't catch what to do (and
> above all WHERE to do it). I have the game logic ready. What I need is
> HOW to create a computer player and where do I write it's code.

You are using KGame/KPlayer?
Then you should do your computer player in a KGameIO derived class, _not_ in 
KPlayer. Then you can easily switch between network and computer player, 
which is the reason behind it all.
Furthermore it is easier :)

You can use KGameIO::sendInput() to send your moves - for both, AI and human 
players.
For the AI it is probably easier to use KGameIO::signalPrepareTurn() directly, 
as long as you are doing a turn based game.

>> For my 'human' player, I can't use the standard playerInput function,
> because clicking on a match isn't the turn end for the player. He may
> want to select several matches, then suppress them.
>
> I imagined this could be done with a 'play' button in my toolbar.

I do not fully understand what you mean here. Your player is meant to select 
several matching buttons and then he has to send these information?
Well, then you can use KGameIO::sendPlayerInput() and are done. 
If you need more advanced logic on which player is the "next" player who is 
allowed to do something than what KGame defaults provide (you will usually 
need), then you can use KGame::setGameSequence(). You will most probably want 
to subclass KGameSequence and rewrite nextPlayer() to fit your needs.

> So, where can I put code, in order to trigger player change when my
> player clicks a button ? A button has no KGAmeIO*, neither QDataStream&
> nor QmouseEvent...So I cannot stream the move and consequently
> playerInput isn't triggered...

You could use the QPushButton::clicked() signal and connect a slot to it, 
which streams the button ID (aka number)...

> Don't know if this clear.
> I studied M. Henri great tutorial, and he has been of great help to me
> already but I think I need some simpler game structure to start with.
>
> Well, any help much welcomed, dear list ;)
>
> Cheers.
> Cantabile.

CU
Andi


More information about the kde-games-devel mailing list