-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.jl
73 lines (61 loc) · 1.89 KB
/
Main.jl
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
workspace()
abstract type Event end
struct WakeUpEvent{T} <: Event
p::PlayerInstance
end
struct MultiWakeUpEvent{T} <: Event
ps::Vector{PlayerInstance}
end
abstract type Skill end
abstract type Role <: Skill end
struct Junkie{T<:Skill} end
play(s::Junkie{T}, args...) where T<:Skill = play(T(), args...)
let pCounter = 0
struct PlayerInstance
gameInstance::GameInstance
playerName::String
playerID::Int
skills::Vector{Skill}
log::Vector{String}
function PlayerInstance(gi::GameInstance, pName::String)
return new(gi, pName, pCounter+=1, Vector{Skill}(), Vector{String}())
end
end
end
canPlay(p::PlayerInstance) = true
getPlayerName(pi::PlayerInstance) = pi.player.name
getSkills(pi::PlayerInstance) = pi.skills
function logEvent(pi::Union{PlayerInstance, GameInstance}, s::String)
push!(pi.log, s)
end
struct Game
roles::Vector{Role}
end
struct GameInstance
game::Game
playerSetup::Dict{Player, PlayerInstance}
skillTags::Dict{Skill, Any}
skillMatchings::Dict{Skill, Vector{PlayerInstance}}
skillSchedulePlan::Vector{Skill}
nightSchedule::Vector{Event}
log::Vector{String}
end
function setSkill(gi::GameInstance, p::PlayerInstance, r::Skill)
push!(get!(gi.skillMatchings, r, Vector{PlayerInstance}()), p)
push!(p.skills, r)
end
function startNight(gi::GameInstance)
foreach(x->prepareNightSchedule!(gi, x), gi.skillSchedulePlan)
end
prepareNightSchedule!(gi::GameInstance, r::T) where T<:Skill = append!(gi.nightSchedule, prepareNightSchedule(gi, r))
function requestInput(pi::PlayerInstance, s::String, T::DataType)
println(s)
while true
try
findPlayer
return parse(T, readline())
catch
println("Invalid type: expected $T; Try again!")
end
end
end