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

Username:   Password: 
 RegisterRegister   
 Dot Racing Game
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Artimes




PostPosted: Tue Nov 04, 2003 8:17 pm   Post subject: Dot Racing Game

I just wanted to say hi, I'm new to this forum. I'm in grade 10, and I attend Ander C. V. I. in Whitby Ontario Canada.

This is my Dot Racing Game, quite fun!

(I just used the name "Andrew's Race Way")

code:

% Andrew's Race Way
% Created by:John Baker
% Created on November 4th, 2003
% This is virtual illigal underground dot racing game

% Variables

var racer1, racer2, speed1, speed2, wager, credits, win, startcredits : int
% racer1/racer2: Represents the posistion of the racers
% speed1/speed2: Represents the speed of the two racers
% wager: Repesents the user's wager
% credits: Represents the amount of credits the user has
% win: Represents wether you have won, lost, or had a tie
% startcredits: Represents the amount of starting credits

var continue, restart, guess : string
% continue: Represents the users choice to race again
% restart: Represents the user choice to start over, if he/she has ran out of money
% guess: Represents the guess of the user

var next : char % Represents the user input of any key, to move to the next screen

% Variable Definition

win := 0
racer1 := 50
racer2 := 50
credits := 100

colourback (7)
colour (0)
cls

% Introduction

put " " : 26, "Welcome to Andrew's Race Way"
put " " : 25, "------------------------------"
put " "
put "Welcome to Andrew's Race Way!"
put " "
put "You will first choose the ammount of starting credits you want."
put " "
put "You will be biding on one of the two racers, grey or red."
put " "
put "The bidding system works as the following,"
put "you will choose the racer you think will win."
put " "
put "You will then be asked to place a bet on your racer."
put " "
put "If you win, you will get your wager back,"
put "plus double your wager on top of it!"
put " "
put "Press any key to begin."
put " "

next := getchar

cls

% Start Credits

loop

    put " " : 26, "Welcome to Andrew's Race Way"
    put " " : 25, "------------------------------"
    put " "
    put "How many credit(s) would you like to start with? (1-1000)"
    put " "

    get startcredits

    if (startcredits >= 1) and (startcredits <= 1000) then

        cls

        exit

    end if

    cls

end loop

credits := startcredits

loop

    racer1 := 50
    racer2 := 50
    wager := 0

    % User Input (Guess)
    loop

        put " " : 26, "Welcome to Andrew's Race Way"
        put " " : 25, "------------------------------"
        put " "
        put "Which racer would you like to bid on?"
        put " "
        put "Each racer has their own speed."
        put " "
        put "Grey Racer - Will move from 2-4 spaces. (Grey) or (1)"
        put "Red Racer - Will move from 1-5 spaces. (Red) or (2)"
        put " "
        put "You have ", credits, " credit(s)."
        put " "

        get guess

        cls

        if (guess = "Grey") or (guess = "grey") or (guess = "1") or (guess = "Red") or (guess = "red") or (guess = "2") then

            exit

        end if

    end loop

    % User Input (Wager)
    loop

        put " " : 26, "Welcome to Andrew's Race Way"
        put " " : 25, "------------------------------"
        put " "
        put "How many credits would you like to wager on your racer?"
        put " "
        put "You have ", credits, " credit(s)."
        put " "

        get wager

        cls

        if wager > 0 and wager <= credits then

            exit

        else

            cls

        end if

    end loop

    % Draws the initial images
    drawfilloval (racer1, 250, 20, 20, 8)
    drawfilloval (racer2, 150, 20, 20, 12)
    drawline (575, 300, 575, 100, 0)

    % Starts race countdown
    put " " : 26, "Welcome to Andrew's Race Way"
    put " " : 25, "------------------------------"
    put " "
    put " " : 27, "On your mark" ..

    delay (1000)

    put ", get set" ..

    delay (1000)

    put ", GO!"

    delay (500)

    cls

    % Race begins
    loop

        put " " : 26, "Welcome to Andrew's Race Way"
        put " " : 25, "------------------------------"
        put " "

        if (guess = "Grey") or (guess = "grey") or (guess = "1") then

            put " " : 26, "You voted for the Grey Racer"

        end if

        if (guess = "Red") or (guess = "red") or (guess = "2") then

            put " " : 26, "You voted for the Red Racer"

        end if

        % Rolls to find speed of each racer
        randint (speed1, 2, 4)
        randint (speed2, 1, 5)

        % Draws images, in their new position
        drawfilloval (racer1, 250, 20, 20, 8)
        drawfilloval (racer2, 150, 20, 20, 12)
        drawline (575, 300, 575, 100, 0)

        % Calculates how far the racers have moved
        racer1 := speed1 + racer1
        racer2 := speed2 + racer2

        delay (40)

        cls

        % Stops race when first racer reaches certian point
        exit when racer1 >= 555 or racer2 >= 555

    end loop

    % Re-draws the racers
    drawfilloval (racer1, 250, 20, 20, 8)
    drawfilloval (racer2, 150, 20, 20, 12)
    drawline (575, 300, 575, 100, 0)

    % Deciding the winner (Racer one)
    if racer1 >= 555 then

        put " " : 26, "Welcome to Andrew's Race Way"
        put " " : 25, "------------------------------"
        put " "
        put "Grey racer is the winner!"
        put " "

        if (guess = "Grey") or (guess = "grey") or (guess = "1") then % Racer one wins, and you guess for him

            put "You won ", wager * 2, " credits!"

            drawfilloval (racer1, 250, 20, 20, 8)
            drawfilloval (racer2, 150, 20, 20, 12)
            drawline (575, 300, 575, 100, 0)

            win := 1

        else % Racer one wins, and you didn't guess for him

            put "You lost ", wager, " credit(s)."

            drawfilloval (racer1, 250, 20, 20, 8)
            drawfilloval (racer2, 150, 20, 20, 12)
            drawline (575, 300, 575, 100, 0)

            win := 2

        end if

    end if

    % Deciding the winner (Racer two)
    if racer2 >= 555 then

        put " " : 26, "Welcome to Andrew's Race Way"
        put " " : 25, "------------------------------"
        put " "
        put "Red racer is the winner!"
        put " "

        if (guess = "Red") or (guess = "red") or (guess = "2") then % Racer two wins, and you guess for him

            put "You won ", wager * 2, " credits!"

            drawfilloval (racer1, 250, 20, 20, 8)
            drawfilloval (racer2, 150, 20, 20, 12)
            drawline (575, 300, 575, 100, 0)

            win := 1

        else % Racer two wins, and you didn't guess for him

            put "You lost ", wager, " credit(s)."

            drawfilloval (racer1, 250, 20, 20, 8)
            drawfilloval (racer2, 150, 20, 20, 12)
            drawline (575, 300, 575, 100, 0)

            win := 2

        end if

    end if

    % Deciding the winner (Tie)
    if (racer1 >= 555) and (racer2 >= 555) then

        cls

        put " " : 26, "Welcome to Andrew's Race Way"
        put " " : 25, "------------------------------"
        put " "
        put "It is a tie!"
        put " "
        put "You get your ", wager, " credit(s) back."

        drawfilloval (racer1, 250, 20, 20, 8)
        drawfilloval (racer2, 150, 20, 20, 12)
        drawline (575, 300, 575, 100, 0)

        win := 3

    end if

    % Process earnings
    if win = 1 then % Win

        credits := credits + (wager * 2)

    elsif win = 2 then % Lose

        credits := credits - wager

    elsif win = 3 then % Tie

        credits := credits

    end if

    put " "
    next := getchar

    cls

    % User Input (Continue)
    if credits > 0 then

        put " " : 26, "Welcome to Andrew's Race Way"
        put " " : 25, "------------------------------"
        put " "
        put "You have ", credits, " credit(s)."
        put " "
        put "Would you like to race again? (Y) or (N)"
        put " "

        get continue : *

        cls

        % User Input (Yes or No)
        if (continue = "N") or (continue = "n") or (continue = "No") or (continue = "no") then

            exit

        end if

    end if

    % User Input (Restart)
    if credits = 0 then

        put " " : 26, "Welcome to Andrew's Race Way"
        put " " : 25, "------------------------------"
        put " "
        put "You have no more credits."
        put " "
        put "Would you like to restart? (Y) or (N)"
        put " "

        get restart : *

        cls

        % User Input (Yes or No)
        if (restart = "Y") or (restart = "y") or (restart = "Yes") or (restart = "yes") then

            % Start Credits
            loop

                put " " : 26, "Welcome to Andrew's Race Way"
                put " " : 25, "------------------------------"
                put " "
                put "How many credit(s) would you like to start with? (1-1000)"
                put " "

                get startcredits

                if (startcredits >= 1) and (startcredits <= 1000) then

                    cls

                    exit

                end if

            end loop

            credits := startcredits

            cls

            put " " : 26, "Welcome to Andrew's Race Way"
            put " " : 25, "------------------------------"
            put " "
            put "You now have ", startcredits, " credit(s)."
            put " "
            put "Press any key to continue."
            put " "

            next := getchar

            cls

        else

            exit

        end if

    end if

    cls

end loop

put " " : 26, "Welcome to Andrew's Race Way"
put " " : 25, "------------------------------"
put " "
put "Thanks for coming out!"
put " "
put "Hope to see you again!"
put " "
put "You are leaving with ", credits, " credit(s)."
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Tue Nov 04, 2003 9:01 pm   Post subject: (No subject)

hey, that's not that bad Very Happy

You could still improve it though.. like better gfx (Pic. module), maybe some sounds and use of View.Update

+20Bits
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Artimes




PostPosted: Tue Nov 04, 2003 10:32 pm   Post subject: (No subject)

Ya, it's just the basics, I might change the ovals to picture, I'm not sure of what. Some sound effecs, baybe a midi or two. You know, this was just the out line.
l0tt0




PostPosted: Wed Nov 05, 2003 6:01 pm   Post subject: (No subject)

i think it's done pretty good. Very Happy
Artimes




PostPosted: Wed Nov 05, 2003 7:40 pm   Post subject: (No subject)

I tried to edit my code, I found a few small, and fatal errors.... So here is a newer vesion!

code:

% Andrew's Race Way
% Created by: Andrew Gunn, John Baker
% Created on November 4th, 2003
% This is virtual illigal underground dot racing game

% Variables

var racer1, racer2, speed1, speed2, wager, credits, win, startcredits : int
% racer1/racer2: Represents the posistion of the racers
% speed1/speed2: Represents the speed of the two racers
% wager: Repesents the user's wager
% credits: Represents the amount of credits the user has
% win: Represents wether you have won, lost, or had a tie
% startcredits: Represents the amount of starting credits

var continue, restart, guess : string
% continue: Represents the users choice to race again
% restart: Represents the user choice to start over, if he/she has ran out of money
% guess: Represents the guess of the user

var next : char % Represents the user input of any key, to move to the next screen

% Variable Definition

win := 0
racer1 := 50
racer2 := 50
credits := 100

colourback (7)
colour (0)
cls

% Introduction

put " " : 26, "Welcome to Andrew's Race Way"
put " " : 25, "------------------------------"
put " "
put "Welcome to Andrew's Race Way!"
put " "
put "You will first choose the ammount of starting credits you want."
put " "
put "You will be biding on one of the two racers, grey or red."
put " "
put "The bidding system works as the following,"
put "you will choose the racer you think will win."
put " "
put "You will then be asked to place a bet on your racer."
put " "
put "If you win, you will get your wager back,"
put "plus double your wager on top of it!"
put " "
put "Press any key to begin."
put " "

next := getchar

cls

% Start Credits

loop

    put " " : 26, "Welcome to Andrew's Race Way"
    put " " : 25, "------------------------------"
    put " "
    put "How many credit(s) would you like to start with? (1-1000)"
    put " "

    get startcredits

    if (startcredits >= 1) and (startcredits <= 1000) then

        cls

        exit

    end if

    cls

end loop

credits := startcredits

loop

    racer1 := 50
    racer2 := 50
    wager := 0

    % User Input (Guess)
    loop

        put " " : 26, "Welcome to Andrew's Race Way"
        put " " : 25, "------------------------------"
        put " "
        put "Which racer would you like to bid on?"
        put " "
        put "Each racer has their own speed."
        put " "
        put "Grey Racer - Will move from 2-4 spaces. (Grey) or (1)"
        put "Red Racer - Will move from 1-5 spaces. (Red) or (2)"
        put " "
        put "You have ", credits, " credit(s)."
        put " "

        get guess

        cls

        if (guess = "Grey") or (guess = "grey") or (guess = "1") or (guess = "Red") or (guess = "red") or (guess = "2") then

            exit

        end if

    end loop

    % User Input (Wager)
    loop

        put " " : 26, "Welcome to Andrew's Race Way"
        put " " : 25, "------------------------------"
        put " "
        put "How many credits would you like to wager on your racer?"
        put " "
        put "You have ", credits, " credit(s)."
        put " "

        get wager

        cls

        if wager > 0 and wager <= credits then

            exit

        else

            cls

        end if

    end loop

    % Draws the initial images
    drawfilloval (racer1, 250, 20, 20, 8)
    drawfilloval (racer2, 150, 20, 20, 12)
    drawline (575, 300, 575, 100, 0)

    % Starts race countdown
    put " " : 26, "Welcome to Andrew's Race Way"
    put " " : 25, "------------------------------"
    put " "
    put " " : 27, "On your mark" ..

    delay (1000)

    put ", get set" ..

    delay (1000)

    put ", GO!"

    delay (500)

    cls

    % Race begins
    loop

        put " " : 26, "Welcome to Andrew's Race Way"
        put " " : 25, "------------------------------"
        put " "

        if (guess = "Grey") or (guess = "grey") or (guess = "1") then

            put " " : 26, "You voted for the Grey Racer"

        end if

        if (guess = "Red") or (guess = "red") or (guess = "2") then

            put " " : 26, "You voted for the Red Racer"

        end if

        % Rolls to find speed of each racer
        randint (speed1, 2, 4)
        randint (speed2, 1, 5)

        % Draws images, in their new position
        drawfilloval (racer1, 250, 20, 20, 8)
        drawfilloval (racer2, 150, 20, 20, 12)
        drawline (575, 300, 575, 100, 0)

        % Calculates how far the racers have moved
        racer1 := speed1 + racer1
        racer2 := speed2 + racer2

        delay (40)

        cls

        % Stops race when first racer reaches certian point
        exit when racer1 >= 555 or racer2 >= 555

    end loop

    % Re-draws the racers
    drawfilloval (racer1, 250, 20, 20, 8)
    drawfilloval (racer2, 150, 20, 20, 12)
    drawline (575, 300, 575, 100, 0)

    % Deciding the winner (Racer one)
    if racer1 >= 555 then

        put " " : 26, "Welcome to Andrew's Race Way"
        put " " : 25, "------------------------------"
        put " "
        put "Grey racer is the winner!"
        put " "

        if (guess = "Grey") or (guess = "grey") or (guess = "1") then % Racer one wins, and you guess for him

            put "You won ", wager * 2, " credits!"

            drawfilloval (racer1, 250, 20, 20, 8)
            drawfilloval (racer2, 150, 20, 20, 12)
            drawline (575, 300, 575, 100, 0)

            win := 1

        else % Racer one wins, and you didn't guess for him

            put "You lost ", wager, " credit(s)."

            drawfilloval (racer1, 250, 20, 20, 8)
            drawfilloval (racer2, 150, 20, 20, 12)
            drawline (575, 300, 575, 100, 0)

            win := 2

        end if

    end if

    % Deciding the winner (Racer two)
    if racer2 >= 555 then

        put " " : 26, "Welcome to Andrew's Race Way"
        put " " : 25, "------------------------------"
        put " "
        put "Red racer is the winner!"
        put " "

        if (guess = "Red") or (guess = "red") or (guess = "2") then % Racer two wins, and you guess for him

            put "You won ", wager * 2, " credits!"

            drawfilloval (racer1, 250, 20, 20, 8)
            drawfilloval (racer2, 150, 20, 20, 12)
            drawline (575, 300, 575, 100, 0)

            win := 1

        else % Racer two wins, and you didn't guess for him

            put "You lost ", wager, " credit(s)."

            drawfilloval (racer1, 250, 20, 20, 8)
            drawfilloval (racer2, 150, 20, 20, 12)
            drawline (575, 300, 575, 100, 0)

            win := 2

        end if

    end if

    % Deciding the winner (Tie)
    if (racer1 >= 555) and (racer2 >= 555) then

        cls

        put " " : 26, "Welcome to Andrew's Race Way"
        put " " : 25, "------------------------------"
        put " "
        put "It is a tie!"
        put " "
        put "You get your ", wager, " credit(s) back."

        drawfilloval (racer1, 250, 20, 20, 8)
        drawfilloval (racer2, 150, 20, 20, 12)
        drawline (575, 300, 575, 100, 0)

        win := 3

    end if

    % Process earnings
    if win = 1 then % Win

        credits := credits + (wager * 2)

    elsif win = 2 then % Lose

        credits := credits - wager

    elsif win = 3 then % Tie

        credits := credits

    end if

    put " "
    next := getchar

    cls

    % User Input (Continue)
    if credits > 0 then

        put " " : 26, "Welcome to Andrew's Race Way"
        put " " : 25, "------------------------------"
        put " "
        put "You have ", credits, " credit(s)."
        put " "
        put "Would you like to race again? (Y) or (N)"
        put " "

        get continue : *

        cls

        % User Input (Yes or No)
        if (continue = "N") or (continue = "n") or (continue = "No") or (continue = "no") then

            exit

        end if

    end if

    % User Input (Restart)
    if credits = 0 then

        put " " : 26, "Welcome to Andrew's Race Way"
        put " " : 25, "------------------------------"
        put " "
        put "You have no more credits."
        put " "
        put "Would you like to restart? (Y) or (N)"
        put " "

        get restart : *

        cls

        % User Input (Yes or No)
        if (restart = "Y") or (restart = "y") or (restart = "Yes") or (restart = "yes") then

            % Start Credits
            loop

                put " " : 26, "Welcome to Andrew's Race Way"
                put " " : 25, "------------------------------"
                put " "
                put "How many credit(s) would you like to start with? (1-1000)"
                put " "

                get startcredits

                if (startcredits >= 1) and (startcredits <= 1000) then

                    cls

                    exit

                end if

            end loop

            credits := startcredits

            cls

            put " " : 26, "Welcome to Andrew's Race Way"
            put " " : 25, "------------------------------"
            put " "
            put "You now have ", startcredits, " credit(s)."
            put " "
            put "Press any key to continue."
            put " "

            next := getchar

            cls

        else

            exit

        end if

    end if

    cls

end loop

put " " : 26, "Welcome to Andrew's Race Way"
put " " : 25, "------------------------------"
put " "
put "Thanks for coming out!"
put " "
put "Hope to see you again!"
put " "
put "You are leaving with ", credits, " credit(s)."
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: