qnetdice
diff src/roll.cc @ 1:92377189a5c6
moving along
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 22 Dec 2013 04:08:50 +0200 |
parents | |
children | 7d28bef3fbca |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/roll.cc Sun Dec 22 04:08:50 2013 +0200 1.3 @@ -0,0 +1,45 @@ 1.4 +#include <stdlib.h> 1.5 +#include <math.h> 1.6 +#include "roll.h" 1.7 + 1.8 +Roll::Roll(int sides) 1.9 +{ 1.10 + this->sides = sides; 1.11 + value = 0; 1.12 +} 1.13 + 1.14 +void Roll::set_name(const char *name) 1.15 +{ 1.16 + this->name = std::string(name); 1.17 +} 1.18 + 1.19 +void Roll::set_sides(int sides) 1.20 +{ 1.21 + this->sides = sides; 1.22 +} 1.23 + 1.24 +void Roll::set_value(int value) 1.25 +{ 1.26 + this->value = value; 1.27 +} 1.28 + 1.29 +const char *Roll::get_name() const 1.30 +{ 1.31 + return name.c_str(); 1.32 +} 1.33 + 1.34 +int Roll::get_sides() const 1.35 +{ 1.36 + return sides; 1.37 +} 1.38 + 1.39 +int Roll::get_value() const 1.40 +{ 1.41 + return value; 1.42 +} 1.43 + 1.44 +int Roll::roll() 1.45 +{ 1.46 + value = (int)floor((double)sides * (double)rand() / (double)RAND_MAX); 1.47 + return value; 1.48 +}