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

Username:   Password: 
 RegisterRegister   
 rerolling!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
SwAnK




PostPosted: Mon Apr 25, 2005 8:50 pm   Post subject: rerolling!

hey, I'm trying to get my dice program, so that when you roll, you can select what dice you wish to keep and which you'd like to roll again.
Here is my code so far. I'm confused about how I can get which dice the user would like to keep. Each of the Rand.Int are already assigned values are they not, in my code, 1..5.??

code:

var roll : array 1 .. 5 of int
var reroll : int
var dice : int

procedure rolling
    for i : 1 .. 5
        roll (i) := Rand.Int (1, 6)
        put "Rolled ", roll (i)
    end for
end rolling


rolling
put "how many dice do you want to reroll"
get reroll
put "what dice do u want to reroll?"
get WHAT DO I PUT HERE???????

for i : 1 .. reroll
    roll (i) := Rand.Int (1, 6)
    put "Rolled", roll (i)
end for



oh, and also it would be cool, so that when they rerolled the dice the orginal dice rolled, actually rerolled. For mine it would display the numbers, then show the rerolls seprately. if you get rid of the one get you'd see what i mean. Thanx again!
Sponsor
Sponsor
Sponsor
sponsor
Token




PostPosted: Tue Apr 26, 2005 6:13 am   Post subject: (No subject)

well what i'd do is number the dice 1-5. each die should have its own variable within an array which i think is what you have. then ask which would you like to re-roll, but say that they'd like to re-roll 1 3 and 5 , they would put 135. make this variable a string so that you can use index. then do this

code:

var reroll : string:= "135"


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

end for

for i : 1 .. 5

    if die (i) = 0 then
        die (i) := Rand.Int (1, 6)
    end if
end for

SwAnK




PostPosted: Tue Apr 26, 2005 11:32 pm   Post subject: (No subject)

alright well the reroll does work, but it does it seperately, how do you reroll so that the actual 'original' numbers change??

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

procedure rolling
    for i : 1 .. 5
        roll (i) := Rand.Int (1, 6)
        put "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)
       put roll (i)
    end if
end for

end check
rolling
check
Token




PostPosted: Wed Apr 27, 2005 3:45 pm   Post subject: (No subject)

right, because youre only putting below so get rid of the put statement within the re-roll thing and just cls and draw them all after like this

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


Edit: oops posted the wrong code, dosent look like ne one saw it cuz no one posted but its been a day lol so heres the updated code
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  [ 4 Posts ]
Jump to:   


Style:  
Search: