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

Username:   Password: 
 RegisterRegister   
 Urgent!! Help with Mouse.Where
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
surfed




PostPosted: Wed Jun 08, 2005 9:55 pm   Post subject: Urgent!! Help with Mouse.Where

code:
% constants
const ROW1P := 230          % row 1 position of first y coordinate
const ROW2P := 170          % row 2 position of first y coordinate
const ROW3P := 110          % row 3 position of first y coordinate
const X_INC := 45           % x coordinate increase number for drawing the cards
const X1_START := 140       % x1 starting coordinate for drawing the cards
const X2_START := 175       % x2 starting coordinate for drawing the cards
const points := 50          % points awarded for each match

% variables
var card : array 1 .. 24 of int     % array to store 24 card colours
var x1, x2 : array 1 .. 8 of int    % stores x1 and x2 coordinates for boxes
var temp, p1, p2 : int      % vars used to shuffle the card clrs to make them random positions
var x, y, z : int                   % Mouse.Where vars
var match : array 1 .. 2 of int     % if a person clicks a card it stores it to this var
var cardsLeft : int := 24           % total cards=24,   -2 cards each 2 card clicks
var score : int := 0                % the total points earned
var clickCount : int := 0

cls

% assigns a random int to card 1..12, then assigns 13..24 with the same values as 1..12
for c : 1 .. 12
    card (c) := Rand.Int (8, 12)
    card (c + 12) := card (c)
end for

% shuffling the cards 24 times
for shuffle : 1 .. 24
    randint (p1, 13, 24)
    randint (p2, 13, 24)

    temp := card (p1)
    card (p1) := card (p2)
    card (p2) := temp
end for

% stores the x coordinates for each row
for k : 1 .. 8
    x1 (k) := X1_START + X_INC * (k - 1)
    x2 (k) := X2_START + X_INC * (k - 1)
end for

% sneak peak of the actual card colours
% draws row with card colours
for a : 1 .. 8
    Draw.FillBox (x1 (a) + 1, ROW1P - 1, x2 (a) - 1, ROW1P - 50 + 1, card (a))
    Draw.Box (140 + (a - 1) * 45, ROW1P, 175 + (a - 1) * 45, ROW1P - 50, 7)
end for

% draws row2 with card colours
for b : 1 .. 8
    Draw.FillBox (x1 (b) + 1, ROW2P - 1, x2 (b) - 1, ROW2P - 50 + 1, card (b + 8))
    Draw.Box (140 + (b - 1) * 45, ROW2P, 175 + (b - 1) * 45, ROW2P - 50, 7)
end for

% draws row3 with card colours
for c : 1 .. 8
    Draw.FillBox (x1 (c) + 1, ROW3P - 1, x2 (c) - 1, ROW3P - 50 + 1, card (c + 16))
    Draw.Box (140 + (c - 1) * 45, ROW3P, 175 + (c - 1) * 45, ROW3P - 50, 7)
end for

delay (2000)

% draws 8 cards in row 1
for i : 0 .. 325 by 45
    Draw.FillBox (140 + i, ROW1P, 175 + i, ROW1P - 50, 19)
    Draw.Box (140 + i, ROW1P, 175 + i, ROW1P - 50, 7)
end for

% draws 8 cards in row 2
for i : 0 .. 325 by 45
    Draw.FillBox (140 + i, ROW2P, 175 + i, ROW2P - 50, 19)
    Draw.Box (140 + i, ROW2P, 175 + i, ROW2P - 50, 7)
end for

% draws 8 cards in row 3
for i : 0 .. 325 by 45
    Draw.FillBox (140 + i, ROW3P, 175 + i, ROW3P - 50, 19)
    Draw.Box (140 + i, ROW3P, 175 + i, ROW3P - 50, 7)
end for

% puts the card colours on top of the screen, first number = colour of the first card
for as : 1 .. 24
    put card (as), " " ..
end for

loop

    for r : 1 .. 2

        loop

            Mouse.Where (x, y, z)           % checks where the mouse is

            if z > 0 then       % if mouse is clicked
                % if mouse is clicked in these particular coordinates, then draw a box on top of the card
                % draws the boxes for row 1 if mouse clicks on a card in row 1
                for a : 1 .. 8
                    if x > x1 (a) and x < x2 (a) and y < ROW1P and y > ROW1P - 50 then
                        Time.Delay (150)
                        Draw.FillBox (x1 (a) + 1, ROW1P - 1, x2 (a) - 1, ROW1P - 50 + 1, card (a))
                        match (r) := card (a)           % assigns match (r) to the card colour
                        clickCount := r
                    end if
                end for

                % draws the boxes for row 2 if mouse clicks on a card in row 2
                for b : 1 .. 8
                    if x > x1 (b) and x < x2 (b) and y < ROW2P and y > ROW2P - 50 then
                        Time.Delay (150)
                        Draw.FillBox (x1 (b) + 1, ROW2P - 1, x2 (b) - 1, ROW2P - 50 + 1, card (b + 8))
                        match (r) := card (b) + 8       % assigns match (r) to the card colour
                        clickCount := r
                    end if
                end for

                % draws the boxes for row 3 if mouse clicks on a card in row 3
                for c : 1 .. 8
                    if x > x1 (c) and x < x2 (c) and y < ROW3P and y > ROW3P - 50 then
                        Time.Delay (150)
                        Draw.FillBox (x1 (c) + 1, ROW3P - 1, x2 (c) - 1, ROW3P - 50 + 1, card (c + 16))
                        match (r) := card (c) + 16      % assigns match (r) to the card colour
                        clickCount := r
                    end if
                end for
            end if

            exit when clickCount = r
        end loop

    end for

    cardsLeft -= 2          % minus 2 cards each time (24 card clicks allowed in total)

    if match (1) = match (2) then
        put "match"
        score += points         % adds points when a match is made
    end if

    delay (100)

    exit when cardsLeft < 1
end loop

Time.Delay (125)
locate (1, 1)
put "score: ", score
Time.Delay (2000)
quit


very long code here.. Please try it, when i click once, i think mouse.where recognizes more than one click... How do i fix this problem?

thanks in advance
Sponsor
Sponsor
Sponsor
sponsor
marsbarz




PostPosted: Thu Jun 09, 2005 1:28 am   Post subject: (No subject)

You can try using Mouse.ButtonMoved and Mouse.ButtonWait in conjunction one after another.

This would require you to declare the variables bnum and bupdwn beforehand.

code:
if Mouse.ButtonMoved ("down") and z > 0 then
Mouse.ButtonWait ("down", bnum, bupdwn)

for a : 1 .. 8
                    if x > x1 (a) and x < x2 (a) and y < ROW1P and y > ROW1P - 50 then
                        Time.Delay (150)
                        Draw.FillBox (x1 (a) + 1, ROW1P - 1, x2 (a) - 1, ROW1P - 50 + 1, card (a))
                        match (r) := card (a)           % assigns match (r) to the card colour
                        clickCount := r
                    end if
...
...
etc


Now if a user holds down the mouse button, he/she will not get repeating matches.

You still have one more problem though- a user can click a card twice and get a match.
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: