Re:How I Learned to Stop Worrying and Love the State Machine
by schoen on Monday February 26, 2018 @08:14PM
(#16470405)
If you look through the later items in the series, it seems to get more complex than this. In particular, a character can use either 0 or 1 weapons at a particular moment, and either class can also use the Dagger weapon. It's not that each character inherently only has, and uses, the only weapon appropriate to that character -- this would make things quite a bit simpler.
[ Parent
| on HN ]
Re:How I Learned to Stop Worrying and Love the State Machine
by bushin on Monday February 26, 2018 @09:24PM
(#16470669)
Well, maybe someday Dotty will be a mainstream language...
trait Weapon
class Sword extends Weapon
class Staff extends Weapon
class Dagger extends Weapon
trait Player {
type T <: Weapon
}
class Wizard extends Player {
type T = Dagger | Staff
var weapon: T = null
}
class Warrior extends Player {
type T = Dagger | Sword
var weapon: T = new Sword
}
Re:How I Learned to Stop Worrying and Love the State Machine
by icebraining on Tuesday February 27, 2018 @02:56AM
(#16471780)
Python already is a mainstream language:
class Weapon: pass
class Sword(Weapon): pass
class Staff(Weapon): pass
class Dagger(Weapon): pass
class Player:
weapon: Weapon
class Wizard(Player):
weapon: Optional[Union[Dagger, Staff]] = None
class Warrior(Player):
weapon: Optional[Union[Dagger, Sword]] = Sword()
Re:How I Learned to Stop Worrying and Love the State Machine
by icebraining on Tuesday February 27, 2018 @02:50AM
(#16471757)
class Wizard extends Player {
type T = Dagger | Staff
var weapon: T = null
}
The billion-dollar mistake in a new language? What a waste.