Class: ConsoleShogi::Piece
- Inherits:
-
Object
- Object
- ConsoleShogi::Piece
show all
- Defined in:
- lib/console_shogi/piece.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(teban: nil) ⇒ Piece
Returns a new instance of Piece.
7
8
9
|
# File 'lib/console_shogi/piece.rb', line 7
def initialize(teban: nil)
@teban = teban
end
|
Instance Attribute Details
#teban ⇒ Object
Returns the value of attribute teban.
5
6
7
|
# File 'lib/console_shogi/piece.rb', line 5
def teban
@teban
end
|
Instance Method Details
#active_image ⇒ Object
33
34
35
|
# File 'lib/console_shogi/piece.rb', line 33
def active_image
File.read("images/active/#{teban}/#{self::class.name.split('::').last.downcase}.png")
end
|
#can_move_long_distance? ⇒ Boolean
63
64
65
|
# File 'lib/console_shogi/piece.rb', line 63
def can_move_long_distance?
[Kaku, Hisha, Kyosha, PromotedPiece::Uma, PromotedPiece::Ryu].include?(self::class)
end
|
#change_player!(player) ⇒ Object
59
60
61
|
# File 'lib/console_shogi/piece.rb', line 59
def change_player!(player)
@player = player
end
|
#focused_image ⇒ Object
37
38
39
|
# File 'lib/console_shogi/piece.rb', line 37
def focused_image
File.read("images/focused/#{teban}/#{self::class.name.split('::').last.downcase}.png")
end
|
#fu? ⇒ Boolean
45
46
47
|
# File 'lib/console_shogi/piece.rb', line 45
def fu?
self::class == Fu
end
|
#image ⇒ Object
29
30
31
|
# File 'lib/console_shogi/piece.rb', line 29
def image
File.read("images/nomal/#{teban}/#{self::class.name.split('::').last.downcase}.png")
end
|
#move ⇒ Object
11
12
13
|
# File 'lib/console_shogi/piece.rb', line 11
def move
raise NotImplementedError
end
|
#moves ⇒ Object
49
50
51
52
53
54
55
56
57
|
# File 'lib/console_shogi/piece.rb', line 49
def moves
ms = base_moves
if teban == Teban::SENTE
ms
else
ms.map {|m| m.transform_values {|v| v * -1 } }
end
end
|
#none? ⇒ Boolean
41
42
43
|
# File 'lib/console_shogi/piece.rb', line 41
def none?
self::class == NonePiece
end
|
#number ⇒ Object
25
26
27
|
# File 'lib/console_shogi/piece.rb', line 25
def number
self::class::NUMBER
end
|
15
16
17
18
19
|
# File 'lib/console_shogi/piece.rb', line 15
def promote
return self unless can_promote?
promoted
end
|
21
22
23
|
# File 'lib/console_shogi/piece.rb', line 21
def promoted?
false
end
|
#same?(piece) ⇒ Boolean
67
68
69
70
|
# File 'lib/console_shogi/piece.rb', line 67
def same?(piece)
self::class == piece::class &&
self.teban == piece.teban
end
|