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

Username:   Password: 
 RegisterRegister   
 dice that do not roll
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
JustTrying2GetBy




PostPosted: Thu Jan 13, 2005 2:41 pm   Post subject: dice that do not roll

=( i have two dice for my program, but only one of them shows a number. can sumone find the error in my code, or the fix to it?

code:

%Dice
drawbox (850, 1030, 900, 1080, 7)
drawbox (930, 1030, 980, 1080, 7)
procedure die1
    loop
    var num1 :int:=0
        Mouse.Where (x, y, button)
        if button = 1
                then
            if x > 850 and x < 900 and y > 1030 and y < 1080 then
                randint (num1, 1, 6)
                if num1 = 1 then
                    drawfilloval (875, 1055, 5, 5, brightred)
                elsif num1 = 2 then
                    drawfilloval (875, 1068, 4, 4, brightred)
                    drawfilloval (875, 1042, 4, 4, brightred)
                elsif num1 = 3 then
                    drawfilloval (875, 1068, 4, 4, brightred)
                    drawfilloval (875, 1055, 4, 4, brightred)
                    drawfilloval (875, 1042, 4, 4, brightred)
                elsif num1 = 4 then
                    drawfilloval (862, 1068, 4, 4, brightred)
                    drawfilloval (887, 1068, 4, 4, brightred)
                    drawfilloval (862, 1042, 4, 4, brightred)
                    drawfilloval (887, 1042, 4, 4, brightred)
                elsif num1 = 5 then
                    drawfilloval (862, 1068, 4, 4, brightred)
                    drawfilloval (887, 1068, 4, 4, brightred)
                    drawfilloval (862, 1042, 4, 4, brightred)
                    drawfilloval (887, 1042, 4, 4, brightred)
                    drawfilloval (875, 1055, 4, 4, brightred)
                elsif num1 = 6 then
                    drawfilloval (862, 1068, 3, 3, brightred)
                    drawfilloval (887, 1068, 3, 3, brightred)
                    drawfilloval (862, 1042, 3, 3, brightred)
                    drawfilloval (887, 1042, 3, 3, brightred)
                    drawfilloval (862, 1055, 3, 3, brightred)
                    drawfilloval (887, 1055, 3, 3, brightred)
                end if
                counter := counter + 1
            end if
            exit when counter = 1
        end if
    end loop
end die1

procedure die2
    loop
        Mouse.Where (x, y, button2)
        var num2:int:=0
        if button2 = 1 then
            if x > 930 and x < 980 and y > 1030 and y < 1080 then
                randint (num2, 1, 1)
                if num2 = 1 then
                    drawfilloval (1035, 1055, 5, 5, brightred)
                elsif num2 = 2 then
                    drawfilloval (1035, 1068, 4, 4, brightred)
                    drawfilloval (1035, 1042, 4, 4, brightred)
                elsif num2 = 3 then
                    drawfilloval (1035, 1068, 4, 4, brightred)
                    drawfilloval (1035, 1055, 4, 4, brightred)
                    drawfilloval (1035, 1042, 4, 4, brightred)
                elsif num2 = 4 then
                    drawfilloval (1022, 1068, 4, 4, brightred)
                    drawfilloval (1047, 1068, 4, 4, brightred)
                    drawfilloval (1022, 1042, 4, 4, brightred)
                    drawfilloval (1047, 1042, 4, 4, brightred)
                elsif num2 = 5 then
                    drawfilloval (1022, 1068, 4, 4, brightred)
                    drawfilloval (1047, 1068, 4, 4, brightred)
                    drawfilloval (1022, 1042, 4, 4, brightred)
                    drawfilloval (1047, 1042, 4, 4, brightred)
                    drawfilloval (1035, 1055, 4, 4, brightred)
                elsif num2 = 6 then
                    drawfilloval (1022, 1068, 3, 3, brightred)
                    drawfilloval (1047, 1068, 3, 3, brightred)
                    drawfilloval (1022, 1042, 3, 3, brightred)
                    drawfilloval (1047, 1042, 3, 3, brightred)
                    drawfilloval (1022, 1055, 3, 3, brightred)
                    drawfilloval (1047, 1055, 3, 3, brightred)
                end if
                counter2 := counter2 + 1
            end if
            exit when counter2 = 1
        end if
    end loop
end die2

die1
die2
Sponsor
Sponsor
Sponsor
sponsor
Mazer




PostPosted: Thu Jan 13, 2005 2:55 pm   Post subject: (No subject)

You are missing alot of code and details that would help us figure out what's wrong.
First, you haven't givent us many of the variable declarations so we can't run the program properly to see exactly what your problem is.
Second, it looks to me like you are trying to draw things at coordinates that wouldn't show up on the screen. But I have not idea how big the window is, so maybe that's not your problem.

Here's my understanding of the code you've provided:
(for die1)
loop
if some obscure area of the screen is clicked
get a random number from 1 to 6 and draw the appropriate dice
increase counter (whatever the hell that is) by 1
if counter is equal to 1 (let's hope it started as 0)
exit this loop
end loop

die2 seems to be exactly the same except for the following differences:
-It checks for a mouse click in a different area of the screen
-It draws the dice in another area of the screen
-It uses a one sided dice (but has the capability to draw any of 6 possible sides)

So, after that long post I guess this could be the problem you're having (in die2):
code:
randint (num2, 1, 1)

Smile
JustTrying2GetBy




PostPosted: Thu Jan 13, 2005 3:01 pm   Post subject: (No subject)

I was trying to find out what was the error, thats why i had

code:

randint (num2,1,1)


As for screen size, i changed it y going prefs. I used 55 rows, and 100 colums.

The full code with variables...
code:

var x, y, button, button2 : int
var counter, counter2 : int := 0

%Dice
drawbox (850, 1030, 900, 1080, 7)
drawbox (930, 1030, 980, 1080, 7)
procedure die1
    loop
    var num1 :int:=0
        Mouse.Where (x, y, button)
        if button = 1
                then
            if x > 850 and x < 900 and y > 1030 and y < 1080 then
                randint (num1, 1, 6)
                if num1 = 1 then
                    drawfilloval (875, 1055, 5, 5, brightred)
                elsif num1 = 2 then
                    drawfilloval (875, 1068, 4, 4, brightred)
                    drawfilloval (875, 1042, 4, 4, brightred)
                elsif num1 = 3 then
                    drawfilloval (875, 1068, 4, 4, brightred)
                    drawfilloval (875, 1055, 4, 4, brightred)
                    drawfilloval (875, 1042, 4, 4, brightred)
                elsif num1 = 4 then
                    drawfilloval (862, 1068, 4, 4, brightred)
                    drawfilloval (887, 1068, 4, 4, brightred)
                    drawfilloval (862, 1042, 4, 4, brightred)
                    drawfilloval (887, 1042, 4, 4, brightred)
                elsif num1 = 5 then
                    drawfilloval (862, 1068, 4, 4, brightred)
                    drawfilloval (887, 1068, 4, 4, brightred)
                    drawfilloval (862, 1042, 4, 4, brightred)
                    drawfilloval (887, 1042, 4, 4, brightred)
                    drawfilloval (875, 1055, 4, 4, brightred)
                elsif num1 = 6 then
                    drawfilloval (862, 1068, 3, 3, brightred)
                    drawfilloval (887, 1068, 3, 3, brightred)
                    drawfilloval (862, 1042, 3, 3, brightred)
                    drawfilloval (887, 1042, 3, 3, brightred)
                    drawfilloval (862, 1055, 3, 3, brightred)
                    drawfilloval (887, 1055, 3, 3, brightred)
                end if
                counter := counter + 1
            end if
            exit when counter = 1
        end if
    end loop
end die1

procedure die2
    loop
        Mouse.Where (x, y, button2)
        var num2:int:=0
        if button2 = 1 then
            if x > 930 and x < 980 and y > 1030 and y < 1080 then
                randint (num2, 1, 6)
                if num2 = 1 then
                    drawfilloval (1035, 1055, 5, 5, brightred)
                elsif num2 = 2 then
                    drawfilloval (1035, 1068, 4, 4, brightred)
                    drawfilloval (1035, 1042, 4, 4, brightred)
                elsif num2 = 3 then
                    drawfilloval (1035, 1068, 4, 4, brightred)
                    drawfilloval (1035, 1055, 4, 4, brightred)
                    drawfilloval (1035, 1042, 4, 4, brightred)
                elsif num2 = 4 then
                    drawfilloval (1022, 1068, 4, 4, brightred)
                    drawfilloval (1047, 1068, 4, 4, brightred)
                    drawfilloval (1022, 1042, 4, 4, brightred)
                    drawfilloval (1047, 1042, 4, 4, brightred)
                elsif num2 = 5 then
                    drawfilloval (1022, 1068, 4, 4, brightred)
                    drawfilloval (1047, 1068, 4, 4, brightred)
                    drawfilloval (1022, 1042, 4, 4, brightred)
                    drawfilloval (1047, 1042, 4, 4, brightred)
                    drawfilloval (1035, 1055, 4, 4, brightred)
                elsif num2 = 6 then
                    drawfilloval (1022, 1068, 3, 3, brightred)
                    drawfilloval (1047, 1068, 3, 3, brightred)
                    drawfilloval (1022, 1042, 3, 3, brightred)
                    drawfilloval (1047, 1042, 3, 3, brightred)
                    drawfilloval (1022, 1055, 3, 3, brightred)
                    drawfilloval (1047, 1055, 3, 3, brightred)
                end if
                counter2 := counter2 + 1
            end if
            exit when counter2 = 1
        end if
    end loop
end die2

die1
die2


The probelm is the 2nd die, which does not display any of the red dots it is soupposed to.

Even if the randint were set to chose between 1 and 1, it will still display the one red dot, but my 2nd die dosent seem to display anything at all =/
Cervantes




PostPosted: Thu Jan 13, 2005 5:26 pm   Post subject: (No subject)

Are you sure that the coordinates for drawing the second die are in fact viewable? They seem to be very, very large. Try running this:
code:

put maxx

If the value that that outputs is less than 1051, you'll be missing some stuff.
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: