-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtile_rack.rb
50 lines (43 loc) · 1.2 KB
/
tile_rack.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
##
# TileRack is the child class of the TileGroup class
# via inheritance
require_relative "tile_group.rb"
require_relative "tile_bag.rb"
require_relative "Word.rb"
class TileRack < TileGroup
## subclass constructor
def initialize
super
end
##
# this method returns the number of tiles needed to fill the
# rack to upto 7 tiles
def number_of_tiles_needed
return 7-self.tiles.length
end
##
# this method returns true if rack has enough
#letters to make the input text parameter
# since only 7 letters are stored at a time this may be acceptable
# if -loop provides speed improvement for rogue(long) inputs
def has_tiles_for?(text)
array = text.upcase.split("")
if(array.length<=self.hand.length)
self.hand.split("").each{|x| i =array.index(x); array.delete_at(i) if i}
array.empty?
else
return false
end
end
##
# method to remove text from tile rack and making a Word
# Word is returned
def remove_word(text)
wordObject = Word.new
if(self.has_tiles_for?(text))
text.upcase.split("").each{|x| i [email protected](x.to_sym);
@arrayOfTiles.delete_at(i);wordObject.append(x.to_sym) }
end
wordObject
end
end