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

Username:   Password: 
 RegisterRegister   
 Cases
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
TheFerret




PostPosted: Wed Mar 10, 2004 7:44 pm   Post subject: Cases

I am using cases to move a thing in programs and I don't know what to have my varriable as... It is the starting of pac man... The variable is called move...

code:
setscreen ("graphics:600;600")
var x, y : int := 51
var change : int := 5
var chars : array char of boolean
var move : string %:= KEY_UP_ARROW
loop

    case move of
        label (KEY_UP_ARROW) :
            y += change
        label (KEY_RIGHT_ARROW) :
            x += change
        label (KEY_DOWN_ARROW) :
            y -= change
        label (KEY_LEFT_ARROW) :
            x -= change
        label :
    end case


    drawbox (0 + 40, 0 + 40, maxx - 40, maxy - 40, 17)
    drawbox (0 + 60, 0 + 60, maxx - 60, maxy - 60, 17)
    drawfillarc (x, y, 10, 10, 0, 320, 49)
    if x <= 40 then
        x += change
    elsif x >= 60 then
        x -= change
    elsif y <= 40 then
        y += change
    elsif y >= 60 then
        y -= change
    elsif x <= maxx - 40 then
        x += change
    elsif x >= maxx - 60 then
        x -= change
    elsif y <= maxy - 40 then
        y += change
    elsif y >= maxy - 60 then
        y -= change
    end if
end loop
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Wed Mar 10, 2004 8:04 pm   Post subject: (No subject)

hmm.. interesting. If you are simply trying to get user input using Input.KeyDown, you should use if statements to determine whether the specific key is pressed.

I don't think it'll let you do it with cases. When you try to put the chars var into the case it gives you an error saying its a bad type for case expression. When you try to put any other var in, it doesn't know what in the world you're talking about when your talking about (KEY_UP_ARROW).
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  [ 2 Posts ]
Jump to:   


Style:  
Search: