Typing Game Help
Author |
Message |
TerW
|
Posted: Tue May 05, 2009 10:50 pm Post subject: Typing Game Help |
|
|
Im trying to create a typing game. And i wanted a bunch of sentences on screen, and the user would have to input what is shown on the screen. Then the program will show how many mistakes the user made. The problem I am having is that im trying to find another way then making each word a variable. I have tried a procedure, but it verifies the whole sentence, instead of each individual word.
|
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Analysis Mode
|
Posted: Tue May 05, 2009 10:51 pm Post subject: Re: Typing Game Help |
|
|
ok why don't you post your code? And when parsing the input, look for spaces and punctuation as indicators that a word has ended. |
|
|
|
|
 |
TerW
|
Posted: Wed May 06, 2009 6:42 pm Post subject: Re: Typing Game Help |
|
|
TerW @ Tue May 05, 2009 10:50 pm wrote:
Im trying to create a typing game. And i wanted a bunch of sentences on screen, and the user would have to input what is shown on the screen. Then the program will show how many mistakes the user made. The problem I am having is that im trying to find another way then making each word a variable. I have tried a procedure, but it verifies the whole sentence, instead of each individual word.
Turing: |
%Typing Game, displays sentences, that require the user to input exact sentences on screen
%Written by TerW
var This : string := "This"
var is : string := "is"
var my : string := "my"
var computer : string := "computer"
var game : string := "game."
var Thank : string := "Thank"
var you : string := "you"
var for1 : string := "for"
var helping : string := "helping"
var me : string := "me"
var with : string := "with"
var the : string := "the"
var code : string := "code"
var mistakes : int := 0
var reply : string
put "Do you want to play?"
get reply
loop
if reply = "yes" then
put This, " ", is, " ", my, " ", computer, " ", game, " "
locate (5, 1)
put Thank, " ", you, " ", for1, " ", helping, " ", me, " ", with, " ", the, " ", code
locate (4, 1)
get This
This := This
loop
if This = "This" then
exit
else
mistakes := mistakes + 1
exit
end if
end loop
get is
is := is
loop
if is = "is" then
exit
else
mistakes := mistakes + 1
exit
end if
end loop
get my
my := my
loop
if my = "my" then
exit
else
mistakes := mistakes + 1
exit
end if
end loop
get computer
is := is
loop
if is = "is" then
exit
else
mistakes := mistakes + 1
exit
end if
end loop
get game
game := game
loop
if game = "game." then
exit
else
mistakes := mistakes + 1
exit
end if
end loop
locate (6, 1)
get Thank
Thank := Thank
loop
if Thank = "Thank" then
exit
else
mistakes := mistakes + 1
exit
end if
end loop
get you
you := you
loop
if you = "you" then
exit
else
mistakes := mistakes + 1
exit
end if
end loop
get for1
for1 := for1
loop
if for1 = "for" then
exit
else
mistakes := mistakes + 1
exit
end if
end loop
get helping
helping := helping
loop
if helping = "helping" then
exit
else
mistakes := mistakes + 1
exit
end if
end loop
get me
me := me
loop
if me = "me" then
exit
else
mistakes := mistakes + 1
exit
end if
end loop
get with
with := with
loop
if with = "with" then
exit
else
mistakes := mistakes + 1
end if
end loop
get the
the := the
loop
if the = "the" then
exit
else
mistakes := mistakes + 1
end if
end loop
get code
code := code
loop
if code = "code" then
exit
else
mistakes := mistakes + 1
end if
end loop
put "You made ", mistakes, " mistake(s)."
exit
end if
end loop
|
|
|
|
|
|
 |
tjmoore1993

|
Posted: Wed May 06, 2009 7:01 pm Post subject: RE:Typing Game Help |
|
|
Turing: |
var Word : array 1 .. 13 of string
var Selection : int
var Score : array 1 .. 2 of int
Word (1) := "Transportation"
Word (2) := "Alcohol"
Word (3) := "Pickles"
Word (4) := "Mississippi"
Word (5) := "United Kingdom"
Word (6) := "Mistake"
Word (7) := "Elephant"
Word (8) := "Eggplant"
Word (9) := "Extremely"
Word (10) := "Hurriedly"
Word (11) := "Belittling"
Word (12) := "Erection"
Score (1) := 0
Score (2) := 0
loop
cls
locate (1, 1)
put "Correct : ", Score (1), " Incorrect : ", Score (2)
Selection := Rand.Int (1, 12)
put "Spell the word"
put Word (Selection )
get Word (13)
if Word (13) = Word (Selection ) then
Score (1) + = 1
put "Correct!"
else
Score (2) + = 1
put "Incorrect!"
end if
end loop
|
This should help you out with efficiency. However you should look at this guide...
http://compsci.ca/v3/viewtopic.php?t=8229 |
|
|
|
|
 |
Dusk Eagle

|
Posted: Wed May 06, 2009 7:12 pm Post subject: Re: Typing Game Help |
|
|
I hate to be blunt, but you're going to have to scrap 90% of that code and start over. Here is a MUCH better way to do it:
Store a sentence inside of a text file. Use File I/O to read that sentence to a variable, with each word being a seperate element in a flexible array. For this example, let's call the array "words". Then, have a separate variable (just one!) to "get" the input from the user. Have a for loop that runs for the length of your sentence, and after each word checks if the input is equal to the word stored in "words" at that position.
If this sounds complicated to you, it kind of is. But if you can implement at least some of this, it will make you a far better programmer. What you are doing is comparable to solving an arithmetic problem like 10^5 by grabbing a pencil and adding 10 + 10 + 10 + 10 + 10 ... Sure, you won't learn exponents overnight, but you might as well start now. You may not learn everything posted up there in a week (such as the flexible arrays - those can be tricky when you're starting), but ultimately you're going to have to strive to improve or go nowhere at all.
Edit: I want to point out that you can always find plenty of Turing tutorials at http://compsci.ca/v3/viewtopic.php?t=8808. |
|
|
|
|
 |
TerW
|
Posted: Wed May 06, 2009 7:40 pm Post subject: Re: Typing Game Help |
|
|
Thanks, Ill look into the tutorials and flexible arrays. I also want to know how i can incorporate a procedure into this program. Thank you. |
|
|
|
|
 |
Dusk Eagle

|
Posted: Wed May 06, 2009 7:59 pm Post subject: Re: Typing Game Help |
|
|
There is, in fact. Here's a couple you could use:
Turing: |
/*Called by getWord below - see documentation there.*/
fcn getKey () : string
var ch : string (1)
loop
getch (ch )
exit when ch ~ = KEY_BACKSPACE
end loop
cls
result ch
end getKey
/*Gets word from user without allowing backspacing, and exits as soon as word is of appropriate length
(available at http://compsci.ca/v3/viewtopic.php?t=20879)*/
fcn getWord (word_length : int) : string
var word : string := ""
loop
exit when length(word ) = word_length
locate (1, length (word ) + 1)
word + = getKey ()
put word
end loop
result word
end getWord
/*Returns true if word1 = word2*/
fcn compareWords (word1, word2 : string) : boolean
result word1 = word2
end compareWords
|
Here's just some examples - see if you can come up with your own. |
|
|
|
|
 |
TerW
|
Posted: Wed May 06, 2009 9:07 pm Post subject: Re: Typing Game Help |
|
|
Thanks, haha, its a little complicated for me, but I will try to comprehend this. Any other suggestions, or tips will be much appreciated. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
TerW
|
Posted: Thu May 07, 2009 10:35 pm Post subject: Re: Typing Game Help |
|
|
Hey, does this seem fine so far? Uh, I have a question as to how to put the words in certain postions, like starting a new sentence, or so a word would not get cut off?
Turing: |
var text : flexible array 1 .. 0 of string
var stream : int
var mistakes : int := 0
var input : string
open : stream, "text1.txt", get
loop
exit when eof (stream )
new text, upper (text ) + 1
get : stream, text (upper (text ))
end loop
for i : 1 .. upper (text )
put text (i ) ..
put " " ..
exit
end for
locate (3, 1)
loop
for i : 1 .. upper (text )
get input
if input = text (i ) then
put text (i ), " " ..
exit
else
mistakes := mistakes + 1
end if
end for
end loop
put "You have made ", mistakes, " mistakes."
|
|
|
|
|
|
 |
Dusk Eagle

|
Posted: Thu May 07, 2009 11:02 pm Post subject: Re: Typing Game Help |
|
|
It looks pretty good when a couple things are fixed. Both the problems I can tell stem from this piece of your code:
Turing: | if input = text (i) then
put text (i), " " ..
exit
|
First of all, why do you exit the for loop? That is like saying "If you type the word correctly, you have to start over." The other issue is that you only display the word the user needs to type in only after they have typed in said word. I can see what you were getting at; you meant to put "text(i+1)", but even that won't work because your for loop will continue on whether or not the user enters in the correct word. So why not just display the word above your "get" line, thus avoiding this problem?
I can't answer your main question because I don't understand it, but my suggestions above should help your code anyway. |
|
|
|
|
 |
TerW
|
Posted: Fri May 08, 2009 6:14 pm Post subject: RE:Typing Game Help |
|
|
Alright, sorry for not stating the question more clearly. My question is asking how I can control the position of words on the screen. For example; when i get the words from the file, and i put them on screen they appear without any spaces in between the lines like this:
"The words all appear, but there are no spaces into between each line, even if the text file does have spaces. I want to have spaces between the lines because that is the space I wanted to user to type in."
I would prefer something like this:
"All I want are spaces between each line, so
there is a space for the user to input and type
in the words that appear on the screen."
I have tried using "locate" but I have difficulty using it in a loop changing the row every certain number of words. |
|
|
|
|
 |
|
|