Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages  

Die.h

00001 /*
00002  * Die.h -- class interface for polyhedral die
00003  * Copyright (C) 2002  Eric Lemings <elemings@users.sourceforge.net>
00004  *
00005  * This software is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This software is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this software; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00018  * 02111-1307, USA
00019  *
00020  * RCS: $Id: Die.h,v 1.2 2003/03/23 22:14:36 elemings Exp $
00021  */
00022 
00023 #ifdef __cplusplus
00024 
00025 #  ifndef OGS_CORE_DIE_H
00026 #    define OGS_CORE_DIE_H
00027 
00028 #    include <ogs/support/Object.h>
00029 #    include <ogs/core/Namespace.h>
00030 
00031 OGS_BEGIN_CORE_NAMESPACE
00032 
00041 class Die: public ogs::support::Object {
00042   public:
00050     typedef unsigned short Sides;
00051 
00056     typedef unsigned short Count;
00057 
00062     typedef short Modifier;
00063 
00069     typedef short Value;
00070 
00072     static const Sides d4 = 4;
00074     static const Sides d6 = 6;
00076     static const Sides d8 = 8;
00078     static const Sides d10 = 10;
00080     static const Sides d12 = 12;
00082     static const Sides d20 = 20;
00083 
00089     static const Sides d2 = 2;
00090 
00095     static const Sides d3 = 3;
00096 
00101     static const Sides d5 = 5;
00102 
00107     static const Sides d100 = 100;
00108 
00109     static Value
00110     roll (Sides sides = d20, Count count = 1, Modifier modifier = 0);
00111 
00112     Die (Sides sides = d20, Count count = 1, Modifier modifier = 0);
00113 
00114     Sides getSides () const;
00115     void setSides (Sides sides);
00116     Count getCount () const;
00117     void setCount (Count count);
00118     Modifier getModifier () const;
00119     void setModifier (Modifier modifier);
00120     Value getValue () const;
00121     void setValue () const;
00122     Value rollValue () const;
00123     Value getMaximumValue () const;
00124     Value getMinimumValue () const;
00125 
00126     //std::string formatNotation () const;
00127     //void parseNotation (const std::string& string);
00128 
00129   private:
00130     Sides sides;
00131     Count count;
00132     Modifier modifier;
00133     // The value can be rerolled even if the die is const.
00134     mutable Value value;
00135 };
00136 
00142 inline Die::Sides Die::getSides () const {
00143   return (this->sides);
00144 }
00145 
00151 inline Die::Count Die::getCount () const {
00152   return (this->count);
00153 }
00154 
00160 inline Die::Modifier Die::getModifier () const {
00161   return (this->modifier);
00162 }
00163 
00169 inline Die::Value Die::getValue () const {
00170   return (this->value);
00171 }
00172 
00179 inline Die::Value Die::rollValue () const {
00180   setValue ();
00181   return (getValue ());
00182 }
00183 
00189 inline Die::Value Die::getMinimumValue () const {
00190   return (this->count + this->modifier);
00191 }
00192 
00198 inline Die::Value Die::getMaximumValue () const {
00199   return ((this->count * this->sides) + this->modifier);
00200 }
00201 
00202 OGS_END_CORE_NAMESPACE
00203 
00204 #  endif /* !defined OGS_CORE_DIE_H */
00205 
00206 #endif /* defined __cplusplus */
00207 

Generated on Sun Apr 20 03:36:18 2003 for Open Gaming System (OGS) by doxygen1.3