stattr 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/stattr.rb +134 -104
- metadata +2 -2
data/lib/stattr.rb
CHANGED
@@ -4,177 +4,207 @@
|
|
4
4
|
|
5
5
|
module Stattr
|
6
6
|
|
7
|
-
#
|
7
|
+
# The Class that defines, in other applications, the "rules" of that game - the stats, the sides of a given die, and so on.
|
8
8
|
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
class Game
|
10
|
+
|
11
|
+
# How many sides the generating dice have in this game.
|
12
|
+
#
|
13
|
+
# @return [Integer]
|
14
|
+
#
|
15
|
+
def self.dice_sides
|
16
|
+
6
|
17
|
+
end #self.dice_sides
|
18
|
+
|
19
|
+
# The number of dice required to create a stat in this game
|
20
|
+
#
|
21
|
+
# @return [Integer]
|
22
|
+
#
|
23
|
+
def self.dice_num
|
24
|
+
3
|
25
|
+
end #self.dice_num
|
26
|
+
|
27
|
+
# The math for generating a stat.
|
16
28
|
#
|
29
|
+
# @return [Object]
|
30
|
+
#
|
31
|
+
def self.make_stat(val=1)
|
32
|
+
Stat.new(DiceRoll.new_roll(Game.dice_sides, Game.dice_num))
|
33
|
+
end #make_stat
|
34
|
+
|
35
|
+
# The list of stats for this game.
|
36
|
+
#
|
37
|
+
# @return [Array]
|
38
|
+
#
|
39
|
+
def self.stats
|
40
|
+
["str", "con", "wis", "int", "cha", "dex"]
|
41
|
+
end #self.stats
|
42
|
+
end #Game
|
43
|
+
|
44
|
+
# Represents a single instance of the result of a dice roll
|
45
|
+
#
|
46
|
+
class DiceRoll
|
47
|
+
|
48
|
+
# @attribute sides [Integer] The number of sides the dice in this roll have.
|
17
49
|
# @attribute count [Integer] The number of die being rolled.
|
18
50
|
#
|
19
51
|
attr_accessor :sides, :count
|
20
|
-
|
52
|
+
|
21
53
|
# New instance of DiceRoll.
|
22
54
|
#
|
23
55
|
# @param [Integer] sides
|
24
|
-
#
|
25
56
|
# @param [Integer] count
|
26
|
-
#
|
27
57
|
# @return [Object] DiceRoll object
|
28
58
|
#
|
29
|
-
def initialize(sides=DICE_SIDES, count=1)
|
59
|
+
#def initialize(sides=DICE_SIDES, count=1)
|
60
|
+
def initialize(sides=Game.dice_sides, count=Game.dice_num)
|
30
61
|
@sides = sides
|
31
62
|
@count = count
|
32
63
|
end #initialize
|
33
|
-
|
34
|
-
# Roll a new die.
|
64
|
+
|
65
|
+
# Roll a new die.
|
35
66
|
#
|
36
67
|
# @param [Integer] sides
|
37
|
-
#
|
38
68
|
# @param [Integer] count
|
69
|
+
# @return [Object] DiceRoll object
|
39
70
|
#
|
40
|
-
|
41
|
-
|
42
|
-
def self.new_roll(sides = DICE_SIDES, count=1)
|
43
|
-
# make a new dice object, then roll it.
|
71
|
+
def self.new_roll(sides = Game.dice_sides, count=Game.dice_num)
|
72
|
+
# make a new dice object, then roll it.
|
44
73
|
new(sides, count).roll
|
45
74
|
end #self.roll
|
46
|
-
|
75
|
+
|
47
76
|
# From 1 to count, that many [sides] sided die.
|
48
|
-
#
|
49
|
-
# @return [Integer] Gives each outcome to Roll.
|
77
|
+
#
|
78
|
+
# @return [Integer] Gives each outcome to Roll.
|
50
79
|
#
|
51
80
|
def rolls
|
52
81
|
(1..count).map { |d| rand(sides) + 1 }
|
53
82
|
end #rolls
|
54
|
-
|
55
|
-
# Adds the rolls from rolls together.
|
83
|
+
|
84
|
+
# Adds the rolls from rolls together.
|
56
85
|
#
|
57
|
-
# @return [Integer] combined rolls
|
86
|
+
# @return [Integer] combined rolls
|
58
87
|
#
|
59
88
|
def roll
|
60
89
|
rolls.inject(0) { |total, d| total += d }
|
61
90
|
end #roll
|
62
91
|
end #DiceRoll
|
63
92
|
|
64
|
-
# Represents the list of Statistics that a player has.
|
93
|
+
# Represents the list of Statistics that a player has.
|
65
94
|
#
|
66
|
-
|
95
|
+
class StatList
|
67
96
|
|
68
|
-
#
|
97
|
+
# Creates an attr_accessor for each stat in STAT
|
69
98
|
#
|
70
|
-
|
71
|
-
|
72
|
-
# Create a new Statlist.
|
99
|
+
# @attribute STATS [Integer] any number of Stats.
|
73
100
|
#
|
74
|
-
|
75
|
-
|
76
|
-
#
|
77
|
-
#
|
78
|
-
# @param [Array] cha
|
101
|
+
attr_accessor *Game.stats
|
102
|
+
|
103
|
+
# Creates a new StatList object. each stat in STAT is an attribute, with the result of makestat assigned to it
|
79
104
|
#
|
80
|
-
|
105
|
+
def initialize
|
106
|
+
Game.stats.each { |s| instance_variable_set("@#{s}", Game.make_stat) }
|
107
|
+
end #initialize
|
108
|
+
|
109
|
+
# Allow manual setting of stats.
|
81
110
|
#
|
82
|
-
# @param [
|
111
|
+
# @param [Attribute] stat
|
112
|
+
# @param [Integer] val
|
83
113
|
#
|
84
|
-
|
114
|
+
def set_stat(stat, value)
|
115
|
+
send "#{stat}=", Stat.new(value)
|
116
|
+
end #set_stat
|
117
|
+
end #StatList
|
118
|
+
|
119
|
+
# Representing a stat in a game.
|
120
|
+
#
|
121
|
+
class Stat
|
122
|
+
|
123
|
+
# @attribute val [Integer] The value of the stat
|
124
|
+
# @attribute mod [Integer] The Calculated modifier of the stat
|
85
125
|
#
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
@
|
90
|
-
@
|
91
|
-
|
92
|
-
|
93
|
-
end #initialize
|
94
|
-
|
95
|
-
# Takes a given value of a stat and creates a D+D style modifier.
|
126
|
+
attr_accessor :val, :mod
|
127
|
+
|
128
|
+
def initialize(value)
|
129
|
+
@val= value
|
130
|
+
@mod= modstat(value)
|
131
|
+
end
|
132
|
+
# Creates stat/mod array.
|
96
133
|
#
|
97
|
-
# @return [
|
134
|
+
# @return [Integer] modlist. Returns the modifier.
|
98
135
|
#
|
99
136
|
def modstat(r)
|
100
137
|
modr = ((r-10)/2).to_int
|
101
|
-
modlist = [r, modr]
|
102
|
-
modlist
|
103
138
|
end #modstat
|
104
|
-
end #StatList
|
105
|
-
|
106
|
-
# CharacterSheet of a given PlayerCharacter.
|
107
|
-
#
|
108
|
-
class CharacterSheet
|
109
139
|
|
110
|
-
#
|
140
|
+
# makes a Stat/mod combination
|
141
|
+
#
|
142
|
+
# @return [Array]
|
111
143
|
#
|
112
|
-
|
144
|
+
end #Stat
|
145
|
+
|
146
|
+
# CharacterSheet of a given PlayerCharacter.
|
147
|
+
#
|
148
|
+
class CharacterSheet
|
149
|
+
|
150
|
+
# @attribute stats [Object] A StatList object
|
151
|
+
# @attribute name [String] The Player Character's name
|
113
152
|
#
|
114
|
-
|
153
|
+
attr_accessor :stats, :name
|
115
154
|
|
116
155
|
# new instance of CharacterSheet
|
156
|
+
# @param [String] name
|
117
157
|
#
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
#
|
127
|
-
#
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
DiceRoll.new_roll(DICE_SIDES, 3),
|
137
|
-
DiceRoll.new_roll(DICE_SIDES, 3),
|
138
|
-
DiceRoll.new_roll(DICE_SIDES, 3),
|
139
|
-
DiceRoll.new_roll(DICE_SIDES, 3),
|
140
|
-
DiceRoll.new_roll(DICE_SIDES, 3)
|
141
|
-
)
|
142
|
-
char
|
143
|
-
end # self.roll_char
|
144
|
-
end #CharacterSheet
|
145
|
-
|
146
|
-
# Player class represents a human, who may have multiple character sheets.
|
147
|
-
#
|
148
|
-
class Player
|
149
|
-
|
150
|
-
# @attribute fname [String] The First Name of the Player
|
151
|
-
#
|
152
|
-
# @attribute lname [String] The last Name of the Player
|
158
|
+
def initialize(name)
|
159
|
+
@name = name
|
160
|
+
@stats = StatList.new
|
161
|
+
end #initialize
|
162
|
+
|
163
|
+
# This is how you roll a brand new random character.
|
164
|
+
#
|
165
|
+
# @param [String] name
|
166
|
+
# @return [Object] New Charactersheet
|
167
|
+
#
|
168
|
+
def self.roll_char(name)
|
169
|
+
char = CharacterSheet.new(name)
|
170
|
+
char.stats = StatList.new
|
171
|
+
char
|
172
|
+
end # self.roll_char
|
173
|
+
end #CharacterSheet
|
174
|
+
|
175
|
+
# Player class represents a human, who may have multiple character sheets.
|
153
176
|
#
|
177
|
+
class Player
|
178
|
+
|
179
|
+
# @attribute fname [String] The First Name of the Player
|
180
|
+
# @attribute lname [String] The last Name of the Player
|
154
181
|
# @attribute characters [Array] An array containing Charactersheet objects
|
155
182
|
#
|
156
183
|
attr_accessor :fname, :lname, :characters
|
157
|
-
|
184
|
+
|
158
185
|
# Create new Player object
|
159
186
|
#
|
160
187
|
# @param [String] fname
|
161
|
-
#
|
162
188
|
# @param [String] lname
|
163
189
|
#
|
164
|
-
def initialize(fname, lname)
|
190
|
+
def initialize(fname, lname)
|
165
191
|
@fname = fname
|
166
|
-
@lname = lname
|
192
|
+
@lname = lname
|
167
193
|
@characters = []
|
168
194
|
end #initialize
|
169
|
-
|
170
|
-
# Creates a new randomly generated character associated with Player
|
195
|
+
|
196
|
+
# Creates a new randomly generated character associated with Player
|
171
197
|
#
|
172
|
-
# @param [String] name
|
198
|
+
# @param [String] name
|
173
199
|
#
|
174
200
|
def new_char(name)
|
175
201
|
new_char = CharacterSheet.roll_char(name)
|
176
|
-
self.characters << new_char
|
202
|
+
self.characters << new_char
|
177
203
|
end #roll_char
|
178
204
|
end #Player
|
179
|
-
|
205
|
+
|
206
|
+
# DM class extends player, fresh for modifying.
|
207
|
+
#
|
208
|
+
class DM < Player
|
209
|
+
end #DM
|
180
210
|
end #Stattr
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stattr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-25 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Stattr is a Gem that includes a number of useful functions for rolling
|
15
15
|
dice in a game like Dungeons and Dragons.
|