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

Username:   Password: 
 RegisterRegister   
 Scoring System
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Mr. T




PostPosted: Sun Mar 20, 2005 7:23 pm   Post subject: Scoring System

Why doesnt my scoring system work?

--------
code:

var score : int := 0 %score
var timeBonus :int :=0 %time bonus
timeBonus:=Time.Elapsed
ceil (timeBonus) %rounds Time.Elapsed up to the nearest whole number
var scoreOverall :real :=0 %score + time bonus
scoreOverall:=(timeBonus * 0.001)+score


put "Your score is: ", score
        put "Your time bonus is: ", timeBonus*0.001
        put "Your overall score is: ", scoreOverall
        put "[press any key to continue to next round]"
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sun Mar 20, 2005 7:41 pm   Post subject: (No subject)

What doesn't work about it? Except for the fact that you are using ceil as a procedure, when it's actually a function. Oh, and you can't assign Time.Elapsed a value: it's not a variable. Lastly, why do you initialize a variable to 0 only to set it to something else in the next line?

Cheers,
-Cervantes
Mr. T




PostPosted: Sun Mar 20, 2005 7:52 pm   Post subject: (No subject)

BAH, first of all the goal i want to achieve is that the shorter the time u spend on a level... the bigger the time bonus... any ideas?
Bacchus




PostPosted: Sun Mar 20, 2005 8:20 pm   Post subject: (No subject)

how about having a set amount on points that the Time.Elapsed in deducted from to get a time bonus
code:
var Bonus:int:=60000 %1 min to be able to get bonus
..
..
var TimeBonus:int:=Bonus-Time.Elapsed
if u get the idea of it
Mr. T




PostPosted: Sun Mar 20, 2005 8:29 pm   Post subject: (No subject)

it doesnt seem to work check out my code...

code:

var col : int := 31
var countdown : int := 6
var ballx1 : int := 200
var bally1 : int := 150
var ballsize : int := 5
var move, move2, move3, move4 := false
var key : array char of boolean
var ring : int := 0
var answer : string
move3 := true %starting direction of snake
var newMaxX : int := 500 %innitial screen dimensions (x co-ords)
var newMaxY : int := 400 %innitial screen dimensions (y co-ords)
var levelUpX : int := 50 %decrease in screen dimensions (x co-ords) upon completion of level
var levelUpY :int :=40 %decrease in screen dimensions (y co-ords) upon completion of level
var scoreLevel : int := 50
var foodBoolean :boolean
var score : int :=0 %score
var bonus:int:=60000 %1 min to be able to get bonus
var timeBonus:int :=bonus-Time.Elapsed
var scoreOverall:int :=score+timeBonus


%gives time for user to get ready
loop
    locate (12, 25)
    put "Starting in...", countdown - 1
    delay (300)
    countdown := countdown - 1
    cls
    exit when countdown = 0
end loop


%creates food in random locations
procedure food
    randint (food1, 1, newMaxX-10) %random food location (but not in the walls)
    randint (food2, 1, newMaxY-10) %random food location (but not in the walls)
    randint (foodSize, 2, 10) %random food size
    drawfilloval (food1, food2, foodSize, foodSize, 2)
end food

%point of contact upon death
procedure ringEnd
    loop
        drawoval (ballx1, bally1, ballsize + ring, ballsize + ring, ring)
        ring += 2
        delay (10)
        exit when ring = 100

    end loop
end ringEnd

%draws food
food

%snake movement
loop
    drawbox (box1, newMaxY-1, newMaxX-1, box4, 7)
    drawfilloval (ballx1, bally1, ballsize, ballsize, col)
    if move then
        bally1 += 1
    elsif move2 then
        bally1 -= 1
    elsif move3 then
        ballx1 += 1
    elsif move4 then
        ballx1 -= 1
    end if
    Input.KeyDown (key)
    if key (KEY_UP_ARROW) and move2 = false then %Two Conditions: 1. up arrow is pressed 2. move2 = false
        move2 := false
        move3 := false
        move4 := false
        move := true
    elsif key (KEY_DOWN_ARROW) and move = false then  %Two Conditions: 1. down arrow is pressed 2. move = false
        move := false
        move3 := false
        move4 := false
        move2 := true
    elsif key (KEY_RIGHT_ARROW) and move4 = false then %Two Conditions: 1. right arrow is pressed 2. move4 = false
        move := false
        move2 := false
        move4 := false
        move3 := true
    elsif key (KEY_LEFT_ARROW) and move3 = false then   %Two Conditions: 1. left arrow is pressed 2. move3 = false
        move := false
        move2 := false
        move3 := false
        move4 := true
    end if
    drawfilloval (ballx1, bally1, ballsize, ballsize, 12)     %deletes the tail
    delay (10)

    %wall collision detection
    if ballx1 = 4 or ballx1 = maxx - 4 or bally1 = 4 or bally1 = maxy - 4 then
        View.Set ("graphics:" + intstr (newMaxX) + ";" + intstr (newMaxY) + ",title:Uncle Worm           Score: " + intstr (score) + "             You Lose!")
        ringEnd
        exit
    end if

    %food collision detection
    if whatdotcolour (food1 + foodSize, food2 + foodSize) = 12 or whatdotcolour (food1 - foodSize, food2 - foodSize) = 12
            then
            score += 10 %when food collision detected points are added to score
        View.Set ("graphics:" + intstr (newMaxX) + ";" + intstr (newMaxY) + ",title:Uncle Worm           Score: " + intstr (score))
        drawfilloval (food1, food2, foodSize, foodSize, white)      %so that no chunk of food is left behind
        food
       
    end if


    %NEXT LEVEL
    if score >= scoreLevel
            then
            drawfillbox ((maxx div 2) - 10, maxy, (maxx div 2) + 10, maxy - 5, 4)
        end if
       
        if whatdotcolour (ballx1+ballsize,bally1+ballsize)=4
        then cls
        put "Your score is: ", score
        put "Your time bonus is: ", timeBonus
        put "Your overall score is: ", scoreOverall
        put "[press any key to continue to next round]"
        Input.Pause         
        newMaxX:=newMaxX-levelUpX 
        newMaxY:=newMaxY-levelUpY
        View.Set ("graphics:" + intstr (newMaxX) + ";" + intstr (newMaxY) + ",title:Uncle Worm           Score: " + intstr (score))
        ballx1:=newMaxX div 2 %new x co-ords for the start of a new level
        bally1:=newMaxY div 2 %new y co-ords for the start of a new level
        food
        scoreLevel:=score+50
    end if


end loop

View.Update
Bacchus




PostPosted: Sun Mar 20, 2005 8:36 pm   Post subject: (No subject)

no you want to set the timeBonus var you have there after they've finished. so once they win it will check the time and give them an appropriate bonus (if you dont check to see if it a negative value then you can have a punishment for going longer then a certain amount of time
Mr. T




PostPosted: Sun Mar 20, 2005 8:45 pm   Post subject: (No subject)

how would i convert milliseconds to seconds...so that the time bonus isnt a ridiculously high number (even though its actually milliseconds)?
Bacchus




PostPosted: Sun Mar 20, 2005 8:46 pm   Post subject: (No subject)

1000 milliseconds = 1 second
sooooo
divide the score by 1000 to put it in seconds
Sponsor
Sponsor
Sponsor
sponsor
Mr. T




PostPosted: Sun Mar 20, 2005 8:58 pm   Post subject: (No subject)

ya sorry i didnt realize you could manipulate Time.Elapsed...anyways...
yup, I got it to work finally, thnx for the input
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  [ 9 Posts ]
Jump to:   


Style:  
Search: