Search for a word program
Author |
Message |
copthesaint
![](http://compsci.ca/v3/uploads/user_avatars/15853548854c9c056fda48d.jpg)
|
Posted: Thu May 28, 2009 1:14 pm Post subject: Search for a word program |
|
|
I was bored in my extended computer class so I decided to make a program that will search for words.
Here it is.
Turing: | const NumItems : int := 45
var SearchItems : array 1 .. NumItems of string := init ("we", "she", "he", "see", "top", "stop", "drop", "dart", "fight", "saint", "joke", "silent", "silence", "welcome", "wonderful", "you", "are", "jew", "jewish", "wrong", "write", "right", "left", "else", "end", "doom", "if", "house", "text", "mouse", "dog", "cat", "bro", "hello", "yo", "canada", "stars", "turing", "all in all", "word", "test", "christian", "test", "chocolate", "cookie")
View.Set ("Offscreenonly")
proc UpdateSearch (SearchString : string, Items : array 1 .. * of string, NumItems : int)
var SimItems, TrueItems : array 1 .. NumItems of string
var NumResults, SimResults : int := 0
SimResults := 1
for i : 1 .. NumItems
SimItems (i ) := ""
TrueItems (i ) := ""
end for
for i : 1 .. NumItems
if SearchString = Items (i ) then
for z : 1 .. NumItems
if TrueItems (z ) = "" then
TrueItems (z ) := Items (i )
NumResults + = 1
exit
elsif TrueItems (z ) not= "" and z = NumItems then
quit
end if
end for
end if
end for
for i : 1 .. NumItems
var EMPTY : string := ""
for x : 1 .. length (Items (i ))
EMPTY + = Items (i ) (x )
if EMPTY = SearchString then
SimItems (SimResults ) := Items (i )
SimResults + = 1
exit
end if
end for
end for
put "Number Of Results for ", '"', SearchString, '"', ": ", NumResults
if SimResults > 1 then
put "Simular Results:"
for i : 1 .. SimResults
put SimItems (i )
end for
end if
end UpdateSearch
proc Active (X1, Y1, X2, Y2 : int, Fnt : string, var S : string, var Act : boolean)
drawbox (X1+ 1,Y1+ 1,X2- 1,Y2- 1, black)
var x, y, b : int
mousewhere (x, y, b )
if Act = true then
Act := false
x := (X1 + X2 ) div 2
y := (Y1 + Y2 ) div 2
b := 1
elsif Act = false then
if x > X1 and x < X2 and y > Y1 and y < Y2 and b = 1 then
Act := true
var Fnt1 : int := Font.New (Fnt )
var EmptyString : string := S
var Keys : array char of boolean
var T1, T2 : int := Time.ElapsedCPU
var Flash : boolean := false
loop
Input.Flush
Input.KeyDown (Keys )
mousewhere (x, y, b )
if x < X1 and b = 1 or x > X2 and b = 1 or y < Y1 and b = 1 or y > Y2 and b = 1 or Keys (chr (10)) = true then
Act := false
exit
else
T1 := Time.ElapsedCPU
if Font.Width (EmptyString, Fnt1 ) <= (((X2 - X1 ) div 8) * 7) then
if length (EmptyString ) < 100 then
for i : 97 .. 122
if Keys (chr (i )) = true then
EmptyString + = chr (i )
Time.Delay (150)
exit
end if
end for
if Keys (KEY_BACKSPACE ) = true then
var EnptyString2 : string := EmptyString
EmptyString := ""
for i : 1 .. length (EnptyString2 ) - 1
EmptyString + = EnptyString2 (i )
end for
Time.Delay (150)
end if
if Keys (' ') = true then
EmptyString := EmptyString + " "
Time.Delay (150)
end if
end if
elsif Font.Width (EmptyString, Fnt1 ) >= (((X2 - X1 ) div 8) * 7) then
if length (EmptyString ) < 100 then
if Keys (KEY_BACKSPACE ) = true then
var EnptyString2 : string := EmptyString
EmptyString := ""
for i : 1 .. length (EnptyString2 ) - 1
EmptyString + = EnptyString2 (i )
end for
Time.Delay (150)
end if
end if
end if
if Flash = false then
if T1 > T2 + 250 then
T2 := Time.ElapsedCPU
Flash := true
end if
elsif Flash = true then
if T1 > T2 + 500 then
T2 := Time.ElapsedCPU
Flash := false
end if
end if
drawbox (X1+ 1,Y1+ 1,X2- 1,Y2- 1, black)
if Flash = true then
Font.Draw (EmptyString + "*", X1 + 5, Y1 + 5, Fnt1, black)
elsif Flash = false then
Font.Draw (EmptyString, X1 + 5, Y1 + 5, Fnt1, black)
end if
View.Update
Time.DelaySinceLast (12)
cls
S := EmptyString
end if
end loop
Font.Free (Fnt1 )
end if
end if
end Active
var True : boolean := false
var Search : string := ""
var fnt1 : int := Font.New ("Arial:28")
loop
Active (0, 0, maxx, 50, "Arial:28", Search,True )
Font.Draw (Search, 5, 5, fnt1, black)
UpdateSearch (Search, SearchItems, NumItems )
View.Update
Time.DelaySinceLast (12)
cls
end loop |
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
|
|