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

Username:   Password: 
 RegisterRegister   
 Specific Menu Options?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
PrinceCooper




PostPosted: Thu Jun 16, 2011 5:46 pm   Post subject: Specific Menu Options?

What is it you are trying to achieve?
I want to have the menu only accept the numerical values; 1, 2 and 3


What is the problem you are having?
The game crashed or errors out every time another number or any other key is pressed, I want the game to either:

1) Not react at all unless 1, 2, or 3 is pressed (NO ERROR)

or

2) Be able to have a message appear the suggests that the user enter the valid integers


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>

Turing:


% VARIABLES
var x1, x2, x3, x4, x5 : int     % Lengths, X-Axis
var xdir, ydir : int             % Keeps Track of Speed of Ball
var y1 : int                     % Height,Y-axis
var key : string (1)             % Key Board Character
var num : int                    % Stores ASCII Numbers
var count : int                  % Keeps Track of Score
var choice : string (1)          % Choice for menu
var name : string                % Name for Highscore
var font1 : int
font1 := Font.New ("Agency FB:30")

% MUSIC
process DoMusic                                  % These lines are responsable for adding backround music to the game.
    loop
        Music.PlayFile ("Davros.mp3")
    end loop
end DoMusic

fork DoMusic


loop
    % MENU
    drawfill (10, 10, 225, 225)
    locate (10, 24)
    colorback (225)
    Font.Draw ("WELCOME TO RYAN'S PADDLEBALL GAME!", 90, 320, font1, 31)
    locate (11, 30)
    color (31)
    put "Created By: Ryan Covell" ..
    locate (13, 28)
    color (31)
    put "PRESS (1) TO START A NEW GAME" ..
    locate (15, 28)
    color (31)
    put "PRESS (2) TO SEE HIGH-SCORE TABLE" ..
    locate (17, 28)
    color (31)
    put "PRESS (3) TO QUIT GAME" ..
    color (31)
    locate (20, 2)
    put "Use the left (<--) and right (-->) arrows to direct the paddle. The point of the game is to try and keep the ball moving and stop it from hitting the ground!"

    getch (choice)
    case choice of

            % MAIN GAME
        label "1" :
            cls
            View.Set ("offscreenonly")
            loop
                cls
                count := 0                %Setting the values for the variables
                num := 0
                x1 := 110
                xdir := 3
                ydir := 3
                y1 := 110
                x4 := 110
                x5 := 160
                x2 := 110
                x3 := 160


                loop
                    drawfill (10, 10, 225, 225)     % Background Colour
                    locate (10, 2)
                    colorback (225)
                    color (31)
                    put "SCORE ", count ..
                    drawbox (110, -100, 635, 389, 31)     % Background
                    drawfillbox (x4, 0, x5, 10, 31)     % Paddle
                    drawfilloval (x1, y1, 5, 5, 31)     % Ball
                    delay (10)
                    View.Update
                    exit when y1 = -10
                    drawfilloval (x1, y1, 5, 5, 225)     % Erasing Ball Trail
                    drawfillbox (x4, 0, x5, 10, 225)     % Erasing Paddle Trail

                    if hasch then
                        getch (key)     % Get Key Pressed
                        num := ord (key)     % Find ASCII number for key
                    end if

                    if num = 203 and x4 >= 120 then     % Left arrow
                        x4 := x4 - 25
                        x5 := x5 - 25
                    elsif num = 205 and x5 <= 620 then     % Right arrow
                        x5 := x5 + 25
                        x4 := x4 + 25
                    end if
                    num := 0


                    if y1 >= 10 and y1 <= 15 and x1 >= x4 and x1 <= x5 then     % makes ball bounce of paddle
                        count := count + 1     % adds 1 point to the score each time it hits paddle
                        ydir := 3
                    end if
                    if x1 <= 101 then     % makes ball not go past 101 on x axis
                        xdir := 3
                    elsif x1 >= 620 then     % makes ball not go past 620 on x axis
                        xdir := -3
                    elsif y1 >= 380 then     % makes ball not go past 380 on y axis
                        ydir := -3
                    elsif y1 <= -60 then     % makes ball not go past -60 on y axis
                        ydir := 3
                    end if

                    y1 := y1 + ydir
                    x1 := x1 + xdir

                end loop

                % GAME OVER

                loop
                    locate (10, 20)
                    put "Do you want to try again? (Y=Yes / N=NO)" ..               % This is the game over menu.
                    View.Update
                    getch (key)
                    exit when key = "n" or key = "y"
                    cls
                    count := 0
                end loop
                exit when key = "n"     %Exit loop when 'n' is pressed.
            end loop
            View.Set ("nooffscreenonly")
            cls
            locate (10, 30)
            put "THANKS FOR PLAYING!"
            locate (12, 30)
            put "PLEASE ENTER YOUR NAME FOR HIGHSCORE TABLE!"
            get name

            var stream : int
            open : stream, name + ".txt", put
            put : stream, count

            name := ""
            count := 0
            close : stream
            cls

        label "2" :
            cls

            var stream : int
            put "Enter Player Name."
            get name

            open : stream, name + ".txt", get     %notice the file has to be in the "get" mode
            get : stream, count
            put count
            delay (4000)
            cls

            name := ""
            count := 0
            close : stream

        label "3" :
            quit




    end case
end loop




Please specify what version of Turing you are using
Version 4.0.4.C
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Jun 16, 2011 6:04 pm   Post subject: Re: Specific Menu Options?

PrinceCooper @ Thu Jun 16, 2011 5:46 pm wrote:
The game crashed or errors out every time another number or any other key is pressed

What does the error say?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
PrinceCooper




PostPosted: Thu Jun 16, 2011 7:43 pm   Post subject: Re: Specific Menu Options?

The error says "Case selector is out of range"
Tony




PostPosted: Thu Jun 16, 2011 8:00 pm   Post subject: RE:Specific Menu Options?

Right. So the problem likely has something to do with your case statement.
Quote:

The case expression is required to match one of the labels.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Zren




PostPosted: Thu Jun 16, 2011 8:00 pm   Post subject: RE:Specific Menu Options?

Read the description of case.

Edit: Ai-ya. Ninja'd. Read the part where you have a label for anything else not specified.
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  [ 5 Posts ]
Jump to:   


Style:  
Search: