-
Notifications
You must be signed in to change notification settings - Fork 0
/
piece.rb
63 lines (51 loc) · 1.38 KB
/
piece.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
60
61
LEFT = 0
UP = 1
RIGHT = 2
DOWN = 3
class Piece
attr_reader :id, :rotation
def initialize left, up, right, down, id
@rotation = 0
@marks = Array.new
@marks << left
@marks << up
@marks << right
@marks << down
@id = id
end
def left
@marks[(LEFT + @rotation) % 4]
end
def up
@marks[(UP + @rotation) % 4]
end
def right
@marks[(RIGHT + @rotation) % 4]
end
def down
@marks[(DOWN + @rotation) % 4]
end
def rotate
@rotation = (@rotation-1)%4
end
def Piece.init
pieces = Array.new
pieces << Piece.new(:prp, :grh, :brh, :brp, 0)
pieces << Piece.new(:prh, :grp, :blp, :brh, 1)
pieces << Piece.new(:blh, :blp, :brp, :brh, 2)
pieces << Piece.new(:blh, :brh, :grp, :prp, 3)
pieces << Piece.new(:prh, :brp, :grp, :blh, 4)
pieces << Piece.new(:prp, :grh, :blh, :brp, 5)
pieces << Piece.new(:prh, :blp, :grp, :brh, 6)
pieces << Piece.new(:blh, :brp, :prp, :brh, 7)
pieces << Piece.new(:grp, :grp, :brh, :prh, 8)
pieces << Piece.new(:grp, :blp, :grh, :prh, 9)
pieces << Piece.new(:brh, :blh, :grp, :prp, 10)
pieces << Piece.new(:blp, :grh, :grh, :brp, 11)
pieces << Piece.new(:brp, :prh, :blh, :grp, 12)
pieces << Piece.new(:blp, :prh, :grh, :brp, 13)
pieces << Piece.new(:prh, :brp, :grp, :grh, 14)
pieces << Piece.new(:prp, :grh, :blh, :brp, 15)
return pieces
end
end