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

Username:   Password: 
 RegisterRegister   
 making a counter for an array
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
SwAnK




PostPosted: Fri Apr 29, 2005 8:25 pm   Post subject: making a counter for an array

hey, so right now i have this game so you enter the players names, and then you roll the dice and then the score is calculated and all that good stuff.
What i want to happen is after a player rolls a roll of no points, his turn exits then loops to the next players turn and when that person rolls no points it loops to the next player and so on, and then after the game is done, using an array it would show each players name and score.
Could somone plz show me some code that does this or show me in my code what to do and where to put it, ive tried put it messes up each time. thanx


this should run, its a little messy however i know.
code:
var dice_to_reroll : string := "string"
var roll : array 1 .. 5 of int
var deroll : int
var dice : int
var dice_roll : array 1 .. 5 of int
var count, name, game, score : int := 0
var numply : int
var players : array 1 .. 4 of string
var answer : string (1)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure roll_dice
    for i : 1 .. 5
        roll (i) := Rand.Int (1, 6)
        put "Die ", i, " rolled ", roll (i)
    end for
end roll_dice


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

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

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

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

end selecting_dice_to_reroll

function straight_on (roll : array 1 .. * of int) : boolean
    var one, two, three, four, five, six : boolean := false
    for i : 1 .. 5
        case roll (i) of
            label 1 :
                one := true
            label 2 :
                two := true
            label 3 :
                three := true
            label 4 :
                four := true
            label 5 :
                five := true
            label 6 :
                six := true
        end case
    end for
    if (one and two and three and four and five) or (two and three and four and five and six)
            then
        result true
    else
        result false
    end if

end straight_on
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


put "Please enter the number of players, 4 max"
get numply


loop
    for i : 1 .. numply
        name += 1
        put "enter player ", i, "'s name."
        get players (name) : *
    end for
    exit when name = 4 or name = numply
end loop

name+=1
cls

    roll_dice


put "Count is at ", count, ""


loop
   

    selecting_dice_to_reroll
    if straight_on (roll) then
        count += 1000
        put "Count is at ", count, ""
    end if

    loop
        put "Do you want to add count to score. Y or N"
        getch (answer)
        if answer = "n" then WHAT GOES HERE
???
        end if
        if answer = "y" then
            score := count
        end if
        exit
    end loop

    for i : 1 .. numply
        put "player ", i, "s current score is ", score, "."
    end for
end loop

for i : 1 .. name
    put players (i), ":             ", count
end for
Sponsor
Sponsor
Sponsor
sponsor
Token




PostPosted: Sun May 01, 2005 1:04 pm   Post subject: (No subject)

here ya go, your problem was that you had an unneccisary loop in there that would keep looping back into the first one you exited. so heres the updated code w/ the re-rolling for new players. another thing i did was re-set the count each time it was a new players turn and i made the player scores into an array. so i hope this helps and enjoy Laughing

code:

var dice_to_reroll : string := "string"
var roll : array 1 .. 5 of int
var deroll : int
var dice : int
var dice_roll : array 1 .. 5 of int
var count, name, game : int := 0
var numply : int
var players : array 1 .. 4 of string
var answer : string (1)
var score : array 1 .. 4 of int

for i : 1 .. 4
    score (i) := 0
end for

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure roll_dice

    for i : 1 .. 5
        roll (i) := Rand.Int (1, 6)
        put "Die ", i, " rolled ", roll (i)
    end for
end roll_dice


proc selecting_dice_to_reroll
    put "which die do u want to reroll? (put 0 for none)"
    get dice_to_reroll
    if strint (dice_to_reroll) not= 0 then
        for i : 1 .. length (dice_to_reroll)
            roll (strint (dice_to_reroll (i))) := 0
        end for

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

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

function straight_on (roll : array 1 .. * of int) : boolean
    var one, two, three, four, five, six : boolean := false
    for i : 1 .. 5
        case roll (i) of
            label 1 :
                one := true
            label 2 :
                two := true
            label 3 :
                three := true
            label 4 :
                four := true
            label 5 :
                five := true
            label 6 :
                six := true
        end case
    end for
    if (one and two and three and four and five) or (two and three and four and five and six) then
        result true
    else
        result false
    end if

end straight_on
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


put "Please enter the number of players, 4 max"
get numply

loop
    for i : 1 .. numply
        name += 1
        put "enter player ", i, "'s name."
        get players (name) : *
    end for
    exit when name = 4 or name = numply
end loop

name += 1
cls

for p : 1 .. numply
    roll_dice
    put "\nIt is ", players (p), "'s turn"
    put players (p), "'s count is at ", count, ""


    loop

        selecting_dice_to_reroll
        if straight_on (roll) then
            count += 1000
            put "Count is at ", count, ""
        end if

        put "Do you want to add count to score. Y or N"
        getch (answer)
        if answer = "n" then
            exit
        end if
        if answer = "y" then
            score (p) := count
            exit
        end if

        for i : 1 .. numply
            put "player ", i, "s current score is ", score (p), "."
        end for
    end loop
    cls
    count := 0
end for

put "\n\tScore"
for i : 1 .. numply
    put players (i) : 20, count
end for
SwAnK




PostPosted: Mon May 02, 2005 7:14 pm   Post subject: (No subject)

lol heres me current problem
for the ones you only get 1000 pts If you get 3 of them one the FIRST roll. mine will give a thousand if you get 3 ones intotal over all you rolls

also ok say you roll a one, and the user keeps that dice and rolls the other four, so right now he has 100pts, the next roll will add that one again, to make it 200pts!! How do u keep the dice you want without them being added up again??

and finally at the if answer = "n" part i dont know what to put there, but the problem is that the user rolls the dice, and as long as the dice he rolls score points he can contiue rolling but as soon as he rolls the dice, even like if he kept a one, and rolled again, if those dice did no score any pts, his turn is over, thats what should happen anyways Rolling Eyes Sad any ideas??? heres my code
code:
var dice_to_reroll : string := "string"
var roll : array 1 .. 5 of int
var deroll : int
var dice : int
var dice_roll : array 1 .. 5 of int
var count, name, game : int := 0
var numply : int
var players : array 1 .. 4 of string
var answer : string (1)
var score : array 1 .. 4 of int
var font2 : int
font2 := Font.New ("sans serif:18:bold")

Font.Draw ("DICE 1", 15, 110, font2, red)
Font.Draw ("DICE 2", 115, 110, font2, red)
Font.Draw ("DICE 3", 215, 110, font2, red)
Font.Draw ("DICE 4", 315, 110, font2, red)
Font.Draw ("DICE 5", 415, 110, font2, red)
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 .. 4
    score (i) := 0
end for
%%%%%%%%%DICE%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure one_on_face (di : int)
    Font.Draw ("DICE 1", 15, 110, font2, red)
    Font.Draw ("DICE 2", 115, 110, font2, red)
    Font.Draw ("DICE 3", 215, 110, font2, red)
    Font.Draw ("DICE 4", 315, 110, font2, red)
    Font.Draw ("DICE 5", 415, 110, font2, red)
    Draw.FillOval (di, 50, 6, 6, black)
end one_on_face
procedure two_on_face (di : int)
    Font.Draw ("DICE 1", 15, 110, font2, red)
    Font.Draw ("DICE 2", 115, 110, font2, red)
    Font.Draw ("DICE 3", 215, 110, font2, red)
    Font.Draw ("DICE 4", 315, 110, font2, red)
    Font.Draw ("DICE 5", 415, 110, font2, red)
    Draw.FillOval (di - 20, 50, 6, 6, black)
    Draw.FillOval (di + 20, 50, 6, 6, black)
end two_on_face

procedure three_on_face (di : int)
    Font.Draw ("DICE 1", 15, 110, font2, red)
    Font.Draw ("DICE 2", 115, 110, font2, red)
    Font.Draw ("DICE 3", 215, 110, font2, red)
    Font.Draw ("DICE 4", 315, 110, font2, red)
    Font.Draw ("DICE 5", 415, 110, font2, red)
    Draw.FillOval (di, 50, 6, 6, black)
    Draw.FillOval (di - 20, 20, 6, 6, black)
    Draw.FillOval (di + 20, 80, 6, 6, black)
end three_on_face

procedure four_on_face (di : int)
    Font.Draw ("DICE 1", 15, 110, font2, red)
    Font.Draw ("DICE 2", 115, 110, font2, red)
    Font.Draw ("DICE 3", 215, 110, font2, red)
    Font.Draw ("DICE 4", 315, 110, font2, red)
    Font.Draw ("DICE 5", 415, 110, font2, red)
    Draw.FillOval (di - 20, 20, 6, 6, black)
    Draw.FillOval (di + 20, 20, 6, 6, black)
    Draw.FillOval (di - 20, 80, 6, 6, black)
    Draw.FillOval (di + 20, 80, 6, 6, black)
end four_on_face

procedure five_on_face (di : int)
    Font.Draw ("DICE 1", 15, 110, font2, red)
    Font.Draw ("DICE 2", 115, 110, font2, red)
    Font.Draw ("DICE 3", 215, 110, font2, red)
    Font.Draw ("DICE 4", 315, 110, font2, red)
    Font.Draw ("DICE 5", 415, 110, font2, red)
    Draw.FillOval (di, 50, 6, 6, black)
    Draw.FillOval (di - 20, 20, 6, 6, black)
    Draw.FillOval (di + 20, 20, 6, 6, black)
    Draw.FillOval (di - 20, 80, 6, 6, black)
    Draw.FillOval (di + 20, 80, 6, 6, black)
end five_on_face

procedure six_on_face (di : int)
    Font.Draw ("DICE 1", 15, 110, font2, red)
    Font.Draw ("DICE 2", 115, 110, font2, red)
    Font.Draw ("DICE 3", 215, 110, font2, red)
    Font.Draw ("DICE 4", 315, 110, font2, red)
    Font.Draw ("DICE 5", 415, 110, font2, red)
    Draw.FillOval (di - 20, 20, 6, 6, black)
    Draw.FillOval (di + 20, 20, 6, 6, black)
    Draw.FillOval (di - 20, 80, 6, 6, black)
    Draw.FillOval (di + 20, 80, 6, 6, black)
    Draw.FillOval (di - 20, 50, 6, 6, black)
    Draw.FillOval (di + 20, 50, 6, 6, black)
end six_on_face
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure roll_dice
    put "Your Dice Roll"
    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_on_face (100 * i - 50)
        elsif roll (i) = 2 then
            two_on_face (100 * i - 50)
        elsif roll (i) = 3 then
            three_on_face (100 * i - 50)
        elsif roll (i) = 4 then
            four_on_face (100 * i - 50)
        elsif roll (i) = 5 then
            five_on_face (100 * i - 50)
        elsif roll (i) = 6 then
            six_on_face (100 * i - 50)
        end if
    end for
end roll_dice

fcn three_ones_on (roll : array 1 .. * of int) : boolean
    var count : int := 0
    for i : 1 .. 5
        if roll (i) = 1 then
            count += 1
        end if
    end for
    if count >= 3 then
        result true
    else
        result false
    end if
end three_ones_on

proc selecting_dice_to_reroll
    put "which die do u want to reroll? (put 0 for none)"
    get dice_to_reroll
    if strint (dice_to_reroll) not= 0 then
        for i : 1 .. length (dice_to_reroll)
            roll (strint (dice_to_reroll (i))) := 0
        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)

        put "Your Dice Roll"
        for i : 1 .. 5
            if roll (i) = 0 then
                roll (i) := Rand.Int (1, 6)
            end if
        end for
        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_on_face (100 * i - 50)
            elsif roll (i) = 2 then
                two_on_face (100 * i - 50)
            elsif roll (i) = 3 then
                three_on_face (100 * i - 50)
            elsif roll (i) = 4 then
                four_on_face (100 * i - 50)
            elsif roll (i) = 5 then
                five_on_face (100 * i - 50)
            elsif roll (i) = 6 then
                six_on_face (100 * i - 50)
            end if
        end for
        for i : 1 .. 5
            put "Die ", i, " rolled ", roll (i)
        end for
    end if
end selecting_dice_to_reroll

function straight_on (roll : array 1 .. * of int) : boolean
    var one, two, three, four, five, six : boolean := false
    for i : 1 .. 5
        case roll (i) of
            label 1 :
                one := true
            label 2 :
                two := true
            label 3 :
                three := true
            label 4 :
                four := true
            label 5 :
                five := true
            label 6 :
                six := true
        end case
    end for
    if (one and two and three and four and five) or (two and three and four and five and six) then
        result true
    else
        result false
    end if

end straight_on

fcn one_one_on (roll : array 1 .. * of int) : boolean
    var count : int := 0
    for i : 1 .. 5
        if roll (i) = 1 then
            count += 1
        end if
    end for
    if count >= 1 then
        result true
    else
        result false
    end if
end one_one_on

fcn two_ones_on (roll : array 1 .. * of int) : boolean
    var count : int := 0
    for i : 1 .. 5
        if roll (i) = 1 then
            count += 1
        end if
    end for
    if count >= 2 then
        result true
    else
        result false
    end if
end two_ones_on


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


put "Please enter the number of players, 4 max"
get numply

loop
    for i : 1 .. numply
        name += 1
        put "enter player ", i, "'s name."
        get players (name) : *
    end for
    exit when name = 4 or name = numply
end loop

loop
    name += 1
    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 p : 1 .. numply
        roll_dice
        put "\nIt is ", players (p), "'s turn"

        if three_ones_on (roll) then
            count += 800
        end if

        loop

            selecting_dice_to_reroll
            if straight_on (roll) then
                count += 1000
            end if
            if one_one_on (roll) then
                count += 100
            end if
            if two_ones_on (roll) then
                count += 100
            end if


            put players (p), "'s count is at ", count, ""
            put "Currently ", players (p), "score is ", score (p), "."

            put "Do you want to add count to score. Y or N"
            getch (answer)

            if answer = "n" then
            end if                  %%I think the problm is here%%
            if answer = "y" then
                score (p) += count
                exit
            end if
            put "Currently ", players (p), "score is ", score (p), "."
        end loop
        for i : 1 .. numply
            put "player ", i, "s current score is ", score (i), "."
        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)
        count := 0
    end for

    put "\n\tScore"
    for i : 1 .. numply
        put players (i) : 20, score (i)
    end for
end loop
Token




PostPosted: Mon May 02, 2005 7:49 pm   Post subject: (No subject)

here, try this, i think its pretty self explanitory

code:

         var dice_to_reroll : string := "string"
var roll : array 1 .. 5 of int
var deroll : int
var dice : int
var dice_roll : array 1 .. 5 of int
var count, name, game : int := 0
var numply : int
var players : array 1 .. 4 of string
var answer : string (1)
var score : array 1 .. 4 of int
var font2, numroll : int
font2 := Font.New ("sans serif:18:bold")

Font.Draw ("DICE 1", 15, 110, font2, red)
Font.Draw ("DICE 2", 115, 110, font2, red)
Font.Draw ("DICE 3", 215, 110, font2, red)
Font.Draw ("DICE 4", 315, 110, font2, red)
Font.Draw ("DICE 5", 415, 110, font2, red)
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 .. 4
    score (i) := 0
end for
%%%%%%%%%DICE%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure one_on_face (di : int)
    Font.Draw ("DICE 1", 15, 110, font2, red)
    Font.Draw ("DICE 2", 115, 110, font2, red)
    Font.Draw ("DICE 3", 215, 110, font2, red)
    Font.Draw ("DICE 4", 315, 110, font2, red)
    Font.Draw ("DICE 5", 415, 110, font2, red)
    Draw.FillOval (di, 50, 6, 6, black)
end one_on_face
procedure two_on_face (di : int)
    Font.Draw ("DICE 1", 15, 110, font2, red)
    Font.Draw ("DICE 2", 115, 110, font2, red)
    Font.Draw ("DICE 3", 215, 110, font2, red)
    Font.Draw ("DICE 4", 315, 110, font2, red)
    Font.Draw ("DICE 5", 415, 110, font2, red)
    Draw.FillOval (di - 20, 50, 6, 6, black)
    Draw.FillOval (di + 20, 50, 6, 6, black)
end two_on_face

procedure three_on_face (di : int)
    Font.Draw ("DICE 1", 15, 110, font2, red)
    Font.Draw ("DICE 2", 115, 110, font2, red)
    Font.Draw ("DICE 3", 215, 110, font2, red)
    Font.Draw ("DICE 4", 315, 110, font2, red)
    Font.Draw ("DICE 5", 415, 110, font2, red)
    Draw.FillOval (di, 50, 6, 6, black)
    Draw.FillOval (di - 20, 20, 6, 6, black)
    Draw.FillOval (di + 20, 80, 6, 6, black)
end three_on_face

procedure four_on_face (di : int)
    Font.Draw ("DICE 1", 15, 110, font2, red)
    Font.Draw ("DICE 2", 115, 110, font2, red)
    Font.Draw ("DICE 3", 215, 110, font2, red)
    Font.Draw ("DICE 4", 315, 110, font2, red)
    Font.Draw ("DICE 5", 415, 110, font2, red)
    Draw.FillOval (di - 20, 20, 6, 6, black)
    Draw.FillOval (di + 20, 20, 6, 6, black)
    Draw.FillOval (di - 20, 80, 6, 6, black)
    Draw.FillOval (di + 20, 80, 6, 6, black)
end four_on_face

procedure five_on_face (di : int)
    Font.Draw ("DICE 1", 15, 110, font2, red)
    Font.Draw ("DICE 2", 115, 110, font2, red)
    Font.Draw ("DICE 3", 215, 110, font2, red)
    Font.Draw ("DICE 4", 315, 110, font2, red)
    Font.Draw ("DICE 5", 415, 110, font2, red)
    Draw.FillOval (di, 50, 6, 6, black)
    Draw.FillOval (di - 20, 20, 6, 6, black)
    Draw.FillOval (di + 20, 20, 6, 6, black)
    Draw.FillOval (di - 20, 80, 6, 6, black)
    Draw.FillOval (di + 20, 80, 6, 6, black)
end five_on_face

procedure six_on_face (di : int)
    Font.Draw ("DICE 1", 15, 110, font2, red)
    Font.Draw ("DICE 2", 115, 110, font2, red)
    Font.Draw ("DICE 3", 215, 110, font2, red)
    Font.Draw ("DICE 4", 315, 110, font2, red)
    Font.Draw ("DICE 5", 415, 110, font2, red)
    Draw.FillOval (di - 20, 20, 6, 6, black)
    Draw.FillOval (di + 20, 20, 6, 6, black)
    Draw.FillOval (di - 20, 80, 6, 6, black)
    Draw.FillOval (di + 20, 80, 6, 6, black)
    Draw.FillOval (di - 20, 50, 6, 6, black)
    Draw.FillOval (di + 20, 50, 6, 6, black)
end six_on_face
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure roll_dice
    put "Your Dice Roll"
    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_on_face (100 * i - 50)
        elsif roll (i) = 2 then
            two_on_face (100 * i - 50)
        elsif roll (i) = 3 then
            three_on_face (100 * i - 50)
        elsif roll (i) = 4 then
            four_on_face (100 * i - 50)
        elsif roll (i) = 5 then
            five_on_face (100 * i - 50)
        elsif roll (i) = 6 then
            six_on_face (100 * i - 50)
        end if
    end for
end roll_dice

fcn three_ones_on (roll : array 1 .. * of int) : boolean
    var count : int := 0
    for i : 1 .. 5
        if roll (i) = 1 then
            count += 1
        end if
    end for
    if count >= 3 then
        result true
    else
        result false
    end if
end three_ones_on

proc selecting_dice_to_reroll
    put "which die do u want to reroll? (put 0 for none)"
    get dice_to_reroll
    if strint (dice_to_reroll) not= 0 then
        for i : 1 .. length (dice_to_reroll)
            roll (strint (dice_to_reroll (i))) := 0
        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)

        put "Your Dice Roll"
        for i : 1 .. 5
            if roll (i) = 0 then
                roll (i) := Rand.Int (1, 6)
            end if
        end for
        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_on_face (100 * i - 50)
            elsif roll (i) = 2 then
                two_on_face (100 * i - 50)
            elsif roll (i) = 3 then
                three_on_face (100 * i - 50)
            elsif roll (i) = 4 then
                four_on_face (100 * i - 50)
            elsif roll (i) = 5 then
                five_on_face (100 * i - 50)
            elsif roll (i) = 6 then
                six_on_face (100 * i - 50)
            end if
        end for
        for i : 1 .. 5
            put "Die ", i, " rolled ", roll (i)
        end for
    end if
end selecting_dice_to_reroll

function straight_on (roll : array 1 .. * of int) : boolean
    var one, two, three, four, five, six : boolean := false
    for i : 1 .. 5
        case roll (i) of
            label 1 :
                one := true
            label 2 :
                two := true
            label 3 :
                three := true
            label 4 :
                four := true
            label 5 :
                five := true
            label 6 :
                six := true
        end case
    end for
    if (one and two and three and four and five) or (two and three and four and five and six) then
        result true
    else
        result false
    end if

end straight_on

fcn one_one_on (roll : array 1 .. * of int) : boolean
    var count : int := 0
    for i : 1 .. 5
        if roll (i) = 1 then
            count += 1
        end if
    end for
    if count >= 1 then
        result true
    else
        result false
    end if
end one_one_on

fcn two_ones_on (roll : array 1 .. * of int) : boolean
    var count : int := 0
    for i : 1 .. 5
        if roll (i) = 1 then
            count += 1
        end if
    end for
    if count >= 2 then
        result true
    else
        result false
    end if
end two_ones_on


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

put "Please enter the number of turns"
get numroll
put "Please enter the number of players, 4 max"
get numply

loop
    for i : 1 .. numply
        name += 1
        put "enter player ", i, "'s name."
        get players (name) : *
    end for
    exit when name = 4 or name = numply
end loop

for r : 1 .. numroll
    name += 1
    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 p : 1 .. numply
        roll_dice
        put "\nIt is ", players (p), "'s turn"

        if three_ones_on (roll) then
            count += 800
        end if

        loop

            selecting_dice_to_reroll
            if straight_on (roll) then
                count += 1000
            end if
            if one_one_on (roll) then
                count += 100
            end if
            if two_ones_on (roll) then
                count += 100
            end if


            put players (p), "'s count is at ", count, ""
            put "Currently ", players (p), "score is ", score (p), "."

            put "Do you want to add count to score. Y or N"
            getch (answer)


            if answer = "y" then
                score (p) += count
                exit
            else
                count := 0
            end if
            put "Currently ", players (p), "score is ", score (p), "."
        end loop
        for i : 1 .. numply
            put "player ", i, "s current score is ", score (i), "."
        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)
        count := 0
    end for

    put "\n\tScore"
    for i : 1 .. numply
        put players (i) : 20, score (i)
    end for
end for
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: