- Joined
- Oct 16, 2008
- Messages
- 10,454
I always get sleepy in class, how about you guys?... ^_^
JASS:
/*
What is this?
A simple system to control class behaviors!!!
HAHAHAHA!!!
*/
library ClassBehavior
struct StudentBehavior
static constant real TIME = .03
static timer t = CreateTimer()
boolean isClassBoring
string behavior
unit student
boolean isLazy
static integer StudentCount = 0
static integer array Students
static thistype data
static thistype datab
static method GetInstance takes unit student returns thistype
local integer i = 1
local thistype a
loop
exitwhen i > StudentCount
set a = Students[StudentCount]
if student == a.student then
set i = StudentCount + 1
else
set a = 0
set i = i + 1
endif
endloop
return a
endmethod
static method GetStudentBehavior takes unit student returns string
return StudentBehavior.GetInstance(student).behavior
endmethod
static method SetClassStatus takes unit student, boolean isClassBoring returns nothing
set StudentBehavior.GetInstance(student).isClassBoring = isClassBoring
endmethod
static method Release takes unit student returns nothing
local thistype b = StudentBehavior.GetInstance(student)
local integer i = 1
loop
exitwhen i > StudentCount
set c = Students[i]
if b.student = c.student then
set i = StudentCount + 1
set Students[i] = Students[StudentCount]
set StudentCount = StudentCount - 1
if StudentCount == 0 then
call PauseTimer(t)
endif
else
set i = i + 1
endif
endloop
call b.destroy()
endmethod
static method Refresh takes nothing returns nothing
local integer i = 1
loop
exitwhen i > StudentCount
set datab = Students[i]
if datab.isLazy == true then
if datab.isClassBoring == true then
set datab.behavior = "sleep"
else
set datab.behavior = "do something else"
endif
else
if datab.isClassBoring == true then
set datab.behavior = "stay quiet"
else
set datab.behavior = "actively participate"
endif
endif
set i = i + 1
endloop
endmethod
static method Create takes unit student, boolean isLazy returns nothing
set data = .allocate()
set StudentCount = StudentCount + 1
set Students[StudentCount] = data
set data.student = student
set data.isLazy = isLaz
if StudentCount == 1 then
call TimerStart(t, thistype.TIME, true, function thistype.Refresh)
endif
endmethod
endstruct
endlibrary