qnetdice

annotate 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
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@1 43 value = (int)floor((double)sides * (double)rand() / (double)RAND_MAX);
nuclear@1 44 return value;
nuclear@1 45 }