Maze ist ein in Pascal programmiertes Spiel, das während einer Informatik-Projektarbeit in der Schule entstanden ist.
Ziel des Spiels ist es, den Ausgang des Labyrinths zu finden. Dieser ist mit einem roten F markiert. Zusätzlich gibt es noch versteckte Extras, die das Finden des Ziels erleichtern sollen.
Program Maze; Uses Crt; CONST width = 50; { x } height = 20; { y } VAR field : ARRAY [1..width,1..height] OF CHAR; level : text; { file, which contains the level structure } str : STRING; levelname: STRING; { name of the level } move : CHAR; { direction } quit : CHAR; moves : INTEGER; { number of moves } i : BYTE; vis : BYTE; { visibility } position : RECORD { current position in the field } x : BYTE; y : BYTE; End; Procedure Introduction; Begin WriteLn(' << Escape >>'); WriteLn; WriteLn(' Ziel dieses Spieles ist es, mit einer Spielfigur den Ausgang eines'); WriteLn(' Labyrinthes zu finden.'); WriteLn(' Die Spielfigur wird mittels der Tasten w (hoch), s (runter),'); WriteLn(' a (nach links) und d (nach rechts) gesteuert.'); WriteLn(' Das Ziel ist mit einem "F" gekennzeichnet, der Start mit einem "S".'); WriteLn(' Zusaetzlich gibt es die Moeglichkeit, Extras aufzusammeln. Dazu'); WriteLn(' zaehlt das Zeichen "V", welches die Sichtweite erhoeht und damit die'); WriteLn(' Orientierung erleichtert.'); WriteLn; WriteLn(' Das Spiel kann jederzeit durch Druecken der Taste "q" abgebrochen'); WriteLn(' werden.'); WriteLn; WriteLn(' ____ '); WriteLn(' __|__|__'); WriteLn(' (*__*) '); WriteLn(' / \ '); WriteLn(' /| |\ '); WriteLn(' | | '); WriteLn(' //\\ '); WriteLn(' // \\ '); ReadLn; End; Procedure LoadLevel (line : BYTE); VAR i : BYTE; { our current position (=character) in str } Begin FOR i := 1 TO width DO { assign str to our field } Begin field[i, line] := str[i]; IF str[i] = 'S' THEN Begin position.x := i; position.y := line; End; End; End; Procedure MoveTo (new_x, new_y : BYTE); Begin GoToXY(position.x, position.y); { go to and clear current position } Write(' '); position.x := new_x; { update to new positions } position.y := new_y; GoToXY(new_x, new_y); { go to and mark new position } Write('O'); End; Function IsFree (new_x, new_y : BYTE) : BOOLEAN; Begin IF (field[new_x, new_y] = 'X') THEN { check if new position is an obstacle } IsFree := false ELSE IsFree := true; End; Function CheckPosition (new_x, new_y : BYTE; character : CHAR) : BOOLEAN; Begin IF (field[new_x, new_y] = character) THEN { check if position = character } CheckPosition := true ELSE CheckPosition := false; End; Procedure MakeFieldVisible(x, y : BYTE); Begin IF (x > 0) AND (x <= width) AND (y > 0) AND (y <= height) THEN Begin GoToXY(x, y); IF ((field[x, y]) = 'V') OR ((field[x, y]) = 'F') OR ((field[x, y]) = 'S') THEN TextColor(Red); Write(field[x, y]); TextColor(Lightblue); End; End; Procedure MakeVisible; VAR i, range : INTEGER; Begin FOR range:=1 TO vis DO Begin FOR i:=-vis TO vis DO Begin MakeFieldVisible(position.x+i, position.y+range); { reveal top } MakeFieldVisible(position.x+i, position.y-range); { reveal bottom } MakeFieldVisible(position.x+range, position.y+i); { reveal right } MakeFieldVisible(position.x-range, position.y+i); { reveal left } End; End; GoToXY(position.x, position.y); { move cursor to current position } End; Procedure ShowGui; Begin TextColor(Red); GoToXY(55, 5); Write('Bewegungen: '); WriteLn(moves); GoToXY(55, 6); Write('Sichtbarkeit: '); WriteLn(vis); GoToXY(55, 8); WriteLn('Steuerung:'); GoToXY(65, 9); WriteLn(' W '); GoToXY(65, 10); WriteLn('ASD'); TextColor(Lightblue); GoToXY(position.x, position.y); { move cursor to current position } End; Begin ClrScr; Introduction; TextColor(Lightblue); TextBackground(Black); REPEAT REPEAT WriteLn(' Gib den Namen des Levels ein, das geladen werden soll.'); WriteLn(' Zu den Standardleveln gehoeren "lev01.txt", "lev02.txt"'); WriteLn(' sowie "lev03.txt". "q" zum Beenden des Programms.'); Write (' Name des Levels: '); ReadLn(levelname); ClrScr; IF levelname = 'q' THEN { quit program } exit; assign(level, levelname); {$I-} reset(level); {$I+} { we want to read this file } UNTIL (ioresult = 0) AND (levelname <> ''); { is the filename valid? } vis := 1; { default visibility = 1 } moves := 0; { number of moves = 0 } FOR i := 1 TO height DO Begin readln(level, str); { read one line into str} LoadLevel(i); { call LoadLevel and tell the current line } End; GoToXY(position.x, position.y); { go to and mark start } Write('O'); REPEAT MakeVisible; ShowGui; move := ReadKey; case move of 'w' : Begin IF IsFree(position.x, position.y-1) THEN Begin MoveTo(position.x, position.y-1); { go up } moves := moves + 1; End; End; 's' : Begin IF IsFree(position.x, position.y+1) THEN Begin MoveTo(position.x, position.y+1); { go down } moves := moves + 1; End; End; 'a' : Begin IF IsFree(position.x-1, position.y) THEN Begin MoveTo(position.x-1, position.y); { go left } moves := moves + 1; End; End; 'd' : Begin IF IsFree(position.x+1, position.y) THEN Begin MoveTo(position.x+1, position.y); { go right } moves := moves + 1; End; End; End; IF CheckPosition(position.x, position.y, 'F') THEN { check for finish } move := 'q'; IF CheckPosition(position.x, position.y, 'V') THEN { check for visibility } Begin { powerup } vis := vis + 1; { increase vis by one } field[position.x, position.y] := ' '; { delete powerup } End; UNTIL (move = 'q'); { q to quit level } ClrScr; close(level); WriteLn(' Enter : erneut spielen'); WriteLn(' q : Spiel beenden '); ReadLn(quit); UNTIL (quit = 'q'); { q to quit whole programm } End.
Es sind beliebig viele neue Level mit Hilfe eines einfachen Texteditors erstellbar. Dazu schaut man sich am besten einfach die bereits vorhandenen Level an und nutzt lev_template.txt als Vorlage.