qnetdice
annotate src/roll.cc @ 4:7d28bef3fbca
ops, forgot to add +1 to random numbers in roll.cc to make them 1-based
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 23 Dec 2013 17:40:34 +0200 |
parents | 92377189a5c6 |
children |
rev | line source |
---|---|
nuclear@1 | 1 #include <stdlib.h> |
nuclear@1 | 2 #include <math.h> |
nuclear@1 | 3 #include "roll.h" |
nuclear@1 | 4 |
nuclear@1 | 5 Roll::Roll(int sides) |
nuclear@1 | 6 { |
nuclear@1 | 7 this->sides = sides; |
nuclear@1 | 8 value = 0; |
nuclear@1 | 9 } |
nuclear@1 | 10 |
nuclear@1 | 11 void Roll::set_name(const char *name) |
nuclear@1 | 12 { |
nuclear@1 | 13 this->name = std::string(name); |
nuclear@1 | 14 } |
nuclear@1 | 15 |
nuclear@1 | 16 void Roll::set_sides(int sides) |
nuclear@1 | 17 { |
nuclear@1 | 18 this->sides = sides; |
nuclear@1 | 19 } |
nuclear@1 | 20 |
nuclear@1 | 21 void Roll::set_value(int value) |
nuclear@1 | 22 { |
nuclear@1 | 23 this->value = value; |
nuclear@1 | 24 } |
nuclear@1 | 25 |
nuclear@1 | 26 const char *Roll::get_name() const |
nuclear@1 | 27 { |
nuclear@1 | 28 return name.c_str(); |
nuclear@1 | 29 } |
nuclear@1 | 30 |
nuclear@1 | 31 int Roll::get_sides() const |
nuclear@1 | 32 { |
nuclear@1 | 33 return sides; |
nuclear@1 | 34 } |
nuclear@1 | 35 |
nuclear@1 | 36 int Roll::get_value() const |
nuclear@1 | 37 { |
nuclear@1 | 38 return value; |
nuclear@1 | 39 } |
nuclear@1 | 40 |
nuclear@1 | 41 int Roll::roll() |
nuclear@1 | 42 { |
nuclear@4 | 43 value = (int)floor((double)sides * (double)rand() / (double)RAND_MAX) + 1; |
nuclear@1 | 44 return value; |
nuclear@1 | 45 } |