File tree Expand file tree Collapse file tree 6 files changed +58
-12
lines changed Expand file tree Collapse file tree 6 files changed +58
-12
lines changed Original file line number Diff line number Diff line change
1
+ --color
2
+ --format progress
Original file line number Diff line number Diff line change
1
+ rvm 1.9.3-p327@tetris --create
Original file line number Diff line number Diff line change
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rspec'
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
1
+ # Game controller
1
2
class Game
2
- def initialize
3
+ def initialize ( screen )
3
4
@current_piece = nil
4
5
@over = false
5
6
@brick_layout = BrickLayout . new
6
- end
7
-
8
- def over?
9
- @over
7
+ @screen = screen
8
+ @screen . layout = @brick_layout
10
9
end
11
10
12
11
def play
13
12
iterate while !over?
14
13
end
15
14
16
- def next_piece
17
- @current_piece = Piece . next
18
- @current_piece . brick_layout = @brick_layout
19
- end
20
-
21
15
def iterate
22
16
next_piece if @current_piece . nil?
23
17
24
- if @current_piece . hit_bottom?
18
+ if @brick_layout . hit_bottom? ( @current_piece )
25
19
@brick_layout . fix_piece ( @current_piece )
26
20
@current_piece = nil
27
21
else
28
22
@current_piece . advance_down
29
- @brick_layout . update ( @current_piece )
23
+ @brick_layout . current_piece ( @current_piece )
30
24
@over = true if @brick_layout . hit_top?
31
25
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
32
37
end
33
38
end
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments