Created
March 28, 2019 14:59
-
-
Save ramiresnas/4dc93e745366a0ebede234f2a7474161 to your computer and use it in GitHub Desktop.
Máquina de estados
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import GameplayKit | |
class JumpState : GKState { | |
override func isValidNextState(_ stateClass: AnyClass) -> Bool { | |
let isValid = stateClass is WalkState.Type | |
if !isValid { | |
print("você só pode entrar no estado de andar") | |
} | |
return isValid | |
} | |
override func didEnter(from previousState: GKState?) { | |
jump() | |
} | |
private func jump() { | |
print("jumping") | |
} | |
} | |
class RunState : GKState { | |
override func isValidNextState(_ stateClass: AnyClass) -> Bool { | |
let isValid = stateClass is WalkState.Type || stateClass is JumpState.Type | |
if !isValid { | |
print("você só pode entrar no estado de andar") | |
} | |
return isValid | |
} | |
override func didEnter(from previousState: GKState?) { | |
run() | |
} | |
private func run() { | |
print("runing") | |
} | |
} | |
class WalkState : GKState { | |
override func isValidNextState(_ stateClass: AnyClass) -> Bool { | |
let isValide = stateClass is JumpState.Type || stateClass is RunState.Type | |
if !isValide { | |
print("você não pode entrar no estado de andar") | |
} | |
return isValide | |
} | |
override func didEnter(from previousState: GKState?) { | |
walk() | |
} | |
private func walk() { | |
print("walking") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment