summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--depre/main.scm274
1 files changed, 240 insertions, 34 deletions
diff --git a/depre/main.scm b/depre/main.scm
index cdb2092..79cf3dc 100644
--- a/depre/main.scm
+++ b/depre/main.scm
@@ -10,8 +10,23 @@
;; Code makes heavy use of functional code and parameters for state.
(define max-100 (lambda (x) (if (> x 100) 100 x)))
-(define %depression (make-parameter 50 max-100))
-(define %tiredness (make-parameter 50 max-100))
+(define *depression* (make-parameter 50 max-100))
+(define *tiredness* (make-parameter 50 max-100))
+(define *day* (make-parameter 1))
+
+;; Show days passed on exit
+(sigaction SIGINT
+ (lambda (sig)
+ (newline)
+ (display "---------------------------")
+ (newline)
+ (display "Exiting game.")
+ (newline)
+ (display (string-append "Days played: " (number->string (*day*))))
+ (newline)
+ (display "Thanks for playing")
+ (newline)
+ (exit)))
(define (nth n lst)
(if (> n (length lst))
@@ -36,28 +51,44 @@
;; Example:
;; - You are too tired for that, so you do this instead
;; - Or you actually do it
+;; NOTE: The functions try with 120 to leave some chance to randomness even if
+;; you are tired or depressed to the limit
(define (f-or-tired f tired)
(lambda ()
- (if (< (random 100) (%tiredness)) (f) (tired))))
+ (if (< (random 120) (*tiredness*)) (f) (tired))))
(define (f-or-depressed f depressed)
(lambda ()
- (if (< (random 100) (%depression)) (f) (depressed))))
+ (if (< (random 120) (*depression*)) (f) (depressed))))
;; State alteration functions for easy access
(define (tire)
- (lambda () (%tiredness (+ (%tiredness) 5))))
+ (lambda () (*tiredness* (+ (*tiredness*) 5))))
(define (rest)
- (lambda () (%tiredness (- (%tiredness) 5))))
+ (lambda () (*tiredness* (- (*tiredness*) 5))))
(define (depress)
- (lambda () (%depression (+ (%depression) 5))))
+ (lambda () (*depression* (+ (*depression*) 5))))
(define (cheer-up)
- (lambda () (%depression (- (%depression) 5))))
+ (lambda () (*depression* (- (*depression*) 5))))
+
+(define (tire+)
+ (lambda () (*tiredness* (+ (*tiredness*) 8))))
+
+(define (rest+)
+ (lambda () (*tiredness* (- (*tiredness*) 8))))
+
+(define (depress+)
+ (lambda () (*depression* (+ (*depression*) 8))))
+
+(define (cheer-up+)
+ (lambda () (*depression* (- (*depression*) 8))))
+(define (next-day)
+ (lambda () (*day* (+ 1 (*day*)))))
;; Simple I/O
(define (answer message)
@@ -78,6 +109,14 @@
(else #\space)))
len))
+(define (day-banner)
+ (lambda ()
+ (newline)
+ (display "---------------------------")
+ (newline)
+ (display (string-append "Day " (number->string (*day*))))
+ (newline)))
+
(define (read-number)
(string->number (get-line (current-input-port))))
@@ -88,10 +127,10 @@
(when (not hide-status)
(newline)
(display "Depression:\t")
- (display (bar (%depression)))
+ (display (bar (*depression*)))
(newline)
(display "Tiredness:\t")
- (display (bar (%tiredness))))
+ (display (bar (*tiredness*))))
(newline)
(display heading)
(newline)
@@ -117,21 +156,19 @@
(define-macro (to-state name)
`(lambda () ((hash-ref %states ,name))))
-(register-state
- 'morning-1
- (state "It's early in the morning. You have time to do whatever you want \
- right now. What do you want to do?"
- (list
- (cons "Work."
- (rest))
- (cons "Relax."
- (rest)))))
(register-state
- 'morning-2
- (state "It's late in the morning. You still have some time before having \
- lunch. What do you want to do?"
- (list (cons "nope" (rest)))))
+ 'start
+ (state "Hi, game starts"
+ (list
+ (cons "Start game"
+ (combine
+ (answer "Let's start, then. Press [ENTER] to continue. \
+ Press [Ctrl-C] and then [ENTER] to finish.")
+ (to-state 'wake-up)))
+ (cons "Quit game"
+ (answer "Good bye!")))
+ #:hide-status))
(register-state
'wake-up
@@ -143,7 +180,7 @@
(answer "You just woke up, had your shower, had some \
breakfast and now you are ready for \
anything.")
- (cheer-up)
+ (cheer-up+)
(tire)
(to-state 'morning-1))
(combine
@@ -164,15 +201,184 @@
(to-state 'morning-2))))))
(register-state
- 'start
- (state "Hi, game starts"
- (list
- (cons "Start game"
- (combine
- (answer "Let's start, then. Press [ENTER] to continue.")
- (to-state 'wake-up)))
- (cons "Quit game"
- (answer "Good bye!")))
- #:hide-status))
+ 'morning-1
+ (state "It's early in the morning. You have time to do whatever you want \
+ right now. What do you want to do?"
+ (list
+ (cons "Work."
+ (f-or-tired
+ (combine
+ (answer "You worked for a couple of hours.")
+ (tire)
+ (to-state 'morning-2))
+ (combine
+ (answer "You are too tired to work. You do nothing for a \
+ couple of hours and you feel for wasting your time.")
+ (depress+)
+ (to-state 'morning-2))))
+
+ (cons "Relax."
+ (combine
+ (answer "You do nothing for a couple of hours and feel guilty \
+ because you didn't work")
+ (depress+)
+ (rest)
+ (to-state 'morning-2))))))
+
+(register-state
+ 'morning-2
+ (state "It's late in the morning. You still have some time before having \
+ lunch. What do you want to do?"
+ (list
+ (cons "Work."
+ (f-or-depressed
+ (f-or-tired
+ (combine
+ (answer "You worked for a couple of hours.")
+ (tire)
+ (to-state 'lunch))
+ (combine
+ (answer "You are too tired to work. You do nothing for a \
+ couple of hours and you feel for wasting your time.")
+ (depress+)
+ (to-state 'lunch)))
+ (combine
+ (answer "It's almost time to have lunch... Maybe it's better \
+ just to leave work for later.")
+ (depress)
+ (to-state 'lunch))))
+
+ (cons "Relax."
+ (combine
+ (answer "You do nothing for a couple of hours and feel guilty \
+ because you didn't work")
+ (depress+)
+ (rest)
+ (to-state 'lunch))))))
+
+
+(register-state
+ 'lunch
+ (state "You have something for lunch. What do you want to do now?"
+ (list
+ (cons "Work."
+ (f-or-depressed
+ (f-or-tired
+ (combine
+ (answer "You worked for a couple of hours.")
+ (tire)
+ (to-state 'evening))
+ (combine
+ (answer "You are too tired to work. You do nothing for a \
+ couple of hours and you feel for wasting your time.")
+ (depress+)
+ (to-state 'evening)))
+ (combine
+ (answer "Work? What for? It's meaningless. Just let your life \
+ pass while asking yourself why you are doing nothing.")
+ (depress)
+ (to-state 'evening))))
+
+ (cons "Relax."
+ (f-or-depressed
+ (combine
+ (answer "You do nothing for a couple of hours and feel guilty \
+ because you didn't work")
+ (depress+)
+ (rest)
+ (to-state 'evening))
+ (combine
+ (answer "You can't just relax. You are worthless if you don't \
+ work.\
+ You overwork and spend the whole afternoon working in \
+ bad conditions.")
+ (tire+)
+ (to-state 'dinner)))))))
+
+(register-state
+ 'evening
+ (state "You still have some time until dinner. What do you want to do"
+ (list
+ (cons "Work"
+ (f-or-depressed
+ (combine
+ (answer "You work. It's late so it's really tiring and you have \
+ a hard time concentrating.")
+ (tire+)
+ (to-state 'dinner))
+ (combine
+ (answer "You work because what else you could do? There's \
+ nothing else in your life.\
+ You work in bad conditions and you skip dinner because \
+ you are obsessed with your job.")
+ (depress)
+ (tire+)
+ (day-banner)
+ (to-state 'wake-up))))
+ (cons "Relax at home."
+ (f-or-depressed
+ (combine
+ (answer "You relax at home. You stayed at home the whole day.")
+ (depress+)
+ (to-state 'dinner))
+ (combine
+ (answer "You are bored, you play around with work related stuff \
+ until it's time to have dinner.")
+ (tire)
+ (to-state 'dinner))))
+ (cons "Go outside."
+ (f-or-depressed
+ (combine
+ (answer "You go outside for a walk.")
+ (cheer-up+)
+ (cheer-up)
+ (to-state 'dinner))
+ (combine
+ (answer "It's already dark outside. You don't feel like going \
+ outside. You wait doing nothing until dinner time.")
+ (depress)
+ (to-state 'dinner)))))))
+
+(register-state
+ 'dinner
+ (state "Time for dinner. What do you want to do afterwards?"
+ (list
+ (cons "Work"
+ (f-or-tired
+ (combine
+ (answer "You work for some time and then go to bed.")
+ (cheer-up)
+ (tire)
+ (next-day)
+ (day-banner)
+ (to-state 'wake-up))
+
+ (combine
+ (answer "You are too tired to work. You watch some TV and \
+ feel bad about it.")
+ (depress)
+ (rest)
+ (next-day)
+ (day-banner)
+ (to-state 'wake-up))))
+ (cons "Relax"
+ (f-or-depressed
+ (combine
+ (answer "You manage to relax watching a film. And go to bed \
+ afterwards.")
+ (day-banner)
+ (to-state 'wake-up))
+ (combine
+ (answer "You didn't work enough during the day and you want \
+ to relax. You shouldn't. \
+ You work until it's late and then go to bed.")
+ (tire+)
+ (depress)
+ (next-day)
+ (lambda ()
+ (newline)
+ (display (string-append "Days " (number->string (*day*))))
+ (newline))
+ (to-state 'wake-up)))))))
((to-state 'start))