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

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




PostPosted: Sat Dec 09, 2006 5:43 pm   Post subject: Lingo Help

I am attempting to re-create the Game Show Network's TV show called "Lingo". So far everything is OK, except for the fact that when I attempt to check my word list (attached) to see if the word entered exists or not, it doesn't go through all my words correctly. The commented out section is that part that needs help on. Here is my code:

code:

View.Set ("graphics;nocursor;offscreenonly")

var counter, points, wrong : int := 0
var file : int
var list : string
var filename : string := "Wordlist.txt"
open : file, filename, get
loop
    exit when eof (file)
    get : file, list
    counter += 1
end loop
close : file
var RANDOM_WORD : array 1 .. counter of string
var junkword : string

open : file, filename, get
for i : 1 .. counter
    get : file, junkword
    RANDOM_WORD (i) := junkword
end for
close : file

var guess : string
var word : string := Str.Upper (RANDOM_WORD (Rand.Int (1, counter)))
var save : array 1 .. length (word) of string
var col : int := white
var font : int := Font.New ("Serif:30")
var X, Y : int := 0
var picID : int
var keys : array char of boolean

picID := Pic.New (0, 0, maxx, maxy)
Pic.Save (picID, "save.bmp")
View.SetTransparentColour (black)

procedure Refresh
    Draw.FillBox (0, 0, maxx, maxy, 11)
    Draw.FillBox (150, 35, maxx - 213, maxy - 85, blue)
    Draw.FillBox (150, maxy - 85, maxx - 213, maxy - 35, yellow)
    %Font.Draw ("THE WORD IS " + word, 225, maxy - 10, defFontID, black)
    Font.Draw ("STARTS WITH " + word (1), 225, maxy - 10, defFontID, black)
    Font.Draw ("LINGO", 235, maxy - 75, font, brightred)
    Font.Draw ("SCORE", 10, maxy div 2, font, black)
    Font.Draw (intstr (points), 60, maxy div 2 - 30, font, black)
    Pic.Draw (picID, 0, 0, picMerge)
    Font.Draw ("~~~RULES~~~", 480, 300, defFontID, black)
    Font.Draw ("Lingo is simple, ", 460, 280, defFontID, black)
    Font.Draw ("Correct Letter", 445, 230, defFontID, black)
    Font.Draw ("turns green", 455, 220, defFontID, green)
    Font.Draw ("Wrong Position", 445, 200, defFontID, black)
    Font.Draw ("turns red", 460, 190, defFontID, brightred)
    Font.Draw ("Isn't In The Word", 445, 170, defFontID, black)
    Font.Draw ("turns white", 465, 160, defFontID, white)
    Font.Draw ("ENTER to enter a word", 445, 130, defFontID, black)
    for i : 0 .. 10 by 2
        Draw.Line (150, 35 + X, maxx - 213, 35 + X, white)
        Draw.Line (150 + X, 35, 150 + X, maxy - 85, white)
        X += 55
    end for
    Draw.Box (150, 35, maxx - 213, maxy - 35, black)
    View.Update
end Refresh

loop
    Refresh
    X := 0
    for i : 1 .. length (word)
        var ch := Str.Upper (getchar)
        save (i) := ch
        if ch = word (i) then
            col := brightgreen
        else
            col := white
        end if
        for x : 1 .. 5
            if ch = word (x) and col not= brightgreen then
                col := brightred
            end if
        end for
        Font.Draw (ch, 175 + X, maxy - 125 - Y, font, col)
        X += 50
        View.Update
    end for
    picID := Pic.New (0, 0, maxx, maxy)
    Pic.Save (picID, "save.bmp")
    loop
        Input.KeyDown (keys)
        exit when keys (KEY_ENTER)
    end loop
    X := 0
    Y += 55

    % for i : 1 .. counter
    %     if save (1) + save (2) + save (3) + save (4) + save (5) not= RANDOM_WORD (i) then
    %         break
    %     end if
    % end for

    if save (1) + save (2) + save (3) + save (4) + save (5) = word then
        points += 1
        cls
        Y := 0
        picID := Pic.New (0, 0, maxx, maxy)
        Pic.Save (picID, "save.bmp")
        word := Str.Upper (RANDOM_WORD (Rand.Int (1, counter)))
    else
        wrong += 1
    end if

    if wrong = 5 then
        Font.Draw ("The word was " + word, maxx div 2 - 100, 10, defFontID, black)
        View.Update
        Input.Pause
        cls
        wrong := 0
        Y := 0
        picID := Pic.New (0, 0, maxx, maxy)
        Pic.Save (picID, "save.bmp")
        word := Str.Upper (RANDOM_WORD (Rand.Int (1, counter)))
    end if
    View.Update
end loop




Wordlist.txt
 Description:
The WordList

Download
 Filename:  Wordlist.txt
 Filesize:  44.95 KB
 Downloaded:  4976 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Prince Pwn




PostPosted: Sat Dec 09, 2006 7:17 pm   Post subject: (No subject)

Just found a bug, no clue how that happened. It ended after 3 guesses not 5.
http://img87.imageshack.us/my.php?image=bugqg6.png
Prince Pwn




PostPosted: Sun Dec 10, 2006 6:41 pm   Post subject: (No subject)

Still no clue how come sometimes if you are on say your 4th guess, it will skip to the next word. It's only supposed to skip a turn if you get the word right or can't guess within 5 turns.... I'm stumped.

UPDATED CODE:
code:

View.Set ("graphics;nocursor;offscreenonly")

var players : int := 2
var counter, wrong : int := 0
var points : array 1 .. players of int

for i : 1 .. players
    points (i) := 0
end for

var file : int
var list : string
var filename : string := "Wordlist.txt"
open : file, filename, get
loop
    exit when eof (file)
    get : file, list
    counter += 1
end loop
close : file
var RANDOM_WORD : array 1 .. counter of string
var junkword : string

open : file, filename, get
for i : 1 .. counter
    get : file, junkword
    RANDOM_WORD (i) := junkword
end for
close : file

var guess : string
var word : string := Str.Upper (RANDOM_WORD (Rand.Int (1, counter)))
var save : array 1 .. length (word) of string
var col : int := white
var font : int := Font.New ("Serif:30")
var X, Y : int := 0
var picID : int
var turn : int := 1
var ch : char
var keys : array char of boolean

picID := Pic.New (0, 0, maxx, maxy)
Pic.Save (picID, "save.bmp")
View.SetTransparentColour (black)

procedure Refresh
    Draw.FillBox (0, 0, maxx, maxy, 11)
    Draw.FillBox (150, 35, maxx - 213, maxy - 85, blue)
    Draw.FillBox (150, maxy - 85, maxx - 213, maxy - 35, yellow)
    Font.Draw ("THE WORD IS " + word, 225, maxy - 10, defFontID, black)
    %Font.Draw ("STARTS WITH " + word (1), 225, maxy - 10, defFontID, black)
    Font.Draw ("LINGO", 235, maxy - 75, font, brightred)
    for i : 1 .. players
        Font.Draw ("P" + intstr (i) + ": ", 15, maxy div 2 + 100 - 35 * i,
            font, black)
        Font.Draw (intstr (points (i)), 90, maxy div 2 + 100 - 35 * i, font,
            brightred)
    end for
    Pic.Draw (picID, 0, 0, picMerge)
    Font.Draw ("~~~RULES~~~", 480, 300, defFontID, black)
    Font.Draw ("Lingo is simple, ", 460, 280, defFontID, black)
    Font.Draw ("Object is to guess a ", 450, 270, defFontID, black)
    Font.Draw ("5 Letter Word", 460, 260, defFontID, black)
    Font.Draw ("Correct Letter", 445, 230, defFontID, black)
    Font.Draw ("turns green", 455, 220, defFontID, green)
    Font.Draw ("Wrong Position", 445, 200, defFontID, black)
    Font.Draw ("turns red", 460, 190, defFontID, brightred)
    Font.Draw ("Isn't In The Word", 445, 170, defFontID, black)
    Font.Draw ("turns white", 465, 160, defFontID, white)
    Font.Draw ("ENTER to enter a word", 445, 130, defFontID, black)
    for i : 0 .. 10 by 2
        Draw.Line (150, 35 + X, maxx - 213, 35 + X, white)
        Draw.Line (150 + X, 35, 150 + X, maxy - 85, white)
        X += 55
    end for
    Draw.Box (150, 35, maxx - 213, maxy - 35, black)
    View.Update
end Refresh

procedure Letter (frequency, duration, clr : int)
    Music.Sound (frequency, duration)
    Music.SoundOff
    Font.Draw (ch, 175 + X, maxy - 125 - Y, font, clr)
end Letter

loop
    Refresh
    X := 0
    for i : 1 .. length (word)
        ch := Str.Upper (getchar)
        save (i) := ch
        if ch = word (i) then
            Letter (200, 10, brightgreen)
            col := brightgreen
        else
            Letter (50, 1, white)
            col := white
        end if
        for x : 1 .. 5
            if ch = word (x) and col not= brightgreen then
                Letter (100, 100, brightred)
            end if
        end for
        %Font.Draw (ch, 175 + X, maxy - 125 - Y, font, col)
        X += 50
        View.Update
    end for
    picID := Pic.New (0, 0, maxx, maxy)
    Pic.Save (picID, "save.bmp")
    loop
        Input.KeyDown (keys)
        exit when keys (KEY_ENTER)
    end loop
    X := 0
    Y += 55

    % for i : 1 .. counter
    %     if save (1) + save (2) + save (3) + save (4) + save (5) not=
    %    RANDOM_WORD (i) then
    %         break
    %     end if
    % end for

    if save (1) + save (2) + save (3) + save (4) + save (5) = word then
        points (turn) += 1
        turn += 1
        cls
        Y := 0
        picID := Pic.New (0, 0, maxx, maxy)
        Pic.Save (picID, "save.bmp")
        word := Str.Upper (RANDOM_WORD (Rand.Int (1, counter)))
    elsif save (1) + save (2) + save (3) + save (4) + save (5) not= word then
        wrong += 1
    end if

    if wrong = 5 then
        Font.Draw ("The word was " + word, maxx div 2 - 100, 10, defFontID,
            black)
        View.Update
        Input.Pause
        cls
        turn += 1
        wrong := 0
        Y := 0
        picID := Pic.New (0, 0, maxx, maxy)
        Pic.Save (picID, "save.bmp")
        word := Str.Upper (RANDOM_WORD (Rand.Int (1, counter)))
    end if

    if turn > players then
        turn := 1
    end if
    View.Update
end loop
Prince Pwn




PostPosted: Sun Dec 10, 2006 9:37 pm   Post subject: (No subject)

I'd also like it so if you press for example, "+" it increases the amount of players (which means resizing the array) which I cannot do. I looked up on flexible arrays:
code:
var points : flexible array 1 .. players of int


code:
       
if ch = KEY_SHIFT_F1 then
       players += 1
       new points,1
end if


That's how far I got before the help file started using several words I do not understand. I know upper(points) would give me the max number in the array, but the help file's example shows:

code:

var lines : flexible array 1 .. 0 of string
new lines, getLines ("text.dat")


I am totally lost Confused
Prince Pwn




PostPosted: Mon Dec 11, 2006 11:55 pm   Post subject: (No subject)

Ok I fixed on of my problems:
code:

    if save (1) + save (2) + save (3) + save (4) + save (5) = word then
        points (turn) += 1
        turn += 1
        cls
        Y := 0
        wrong := 0 %THIS FIXED ONE PROBLEM
        picID := Pic.New (0, 0, maxx, maxy)
        Pic.Save (picID, "save.bmp")
        word := Str.Upper (RANDOM_WORD (Rand.Int (1, counter)))
    elsif save (1) + save (2) + save (3) + save (4) + save (5) not= word then
        wrong += 1
    end if


I still need help resizing the array.
Clayton




PostPosted: Tue Dec 12, 2006 1:44 pm   Post subject: (No subject)

you need to tell it what the new upper bounds is going to be. Everytime you want to add an element to your array, you are just making its upper bounds 1, instead, make use of the upper() function, which returns the upper bounds of an array. Use something like this:

code:

new points, upper(points) + 1
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  [ 6 Posts ]
Jump to:   


Style:  
Search: