kwin4player.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                             KWin4Player
00003                             -------------------
00004     begin                :  August 2001
00005     copyright            : (C) |1995-2007 by Martin Heni
00006     email                : kde@heni-online.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 
00019 // KDE includes
00020 #include <kdebug.h>
00021 #include <kgamepropertyhandler.h>
00022 
00023 // Local includes
00024 #include "kwin4player.h"
00025 
00026 
00027 // Construct a player object
00028 KWin4Player::KWin4Player() : KPlayer()
00029 {
00030   // Register KGameProperties in KGame framework  
00031   int id;
00032   mStatus = 0;
00033   id=mWin.registerData(dataHandler(),KGamePropertyBase::PolicyDirty,QString("mWin"));
00034   id=mRemis.registerData(dataHandler(),KGamePropertyBase::PolicyDirty,QString("mRemis"));
00035   id=mLost.registerData(dataHandler(),KGamePropertyBase::PolicyDirty,QString("mLost"));
00036   id=mBrk.registerData(dataHandler(),KGamePropertyBase::PolicyDirty,QString("mBrk"));
00037   id=mAllWin.registerData(dataHandler(),KGamePropertyBase::PolicyDirty,QString("mAllWin"));
00038   id=mAllRemis.registerData(dataHandler(),KGamePropertyBase::PolicyDirty,QString("mAllRemis"));
00039   id=mAllLost.registerData(dataHandler(),KGamePropertyBase::PolicyDirty,QString("mAllLost"));
00040   id=mAllBrk.registerData(dataHandler(),KGamePropertyBase::PolicyDirty,QString("mAllBrk"));
00041 
00042   dataHandler()->setPolicy(KGamePropertyBase::PolicyDirty,false);
00043 
00044   // Clear all stats (they will be loaded from the config file later on)
00045   resetStats();
00046   connect(this,SIGNAL(signalPropertyChanged(KGamePropertyBase *,KPlayer *)),
00047           this,SLOT(slotPlayerPropertyChanged(KGamePropertyBase *,KPlayer *)));
00048 
00049   mWin.setValue(0);
00050   mLost.setValue(0);
00051   mBrk.setValue(0);
00052   mRemis.setValue(0);
00053 }
00054 
00055 
00056 // A registered player property changed (KGame framework function). Store this property
00057 // in the score object for the GUI.
00058 void KWin4Player::slotPlayerPropertyChanged(KGamePropertyBase *prop, KPlayer * /*player*/)
00059 {
00060   if (!mStatus) return ;
00061   if (!isActive()) return ;
00062   if (prop->id()==KGamePropertyBase::IdName)
00063   {
00064     mStatus->setPlayerName(name(), userId());
00065   }
00066   else if (prop->id()==mAllWin.id())
00067   {
00068     mStatus->setWins(mAllWin, userId());
00069   }
00070   else if (prop->id()==mAllRemis.id())
00071   {
00072     mStatus->setRemis(mAllRemis, userId());
00073   }
00074   else if (prop->id()==mAllLost.id())
00075   {
00076     mStatus->setLosses(mAllLost, userId());
00077   }
00078   else if (prop->id()==mAllBrk.id())
00079   {
00080     mStatus->setBreaks(mAllBrk, userId());
00081   }
00082 }
00083 
00084 
00085 // Read the player all time score from the config file
00086 void KWin4Player::readConfig(KConfigGroup& config)
00087 {
00088   mAllWin.setValue(config.readEntry("win",0));
00089   mAllRemis.setValue(config.readEntry("remis",0));
00090   mAllLost.setValue(config.readEntry("lost",0));
00091   mAllBrk.setValue(config.readEntry("brk",0));
00092 }
00093 
00094 
00095 // Write the player all time score to the config file
00096 void KWin4Player::writeConfig(KConfigGroup& config)
00097 {
00098   config.writeEntry("win",mAllWin.value());
00099   config.writeEntry("remis",mAllRemis.value());
00100   config.writeEntry("lost",mAllLost.value());
00101   config.writeEntry("brk",mAllBrk.value());
00102 }
00103 
00104 
00105 // Increase the number of wins
00106 void KWin4Player::incWin()
00107 {
00108   mWin.setValue(mWin.value()+1);
00109   mAllWin.setValue(mAllWin.value()+1);
00110 }
00111 
00112 
00113 // Increase the number of losses
00114 void KWin4Player::incLost()
00115 {
00116   mLost.setValue(mLost.value()+1);
00117   mAllLost.setValue(mAllLost.value()+1);
00118 }
00119 
00120 
00121 // Increase the number of draws
00122 void KWin4Player::incRemis()
00123 {
00124   mRemis.setValue(mRemis.value()+1);
00125   mAllRemis.setValue(mAllRemis.value()+1);
00126 }
00127 
00128 
00129 // Increase the number of aborted games
00130 void KWin4Player::incBrk()
00131 {
00132   mBrk.setValue(mBrk.value()+1);
00133   mAllBrk.setValue(mAllBrk.value()+1);
00134 }
00135 
00136 
00137 // Clear player status: For the argument true the long time
00138 // statistics in the config file is cleared as well. For the
00139 // argument false only the current session is cleared.
00140 void KWin4Player::resetStats(bool all)
00141 {
00142   mWin=0;
00143   mLost=0;
00144   mBrk=0;
00145   mRemis=0;
00146   if (all)
00147   {
00148     mAllWin=0;
00149     mAllLost=0;
00150     mAllBrk=0;
00151     mAllRemis=0;
00152   }
00153 }
00154 
00155 #include "kwin4player.moc"
00156 
00157 
00158 

Generated on Sun Mar 4 10:56:43 2007 for KWin4 by  doxygen 1.4.6