Skip to content

Commit 38647e6

Browse files
committed
Rspec
1 parent 829a26a commit 38647e6

File tree

6 files changed

+58
-12
lines changed

6 files changed

+58
-12
lines changed

.rspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--color
2+
--format progress

.rvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rvm 1.9.3-p327@tetris --create

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source 'http://rubygems.org'
2+
3+
gem 'rspec'

Gemfile.lock

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
GEM
2+
remote: http://rubygems.org/
3+
specs:
4+
diff-lcs (1.2.1)
5+
rspec (2.13.0)
6+
rspec-core (~> 2.13.0)
7+
rspec-expectations (~> 2.13.0)
8+
rspec-mocks (~> 2.13.0)
9+
rspec-core (2.13.1)
10+
rspec-expectations (2.13.0)
11+
diff-lcs (>= 1.1.3, < 2.0)
12+
rspec-mocks (2.13.0)
13+
14+
PLATFORMS
15+
ruby
16+
17+
DEPENDENCIES
18+
rspec

lib/game.rb

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,38 @@
1+
# Game controller
12
class Game
2-
def initialize
3+
def initialize(screen)
34
@current_piece = nil
45
@over = false
56
@brick_layout = BrickLayout.new
6-
end
7-
8-
def over?
9-
@over
7+
@screen = screen
8+
@screen.layout = @brick_layout
109
end
1110

1211
def play
1312
iterate while !over?
1413
end
1514

16-
def next_piece
17-
@current_piece = Piece.next
18-
@current_piece.brick_layout = @brick_layout
19-
end
20-
2115
def iterate
2216
next_piece if @current_piece.nil?
2317

24-
if @current_piece.hit_bottom?
18+
if @brick_layout.hit_bottom?(@current_piece)
2519
@brick_layout.fix_piece(@current_piece)
2620
@current_piece = nil
2721
else
2822
@current_piece.advance_down
29-
@brick_layout.update(@current_piece)
23+
@brick_layout.current_piece(@current_piece)
3024
@over = true if @brick_layout.hit_top?
3125
end
26+
27+
@screen.redraw
28+
end
29+
30+
def over?
31+
@over
32+
end
33+
34+
def next_piece
35+
@current_piece = Piece.next
36+
@current_piece.brick_layout = @brick_layout
3237
end
3338
end

spec/spec_helper.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This file was generated by the `rspec --init` command. Conventionally, all
2+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3+
# Require this file using `require "spec_helper"` to ensure that it is only
4+
# loaded once.
5+
#
6+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7+
RSpec.configure do |config|
8+
config.treat_symbols_as_metadata_keys_with_true_values = true
9+
config.run_all_when_everything_filtered = true
10+
config.filter_run :focus
11+
12+
# Run specs in random order to surface order dependencies. If you find an
13+
# order dependency and want to debug it, you can fix the order by providing
14+
# the seed, which is printed after each run.
15+
# --seed 1234
16+
config.order = 'random'
17+
end

0 commit comments

Comments
 (0)