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

Username:   Password: 
 RegisterRegister   
 Commanding To Draw In a Certain Place
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
SwAnK




PostPosted: Wed Apr 27, 2005 6:31 pm   Post subject: Commanding To Draw In a Certain Place

For my dice, i want it so if the first dice rolled is a 1 then it shows that 1 in the first dice, but if the 2nd dice is a one it shows that one in the second die. What is the for command for this, what i'm doing only goes through and checks for a 1 anywhere, and if there is it draws the dot in the first die no matter what.

Heres my code
code:
var reroll : string := "135"
var roll : array 1 .. 5 of int
var deroll : int
var dice : int

Draw.Box (0, 0, 100, 100, black)
Draw.Box (100, 0, 200, 100, black)
Draw.Box (200, 0, 300, 100, black)
Draw.Box (300, 0, 400, 100, black)
Draw.Box (400, 0, 500, 100, black)

%%%DICE 1%%%
proc dice_1

    Draw.FillOval (50, 50, 6, 6, black)
end dice_1
%%%DICE 2%%%
proc dice_2

    Draw.FillOval (125, 25, 6, 6, black)
    Draw.FillOval (175, 75, 6, 6, black)
end dice_2
procedure rolling
    for i : 1 .. 5
        roll (i) := Rand.Int (1, 6)
        put "Die ", i, " rolled ", roll (i)
    end for

end rolling


proc check
    put "which die do u want to reroll?"
    get reroll

    for i : 1 .. length (reroll)
        roll (strint (reroll (i))) := 0

    end for

    for i : 1 .. 5
        if roll (i) = 0 then
            roll (i) := Rand.Int (1, 6)

        end if
    end for
    cls
    Draw.Box (0, 0, 100, 100, black)
    Draw.Box (100, 0, 200, 100, black)
    Draw.Box (200, 0, 300, 100, black)
    Draw.Box (300, 0, 400, 100, black)
    Draw.Box (400, 0, 500, 100, black)
   
    for i : 1 .. 5
        if roll (i)=1 then THIS PART IS THE TROUBLE
            Draw.FillOval (50, 50, 6, 6, black)

        end if
    end for
    for i : 1 .. 5
        put "Die ", i, " rolled ", roll (i)

    end for

end check


rolling
loop
    check
end loop
Sponsor
Sponsor
Sponsor
sponsor
Token




PostPosted: Wed Apr 27, 2005 7:41 pm   Post subject: (No subject)

okay what I did here was made a series of procedures, one for each of the 6 numbers on the die, and made a parameter for the center of a die, that way i could center it all around that centerpoint and put it thru some math to find the center point of the die, if its confusing thats my bad, you seemed to have the right idea you just needed to include the parameter. i also put that if statement within the first roll so that they apear right off the start.


code:

var reroll : string := "135"
var roll : array 1 .. 5 of int
var deroll : int
var dice : int

Draw.Box (0, 0, 100, 100, black)
Draw.Box (100, 0, 200, 100, black)
Draw.Box (200, 0, 300, 100, black)
Draw.Box (300, 0, 400, 100, black)
Draw.Box (400, 0, 500, 100, black)

procedure one (mid : int)
    Draw.FillOval (mid, 50, 6, 6, black)
end one
procedure two (mid : int)
    Draw.FillOval (mid - 20, 50, 6, 6, black)
    Draw.FillOval (mid + 20, 50, 6, 6, black)
end two

procedure three (mid : int)
    Draw.FillOval (mid, 50, 6, 6, black)
    Draw.FillOval (mid - 20, 20, 6, 6, black)
    Draw.FillOval (mid + 20, 80, 6, 6, black)
end three

procedure four (mid : int)
    Draw.FillOval (mid - 20, 20, 6, 6, black)
    Draw.FillOval (mid + 20, 20, 6, 6, black)
    Draw.FillOval (mid - 20, 80, 6, 6, black)
    Draw.FillOval (mid + 20, 80, 6, 6, black)
end four

procedure five (mid : int)
    Draw.FillOval (mid, 50, 6, 6, black)
    Draw.FillOval (mid - 20, 20, 6, 6, black)
    Draw.FillOval (mid + 20, 20, 6, 6, black)
    Draw.FillOval (mid - 20, 80, 6, 6, black)
    Draw.FillOval (mid + 20, 80, 6, 6, black)
end five

procedure six (mid : int)

    Draw.FillOval (mid - 20, 20, 6, 6, black)
    Draw.FillOval (mid + 20, 20, 6, 6, black)
    Draw.FillOval (mid - 20, 80, 6, 6, black)
    Draw.FillOval (mid + 20, 80, 6, 6, black)
    Draw.FillOval (mid - 20, 50, 6, 6, black)
    Draw.FillOval (mid + 20, 50, 6, 6, black)
end six

%%%DICE 1%%%
proc dice_1

    Draw.FillOval (50, 50, 6, 6, black)
end dice_1
%%%DICE 2%%%
proc dice_2

    Draw.FillOval (125, 25, 6, 6, black)
    Draw.FillOval (175, 75, 6, 6, black)
end dice_2
procedure rolling
    for i : 1 .. 5
        roll (i) := Rand.Int (1, 6)
        put "Die ", i, " rolled ", roll (i)

    end for
    for i : 1 .. 5
        if roll (i) = 1 then
            one (100 * i - 50)
        elsif roll (i) = 2 then
            two (100 * i - 50)
        elsif roll (i) = 3 then
            three (100 * i - 50)
        elsif roll (i) = 4 then
            four (100 * i - 50)
        elsif roll (i) = 5 then
            five (100 * i - 50)
        elsif roll (i) = 6 then
            six (100 * i - 50)
        end if
    end for
end rolling


proc check
    put "which die do u want to reroll?"
    get reroll

    for i : 1 .. length (reroll)
        roll (strint (reroll (i))) := 0

    end for

    for i : 1 .. 5
        if roll (i) = 0 then
            roll (i) := Rand.Int (1, 6)

        end if
    end for
    cls
    Draw.Box (0, 0, 100, 100, black)
    Draw.Box (100, 0, 200, 100, black)
    Draw.Box (200, 0, 300, 100, black)
    Draw.Box (300, 0, 400, 100, black)
    Draw.Box (400, 0, 500, 100, black)

    for i : 1 .. 5
        if roll (i) = 1 then
            one (100 * i - 50)
        elsif roll (i) = 2 then
            two (100 * i - 50)
        elsif roll (i) = 3 then
            three (100 * i - 50)
        elsif roll (i) = 4 then
            four (100 * i - 50)
        elsif roll (i) = 5 then
            five (100 * i - 50)
        elsif roll (i) = 6 then
            six (100 * i - 50)
        end if
    end for
    for i : 1 .. 5
        put "Die ", i, " rolled ", roll (i)
    end for

end check


rolling
loop
    check
end loop
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  [ 2 Posts ]
Jump to:   


Style:  
Search: