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

Username:   Password: 
 RegisterRegister   
 Guessing GAme
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Codi




PostPosted: Mon May 15, 2006 8:27 am   Post subject: Guessing GAme

before you run this make a program like this
bestscore.t
save the program as that and in it put
name
1234567









code:
%%%%^^^^^^^%%%%%%%%%%%^^^^^^^^^^^^GUESSING GAME%%%%%%%%%%%^^^^^^^^^^^%%%%%%%%%%%%%%%%%%%%%
%%% By Codi
%%% DO not Copy
% Picking a color for the back ground
colorback (9)

Draw.FillBox (1, 1, maxx, maxy, 9)

var number : int
var guess : int
var numberOfGuesses : int := 0
var start : string
var lowscore : int := 100
var Smiley : int
var x, y : int
var theDateTime, theDate, theTime : string
var lvl : string
var name, fileName : string := "bestscore.t"
var score, fileNo : int
var timeRunning : int
var greeting : string
theDateTime := Time.Date
theDate := theDateTime (1 .. 9)
theTime := theDateTime (11 .. *)

put "Greetings Neigbour!!  The date and time today is ", Time.Date

put "Hello, World!"
for i : 1 .. 10
    delay (1)
    Window.Hide (defWinID)
    delay (1)
    Window.Show (defWinID)
end for
put "How are you?"
get greeting
if greeting = "good" then
    put "thats good i am fine too"
elsif greeting = "bad" then
    cls
    put " Aww I hope you are better soon"

end if



put "In this game you have to pick a number betwen 1,100 the program will then tell you to guess higher or lower until you get the number"

put "guessed.  See how few of guesses it will take you."

loop


    % Generating a Random Number
    number := Rand.Int (1, 100)
    numberOfGuesses := 0
    %Asks if the user would like to play again or quit

    put "Would you like to play a guessing game?  i know you do so all you have to do is type Yes It is CaSe SeNsItIvE or Type No to Quit"


    get start
    if start = "No" then
        quit
    elsif start = "Yes" then
    end if
    cls
    loop
        locate (4, 1)
        put "Please enter a number in the flashing space its about 1/2 a cm tall and 1/4 cm    wide."

        % Asks the user for a number to see if they get it or not
        get guess
        % This is the counter it adds one number everytime you make a guess
        numberOfGuesses += 1
        % this is when the guess is entered the program will tell you to guess higher or lower or you got it!
        if guess > number then
            put "GUESS LOWER THEN  ", guess
        elsif guess < number then
            put "GUESS HIGHER THEN  ", guess
        elsif guess = number then
            setscreen ("graphics")
            for i : 1 .. 3
                color (i)
                put "Bravo"
            end for
        end if
        exit when guess = number
    end loop

    % tells you how many guesses
    colorback (black)
    put "It took you ", numberOfGuesses, " guesses to guess the correct number."
    if numberOfGuesses < 5 then

        put "Excellent you spend way to much time on this! "
    elsif numberOfGuesses > 5 and numberOfGuesses < 10 then
        put "Great but there is still room for improvment!"
    else
        put "Mabye next time you wont suck so bad!"
    end if

    %getting the best score so far from file
    open : fileNo, fileName, get
    get : fileNo, name : * %the :*the :* is optional butreads the whole line for multiple names
    get : fileNo, score
    put " the best score so far is by ", name, " and its a score of ", score
    close : fileNo
    if numberOfGuesses < score then
        put "Congrats you got a best score"
        open : fileNo, fileName, put
        put "enter your name"
        get name

        put : fileNo, name
        put : fileNo, numberOfGuesses
        close : fileNo
    end if
    timeRunning := Time.Elapsed div 1000
    put "This program has ran ", timeRunning, " Seconds"

end loop
Sponsor
Sponsor
Sponsor
sponsor
Carey




PostPosted: Mon May 15, 2006 9:46 am   Post subject: (No subject)

nice game but i think someone has already done it http://www.compsci.ca/v2/viewtopic.php?t=11831 Very Happy also i think someone else has done it before that... and before that

anyway good job

Tips: erase the number when you are guessing numbers
add
code:
put ""

right after the line where you enter the number

the background is kinda annoying

take out some of the obvius instructions like when you tell the user where to put in the number

make the "do you want to play" question one letter (use getch: y or n) and make it not case sensitive
longlivem8




PostPosted: Mon May 15, 2006 11:17 am   Post subject: (No subject)

Sweet game.
upthescale




PostPosted: Mon May 15, 2006 4:38 pm   Post subject: (No subject)

You have 4 posts in a row, you might as well just make one topic called Games, and put them all in there
blaster009




PostPosted: Mon May 15, 2006 7:20 pm   Post subject: (No subject)

Case sensitivity shouldn't be a problem.

Check out the Str.Upper/Str.Lower commands for more info.
Codi




PostPosted: Tue May 16, 2006 12:00 pm   Post subject: (No subject)

That was the first game i ever made
Codi




PostPosted: Tue May 16, 2006 12:00 pm   Post subject: (No subject)

That was the first game i ever made
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  [ 7 Posts ]
Jump to:   


Style:  
Search: