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

Username:   Password: 
 RegisterRegister   
 risk dice problem
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
aliveiswell




PostPosted: Fri Jan 23, 2004 5:38 pm   Post subject: risk dice problem

i was making this so my friends and i could skip the difficult process of throwing dice while playing risk, but it sometimes does not work. when you click on number of dice, it sometimes does not find the right amount of random numbers for the number of dice you chose (you'll see if im not making sense). could anyone help me with this problem

the code:
code:

% die
var die : array 1 .. 6 of int
% attack/defend variables
var attackDie : int
var defendDie : int
var counter1 : int := 0
var attack : array 1 .. 3 of int := init (0, 0, 0)
var defend : array 1 .. 2 of int := init (0, 0)
% mouse variables
var mouseX, mouseY, onOff : int
var void : string (1)

% dice pictures
drawfillbox (220, 200, 270, 250, brightred)     % 1 dice
drawfilloval (245, 225, 5, 5, white)     % middle circle

drawfillbox (290, 200, 340, 250, brightred)     % 2 dice
drawfilloval (331, 210, 5, 5, white)     % top left circle
drawfilloval (300, 240, 5, 5, white)     % bottom left circle

drawfillbox (360, 200, 410, 250, brightred)     % 3 dice
drawfilloval (370, 240, 5, 5, white)     % top left circle
drawfilloval (401, 210, 5, 5, white)     % bottom right circle
drawfilloval (385, 225, 5, 5, white)     % middle circle

drawfillbox (430, 200, 480, 250, brightred)
drawfilloval (440, 240, 5, 5, white)
drawfilloval (440, 210, 5, 5, white)
drawfilloval (471, 240, 5, 5, white)
drawfilloval (471, 210, 5, 5, white)

drawfillbox (500, 200, 550, 250, brightred)
drawfilloval (510, 240, 5, 5, white)
drawfilloval (510, 210, 5, 5, white)
drawfilloval (541, 240, 5, 5, white)
drawfilloval (541, 210, 5, 5, white)
drawfilloval (525, 225, 5, 5, white)

drawfillbox (570, 200, 620, 250, brightred)
drawfilloval (580, 240, 5, 5, white)
drawfilloval (580, 210, 5, 5, white)
drawfilloval (611, 240, 5, 5, white)
drawfilloval (611, 210, 5, 5, white)
drawfilloval (580, 225, 5, 5, white)
drawfilloval (611, 225, 5, 5, white)

die (1) := Pic.New (220, 200, 270, 250)
die (2) := Pic.New (290, 200, 340, 250)
die (3) := Pic.New (360, 200, 410, 250)
die (4) := Pic.New (430, 200, 480, 250)
die (5) := Pic.New (500, 200, 550, 250)
die (6) := Pic.New (570, 200, 620, 250)

% dice procedures
proc decide
    locate (8, 2)
    put "Attacker: "
    locate (14, 2)
    put "Defender: "
    if attack (1) = 1 then
        Pic.Draw (die (1), 50, 200, picCopy)
    elsif attack (1) = 2 then
        Pic.Draw (die (2), 110, 200, picCopy)
    elsif attack (1) = 3 then
        Pic.Draw (die (3), 170, 200, picCopy)
    elsif attack (1) = 4 then
        Pic.Draw (die (4), 230, 200, picCopy)
    elsif attack (1) = 5 then
        Pic.Draw (die (5), 300, 200, picCopy)
    elsif attack (1) = 6 then
        Pic.Draw (die (6), 360, 200, picCopy)
    end if
    if attack (2) = 1 then
        Pic.Draw (die (1), 50, 200, picCopy)
    elsif attack (2) = 2 then
        Pic.Draw (die (2), 110, 200, picCopy)
    elsif attack (2) = 3 then
        Pic.Draw (die (3), 170, 200, picCopy)
    elsif attack (2) = 4 then
        Pic.Draw (die (4), 230, 200, picCopy)
    elsif attack (2) = 5 then
        Pic.Draw (die (5), 300, 200, picCopy)
    elsif attack (2) = 6 then
        Pic.Draw (die (6), 360, 200, picCopy)
    end if
    if attack (3) = 1 then
        Pic.Draw (die (1), 50, 200, picCopy)
    elsif attack (3) = 2 then
        Pic.Draw (die (2), 110, 200, picCopy)
    elsif attack (3) = 3 then
        Pic.Draw (die (3), 170, 200, picCopy)
    elsif attack (3) = 4 then
        Pic.Draw (die (4), 230, 200, picCopy)
    elsif attack (3) = 5 then
        Pic.Draw (die (5), 300, 200, picCopy)
    elsif attack (3) = 6 then
        Pic.Draw (die (6), 360, 200, picCopy)
    end if
    if defend (1) = 1 then
        Pic.Draw (die (1), 50, 100, picCopy)
    elsif defend (1) = 2 then
        Pic.Draw (die (2), 110, 100, picCopy)
    elsif defend (1) = 3 then
        Pic.Draw (die (3), 170, 100, picCopy)
    elsif defend (1) = 4 then
        Pic.Draw (die (4), 230, 100, picCopy)
    elsif defend (1) = 5 then
        Pic.Draw (die (5), 300, 100, picCopy)
    elsif defend (1) = 6 then
        Pic.Draw (die (6), 360, 100, picCopy)
    end if
    if defend (2) = 1 then
        Pic.Draw (die (1), 50, 100, picCopy)
    elsif defend (2) = 2 then
        Pic.Draw (die (2), 110, 100, picCopy)
    elsif defend (2) = 3 then
        Pic.Draw (die (3), 170, 100, picCopy)
    elsif defend (2) = 4 then
        Pic.Draw (die (4), 230, 100, picCopy)
    elsif defend (2) = 5 then
        Pic.Draw (die (5), 300, 100, picCopy)
    elsif defend (2) = 6 then
        Pic.Draw (die (6), 360, 100, picCopy)
    end if
end decide
% misc procedures
proc processingBar
    for counter : 1 .. 190 by 5
        drawfillbox (220, 35, 220 + counter, 30, brightred)
        delay (25)
    end for
end processingBar
proc logo
    drawfillbox (0, 300, maxx, maxy, brightred)
    locatexy (220, 351)
    put "EHS Risk Roller by EHSoft"
    for counter : 0 .. 21 by 2
        drawbox (2 + counter, 299 + counter, maxx - counter, maxy - counter, brightred)
    end for
    for counter : 1 .. 20 by 2
        drawbox (2 + counter, 299 + counter, maxx - counter, maxy - counter, white)
    end for
end logo
proc bodyBack
    drawfillbox (5, 292, maxx - 5, 5, white)
end bodyBack
proc numberDiceAttack
    % attacker
    drawfillbox (220, 200, 270, 250, brightred)     % 1 dice
    drawfilloval (245, 225, 5, 5, white)     % middle circle
    drawfillbox (290, 200, 340, 250, brightred)     % 2 dice
    drawfilloval (331, 210, 5, 5, white)     % top left circle
    drawfilloval (300, 240, 5, 5, white)     % bottom left circle
    drawfillbox (360, 200, 410, 250, brightred)     % 3 dice
    drawfilloval (370, 240, 5, 5, white)     % top left circle
    drawfilloval (401, 210, 5, 5, white)     % bottom right circle
    drawfilloval (385, 225, 5, 5, white)     % middle circle
end numberDiceAttack
proc numberDiceDefend
    % defender
    drawfillbox (220, 85, 270, 135, brightred)     % 1 dice
    drawfilloval (245, 110, 5, 5, white)     % middle circle
    drawfillbox (290, 85, 340, 135, brightred)     % 2 dice
    drawfilloval (331, 95, 5, 5, white)     % top left circle
    drawfilloval (300, 125, 5, 5, white)     % bottom left circle
end numberDiceDefend
proc whiteColumn
    drawfillbox (634, 287, 631, 5, white)
end whiteColumn

setscreen ("nocursor")

colorback (brightred)
color (white)
cls

logo
bodyBack

loop
    numberDiceAttack
    locate (8, 2)
    put "                     How many dice is the attacker using?"
    whiteColumn
    loop
        mousewhere (mouseX, mouseY, onOff)
        if onOff = 1 then
            if mouseX > 220 and mouseX < 270 and mouseY > 200 and mouseY < 250 then
                attackDie := 1
                exit
            elsif mouseX > 290 and mouseX < 340 and mouseY > 200 and mouseY < 250 then
                attackDie := 2
                exit
            elsif mouseX > 360 and mouseX < 410 and mouseY > 200 and mouseY < 250 then
                attackDie := 3
                exit
            end if
        end if
    end loop
    locate (9, 2)
    put "                                    ::", attackDie, "::"
    numberDiceDefend
    locate (15, 2)
    put "                     How many dice is the defender using?"
    whiteColumn
    loop
        mousewhere (mouseX, mouseY, onOff)
        if onOff = 1 then
            if mouseX > 220 and mouseX < 270 and mouseY > 85 and mouseY < 135 then
                defendDie := 1
                exit
            elsif mouseX > 290 and mouseX < 340 and mouseY > 85 and mouseY < 135 then
                defendDie := 2
                exit
            end if
        end if
    end loop
    locate (16, 2)
    put "                                    ::", defendDie, "::"
    whiteColumn
    locate (22, 2)
    put "                                 Processing..."
    whiteColumn
    processingBar
    delay (500)
    bodyBack
    if attackDie = 1 and defendDie = 1 then
        randint (attack (1), 1, 6)
        randint (defend (1), 1, 6)
        decide
    elsif attackDie = 1 and defendDie = 2 then
        randint (attack (1), 1, 6)
        randint (defend (1), 1, 6)
        randint (defend (2), 1, 6)
        decide
    elsif attackDie = 2 and defendDie = 1 then
        randint (attack (1), 1, 6)
        randint (attack (2), 1, 6)
        randint (defend (1), 1, 6)
        decide
    elsif attackDie = 2 and defendDie = 2 then
        randint (attack (1), 1, 6)
        randint (attack (2), 1, 6)
        randint (defend (1), 1, 6)
        randint (defend (2), 1, 6)
        decide
    elsif attackDie = 3 and defendDie = 1 then
        randint (attack (1), 1, 6)
        randint (attack (2), 1, 6)
        randint (attack (3), 1, 6)
        randint (defend (1), 1, 6)
        decide
    elsif attackDie = 3 and defendDie = 2 then
        randint (attack (1), 1, 6)
        randint (attack (2), 1, 6)
        randint (attack (3), 1, 6)
        randint (defend (1), 1, 6)
        randint (defend (2), 1, 6)
        decide
    end if

    attack (1) := 0
    attack (2) := 0
    attack (3) := 0
    defend (1) := 0
    defend (2) := 0

    loop
        mousewhere (mouseX, mouseY, onOff)
        if onOff = 1 then
            if mouseX > 0 and mouseY > 0 then
                exit
            end if
        end if
    end loop
    bodyBack
end loop
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Fri Jan 23, 2004 5:48 pm   Post subject: (No subject)

augh you used a loading bar to make it look good!!

*ward off!!*


but seriously, I would first suggest that you clean up that code, as it appears to be very long and could be done more efficiently.

as for fixing your problem, I haven't taken much of a look at the code but I think that it is probably just a simple mistake that you can fix easily as soon as you find it. (that's the major reason why I suggest cleaning up that code)
shorthair




PostPosted: Fri Jan 23, 2004 6:31 pm   Post subject: (No subject)

i just copied and pasted the code , but how the heck did you waste all that code jsut to make some dice on the screen , this code is really messy , AND theres a loading bar , you need to smarten up mister , as befoer if you want a real loading bar i will make one for you , same rules for everyone else , its 20 bits a bar , i jsut need your code and 1 day , and its done
Cervantes




PostPosted: Fri Jan 23, 2004 9:01 pm   Post subject: (No subject)

lol 20 bits for a loading baR?!

code:
Draw.FillBox (1,1,50, 10, white)
delay (2)
Draw.FillBox (1,1,50,10,brightred)


kinda like that? Laughing
Andy




PostPosted: Fri Jan 23, 2004 9:02 pm   Post subject: (No subject)

ummm u know u can make them in paint, use a forloop to load them in and then use randint...
shorthair




PostPosted: Fri Jan 23, 2004 10:47 pm   Post subject: (No subject)

Im sorry but does no one here know how to read Sad , i said " il make you a real loding bar " , not a fake one not a randomized one , one that actually takes as long as it does to load your files , mostly they goes instentainiously , but in a couple of my apps they take about 4 seconds
aliveiswell




PostPosted: Fri Jan 23, 2004 11:03 pm   Post subject: (No subject)

oh no ive disgraced myself... damn
i don't know how to clean it up, ive been turing for like 2 months and my class in one semester got to doing arrays, and half didn't know how to initialize them or whatever it's called.
McKenzie




PostPosted: Fri Jan 23, 2004 11:58 pm   Post subject: (No subject)

don't worry disgrace only lasts for about a day around here. The only truly disgracefull are the repeat/stupid flamers. You gave some context to your situation so you're OK.
As far as your code, in two months you'll be calling it a mess too. We all go through the same thing.
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sat Jan 24, 2004 11:30 am   Post subject: (No subject)

yeah but shorthair, we know you said a REAL loading bar, but in effect (at least on my comp) all it would do is go from 0% to 100% in 2 milliseconds.
probably less Razz
shorthair




PostPosted: Sat Jan 24, 2004 11:42 am   Post subject: (No subject)

i also stated that, but once you get into reading and writing , and algorithms , you end actually seeing the bar load , im well aware that its instintanious for most apps , and that proves that you dont need one , ther emeant to show the user that the computer has not died and somthing is going on ,
Cervantes




PostPosted: Sat Jan 24, 2004 11:55 am   Post subject: (No subject)

pffft even if it takes four seconds.... thats fine. No one would ctrl alt del the program after 4 seconds...
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  [ 11 Posts ]
Jump to:   


Style:  
Search: