-
Notifications
You must be signed in to change notification settings - Fork 0
/
babble.rb
59 lines (50 loc) · 1.77 KB
/
babble.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
50
51
52
53
54
55
56
57
58
59
require_relative "tile_group.rb"
require_relative "tile_bag.rb"
require_relative "tile_rack.rb"
require_relative "Word.rb"
require 'spellchecker'
require 'tempfile'
##
# babble is the driver class for the babble program
class Babble
##
#subclass constructor
def initialize
@tileBag = TileBag.new
@tileRack = TileRack.new
@tileRack.number_of_tiles_needed.times{@tileRack.append(@tileBag.draw_tile())}
@word = Word.new
@score = 0
end
##
# The run method for
# the scrabble application
# has to run till the rack is empty and not the bag!
# Game can end with :quit or it can end with empty bag and empty rack!
def run
until @tileRack.tiles.length == 0
puts "The letters in the tile rack are: " + @tileRack.hand + "\n\n";
print "Please guess a word and enter it here: "
input = gets.chomp
puts "\n"
if(input.eql? ":quit")
puts "Thanks for playing, total score: " + @score.to_s + "\n\n";
break
elsif(input.strip.empty? or !Spellchecker::check(input)[0][:correct])
puts "Not a valid word"
elsif ([email protected]_tiles_for?(input))
puts "Not enought tiles"
else
@word = @tileRack.remove_word(input)
puts "You made " + @word.hand + " for " + @word.score.to_s + " points"
@score = @score + @word.score
@tileRack.number_of_tiles_needed.times{@tileRack.append(@tileBag.draw_tile) if [email protected]?}
end
puts "The current total score is " + @score.to_s + "\n\n"
end
if(@tileRack.tiles.length == 0)
puts "Thanks for playing, total score: " + @score.to_s + "\n\n";
end
end
end
Babble.new.run