-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.rb
88 lines (75 loc) · 1.59 KB
/
player.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
require './const.rb'
require 'active_record'
module RoleID
VILLAGER = 1
WEREWOLF = 2
BODYGUARD = 3
SEER = 4
ROLE_NAME = {
RoleID::VILLAGER => '村人',
RoleID::WEREWOLF => '人狼',
RoleID::BODYGUARD => 'ボディガード',
RoleID::SEER => '預言者'
}
def self.all
self.constants.map { |name| self.const_get(name) }
end
end
class PlayerFactory
def create(id, name, role)
p ("role is : " + role.to_s)
player = nil
case role
when RoleID::WEREWOLF
player = Werewolf.new
when RoleID::BODYGUARD
player = Bodyguard.new
when RoleID::SEER
player = Seer.new
else
player = Player.new
end
player.user_id = id
player.name = name
player.role = role
player.votes_count = 0
player.is_dead = false
player.is_saved = false
p player
return player
end
end
class Player < ActiveRecord::Base
def action(selected_player)
end
def vote(selected_player)
selected_player.votes_count += 1
end
end
class Werewolf < Player
def action(selected_player)
if selected_player.is_saved
p sprintf("%s はボディガードに守られました", selected_player.name)
return
elsif selected_player.role == RoleID::WEREWOLF
p "人狼の同士討ちはできません"
return
else
selected_player.is_dead = 1
end
end
end
class Bodyguard < Player
def action(selected_player)
selected_player.is_saved = true
end
end
class Seer < Player
def action(selected_player)
if selected_player.role == RoleID::WEREWOLF
p sprintf("%s は 人狼 です", selected_player.name)
else
p sprintf("%s は 村人 です", selected_player.name)
end
end
end