Skip to content

Commit 93a4806

Browse files
committed
work
1 parent c64f259 commit 93a4806

File tree

1 file changed

+82
-1
lines changed

1 file changed

+82
-1
lines changed

hw6assignment.rb

+82-1
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,99 @@
66
class MyPiece < Piece
77
# The constant All_My_Pieces should be declared here
88

9+
def initialize(point_array, board)
10+
super(point_array, board)
11+
end
12+
13+
def self.next_piece(board)
14+
if board.set_check
15+
board.set_check = false
16+
piece = [[[0,0]]]
17+
else
18+
piece = All_Pieces.sample
19+
end
20+
MyPiece.new(piece, board)
21+
end
22+
923
# your enhancements here
24+
#
25+
26+
All_My_Pieces = All_Pieces
27+
28+
All_Pieces << [ [[0,0], [-1, 0], [-2, 0], [1, 0], [2, 0]],
29+
[[0,0], [0, 1], [0, 2], [0, -1], [0, -2]]]
30+
All_Pieces << rotations([[0, 0], [0, 1], [1,1]])
31+
All_Pieces << rotations([[0,0], [-1,0], [-1,1], [0, 1], [1, 1]])
1032

1133
end
1234

1335
class MyBoard < Board
1436
# your enhancements here
37+
attr_accessor :set_check
38+
39+
def initialize(game)
40+
super(game)
41+
@set_check = false
42+
end
43+
44+
def rotate180
45+
if !game_over? and @game.is_running?
46+
@current_block.move(0, 0, 1)
47+
@current_block.move(0, 0, 1)
48+
end
49+
draw
50+
end
51+
52+
def store_current
53+
locations = @current_block.current_rotation
54+
displacement = @current_block.position
55+
locations.each_index{|index|
56+
current = locations[index];
57+
@grid[current[1]+displacement[1]][current[0]+displacement[0]] =
58+
@current_pos[index]
59+
}
60+
remove_filled
61+
@delay = [@delay - 2, 80].max
62+
end
63+
64+
def check
65+
return if @set_check or score < 100
66+
@set_check = true
67+
@score -= 100
68+
end
69+
70+
def next_piece
71+
@current_block = MyPiece.next_piece(self)
72+
@current_pos = nil
73+
end
1574

1675
end
1776

1877
class MyTetris < Tetris
1978
# your enhancements here
2079

21-
end
80+
def initialize
81+
super
82+
end
83+
84+
def set_board
85+
@canvas = TetrisCanvas.new
86+
@board = MyBoard.new(self)
87+
@canvas.place(@board.block_size * @board.num_rows + 3,
88+
@board.block_size * @board.num_columns + 6, 24, 80)
89+
@board.draw
90+
end
2291

2392

93+
def check
94+
@board.check
95+
update_score
96+
end
97+
98+
def key_bindings
99+
super
100+
101+
@root.bind('c', proc {self.check})
102+
@root.bind('u', proc {@board.rotate180})
103+
end
104+
end

0 commit comments

Comments
 (0)