forked from oplS15projects/Tune-Traveler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevels.rkt
31 lines (26 loc) · 1.13 KB
/
levels.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#lang racket
(require racket/file)
(require "constants.rkt")
(define maps (list (file->lines "levels/level1.txt")
(file->lines "levels/level2.txt")
(file->lines "levels/level3.txt")
(file->lines "levels/level4.txt")
(file->lines "levels/level5.txt")))
; Checks to make sure the map in the file is a 15x15 grid.
(define (validMap? m)
(if (and (= (length m) GRID_SIZE)
(= (length (string->list (car m))) GRID_SIZE))
#t
#f))
; Constructs the map by making wall tiles in the grid unwalkable and setting the start, goal and player positions.
(define (buildMap GRID lvl)
(if (validMap? lvl)
(for ([row (in-range 0 GRID_SIZE)])
(let ([r (string->list (list-ref lvl row))])
(for ([col (in-range 0 GRID_SIZE)])
(let ([c (list-ref r col)])
(when (eq? c #\1) (send ((get row col) GRID) setWalk #f))
(when (eq? c #\S) (moveStart row col))
(when (eq? c #\E) (moveGoal row col))))))
(error "Invalid map format. Please check the input file...")))
(provide (all-defined-out))