initial commit
This commit is contained in:
parent
1d28e07738
commit
0ae96fa0b3
|
@ -1,3 +1,9 @@
|
||||||
# clicket
|
# clicket
|
||||||
|
|
||||||
clicker game in racket
|
clicker game in racket
|
||||||
|
|
||||||
|
## features
|
||||||
|
- click
|
||||||
|
- it
|
||||||
|
- clickers
|
||||||
|
- farms
|
||||||
|
- help me! 🙂
|
||||||
|
|
62
clicket.rkt
Normal file
62
clicket.rkt
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
#lang racket/gui
|
||||||
|
|
||||||
|
; setup main frame layout
|
||||||
|
(define frame (new (class frame% (super-new)
|
||||||
|
(define/augment (on-close)
|
||||||
|
(send timer stop)))
|
||||||
|
[label "Clicket"]
|
||||||
|
[border 5]))
|
||||||
|
(define panel (new horizontal-panel%
|
||||||
|
[parent frame]
|
||||||
|
[spacing 15]))
|
||||||
|
(define left-side (new vertical-pane% [parent panel]))
|
||||||
|
(define right-side (new vertical-pane% [parent panel]))
|
||||||
|
|
||||||
|
; setup click var and associated display text
|
||||||
|
(define clicks 0)
|
||||||
|
(define (click-str) (~a "Clicks: " clicks))
|
||||||
|
(define click-msg (new message%
|
||||||
|
[parent left-side]
|
||||||
|
[label (click-str)]
|
||||||
|
[auto-resize #t]))
|
||||||
|
|
||||||
|
; helper procedure
|
||||||
|
(define-syntax-rule (new-inc-button container name counter)
|
||||||
|
(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])]
|
||||||
|
[counter-msg (new message%
|
||||||
|
[parent button-pane]
|
||||||
|
[label "Owned: 0"]
|
||||||
|
[auto-resize #t])])
|
||||||
|
(new button% [parent button-pane]
|
||||||
|
[label (~a "Buy " name " (" price "¢)")]
|
||||||
|
[callback (λ (b e)
|
||||||
|
(when (>= clicks price)
|
||||||
|
(set! counter (add1 counter))
|
||||||
|
(set! clicks (- clicks price))
|
||||||
|
(send counter-msg set-label (~a "Owned: " counter))))])))
|
||||||
|
|
||||||
|
; 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)
|
||||||
|
|
||||||
|
; setup timer
|
||||||
|
(define timer-ctr 0)
|
||||||
|
(define timer (new timer% [interval 100]
|
||||||
|
[notify-callback
|
||||||
|
(λ ()
|
||||||
|
(when (= 0 (modulo timer-ctr 10))
|
||||||
|
(set! clicks (+ clicks clickers (* farms 5))))
|
||||||
|
(send click-msg set-label (click-str))
|
||||||
|
(set! timer-ctr (add1 timer-ctr)))]))
|
||||||
|
|
||||||
|
; show frame
|
||||||
|
(send frame show #t)
|
Loading…
Reference in a new issue