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

Username:   Password: 
 RegisterRegister   
 Can u see any errors???? plz post!!!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Amreen




PostPosted: Tue Jan 18, 2005 5:20 pm   Post subject: Can u see any errors???? plz post!!!

i added level to my blocksies game but there seems to be an error...i just can't figure it out! plz assist me!!! Im beginner at turing!

code:
% ******************************************************
%
% The Turing Programming Language
% Activity #15: The 'Blocksies' Game!
% Date: Friday, January 21st, 2005
% Prepared by: Amreen Azam
% Prepared for: Mr. Henrich
% Class: TEE201-01
%
% ******************************************************

var Level: int
var Response: string

put "Welcome to the Blocksies Game!"
put "Please choose your level (1, 2 or 3): "
put "1. BABY (The blocker is large and the asterisks fall slower!)"
put "2. INTERMEDIATE (The blocker is medium and the asterisks at a steady pace!)"
put "3. ADVANCED (The blocker is small and the asterisks fall fast!)"
get Level

cls

case Level of
    label 1: put "Welcome to Blocksies Game. This level is Baby which means that"
             put "the blocker located on the bottom of the screen is larger than"
             put "the rest of the levels and also, the asterisks fall slower."
             put "The object of this game is to block the asterisks by moving the"
             put "blocker at the bottom of the screen, by using left and right <ARROW>"
             put "key along with the <HOME>, which makes the blocker move to the far"
             put "left of the screen, and <END>, which makes the blocker move to the"
             put "far right of the screen. You have 10 asterisks to hit. GOOD LUCK!!!"
             put "BEAT THE CLOCK!"
   
    label 2: put "Welcome to Blocksies Game. This level is Intermediate which means that"
             put "the blocker located on the bottom of the screen is small"
             put "and also, the asterisks fall slower."
             put "The object of this game is to block the asterisks by moving the"
             put "blocker at the bottom of the screen, by using left and right <ARROW>"
             put "key along with the <HOME>, which makes the blocker move to the far"
             put "left of the screen, and <END>, which makes the blocker move to the"
             put "far right of the screen. You have 10 asterisks to hit. GOOD LUCK!!!"
             put "BEAT THE CLOCK!"
             
    label 3: put "Welcome to Blocksies Game. This level is Advance which means that"
             put "the blocker located on the bottom of the screen is the smallest compared"
             put "to the rest of the levels. Also, the asterisks fall the fastest in this level."
             put "The object of this game is to block the asterisks by moving the"
             put "blocker at the bottom of the screen, by using left and right <ARROW>"
             put "key along with the <HOME>, which makes the blocker move to the far"
             put "left of the screen, and <END>, which makes the blocker move to the"
             put "far right of the screen. You have 10 asterisks to hit. GOOD LUCK!!!"
             put "BEAT THE CLOCK!"
             
    label : put "You entered an invalid number! Please pick a level!"
   
end case

if Level=1 then
%This program is what the BLOCKSIES game is going to look like
%as this is the structure of the game.

const BLOCKER:=
    chr(220)+chr(220)+chr(220)+chr(220)+chr(220)
const WAIT:=125
const NUMBER_OF_ASTERISKS:=10
const LEFT_ARROW:= chr(203)
const RIGHT_ARROW:= chr(205)
const HOME:= chr(199)
const END:= chr(207)
const BLOCKER_ROW:=24
const BLANK_BLOCKER:= "          " % 10 blank spaces

var Key:string (1)
var Asterisks_Column, Start, Finish:int
var Blocker_Column:= 38
var Asterisks_Row:=2

setscreen ("noecho, nocursor")
% We set the screen because we want to make sure that the user's
% keystrokes and not displayed and also to hide the cursor
% while the game is being played. Also, we set up the global vaiables
% and constants that will be needed in this program.

procedure Move_Blocker

    %We wait for the user to press a key.
    getch (Key)
   
    %We erase a previously positioned blocker.
    locate (BLOCKER_ROW, Blocker_Column)
    put BLANK_BLOCKER
   
    %We adjust the position of the blocker according
    %to the direction specified by the user.
   
    if Key = RIGHT_ARROW then
        Blocker_Column:= Blocker_Column + 2
    elsif Key = LEFT_ARROW then
        Blocker_Column :=Blocker_Column - 2
    elsif Key = HOME then
        Blocker_Column:= 2
    elsif Key = END then
        Blocker_Column:= 75
    end if
   
    %We do not allow the blocker to be moved
    %beyond the borders of the screen.
   
    if Blocker_Column > 75 then
       Blocker_Column:=75
    elsif Blocker_Column < 2 then
       Blocker_Column:=2
    end if

    %The blocker is displayed on the screen.
   
    locate (BLOCKER_ROW, Blocker_Column)
    put BLOCKER
   
    end Move_Blocker

%This will randomly determine the column that each
%asterisk is going to fall from.
randomize

%Clock keeps track of the time (in milliseconds) that
%Turing has been in use.
clock(Start)

for Asterisk:1..NUMBER_OF_ASTERISKS

locate (1,1)
put "Asterisk #",Asterisk


randint (Asterisks_Column, 2, 79)

loop
    locate (Asterisks_Row, Asterisks_Column)
    put "*"..
    delay (WAIT)

    if hasch then
        Move_Blocker
    end if
   
    locate (Asterisks_Row, Asterisks_Column)
    put " "
   
    Asterisks_Row:=Asterisks_Row + 1
   
    if Asterisks_Row > 24 then
        Asterisks_Row:= 2
    end if
   
    if Asterisks_Column >= Blocker_Column and
        Asterisks_Column <= Blocker_Column + 4 and
        Asterisks_Row = 24 then
        sound (100, 100)
        exit
    elsif Asterisks_Row = 24 and
    (Asterisks_Column < Blocker_Column or
     Asterisks_Column > Blocker_Column + 4) then
    sound (100,100)
    end if
   
    end loop
end for

clock (Finish)

cls
put "TIME: ", (Finish - Start) / 1000, " Seconds."

elsif Level=2 then

const BLOCKER:=
    chr(220)+chr(220)+chr(220)+chr(220)+chr(220)
const WAIT:=125
const NUMBER_OF_ASTERISKS:=10
const LEFT_ARROW:= chr(203)
const RIGHT_ARROW:= chr(205)
const HOME:= chr(199)
const END:= chr(207)
const BLOCKER_ROW:=24
const BLANK_BLOCKER:= "      " % 6 blank spaces

var Key:string (1)
var Asterisks_Column, Start, Finish:int
var Blocker_Column:= 38
var Asterisks_Row:=2

setscreen ("noecho, nocursor")
% We set the screen because we want to make sure that the user's
% keystrokes and not displayed and also to hide the cursor
% while the game is being played. Also, we set up the global vaiables
% and constants that will be needed in this program.

procedure Move_Blocker

    %We wait for the user to press a key.
    getch (Key)
   
    %We erase a previously positioned blocker.
    locate (BLOCKER_ROW, Blocker_Column)
    put BLANK_BLOCKER
   
    %We adjust the position of the blocker according
    %to the direction specified by the user.
   
    if Key = RIGHT_ARROW then
        Blocker_Column:= Blocker_Column + 2
    elsif Key = LEFT_ARROW then
        Blocker_Column :=Blocker_Column - 2
    elsif Key = HOME then
        Blocker_Column:= 2
    elsif Key = END then
        Blocker_Column:= 75
    end if
   
    %We do not allow the blocker to be moved
    %beyond the borders of the screen.
   
    if Blocker_Column > 75 then
       Blocker_Column:=75
    elsif Blocker_Column < 2 then
       Blocker_Column:=2
    end if

    %The blocker is displayed on the screen.
   
    locate (BLOCKER_ROW, Blocker_Column)
    put BLOCKER
   
    end Move_Blocker

%This will randomly determine the column that each
%asterisk is going to fall from.
randomize

%Clock keeps track of the time (in milliseconds) that
%Turing has been in use.
clock(Start)

for Asterisk:1..NUMBER_OF_ASTERISKS

locate (1,1)
put "Asterisk #",Asterisk


randint (Asterisks_Column, 2, 79)

loop
    locate (Asterisks_Row, Asterisks_Column)
    put "*"..
    delay (2000)

    if hasch then
        Move_Blocker
    end if
   
    locate (Asterisks_Row, Asterisks_Column)
    put " "
   
    Asterisks_Row:=Asterisks_Row + 1
   
    if Asterisks_Row > 24 then
        Asterisks_Row:= 2
    end if
   
    if Asterisks_Column >= Blocker_Column and
        Asterisks_Column <= Blocker_Column + 4 and
        Asterisks_Row = 24 then
        sound (100, 100)
        exit
    elsif Asterisks_Row = 24 and
    (Asterisks_Column < Blocker_Column or
     Asterisks_Column > Blocker_Column + 4) then
    sound (100,100)
    end if
   
    end loop
end for

clock (Finish)

cls
put "TIME: ", (Finish - Start) / 1000, " Seconds."

elsif Level=3 then
%This program is what the BLOCKSIES game is going to look like
%as this is the structure of the game.

const BLOCKER:=
    chr(220)+chr(220)+chr(220)+chr(220)+chr(220)
const WAIT:=125
const NUMBER_OF_ASTERISKS:=10
const LEFT_ARROW:= chr(203)
const RIGHT_ARROW:= chr(205)
const HOME:= chr(199)
const END:= chr(207)
const BLOCKER_ROW:=24
const BLANK_BLOCKER:= "   " % 3 blank spaces

var Key:string (1)
var Asterisks_Column, Start, Finish:int
var Blocker_Column:= 38
var Asterisks_Row:=2

setscreen ("noecho, nocursor")
% We set the screen because we want to make sure that the user's
% keystrokes and not displayed and also to hide the cursor
% while the game is being played. Also, we set up the global vaiables
% and constants that will be needed in this program.

procedure Move_Blocker

    %We wait for the user to press a key.
    getch (Key)
   
    %We erase a previously positioned blocker.
    locate (BLOCKER_ROW, Blocker_Column)
    put BLANK_BLOCKER
   
    %We adjust the position of the blocker according
    %to the direction specified by the user.
   
    if Key = RIGHT_ARROW then
        Blocker_Column:= Blocker_Column + 2
    elsif Key = LEFT_ARROW then
        Blocker_Column :=Blocker_Column - 2
    elsif Key = HOME then
        Blocker_Column:= 2
    elsif Key = END then
        Blocker_Column:= 75
    end if
   
    %We do not allow the blocker to be moved
    %beyond the borders of the screen.
   
    if Blocker_Column > 75 then
       Blocker_Column:=75
    elsif Blocker_Column < 2 then
       Blocker_Column:=2
    end if

    %The blocker is displayed on the screen.
   
    locate (BLOCKER_ROW, Blocker_Column)
    put BLOCKER
   
    end Move_Blocker

%This will randomly determine the column that each
%asterisk is going to fall from.
randomize

%Clock keeps track of the time (in milliseconds) that
%Turing has been in use.
clock(Start)

for Asterisk:1..NUMBER_OF_ASTERISKS

locate (1,1)
put "Asterisk #",Asterisk


randint (Asterisks_Column, 2, 79)

loop
    locate (Asterisks_Row, Asterisks_Column)
    put "*"..
    delay (500)

    if hasch then
        Move_Blocker
    end if
   
    locate (Asterisks_Row, Asterisks_Column)
    put " "
   
    Asterisks_Row:=Asterisks_Row + 1
   
    if Asterisks_Row > 24 then
        Asterisks_Row:= 2
    end if
   
    if Asterisks_Column >= Blocker_Column and
        Asterisks_Column <= Blocker_Column + 4 and
        Asterisks_Row = 24 then
        sound (100, 100)
        exit
    elsif Asterisks_Row = 24 and
    (Asterisks_Column < Blocker_Column or
     Asterisks_Column > Blocker_Column + 4) then
    sound (100,100)
    end if
   
    end loop
end for

clock (Finish)

cls
put "TIME: ", (Finish - Start) / 1000, " Seconds."

else
    Response:= "You entered an invalid number."

end if

put ""
Sponsor
Sponsor
Sponsor
sponsor
Neo




PostPosted: Tue Jan 18, 2005 5:26 pm   Post subject: (No subject)

You have 2 procedures with identical names and they are declared inside if statments. That is not the point of procedures.
Amreen




PostPosted: Tue Jan 18, 2005 5:34 pm   Post subject: (No subject)

then what do i do to change it? any suggestions...?
Delos




PostPosted: Tue Jan 18, 2005 6:02 pm   Post subject: (No subject)

A procedure may only be declared at the programme, class, or module level. Declaing them within a construct such as if or for cannot be done.
Declare your procedures sometime at the outset of your proggie, then call them when you get to your if statement.
I havn't looked at your code yet, but chances are that you could use a single procedure with parameters.

For a good idea what this is all about:
Procedures and such by tony
Modules by myself (shameless plug). This is not primarily a procedure oriented tutorial but it will give you a good idea of how to use parameters and such.

BTW, for code that long, you'd be better off attaching a file than pasting the code.
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  [ 4 Posts ]
Jump to:   


Style:  
Search: