Refactor(Score ADT): Encapsulate score as message-passing ADT without graphics
Pure logic ADT with punten getter and verhoog! mutator. Uses punten-per-muntje constant. No graphics code. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
32
pacman-project/adt-score.rkt
Normal file
32
pacman-project/adt-score.rkt
Normal file
@@ -0,0 +1,32 @@
|
||||
#lang r7rs
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Score ADT ;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
;; Houdt de score bij. Bevat GEEN grafische code.
|
||||
|
||||
(define-library (pacman-project adt-score)
|
||||
(import (scheme base)
|
||||
(pacman-project constanten))
|
||||
(export maak-score)
|
||||
|
||||
(begin
|
||||
|
||||
;; maak-score :: -> score
|
||||
;; Maakt een nieuw score-object aan, startend bij 0.
|
||||
(define (maak-score)
|
||||
(let ((punten 0))
|
||||
|
||||
;; verhoog! :: -> /
|
||||
;; Verhoogt de score met het aantal punten per muntje.
|
||||
(define (verhoog!)
|
||||
(set! punten (+ punten punten-per-muntje)))
|
||||
|
||||
;; dispatch-score :: symbol -> any
|
||||
(define (dispatch-score msg)
|
||||
(cond ((eq? msg 'punten) punten)
|
||||
((eq? msg 'verhoog!) verhoog!)
|
||||
(else (error "Score ADT -- Onbekend bericht:" msg))))
|
||||
|
||||
dispatch-score))))
|
||||
Reference in New Issue
Block a user