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

cantabile cantabile.03 at wanadoo.fr
Mon Sep 1 04:57:32 CEST 2003


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);
        player->setUserId(2);
        player->setName(i18n("Computer"));
        addPlayer(computer);
}

// Player settings and methods
bool KMatchesDoc::playerInput(QDataStream &msg,KPlayer *player)
{
	// not yet implemented
        return true;
}

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;
}

void KMatchesDoc::createIO(KPlayer *player,KGameIO::IOMode io)
{
        if (!player)
                return;
        switch(io) {
        case (KGameIO::MouseIO):
                KGameMouseIO *mouse_input;
                mouse_input=new KGameMouseIO(boardView);
                // Mouse input  not connected yet
                player->addGameIO(mouse_input);
                break;
        case (KGameIO::ComputerIO):
		KGameComputerIO *computer_input;
		computer_input=new KGameComputerIO();
                // Computer input not connected yet
                player->addGameIO(computer_input);
		break;
        // other KGameIO modes won't be used
	default:
                break;
        }
}

My players are :

MatchesPlayer(): KPlayer(); //human (public inheritance)
ComputerPlayer(): KGameIO(); // computer (public inheritance)

Human rtti returns 1 and computer 2.

Is there something wrong in this ?

BTW, isn't there something strange in "player=(KPlayer *)new
ComputerPlayer();" since ComputerPlayer inherits from KGameIO ?

Thanks for your patient help, Andeas.
Cheers.








More information about the kde-games-devel mailing list