upwords 0.1.1 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Upwords
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -1,12 +1,10 @@
1
1
  module Upwords
2
2
  class Word
3
-
4
- # MIN_WORD_LENGTH = 2
5
-
6
3
  attr_reader :score, :length
7
4
 
8
5
  def initialize(posns, board)
9
6
  posns = posns.uniq if posns.is_a?(Array)
7
+
10
8
  @text = Word.make_string(board, posns)
11
9
  @score = Word.calc_score(board, posns)
12
10
  @length = @text.length
@@ -20,11 +18,14 @@ module Upwords
20
18
  dict.legal_word?(self.to_s)
21
19
  end
22
20
 
23
- # A word's score is the sum of the tile heights of its letters
24
- # However, if all of a word's tile heights are exactly 1, then the score is double the word's length
25
- # also add two points for each 'Qu' if all words are 1 tile high
26
- # Add 20 points if a player uses all their letters to form a word (this logic is in the MoveManager class,
27
- # because it requires the player as an input
21
+ # Calculate the score of word on board
22
+ # NOTE: this method assumes that the word has already been played on the board
23
+ #
24
+ # A word's score is calculated as follows:
25
+ # - Sum tile heights of all positions in word
26
+ # - Multiple score by 2 if all positions in word are only 1 tile high
27
+ # - Add two points for all 'Qu' tiles in word, if all positions in word are only 1 tile high (somewhat strange rule but whatever)
28
+ # NOTE: players get a 20 point bonus for using all of their tiles in a move -> this logic is in a separate class
28
29
  def self.calc_score(board, posns)
29
30
  stack_heights = posns.map{|row, col| board.stack_height(row, col)}
30
31
 
@@ -46,5 +47,5 @@ module Upwords
46
47
  posns.map{|row, col| board.top_letter(row, col)}.join
47
48
  end
48
49
 
49
- end
50
50
  end
51
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upwords
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maxim Pertsov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-05 00:00:00.000000000 Z
11
+ date: 2016-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curses
@@ -118,13 +118,13 @@ files:
118
118
  - lib/upwords/cursor.rb
119
119
  - lib/upwords/dictionary.rb
120
120
  - lib/upwords/game.rb
121
- - lib/upwords/graphics.rb
122
121
  - lib/upwords/letter_bank.rb
123
122
  - lib/upwords/letter_rack.rb
124
123
  - lib/upwords/move.rb
125
124
  - lib/upwords/move_manager.rb
126
125
  - lib/upwords/player.rb
127
126
  - lib/upwords/shape.rb
127
+ - lib/upwords/ui.rb
128
128
  - lib/upwords/version.rb
129
129
  - lib/upwords/word.rb
130
130
  - upwords.gemspec
@@ -1,149 +0,0 @@
1
- # require 'colored'
2
-
3
- module Upwords
4
- class Graphics < Curses::Window
5
-
6
- def initialize(game)
7
- super(0,0,0,0)
8
- @game = game
9
- @board = @game.board
10
- @cursor = @game.cursor
11
- @message = ''
12
- @rack_visibility = false
13
- end
14
-
15
- def refresh
16
- clear
17
- self << self.to_s
18
- super
19
- end
20
-
21
- def to_s
22
- (draw_board + draw_message).zip(draw_stats).map do |board_row, stats_row|
23
- (board_row.to_s) + (stats_row.to_s)
24
- end.join("\n")
25
- end
26
-
27
- def message=(new_message)
28
- if new_message.nil?
29
- @message = ""
30
- else
31
- @message = new_message
32
- end
33
- end
34
-
35
- def show_rack
36
- @rack_visibility = true
37
- end
38
-
39
- def hide_rack
40
- @rack_visibility = false
41
- end
42
-
43
- def toggle_rack_visibility
44
- @rack_visibility = !@rack_visibility
45
- end
46
-
47
- private
48
-
49
- def format_letter(row, col)
50
- letter = @board.top_letter(row, col)
51
- if letter.nil?
52
- letter = " "
53
- # add blank space after all other letters except Qu
54
- elsif letter != "Qu"
55
- letter += " "
56
- end
57
- letter
58
- end
59
-
60
- def draw_player_name
61
- "#{@game.current_player.name}'s turn"
62
- end
63
-
64
- def draw_score(player)
65
- "#{player.name}'s Score: #{player.score}"
66
- end
67
-
68
- def draw_last_turn(player)
69
- "Last Move: #{player.last_turn}"
70
- end
71
-
72
- def draw_letter_rack
73
- "Letters: #{@game.current_player.show_rack(!@rack_visibility)} "
74
- end
75
-
76
- def draw_space(row, col, cursor_posn)
77
- cursor = cursor_posn == [row, col] ? "*" : " "
78
- "#{cursor}#{format_letter(row, col)} "
79
- end
80
-
81
- def draw_row(row, cursor_posn)
82
- ["|",
83
- (0...@board.num_columns).map do |col|
84
- draw_space(row, col, cursor_posn)
85
- end.join("|"),
86
- "|"].join
87
- end
88
-
89
- # This will also display the stack height for now
90
- def draw_divider(row, col, show_height=true)
91
- height = @board.stack_height(row, col)
92
- if show_height && height > 0
93
- height = height.to_s
94
- else
95
- height = "-"
96
- end
97
- "---#{height}"
98
- end
99
-
100
- def draw_row_divider(row, show_height=true)
101
- ["+",
102
- (0...@board.num_columns).map do |col|
103
- draw_divider(row, col, show_height)
104
- end.join("+"),
105
- "+"].join
106
- end
107
-
108
- # print grid of top letter on each stack and stack height
109
- def draw_board
110
- b = [draw_row_divider(0, false)]
111
-
112
- (0...@board.num_rows).each do |i|
113
- b << draw_row(i, @cursor.posn)
114
- b << draw_row_divider(i)
115
- end
116
-
117
- b.to_a
118
- end
119
-
120
- def draw_message
121
- ["", @message.to_s]
122
- end
123
-
124
- def draw_stats
125
- ["--------------------",
126
- draw_score(@game.players[0]),
127
- "",
128
- draw_letter_rack,
129
- "--------------------",
130
- "",
131
- @game.player_count > 1 ?draw_score(@game.players[1]) : "",
132
- "",
133
- @game.player_count > 2 ? draw_score(@game.players[2]) : "",
134
- "",
135
- @game.player_count > 3 ? draw_score(@game.players[3]) : "",
136
- "",
137
- "----------------------",
138
- "| Controls |",
139
- "----------------------",
140
- "Show Letters [SPACE]",
141
- "Undo Last Move [DEL]",
142
- "Submit Move [ENTER]",
143
- "Swap Letter [+]",
144
- "Skip Turn [-]",
145
- "Quit Game [SHIFT+Q]"].map{|s| " #{s}"} # Left padding
146
- end
147
-
148
- end
149
- end