From 8619785617eb73f8a4246c69b115b76769130d6f Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Tue, 6 Jul 2021 21:25:00 +0100 Subject: Initial Commit --- player.tcl | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 player.tcl (limited to 'player.tcl') diff --git a/player.tcl b/player.tcl new file mode 100644 index 0000000..156c1f8 --- /dev/null +++ b/player.tcl @@ -0,0 +1,37 @@ +oo::class create player { + constructor {} { + my variable satiation + set satiation 100 + } + + method status {} { + my variable satiation + return "Satiation: $satiation" + } + + method died {} { + my variable satiation + return [expr $satiation <= 0] + } + + method update {} { + my variable satiation + incr satiation -2 + } + + method eat {food} { + if {$food != ""} { + my variable satiation + set satiation [expr min($satiation + [$food value], 100)] + $food eat + } else { + puts "The town has no food." + } + } + + method work {amount} { + my variable satiation + set satiation [expr $satiation - $amount] + puts "You wipe the sweat from your brow." + } +} -- cgit v1.2.1