Code: Select all
DIM scr$(10, 10)' create an array to hold data
FOR x = 1 TO 10
FOR y = 1 TO 10
READ s$
IF LEN(s$) > 1 THEN scr$(x, y) = CHR$(VAL(s$)) ELSE scr$(x, y) = s$
NEXT y
NEXT x
DATA 177,177,177,177,177,177,177,177,177,177
DATA 177,032,032,032,032,032,032,032,032,177
DATA 177,032,177,177,177,177,177,177,032,177
DATA 177,032,177,032,G ,177,032,177,032,177
DATA 177,032,177,032,032,177,032,032,032,177
DATA 177,032,032,032,177,177,032,032,177,177
DATA 177,177,177,177,177,032,032,032,032,177
DATA 177,032,032,032,032,032,032,032,177,177
DATA 177,032,032,032,032,P ,032,032,032,177
DATA 177,177,177,177,177,177,177,177,177,177
gameover = 0
WHILE gameover = 0
FOR x = 1 TO 10
FOR y = 1 TO 10
PRINT scr$(x, y);
IF scr$(x, y) = "P" THEN px = x: py = y
NEXT y
PRINT " "
NEXT x
x = px: y = py
INPUT "Enter your move "; m$
m$ = UCASE$(LEFT$(m$, 1))
SELECT CASE m$
CASE "W"
IF y > 1 THEN ' player is moving off-screen
IF scr$(x, y - 1) = " " THEN
SWAP scr$(x, y - 1), scr$(x, y)
END IF
IF scr$(x, y - 1) = "G" THEN
GOSUB general
END IF
END IF
CASE "E"
IF y < 10 THEN ' check player going off screen
IF scr$(x, y + 1) = " " THEN
SWAP scr$(x, y + 1), scr$(x, y)
END IF
IF scr$(x, y + 1) = "G" THEN
GOSUB general
END IF
END IF
CASE "N"
IF x > 1 THEN
IF scr$(x - 1, y) = " " THEN
SWAP scr$(x - 1, y), scr$(x, y)
END IF
IF scr$(x - 1, y) = "G" THEN
GOSUB general
END IF
END IF
CASE "S"
IF x < 10 THEN
IF scr$(x + 1, y) = " " THEN
SWAP scr$(x + 1, y), scr$(x, y)
END IF
IF scr$(x + 1, y) = "G" THEN
GOSUB general
END IF
END IF
CASE "Q"
SYSTEM
CASE ELSE ' to be done if no cases above match
PRINT "I don't understand that move"
END SELECT
WEND
SYSTEM
general:
gameover = 1
RETURN
' this part could also be coded as a subroutine!
This will actually run in QB4.5 You might need to make some minor modifications to run it under qb 1.1 or FreeBasic.