Introduction
Do you like small games that you just cant stop playing? Try this one...
Background
I was playing Super Text Twist® by GameHouse™ Games and it kept crashing on me.
I run Windows7®™ and win7 doesnt like the game. I then decided to start my own version of the game but didnt quite know
where to start. I first created all the forms I was going to use and then I started searching for code at PSC and came across a VB 2005® beta express
version by Salan S. Al-Ani. His version of the game can be seen at PSC.
I added a more visual effect to my version of the game. I also added scoring, add high scores and remove them, total of the words you have to find, and 3 to 7 letter word
counters depending on the difficulty stage using 5, 6, or 7 letter words.
Using the code
I tried to keep the main form(shown above) as close as possible to the original(referring to the program on PSC®™) without trying to copy it to a TEE.
I added color and a mellow visual feeling to the app for a better playing effect(pic shown above). All backgrounds were created in PS CS3®™. I did use
some of the old code from the PSC version and re-edited and added a lot of code to work like the original( Super Text Twist® ).
Moving the Forms
Let's get started, As the main form(shown above) and the Options
form(shown below) have no TitleBars
, we need a way to move them when needed. (Code will be displayed below).
All other forms are stationary. When in fullscreen mode we need a way to exit out of fullscreen mode. I used a flashing Label
in a Timer
to display how do to this to the user.
Private Sub frmTextTwist_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
Me.isDragging = True
pointClicked = New Point(e.X, e.Y)
Else
Me.isDragging = False
End If
End Sub
Private Sub frmTextTwist_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If Me.isDragging Then
Dim pointMovedTo As Point
pointMovedTo = Me.PointToScreen(New Point(e.X, e.Y))
pointMovedTo.Offset(-pointClicked.X, -pointClicked.Y)
Me.Location = pointMovedTo
End If
End Sub
Private Sub frmTextTwist_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
Me.isDragging = False
End Sub
Load and Exit FullScreen Mode
If you want to play in fullscreen mode, just check the CheckBox
in the Options form and click the CLOSE LABEL
.
This will lode the fullscreen mode. Once loaded, you will see a flashing Label
. The frmTextTwist_KeyDown
event
gets fired when you press the Escape Key
on your keyboard. (Code below for both events)...
Private Sub frmTextTwist_SizeChanged(sender As Object, e As System.EventArgs) Handles Me.SizeChanged
If Me.WindowState = FormWindowState.Maximized Then
lblNotice.Location = New Point(CInt((Me.Width - lblNotice.Width) / 2), CInt((Me.Height - lblNotice.Height) / 2))
lblNotice.Visible = True
timerNotice.Start()
Else
lblNotice.Location = New Point(241, 229)
lblNotice.Visible = False
timerNotice.Stop()
End If
End Sub
Private Sub timerNotice_Tick(sender As Object, e As System.EventArgs) Handles timerNotice.Tick
iTick += 1
Select Case iTick
Case 1
lblNotice.ForeColor = Color.Black
Case 2
lblNotice.ForeColor = Color.White
Case 3
lblNotice.ForeColor = Color.Black
Case 4
lblNotice.ForeColor = Color.White
Case 5
lblNotice.ForeColor = Color.Black
End Select
If iTick = 5 Then
iTick = 0
lblNotice.Visible = False
timerNotice.Stop()
End If
End Sub
Private Sub frmTextTwist_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyData <> Keys.Escape Then
Else
Me.WindowState = FormWindowState.Normal
frmOptions.chkFullScreen.Checked = False
End If
End Sub
Real Butter or Fake Butter?
Next, we have the the FAKE animation of the buttons(Button
1 thru Button
7). This is accomplished by setting some Points
and setting some Booleans
to True
or False
. The code that follows is the same for all seven buttons
except for the buttons name. We also add the button text to an invisible Label
to be used when we click the Enter Button
.
Private Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
If NowPlaying = True And FirstRun = False Then
Dim s As String
Select Case Difficulty
Case 1
If AO1 = True And AO2 = False And AO3 = False And AO4 = False And AO5 = False And Button1.Location <> BL1 Then AO1 = False
If AO1 = True And AO2 = True And AO3 = False And AO4 = False And AO5 = False And Button1.Location <> BL1 Then AO2 = False
If AO1 = True And AO2 = True And AO3 = True And AO4 = False And AO5 = False And Button1.Location <> BL1 Then AO3 = False
If AO1 = True And AO2 = True And AO3 = True And AO4 = True And AO5 = False And Button1.Location <> BL1 Then AO4 = False
If AO1 = True And AO2 = True And AO3 = True And AO4 = True And AO5 = True And Button1.Location <> BL1 Then AO5 = False
If Button1.Location <> BL1 Then
Button1.Location = BL1
s = lblAnswer.Text
s = s.Replace(Button1.Text, "")
lblAnswer.Text = s
Exit Sub
End If
lblAnswer.Text += Button1.Text
If AO1 = False And AO2 = False And AO3 = False And AO4 = False And AO5 = False Then
Button1.Location = BL1a
AO1 = True
ElseIf AO1 = True And AO2 = False And AO3 = False And AO4 = False And AO5 = False Then
Button1.Location = BL2b
AO2 = True
ElseIf AO1 = True And AO2 = True And AO3 = False And AO4 = False And AO5 = False Then
Button1.Location = BL3c
AO3 = True
ElseIf AO1 = True And AO2 = True And AO3 = True And AO4 = False And AO5 = False Then
Button1.Location = BL4d
AO4 = True
ElseIf AO1 = True And AO2 = True And AO3 = True And AO4 = True And AO5 = False Then
Button1.Location = BL5e
AO5 = True
End If
Case 2
If AO1 = True And AO2 = False And AO3 = False And AO4 = False And AO5 = False And AO6 = False And Button1.Location <> BL1 Then AO1 = False
If AO1 = True And AO2 = True And AO3 = False And AO4 = False And AO5 = False And AO6 = False And Button1.Location <> BL1 Then AO2 = False
If AO1 = True And AO2 = True And AO3 = True And AO4 = False And AO5 = False And AO6 = False And Button1.Location <> BL1 Then AO3 = False
If AO1 = True And AO2 = True And AO3 = True And AO4 = True And AO5 = False And AO6 = False And Button1.Location <> BL1 Then AO4 = False
If AO1 = True And AO2 = True And AO3 = True And AO4 = True And AO5 = True And AO6 = False And Button1.Location <> BL1 Then AO5 = False
If AO1 = True And AO2 = True And AO3 = True And AO4 = True And AO5 = True And AO6 = True And Button1.Location <> BL1 Then AO6 = False
If Button1.Location <> BL1 Then
Button1.Location = BL1
s = lblAnswer.Text
s = s.Replace(Button1.Text, "")
lblAnswer.Text = s
Exit Sub
End If
lblAnswer.Text += Button1.Text
If AO1 = False And AO2 = False And AO3 = False And AO4 = False And AO5 = False And AO6 = False Then
Button1.Location = BL1a
AO1 = True
ElseIf AO1 = True And AO2 = False And AO3 = False And AO4 = False And AO5 = False And AO6 = False Then
Button1.Location = BL2b
AO2 = True
ElseIf AO1 = True And AO2 = True And AO3 = False And AO4 = False And AO5 = False And AO6 = False Then
Button1.Location = BL3c
AO3 = True
ElseIf AO1 = True And AO2 = True And AO3 = True And AO4 = False And AO5 = False And AO6 = False Then
Button1.Location = BL4d
AO4 = True
ElseIf AO1 = True And AO2 = True And AO3 = True And AO4 = True And AO5 = False And AO6 = False Then
Button1.Location = BL5e
AO5 = True
ElseIf AO1 = True And AO2 = True And AO3 = True And AO4 = True And AO5 = True And AO6 = False Then
Button1.Location = BL6f
AO6 = True
End If
Case 3
If AO1 = True And AO2 = False And AO3 = False And AO4 = False And AO5 = False And AO6 = False And AO7 = False And Button1.Location <> BL1 Then AO1 = False
If AO1 = True And AO2 = True And AO3 = False And AO4 = False And AO5 = False And AO6 = False And AO7 = False And Button1.Location <> BL1 Then AO2 = False
If AO1 = True And AO2 = True And AO3 = True And AO4 = False And AO5 = False And AO6 = False And AO7 = False And Button1.Location <> BL1 Then AO3 = False
If AO1 = True And AO2 = True And AO3 = True And AO4 = True And AO5 = False And AO6 = False And AO7 = False And Button1.Location <> BL1 Then AO4 = False
If AO1 = True And AO2 = True And AO3 = True And AO4 = True And AO5 = True And AO6 = False And AO7 = False And Button1.Location <> BL1 Then AO5 = False
If AO1 = True And AO2 = True And AO3 = True And AO4 = True And AO5 = True And AO6 = True And AO7 = False And Button1.Location <> BL1 Then AO6 = False
If AO1 = True And AO2 = True And AO3 = True And AO4 = True And AO5 = True And AO6 = True And AO7 = True And Button1.Location <> BL1 Then AO7 = False
If Button1.Location <> BL1 Then
Button1.Location = BL1
s = lblAnswer.Text
s = s.Replace(Button1.Text, "")
lblAnswer.Text = s
Exit Sub
End If
lblAnswer.Text += Button1.Text
If AO1 = False And AO2 = False And AO3 = False And AO4 = False And AO5 = False And AO6 = False And AO7 = False Then
Button1.Location = BL1a
AO1 = True
ElseIf AO1 = True And AO2 = False And AO3 = False And AO4 = False And AO5 = False And AO6 = False And AO7 = False Then
Button1.Location = BL2b
AO2 = True
ElseIf AO1 = True And AO2 = True And AO3 = False And AO4 = False And AO5 = False And AO6 = False And AO7 = False Then
Button1.Location = BL3c
AO3 = True
ElseIf AO1 = True And AO2 = True And AO3 = True And AO4 = False And AO5 = False And AO6 = False And AO7 = False Then
Button1.Location = BL4d
AO4 = True
ElseIf AO1 = True And AO2 = True And AO3 = True And AO4 = True And AO5 = False And AO6 = False And AO7 = False Then
Button1.Location = BL5e
AO5 = True
ElseIf AO1 = True And AO2 = True And AO3 = True And AO4 = True And AO5 = True And AO6 = False And AO7 = False Then
Button1.Location = BL6f
AO6 = True
ElseIf AO1 = True And AO2 = True And AO3 = True And AO4 = True And AO5 = True And AO6 = True And AO7 = False Then
Button1.Location = BL7g
AO7 = True
End If
End Select
End If
End Sub
Loading the Dictionaries at Start-up
We need to start by loading the dictionaries to 4 different StreamReader
s and again to 4 different FileInfo
holders.
Declare
a integer
to hold the total of the 4 FileInfo
holders, show our progress to the user
by way of a Progressbar
, Declare some New ArrayLists
and start reading the files into the arrays. Then clean up and
set the game timer to False
until we start the game.
Public Sub Startup()
NowPlaying = False
Dim line As String
Dim MyReaderDicAll As System.IO.StreamReader
Dim MyReaderDic5L As System.IO.StreamReader
Dim MyReaderDic6L As System.IO.StreamReader
Dim MyReaderDic7L As System.IO.StreamReader
MyReaderDicAll = My.Computer.FileSystem.OpenTextFileReader(Application.StartupPath & "\Dic\DicAll.txt")
MyReaderDic5L = My.Computer.FileSystem.OpenTextFileReader(Application.StartupPath & "\Dic\Dic5L.txt")
MyReaderDic6L = My.Computer.FileSystem.OpenTextFileReader(Application.StartupPath & "\Dic\Dic6L.txt")
MyReaderDic7L = My.Computer.FileSystem.OpenTextFileReader(Application.StartupPath & "\Dic\Dic7L.txt")
Dim infoAll As System.IO.FileInfo
Dim info5L As System.IO.FileInfo
Dim info6L As System.IO.FileInfo
Dim info7L As System.IO.FileInfo
infoAll = My.Computer.FileSystem.GetFileInfo(Application.StartupPath & "\Dic\DicAll.txt")
info5L = My.Computer.FileSystem.GetFileInfo(Application.StartupPath & "\Dic\Dic5L.txt")
info6L = My.Computer.FileSystem.GetFileInfo(Application.StartupPath & "\Dic\Dic6L.txt")
info7L = My.Computer.FileSystem.GetFileInfo(Application.StartupPath & "\Dic\Dic7L.txt")
Dim max As Integer
max = CInt(infoAll.Length + info5L.Length + info6L.Length + info7L.Length)
PB_Loading.Style = ProgressBarStyle.Blocks
PB_Loading.Minimum = 0
PB_Loading.Maximum = max
PB_Loading.Value = 0
DicAll = New ArrayList
line = MyReaderDicAll.ReadLine()
While Not line Is Nothing
PB_Loading.Value = PB_Loading.Value + line.Length + 2
DicAll.Add(line.ToString)
line = MyReaderDicAll.ReadLine()
End While
Dic5L = New ArrayList
line = MyReaderDic5L.ReadLine()
While Not line Is Nothing
PB_Loading.Value = PB_Loading.Value + line.Length + 2
Dic5L.Add(line.ToString)
line = MyReaderDic5L.ReadLine()
End While
Dic6L = New ArrayList
line = MyReaderDic6L.ReadLine()
While Not line Is Nothing
PB_Loading.Value = PB_Loading.Value + line.Length + 2
Dic6L.Add(line.ToString)
line = MyReaderDic6L.ReadLine()
End While
Dic7L = New ArrayList
line = MyReaderDic7L.ReadLine()
While Not line Is Nothing
PB_Loading.Value = PB_Loading.Value + line.Length + 2
Dic7L.Add(line.ToString)
line = MyReaderDic7L.ReadLine()
End While
MyReaderDicAll.Close()
MyReaderDic5L.Close()
MyReaderDic6L.Close()
MyReaderDic7L.Close()
timerGame.Enabled = False
End Sub
The Enter Button
This is where about 60% of the program lurks. First we check some Booleans
to see if we are going to exit the Sub
or not. Next we declare
some in-sub variables(String, Integer and Boolean
)respectively. Remember above where I made reference to a invisible Label
?. This is where
we set our String
(just declared) to the invisible labels
text(lblAnswer
). Next we will check the length of our String
.
If the String
is less than 3 characters long, then we Clear
(Explained later) everything and exit the Sub
, Else, we continue on and
check to see if we already have our String
in our ListBox
(lstCorrectWords) using the StrCompare()
method. If our String
is in the ListBox, then we Clear
everything , Exit the sub and start over once more, Else, we continue on. Messages are displayed to the user if the word is or isnt
long enough, Correct, Already in Listbox
, Is the ChoosenWord
or not. All word counters are updated(if word is 3 letters long then (threeLetters
-= 1)) and so on for
the rest of the counters. If all PossibleWords
are found then we do alot of clean-up and display to the user all possible words in the ListBox
in alphabetical order
according to length. Your score is displayed also. Then we continue the game by pressing the Proceed Button
.
Private Sub btnEnter_Click(sender As System.Object, e As System.EventArgs) Handles btnEnter.Click
If NowPlaying = False Or FirstRun = True Then
Exit Sub
End If
Dim str As String
Dim i As Integer
Dim Okay As Boolean
str = lblAnswer.Text
If str.Length < 3 Then
lblNotify.Text = "The word should be at least 3 letters long."
Clear()
Exit Sub
End If
For i = 0 To lstCorrectWords.Items.Count - 1
If StrComp(lstCorrectWords.Items(i).ToString, str, CompareMethod.Text) = 0 Then
lblNotify.Text = "You already submitted this word (" & str & ")"
Clear()
Exit Sub
End If
Next i
Okay = False
For i = 0 To PossibleWords.Count - 1
If StrComp(str, PossibleWords.Item(i).ToString, CompareMethod.Text) = 0 Then
Okay = True
Exit For
End If
Next i
If Okay = True Then
If str.Length = 4 + Difficulty And str = ChoosenWord Then
lblNotify.Text = "Excellent (" & str & ")"
scoreTotal += 1500
totalWords -= 1
lblWordsToFind.Text = "Number of words to find ====>> " & totalWords.ToString
If Difficulty = 3 And str = ChoosenWord Then
sevenLetters -= 1
lblWordsWithSevenLetters.Text = "Words with 7 letters : " & sevenLetters.ToString()
ElseIf Difficulty = 2 And str = ChoosenWord Then
sixLetters -= 1
lblWordsWithSixLetters.Text = "Words with 6 letters : " & sixLetters.ToString()
ElseIf Difficulty = 1 And str = ChoosenWord Then
fiveLetters -= 1
lblWordsWithFiveLetters.Text = "Words with 5 letters : " & fiveLetters.ToString()
End If
btnProceed.Enabled = True
Else
lblNotify.Text = "Correct Word (" & str & ")"
If str.Length = 3 Then
scoreTotal += 250
totalWords -= 1
lblWordsToFind.Text = "Number of words to find ====>> " & totalWords.ToString
threeLetters -= 1
lblWordsWithThreeLetters.Text = "Words with 3 letters : " & threeLetters.ToString()
ElseIf str.Length = 4 Then
scoreTotal += 500
totalWords -= 1
lblWordsToFind.Text = "Number of words to find ====>> " & totalWords.ToString
fourLetters -= 1
lblWordsWithFourLetters.Text = "Words with 4 letters : " & fourLetters.ToString()
ElseIf str.Length = 5 Then
scoreTotal += 750
totalWords -= 1
lblWordsToFind.Text = "Number of words to find ====>> " & totalWords.ToString
fiveLetters -= 1
lblWordsWithFiveLetters.Text = "Words with 5 letters : " & fiveLetters.ToString()
ElseIf str.Length = 6 Then
scoreTotal += 1000
totalWords -= 1
lblWordsToFind.Text = "Number of words to find ====>> " & totalWords.ToString
sixLetters -= 1
lblWordsWithSixLetters.Text = "Words with 6 letters : " & sixLetters.ToString()
ElseIf str.Length = 7 Then
scoreTotal += 1500
totalWords -= 1
lblWordsToFind.Text = "Number of words to find ====>> " & totalWords.ToString
sevenLetters -= 1
lblWordsWithSevenLetters.Text = "Words with 7 letters : " & sevenLetters.ToString()
End If
End If
lstCorrectWords.Items.Add(str)
If lstCorrectWords.Items.Count = PossibleWords.Count Then
lblNotify.Text = "Excellent, you submitted all the possible words"
totalWords = 0
lblWordsToFind.Text = "Number of words to find ====>> " & totalWords.ToString
NowPlaying = False
GameTimerSec = 0
lblTimeHolder.Text = "0:00"
timerGame.Enabled = False
RedoList()
ShowWords()
Exit Sub
End If
Else
lblNotify.Text = "Sorry, this word is not supported in our dictionary (" & str & ")"
End If
lblScoreHolder.Text = scoreTotal.ToString()
Clear()
End Sub
Clear, Sort, Shuffle and Twist, This is How We "Doit-Doit"
The Clear
sub resets lblAnswer
to Nothing
, Sets the Enabled
and Location Properties
of (Button
1 thru Button
7)
to True
and respective locations and sets their Booleans
to True
.
Public Sub Clear()
lblAnswer.Text = ""
Button1.Enabled = True
Button2.Enabled = True
Button3.Enabled = True
Button4.Enabled = True
Button5.Enabled = True
Button6.Enabled = True
Button7.Enabled = True
Button1.Location = BL1
Button2.Location = BL2
Button3.Location = BL3
Button4.Location = BL4
Button5.Location = BL5
Button6.Location = BL6
Button7.Location = BL7
AO1 = False
AO2 = False
AO3 = False
AO4 = False
AO5 = False
AO6 = False
AO7 = False
End Sub
Now we do the sorting of all the words that we put into our declared ArrayLists
. This is the list of arrays...
- threeLetterWords
- fourLetterWords
- fiveLetterWords
- sixLetterWords
- sevenLetterWords
We sort all the words according to thier length. Then they are displayed in the ListBox
in alphabetical order according to thier lengths. This is done with a lot of
For...Next Loops
Private Sub RedoList()
lstCorrectWords.Items.Clear()
Dim i As Integer
For i = 0 To PossibleWords.Count - 1
If PossibleWords(i).ToString.Length = 3 Then
threeLetterWords.Add(PossibleWords(i))
End If
Next i
threeLetterWords.Sort()
For i = 0 To PossibleWords.Count - 1
If PossibleWords(i).ToString.Length = 4 Then
fourLetterWords.Add(PossibleWords(i))
End If
Next i
fourLetterWords.Sort()
For i = 0 To PossibleWords.Count - 1
If PossibleWords(i).ToString.Length = 5 Then
fiveLetterWords.Add(PossibleWords(i))
End If
Next i
fiveLetterWords.Sort()
For i = 0 To PossibleWords.Count - 1
If PossibleWords(i).ToString.Length = 6 Then
sixLetterWords.Add(PossibleWords(i))
End If
Next i
sixLetterWords.Sort()
For i = 0 To PossibleWords.Count - 1
If PossibleWords(i).ToString.Length = 7 Then
sevenLetterWords.Add(PossibleWords(i))
End If
Next i
sevenLetterWords.Sort()
End Sub
Private Sub ShowWords()
Dim i As Integer
For i = 0 To threeLetterWords.Count - 1
lstCorrectWords.Items.Add(threeLetterWords(i))
Next
For i = 0 To fourLetterWords.Count - 1
lstCorrectWords.Items.Add(fourLetterWords(i))
Next
For i = 0 To fiveLetterWords.Count - 1
lstCorrectWords.Items.Add(fiveLetterWords(i))
Next
For i = 0 To sixLetterWords.Count - 1
lstCorrectWords.Items.Add(sixLetterWords(i))
Next
For i = 0 To sevenLetterWords.Count - 1
lstCorrectWords.Items.Add(sevenLetterWords(i))
Next
End Sub
All that is being done in the next sub (Twist) is changing the letters around so that they are not on the same button as before.
Public Sub Twist()
Dim AlReadyPicked() As Integer
Dim PickedSeq() As Integer
Dim LetterCount As Integer
Dim i As Integer
Dim j As Integer
Dim rndNo As Integer
Dim Okay As Boolean
LetterCount = Difficulty + 4
ReDim AlReadyPicked(LetterCount)
ReDim PickedSeq(LetterCount)
For j = 0 To LetterCount - 1
PickedSeq(j) = 0
Next j
Randomize()
For i = 0 To LetterCount - 1
Do
rndNo = CInt(Int(LetterCount * Rnd()) + 1)
Okay = True
For j = 0 To LetterCount - 1
If rndNo = PickedSeq(j) Then
Okay = False
Exit For
End If
Next j
If Okay = True Then
PickedSeq(i) = rndNo
Exit Do
End If
Loop
Next i
Button1.Text = Mid(ChoosenWord, PickedSeq(0), 1)
Button2.Text = Mid(ChoosenWord, PickedSeq(1), 1)
Button3.Text = Mid(ChoosenWord, PickedSeq(2), 1)
Button4.Text = Mid(ChoosenWord, PickedSeq(3), 1)
Button5.Text = Mid(ChoosenWord, PickedSeq(4), 1)
If Difficulty = 2 Then
Button6.Text = Mid(ChoosenWord, PickedSeq(5), 1)
ElseIf Difficulty = 3 Then
Button6.Text = Mid(ChoosenWord, PickedSeq(5), 1)
Button7.Text = Mid(ChoosenWord, PickedSeq(6), 1)
End If
End Sub
Conclusion
Although this game has been done before, You had to pay for it. Now you dont. It is fun to play and then sometimes its not because you dont have enough time
to finish your word and press Enter to get the last word. I was going to extend the time, but, "aaaaa". That just would not be fun anymore. Have fun playing.
Voting...I just put this on the site for anyone who wants to pull thier hair out.
Points of Interest
History of the World, Part 1.
- First Completion 03.30.2012