switch to structs for autoclickers
This commit is contained in:
parent
0ae96fa0b3
commit
f16927e356
29
clicket.rkt
29
clicket.rkt
|
@ -25,28 +25,32 @@
|
|||
(new button% [parent container]
|
||||
[label name]
|
||||
[callback (λ (b e) (set! counter (add1 counter)))]))
|
||||
(define-syntax-rule (new-buy-button container name counter price)
|
||||
(let* ([button-pane (new horizontal-pane% [parent container])]
|
||||
; assume we're placing all buy buttons in the right-side container
|
||||
(define-syntax-rule (new-buy-button cl)
|
||||
(let* ([button-pane (new horizontal-pane% [parent right-side])]
|
||||
[counter-msg (new message%
|
||||
[parent button-pane]
|
||||
[label "Owned: 0"]
|
||||
[auto-resize #t])])
|
||||
(new button% [parent button-pane]
|
||||
[label (~a "Buy " name " (" price "¢)")]
|
||||
[label (~a "Buy " (clicker-name cl) " (" (clicker-price cl) "¢)")]
|
||||
[callback (λ (b e)
|
||||
(when (>= clicks price)
|
||||
(set! counter (add1 counter))
|
||||
(set! clicks (- clicks price))
|
||||
(send counter-msg set-label (~a "Owned: " counter))))])))
|
||||
(when (>= clicks (clicker-price cl))
|
||||
(set-clicker-count! cl (add1 (clicker-count cl)))
|
||||
(set! clicks (- clicks (clicker-price cl)))
|
||||
(send counter-msg set-label (~a "Owned: " (clicker-count cl)))))])))
|
||||
|
||||
|
||||
; button to manually increase click count
|
||||
(new-inc-button left-side "Clicket?" clicks)
|
||||
|
||||
; clicks on a timer
|
||||
(define clickers 0)
|
||||
(new-buy-button right-side "clicker" clickers 10)
|
||||
(define farms 0)
|
||||
(new-buy-button right-side "paren farm" farms 25)
|
||||
(struct clicker (name price multiplier (count #:mutable)))
|
||||
(define all-clickers (list
|
||||
(clicker "mouse" 10 1 0)
|
||||
(clicker "coder" 150 5 0)
|
||||
(clicker "paren farm" 1000 10 0)))
|
||||
(for ([cl all-clickers]) (new-buy-button cl))
|
||||
|
||||
; setup timer
|
||||
(define timer-ctr 0)
|
||||
|
@ -54,7 +58,8 @@
|
|||
[notify-callback
|
||||
(λ ()
|
||||
(when (= 0 (modulo timer-ctr 10))
|
||||
(set! clicks (+ clicks clickers (* farms 5))))
|
||||
(for ([cl all-clickers])
|
||||
(set! clicks (+ clicks (* (clicker-multiplier cl) (clicker-count cl))))))
|
||||
(send click-msg set-label (click-str))
|
||||
(set! timer-ctr (add1 timer-ctr)))]))
|
||||
|
||||
|
|
Loading…
Reference in a new issue