/*************************************************************************** lskatdoc.cpp - description ------------------- begin : Tue May 2 15:47:11 CEST 2000 copyright : (C) 2000 by Martin Heni email : martin@heni-online.de ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ // include files for TQt #include #include #include #include #include #include #include // include files for TDE #include // application specific includes #include "lskatdoc.h" #include "lskat.h" #include "lskatview.h" #include TQPtrList *LSkatDoc::pViewList = 0L; LSkatDoc::LSkatDoc(TQWidget *parent, const char *name) : TQObject(parent, name) { int i; if(!pViewList) { pViewList = new TQPtrList(); } pViewList->setAutoDelete(true); isrunning=0; wasgame=false; initrandom(); // Allow translation of playernames /* names[0]=i18n("Alice"); names[1]=i18n("Bob"); */ for (i=0;i<14;i++) cardvalues[i]=0; cardvalues[(int)Ace]=11; cardvalues[(int)Ten]=10; cardvalues[(int)King]=4; cardvalues[(int)Queen]=3; cardvalues[(int)Jack]=2; /* computerlevel=2; playedby[1]=KG_INPUTTYPE_INTERACTIVE; playedby[0]=KG_INPUTTYPE_PROCESS; // playedby[1]=KG_INPUTTYPE_INTERACTIVE; */ isintro=1; server=false; port=7432; host=""; Name=""; remoteswitch=false; ClearStats(); } LSkatDoc::~LSkatDoc() { } void LSkatDoc::addView(LSkatView *view) { pViewList->append(view); } void LSkatDoc::removeView(LSkatView *view) { pViewList->remove(view); } void LSkatDoc::setAbsFilePath(const TQString &filename) { absFilePath=filename; } const TQString &LSkatDoc::getAbsFilePath() const { return absFilePath; } void LSkatDoc::setTitle(const TQString &_t) { title=_t; } const TQString &LSkatDoc::getTitle() const { return title; } void LSkatDoc::InitMove(LSkatView *sender,int player,int x,int y) { LSkatView *w; if(pViewList) { for(w=pViewList->first(); w!=0; w=pViewList->next()) { if(w!=sender) w->InitMove(player,x,y); } } } void LSkatDoc::slotUpdateAllViews(LSkatView *sender) { LSkatView *w; if(pViewList) { for(w=pViewList->first(); w!=0; w=pViewList->next()) { if(w!=sender) w->repaint(); } } } void LSkatDoc::UpdateViews(int mode) { LSkatView *w; if (IsIntro()) return ; if(pViewList) { for(w=pViewList->first(); w!=0; w=pViewList->next()) { if (mode & UPDATE_STATUS) w->updateStatus(); } } } bool LSkatDoc::saveModified() { return true; } void LSkatDoc::closeDocument() { deleteContents(); } bool LSkatDoc::newDocument(TDEConfig * /*config*/,TQString path) { int res; modified=false; absFilePath=TQDir::homeDirPath(); title=i18n("Untitled"); if (global_debug>1) printf("path=%s\n",path.latin1()); res=LoadBitmap(path); if (res==0) return false; return true; } bool LSkatDoc::LoadGrafix(TQString path) { int res; res=LoadCards(cardPath); if (res==0) return false; res=LoadDeck(deckPath); if (res==0) return false; return true; } bool LSkatDoc::SetCardDeckPath(TQString deck,TQString card) { bool update=false; if (!deck.isNull() && deck!=deckPath) { update=true; deckPath=deck; LoadDeck(deckPath); } if (!card.isNull() && card!=cardPath) { update=true; cardPath=card; LoadCards(cardPath); } return update; } bool LSkatDoc::openDocument(const TQString &filename, const char * /*format*/ /*=0*/) { TQFileInfo fileInfo(filename); title=fileInfo.fileName(); absFilePath=fileInfo.absFilePath(); ///////////////////////////////////////////////// // TODO: Add your document opening code here ///////////////////////////////////////////////// modified=false; return true; } bool LSkatDoc::saveDocument(const TQString & /*filename*/, const char * /*format*/ /*=0*/) { ///////////////////////////////////////////////// // TODO: Add your document saving code here ///////////////////////////////////////////////// modified=false; return true; } void LSkatDoc::deleteContents() { ///////////////////////////////////////////////// // TODO: Add implementation to delete the document contents ///////////////////////////////////////////////// } // Called after game ends..give points to players void LSkatDoc::EvaluateGame() { if (score[0]+score[1]!=120) { printf("Warning: Score does not end up to 120\n"); } stat_games[0]++; stat_games[1]++; if (score[0]==score[1]) // drawn { stat_points[0]++; stat_points[1]++; } else if (score[0]>score[1]) { stat_won[0]++; stat_points[0]+=2; if (score[0]>=90) stat_points[0]++; // Schneider if (score[0]>=120) stat_points[0]++; // SChwarz } else { stat_won[1]++; stat_points[1]+=2; if (score[1]>=90) stat_points[1]++; // Schneider if (score[1]>=120) stat_points[1]++; // SChwarz } } void LSkatDoc::EndGame(bool aborted) { if (aborted) { stat_brk[0]++; stat_brk[1]++; } else { startplayer=1-began_game; } isrunning=0; wasgame=true; } void LSkatDoc::NewGame() { int i,r; int num[NO_OF_CARDS]; isintro=0; began_game=startplayer; for (i=0;i5) printf("Trump=%d\n",trump); if (random(8)==0) trump=Grand; // grand // Fast drawing of random cards for (i=0;i5) printf("Loading bitmaps\n"); for (i=0;ipw_gecos ); } config->setGroup("Parameter"); host=config->readEntry("host"); port=(unsigned short)config->readNumEntry("port",7432); procfile=config->readEntry("process",TQCString("lskatproc")); Name=config->readEntry("gamename"); names[0]=config->readEntry("Name1",i18n("Alice")); // names[1]=config->readEntry("Name2",i18n("Bob")); names[1]=config->readEntry("Name2", name.isEmpty() ? i18n("Bob") : name); // This is for debug and testing as you can run it from the CVS without // installing the carddecks ! // For the release version you can remove the aruments to the following two // functions !!!! cardPath=config->readPathEntry("cardpath", KCardDialog::getDefaultCardDir()); deckPath=config->readPathEntry("deckpath", KCardDialog::getDefaultDeck()); // Debug only if (global_debug>3) printf("cardPath=%s\ndeckPath=%s\n",cardPath.latin1(),deckPath.latin1()); startplayer=config->readNumEntry("Startplayer",0); if (startplayer>1 || startplayer<0) startplayer=0; began_game=startplayer; computerlevel=config->readNumEntry("Level",2); playedby[0]=(KG_INPUTTYPE)config->readNumEntry("Player1", (int)KG_INPUTTYPE_PROCESS); playedby[1]=(KG_INPUTTYPE)config->readNumEntry("Player2", (int)KG_INPUTTYPE_INTERACTIVE); stat_won[0]=config->readNumEntry("Stat1W",0); stat_won[1]=config->readNumEntry("Stat2W",0); stat_brk[0]=config->readNumEntry("Stat1B",0); stat_brk[1]=config->readNumEntry("Stat2B",0); stat_points[0]=config->readNumEntry("Stat1P",0); stat_points[1]=config->readNumEntry("Stat2P",0); stat_games[0]=config->readNumEntry("Stat1G",0); stat_games[1]=config->readNumEntry("Stat2G",0); } /** write config file */ void LSkatDoc::WriteConfig(TDEConfig *config) { config->setGroup("Parameter"); config->writeEntry("host",host); config->writeEntry("port",port); config->writeEntry("process",procfile); config->writePathEntry("tmppath",picpath); config->writeEntry("delpath",delpath); config->writeEntry("Name1",names[0]); config->writeEntry("Name2",names[1]); config->writeEntry("gamename",Name); config->writeEntry("Startplayer",startplayer); config->writeEntry("Level",computerlevel); config->writeEntry("Player1",int(playedby[0])); config->writeEntry("Player2",int(playedby[1])); config->writeEntry("Stat1W",stat_won[0]); config->writeEntry("Stat2W",stat_won[1]); config->writeEntry("Stat1B",stat_brk[0]); config->writeEntry("Stat2B",stat_brk[1]); config->writeEntry("Stat1P",stat_points[0]); config->writeEntry("Stat2P",stat_points[1]); config->writeEntry("Stat1G",stat_games[0]); config->writeEntry("Stat2G",stat_games[1]); config->writePathEntry("cardpath",cardPath); config->writePathEntry("deckpath",deckPath); config->sync(); } #include "lskatdoc.moc"