qnetdice
view src/roll.cc @ 3:2e57c80653af
more stuff
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 23 Dec 2013 06:09:25 +0200 |
parents | |
children | 7d28bef3fbca |
line source
1 #include <stdlib.h>
2 #include <math.h>
3 #include "roll.h"
5 Roll::Roll(int sides)
6 {
7 this->sides = sides;
8 value = 0;
9 }
11 void Roll::set_name(const char *name)
12 {
13 this->name = std::string(name);
14 }
16 void Roll::set_sides(int sides)
17 {
18 this->sides = sides;
19 }
21 void Roll::set_value(int value)
22 {
23 this->value = value;
24 }
26 const char *Roll::get_name() const
27 {
28 return name.c_str();
29 }
31 int Roll::get_sides() const
32 {
33 return sides;
34 }
36 int Roll::get_value() const
37 {
38 return value;
39 }
41 int Roll::roll()
42 {
43 value = (int)floor((double)sides * (double)rand() / (double)RAND_MAX);
44 return value;
45 }