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

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




PostPosted: Wed Dec 14, 2011 9:52 am   Post subject: Selecting a dice

What is the problem?
I can't find the correct way to select a die and keep the face value of the die

Describe what you have tried to solve this problem
I have tried every possible combination of variables I can think of but I don't know how to get it to run
here is my code the procedure "Keep" I know is unfinished this is the procedure I am trying to get to select the dice and keep the face value.

Thanks!


Turing:


var dicey : int
var arrow : string (1)
var winMain : int := Window.Open ("graphics : 781 ; 541")
var font : int := Font.New ("serif:10")
var num : int
var key : string (1)
var die : array 1 .. 3 of int
var dicekeep, dicex : array 1 .. 3 of int
var X, Y : int := 80
dicex (1) := 100
dicex (2) := 300
dicex (3) := 500
dicey := 100

procedure one (X, Y : int)
    drawfilloval (X + 70, Y + 70, 5, 5, black)
end one
procedure two (X, Y : int)
    drawfilloval (X + 20, Y + 20, 5, 5, black)
    drawfilloval (X + 120, Y + 120, 5, 5, black)
end two
procedure three (X, Y : int)
    one (X, Y)
    two (X, Y)
end three
procedure four (X, Y : int)
    two (X, Y)
    drawfilloval (X + 20, Y + 120, 5, 5, black)
    drawfilloval (X + 120, Y + 20, 5, 5, black)
end four
procedure five (X, Y : int)
    one (X, Y)
    four (X, Y)
end five
procedure six (X, Y : int)

    four (X, Y)
    drawfilloval (X + 20, Y + 65, 5, 5, black)
    drawfilloval (X + 120, Y + 65, 5, 5, black)
end six
procedure keep (X, Y : int)
    var dicexx : int := 90
    var diceyy : int := 99
    var dicexxx : int := 270
    var diceyyy : int := 241
    var keepdi : array 1 .. 3 of int
    var onedie : int
    onedie := 0
    drawfillbox (dicexx, diceyy, dicexxx, diceyyy, yellow)
    for d : 1 .. 3
        getch (arrow)
        if ord (arrow) = 205 then
            drawfillbox (dicexx + 200, diceyy, dicexxx + 200, diceyyy, yellow)
        elsif ord (arrow) = 203 then
            drawfillbox (dicexx - 200, diceyy, dicexxx - 200, diceyyy, yellow)
            elsif ord (arrow) = 32 then
           
        end if
        end for
    end keep


    colorback (7)
    color (0)
    Font.Draw (" Welcome to The Dice Game! Intializing... ", 250, 270, font, 1) % adds effect of loading game
    delay (1000)
    cls
    put " The rules are simple, 3 dice, 10 rolls , gather points as you go. Simple. "
    delay (700)
    cls
    put " Here's how you get points.."
    put " Roll Call " : 20, " Points " : 20 ..
    %left side of menu
    put "  " : 20
    put "  "

    put " Three of a kind " : 20
    put " Oddball " : 20
    put " Evenball " : 20
    put " Straight " : 20
    put " pair " : 20
    %right side of menu
    put "" : 20, " 30 "
    put "" : 20, " 100 "
    put "" : 20, " 50 "
    put "" : 20, " 50 "
    put "" : 20, " 80 "
    delay (2000)
    cls

    put " Use the arrow keys to select a dice press space to keep the selected die's score "
    %three dice
    loop
        drawfillbox (dicex (1), 100, dicex (1) + 140, dicey + 140, red)
        drawfillbox (dicex (2), 100, dicex (2) + 140, dicey + 140, red)
        drawfillbox (dicex (3), 100, dicex (3) + 140, dicey + 140, red)
        for i : 1 .. 3
            randint (die (i), 1, 6)
            if die (i) = 1 then
                one (dicex (i), dicey)
            elsif die (i) = 2 then
                two (dicex (i), dicey)
            elsif die (i) = 3 then
                three (dicex (i), dicey)
            elsif die (i) = 4 then
                four (dicex (i), dicey)
            elsif die (i) = 5 then
                five (dicex (i), dicey)
            elsif die (i) = 6 then
                six (dicex (i), dicey)
            end if
        end for
        delay (150)
       
    end loop

Sponsor
Sponsor
Sponsor
sponsor
Dreadnought




PostPosted: Wed Dec 14, 2011 3:33 pm   Post subject: Re: Selecting a dice

Ok, I think I didn't really understand what you were asking last time, but now I do (I think). So you have an array of dice values that is continuously changing. You want to stop one of the dice from changing and keep the others going.

So you need some other array, to keep track of which dice to change and which not to change. Am array of Boolean values might do nicely.
Then you'll need to check before randomizing each die whether of not the die should be changed.

Here's an example (it's very primitive but should suffice to illustrate)
Turing:

View.Set ("text")
var nums : array 1 .. 5 of int
var randNums : array 1 .. 5 of boolean := init (true, true, true, true, true)
var choice, memory : int
put "Hit any key to see the new set of numbers"
loop
    put "The numbers are now:"
    for i : 1 .. 5
        if randNums (i) then
            nums (i) := Rand.Int (1, 10) % create some random numbers
        end if
        put nums (i)
    end for
    choice := Rand.Int (1, 5) % Chose one of the numbers
    randNums (choice) := false
    put ""
    put "I chose to not randomize the number in position ", choice
    put ""
    Time.Delay (150)
    Input.Flush
    loop
        exit when hasch
    end loop
end loop
Velocity




PostPosted: Wed Dec 14, 2011 8:43 pm   Post subject: RE:Selecting a dice

var arrow : array char of boolean
Input.KeyDown (arrow)
if arrow (KEY_LEFT_ARROW) then
%dice procedure on the left
end if
if arrow (KEY_RIGHT_ARROW) then
% procedure on the right
end if

thats the use of right and left arrows and how you would use them, work from there :O
LEEEEROYJENKINS




PostPosted: Thu Dec 15, 2011 9:45 am   Post subject: Re: Selecting a dice

I have tried to use the code you gave me (dreadnaught) but I think we have a misconception I am trying to randomize the face value of the dice (simulate a roll) the user then selects a dice he/she wants to keep then rolls the other two and so on until they get 3 of a kind, a pair etc. While this is going on I must keep a running tally to display it in a "Score" chart.
The reply posted about moving something around to select the die works. I know I need another array to store my numbers.
I just don't know how to do it properly. Apologies if I am frustrating this is my first year of programing. Thanks!
LEEEEROYJENKINS




PostPosted: Thu Dec 15, 2011 10:03 am   Post subject: Re: Selecting a dice

Ok, I have the dice rolling but they always have 7 dots on them. No matter how many times I roll. I haven't even made a procedure to make 7 on the dice.
Here is my code..



DICE.T
 Description:
My program so far.

Download
 Filename:  DICE.T
 Filesize:  2.98 KB
 Downloaded:  59 Time(s)

Dreadnought




PostPosted: Thu Dec 15, 2011 9:28 pm   Post subject: Re: Selecting a dice

For the 7 dots, your "rolling" procedure seems to be the problem. It has a loop that does not exit (or does not exit when it should).

As for my example, I agree it was probably not the greatest. What I was trying to show was a way of choosing to not randomize some values in an array.
Here's a (hopefully) better version.
Turing:
View.Set ("text") % Just so you can scroll up and down if you need to.
var dice : array 1 .. 3 of int
var changeDice : array 1 .. 3 of boolean := init (true, true, true)
var input : int
loop
    for i : 1 .. 3
        if changeDice (i) then % We should randomize the die
            dice (i) := Rand.Int (1, 6)
            put "Dice ", i, " was randomized, its value is now: ", dice (i), "."
        else % We should not randomize the die
            put "Dice ", i, " was not randomized, its value is still: ", dice (i), "."
        end if
    end for
    put ""
    put "Enter the number of the die you don't want randomized."
    get input
    changeDice (input) := false % We don't want to randomize this die
    put ""
end loop

As you can probably see, you don't need an extra array to store the numbers. We know which dice are not randomized and if we don't randomize them, then they store the value of that die.
So on each roll you just have to count up the values of the dice that are not randomized to find out what the score is. I hope this makes sense.
LEEEEROYJENKINS




PostPosted: Fri Dec 16, 2011 9:21 am   Post subject: Re: Selecting a dice

My dice still keep showing up as seven, I am at a dead end here :\. My die will randomly roll, stay at random for a split second then put seven dots on my dice ( I don't even have a seventh dot programed.) You guys are helping me out a lot, thanks for that, But it's like I am taking 1 step forward and 2 steps back with this program. Could you please explain to me how to get these dice to "Roll", be given a random number, and stop.


Thanks, again
LEEEEROYJENKINS




PostPosted: Fri Dec 16, 2011 9:38 am   Post subject: Re: Selecting a dice

UPDATE!
I got the dice too work, now I just need help figuring out how to select them I am using the Input.Keydown method but my box that's suppose to highlight the dice and select it does not show up.
Sponsor
Sponsor
Sponsor
sponsor
Dreadnought




PostPosted: Fri Dec 16, 2011 5:13 pm   Post subject: Re: Selecting a dice

Just from looking at the last code you posted, does your "rolling" procedure ever exit or finish?
LEEEEROYJENKINS




PostPosted: Mon Dec 19, 2011 9:28 am   Post subject: Re: Selecting a dice

Oh it finishes, I have no Idea how, I think the delay ends then the loop exits and that's when it stops.
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  [ 10 Posts ]
Jump to:   


Style:  
Search: