forked from oplS15projects/Tune-Traveler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added file reading for pre-defined levels.
Two pre-defined map configurations have been added as well as a couple of helper functions that turn the configuration in that file into a map by making all 1s unwalkable, and making S the start position and E the end position.
- Loading branch information
1 parent
6c69d50
commit 9752a1a
Showing
16 changed files
with
109 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#lang racket | ||
(require racket/file) | ||
|
||
(require "constants.rkt") | ||
|
||
(define maps (list (file->lines "levels/level1.txt") | ||
(file->lines "levels/level2.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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
111111111111111 | ||
100000000000001 | ||
100000000000S01 | ||
100000000111111 | ||
1000000001000E1 | ||
100000000101111 | ||
100000000101111 | ||
100000111101111 | ||
100000000001111 | ||
100000111111111 | ||
111111111111111 | ||
111111111111111 | ||
111111111111111 | ||
111111111111111 | ||
111111111111111 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
111111111111111 | ||
1000000101E0001 | ||
101111110111101 | ||
101000010000101 | ||
101011010110101 | ||
101010010010001 | ||
100011111011111 | ||
101000001010001 | ||
101111101000101 | ||
101000001111101 | ||
101110100000001 | ||
101000111111101 | ||
101111111111101 | ||
1S1000000000001 | ||
111111111111111 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters