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

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




PostPosted: Tue Jan 22, 2008 6:41 pm   Post subject: Need Help Fast

Can someone help me with this code, i want to be able to win the game when some drags the words into the box in alpha order:

code:

import GUI
%need to finish sorting the names in alphabetical order
setscreen ("graphics:300;200,nobuttonbar")

put "Alpha Game"

var xpos, ypos, btn : int

var frame : int := GUI.CreateFrame (200, 70, 100, 170, GUI.LINE)


var x : flexible array 1 .. 1 of string

%get names
var fstream : int
open : fstream, "wordlist.txt", get
loop
    exit when eof (fstream)
    get : fstream, x (upper (x))
    new x, upper (x) + 1
end loop

var word : array 1..5 of string
word(1) := x(Rand.Int(1,26))
word(2) := x(Rand.Int(1,26))
word(3) := x(Rand.Int(1,26))
word(4) := x(Rand.Int(1,26))
word(5) := x(Rand.Int(1,26))


%bubble sort nooby but works
var temp : string

for i : 1 .. 4
    for j : 1 .. i - 1
        if ord (word (i) (1)) > ord (word (i + 1) (1)) then
            temp := word (i)
            word (i) := word (i + 1)
            word (i + 1) := temp
        end if
    end for
end for

var word1x : int := 3
var word2x : int := 3
var word3x : int := 3
var word4x : int := 3
var word5x : int := 3

var word1y : int := 150
var word2y : int := 130
var word3y : int := 110
var word4y : int := 90
var word5y : int := 70

var word1 : int := GUI.CreateLabel (word1x, word1y, word (1))
var word2 : int := GUI.CreateLabel (word2x, word2y, word (2))
var word3 : int := GUI.CreateLabel (word3x, word3y, word (3))
var word4 : int := GUI.CreateLabel (word4x, word4y, word (4))
var word5 : int := GUI.CreateLabel (word5x, word5y, word (5))

var width1 : int := GUI.GetWidth (word1)
var width2 : int := GUI.GetWidth (word2)
var width3 : int := GUI.GetWidth (word3)
var width4 : int := GUI.GetWidth (word4)
var width5 : int := GUI.GetWidth (word5)

var height1 : int := GUI.GetHeight (word1)
var height2 : int := GUI.GetHeight (word2)
var height3 : int := GUI.GetHeight (word3)
var height4 : int := GUI.GetHeight (word4)
var height5 : int := GUI.GetHeight (word5)

var bool : int := 0
%drag and drop
loop
    mousewhere (xpos, ypos, btn)
    locate (10, 1)
    put xpos, ",", ypos
 
    if btn = 1 and xpos >= word1x - 10 and xpos <= word1x + width1 and ypos >= word1y - 10 and ypos <= word1y + height1 then
        loop
            mousewhere (xpos, ypos, btn)
            word1x := xpos
            word1y := ypos
            GUI.SetPosition (word1, word1x, word1y)
            exit when btn = 0
        end loop
    end if

    if btn = 1 and xpos >= word2x - 10 and xpos <= word2x + width2 and ypos >= word2y - 10 and ypos <= word2y + height2 then
        loop
            mousewhere (xpos, ypos, btn)
            word2x := xpos
            word2y := ypos
            GUI.SetPosition (word2, word2x, word2y)
            exit when btn = 0
        end loop
    end if

    if btn = 1 and xpos >= word3x - 10 and xpos <= word3x + width3 and ypos >= word3y - 10 and ypos <= word3y + height3 then
        loop
            mousewhere (xpos, ypos, btn)
            word3x := xpos
            word3y := ypos
            GUI.SetPosition (word3, word3x, word3y)
            exit when btn = 0
        end loop
    end if

    if btn = 1 and xpos >= word4x - 10 and xpos <= word4x + width4 and ypos >= word4y - 10 and ypos <= word4y + height4 then
        loop
            mousewhere (xpos, ypos, btn)

            word4x := xpos
            word4y := ypos
            GUI.SetPosition (word4, word4x, word4y)
            exit when btn = 0
        end loop
    end if

    if btn = 1 and xpos >= word5x - 10 and xpos <= word5x + width5 and ypos >= word5y - 10 and ypos <= word5y + height5 then
        loop
            mousewhere (xpos, ypos, btn)
            word5x := xpos
            word5y := ypos
            GUI.SetPosition (word5, word5x, word5y)
            exit when btn = 0
        end loop
    end if

%win
    if word1y > word2y and word2y > word5y and word5y > word3y and word3y > word4y then
        if word1x > 100 and word2x > 100 and word3x > 100 and word4x > 100 and word5x > 100 then
            put "you win"
        end if
    end if

end loop
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: Tue Jan 22, 2008 6:46 pm   Post subject: RE:Need Help Fast

You're going to have to be a bit more specific. I'm not sure exactly what your question is. However, you could definitely use some arrays in there instead of height1, height2 etc. Also, your sorting is a bit flawed, what if I have the words azureus and aardvark in that order in your array? They won't get sorted properly because you only look at the first character.
firex2249




PostPosted: Tue Jan 22, 2008 6:51 pm   Post subject: Re: Need Help Fast

k, thx
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  [ 3 Posts ]
Jump to:   


Style:  
Search: