summaryrefslogtreecommitdiff
path: root/wake-up.scm
diff options
context:
space:
mode:
Diffstat (limited to 'wake-up.scm')
-rw-r--r--wake-up.scm60
1 files changed, 34 insertions, 26 deletions
diff --git a/wake-up.scm b/wake-up.scm
index 4eb38ad..5c4a276 100644
--- a/wake-up.scm
+++ b/wake-up.scm
@@ -15,31 +15,35 @@
(define *tiredness* (make-parameter 40 max-100))
(define *day* (make-parameter 1))
-;; Show days passed on exit
+;; Control SIGINT
(sigaction SIGINT
(lambda (sig)
- (newline)
- (display "---------------------------")
- (newline)
- (display "Exiting game.")
- (newline)
- (display (string-append "Days played: " (number->string (*day*))))
- (newline)
- (newline)
- (display "This game tries to show the internal dialog of a \
- depressed person that is alone at home, working as a \
- freelance, on a phd or any job that allows to work on \
- an independent way.\n\
- Somehow, it tries to express the life of those who \
- suffer in silence, alone in their caves. Hopefully, \
- this game made you empathize with them. \n\
- If you feel identified by what it is shown here, it \
- might be time to review your internal dialog and treat \
- yourself better. You deserve to be loved.\n")
- (newline)
- (display "Thanks for playing.")
- (newline)
- (exit)))
+ (exit-with-message)))
+
+;; Exit message
+(define (exit-with-message)
+ (newline)
+ (display "---------------------------")
+ (newline)
+ (display "Exiting game.")
+ (newline)
+ (display (string-append "Days played: " (number->string (*day*))))
+ (newline)
+ (newline)
+ (display "This game tries to show the internal dialog of a \
+ depressed person that is alone at home, working as a \
+ freelance, on a phd or any job that allows to work on \
+ an independent way.\n\
+ Somehow, it tries to express the life of those who \
+ suffer in silence, alone in their caves. Hopefully, \
+ this game made you empathize with them. \n\
+ If you feel identified by what it is shown here, it \
+ might be time to review your internal dialog and treat \
+ yourself better. You deserve to be loved.\n")
+ (newline)
+ (display "Thanks for playing.")
+ (newline)
+ (exit))
(define (nth n lst)
(if (> n (length lst))
@@ -108,7 +112,8 @@
(lambda ()
(newline)
(display message)
- (get-line (current-input-port))))
+ (when (eof-object? (get-line (current-input-port)))
+ (exit-with-message))))
(define (bar percent)
"A simple 12 character bar for life-like variable representation"
@@ -131,7 +136,10 @@
(newline)))
(define (read-number)
- (string->number (get-line (current-input-port))))
+ (let ((line (get-line (current-input-port))))
+ (if (eof-object? line)
+ (exit-with-message)
+ (string->number line))))
;; Basic state representation and creation: A state is a function that knows
;; how to jump to other states through a menu.
@@ -177,7 +185,7 @@
(cons "Start game"
(combine
(answer "Let's start, then. Press [ENTER] to continue. \
- Press [Ctrl-C] and then [ENTER] to finish.")
+ Exit with [Ctrl-D].")
(to-state 'wake-up)))
(cons "Quit game"
(answer "Good bye!")))