make save-game function use a file, consistentize terminology
This commit is contained in:
parent
087fec0cdd
commit
d9d7a6ab49
10
main.rkt
10
main.rkt
|
@ -77,7 +77,7 @@
|
||||||
|
|
||||||
; Point Grid -> Number
|
; Point Grid -> Number
|
||||||
; given a point that is the top-left corner of a square on the grid, returns the amount of edges surrounding that square.
|
; given a point that is the top-left corner of a square on the grid, returns the amount of edges surrounding that square.
|
||||||
(define (count-square p g)
|
(define (count-box p g)
|
||||||
; explanation:
|
; explanation:
|
||||||
; for every item in the grid (g), test it against every edge of the box for equality. if any are equal, it matches.
|
; for every item in the grid (g), test it against every edge of the box for equality. if any are equal, it matches.
|
||||||
; then only those that match are kept and this list is checked for length to determine the matching lines.
|
; then only those that match are kept and this list is checked for length to determine the matching lines.
|
||||||
|
@ -170,7 +170,7 @@
|
||||||
(let
|
(let
|
||||||
([boxes (boxes-for l gr)]
|
([boxes (boxes-for l gr)]
|
||||||
[g (append-move gr l)])
|
[g (append-move gr l)])
|
||||||
(length (filter (lambda (b) (= (count-square b g) 4)) boxes))))
|
(length (filter (lambda (b) (= (count-box b g) 4)) boxes))))
|
||||||
|
|
||||||
; Grid -> Number
|
; Grid -> Number
|
||||||
; returns the total amount of moves possible for grid g.
|
; returns the total amount of moves possible for grid g.
|
||||||
|
@ -227,7 +227,7 @@
|
||||||
(+ 4 (* GRID-SCALE (point-y (line-to l))))) ; draw the line
|
(+ 4 (* GRID-SCALE (point-y (line-to l))))) ; draw the line
|
||||||
(let ([boxes (boxes-for l g)])
|
(let ([boxes (boxes-for l g)])
|
||||||
(for ([b boxes])
|
(for ([b boxes])
|
||||||
(if (= (count-square b (grid passed (grid-width g) (grid-height g))) 4)
|
(if (= (count-box b (grid passed (grid-width g) (grid-height g))) 4)
|
||||||
(send dc draw-text
|
(send dc draw-text
|
||||||
(if (= (line-player l) 0) "R" "B")
|
(if (= (line-player l) 0) "R" "B")
|
||||||
(+ 6 (* GRID-SCALE (point-x b)))
|
(+ 6 (* GRID-SCALE (point-x b)))
|
||||||
|
@ -235,11 +235,11 @@
|
||||||
0))))
|
0))))
|
||||||
(send dc draw-bitmap (grid-dots (grid-width g) (grid-height g)) 0 0)) ; overlay dot grid
|
(send dc draw-bitmap (grid-dots (grid-width g) (grid-height g)) 0 0)) ; overlay dot grid
|
||||||
|
|
||||||
; GameState !
|
; GameState path !
|
||||||
; saves a game into the .dbn file format that I just made up.
|
; saves a game into the .dbn file format that I just made up.
|
||||||
; don't worry, it's sexpy.
|
; don't worry, it's sexpy.
|
||||||
; TODO write loader
|
; TODO write loader
|
||||||
(define (save-game s filename)
|
(define (save-game! s filename)
|
||||||
(let ([g (GameState-grid s)]
|
(let ([g (GameState-grid s)]
|
||||||
[f (open-output-file filename)])
|
[f (open-output-file filename)])
|
||||||
(pretty-write
|
(pretty-write
|
||||||
|
|
Loading…
Reference in New Issue