Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 text file map help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Shyfire




PostPosted: Fri Dec 16, 2005 8:11 pm   Post subject: text file map help

this code make it so your character walks through the text of the map is there an easier way to do this?
and could you explaine it plz

heres the code (btw its not my code i got it from the source section Smile ....)
code:

setscreen ("graphics:150;150,nobuttonbar,position:center;center,offscreenonly")
colorback (black)
color (white)
cls
var spot : array 1 .. maxrow + 1, 1 .. maxcol + 1 of int
% The +1 is for when the game is running, it checks at maxrow+1 which does not exist . . so lets make it exist

for q : 1 .. upper (spot, 1) %maxrow
    for i : 1 .. upper (spot, 2) %maxcol
        spot (q, i) := Rand.Int (0, 4) %4 means cannot walk there
    end for
end for

spot (1, 1) := 0 %Make the first spot open
var x, y : int := 1 %(x,y) starts at (1,1) which is =0
var xHold, yHold : int := x
var valueHold : string := ""

var key : array char of boolean

proc refresh
    for q : 1 .. upper (spot, 1) - 1    %we cannot go to maxrow+1 so dont
        for i : 1 .. upper (spot, 2) - 1 %we cannot go to maxcol+1 so dont
            color (spot (q, i)+28)
            locate (q, i) %locate properly
            put spot (q, i) .. %put whatever value is there
        end for
    end for
    color (10)
    locate (x, y) %locate where our man is
    put "P" ..
end refresh

loop
    Input.KeyDown (key)
    % Basically the if statements say, if the next spot is NOT 4 and is NOT off screen then go ahead
    if key (KEY_LEFT_ARROW) and y - 1 not= 0 and spot (x, y - 1) not= 4 then
        y -= 1
    elsif key (KEY_RIGHT_ARROW) and y + 1 <= maxcol and spot (x, y + 1) not= 4 then
        y += 1
    end if
    if key (KEY_UP_ARROW) and x - 1 not= 0 and spot (x - 1, y) not= 4 then
        x -= 1
    elsif key (KEY_DOWN_ARROW) and x + 1 <= maxrow and spot (x + 1, y) not= 4 then
        x += 1
    end if
    refresh
    View.Update
    delay (100)
end loop
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: