blob: b81721297503cf40f324be54096373a90e41164d (
plain)
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
|
#!/usr/bin/env tclsh
source player.tcl
source town.tcl
source resources.tcl
proc statusline {player town} {
puts -nonewline [$player status]
puts -nonewline " -- "
puts [$town status]
}
proc checkeog {player} {
if [$player died] {
puts "You lie, exhausted, as the light fades away."
puts "Game over."
exit
}
}
proc help {} {
puts {Available commmands:
quit: quit game
help: show this help
make power: make power for the town's supply
gather water: gather water for the town's supply
gather food: gather food for the town's supply
build house: build a house in the town which can house people
hire power maker: set an unassigned occupant to generate power
hire food gatherer: set an unassigned occupant to gather food
drink: gather some water for yourself
eat: eat an item from the town's food supply}
}
set p [player new]
set t [town new]
while true {
statusline $p $t
checkeog $p
set update true
puts -nonewline ">: "
flush stdout
gets stdin ent
switch -nocase $ent {
{} {set update false}
quit exit
help {help; set update false}
"make power" {$t crank; $p work 5}
"gather water" {$t putfood [water new]}
"gather food" {$t putfood [apples new]; $p work 3}
"build house" {$t build house; $p work 15}
drink {$p eat [water new]}
eat {$p eat [$t takefood]}
default {puts "You consider it deeply, but you're not sure how to $ent."; set update false}
}
if $update {
$p update
$t update
}
}
|