Initially I was hung up on the idea of using actual commands, which would have been a great learning tool, but also harder to implement. Then I realized what I really cared about was teaching my fingers to find the weird keys, and random text works fine for that. So I created the following. Characters I've been having trouble with are listed multiple times so I get more practice on them.
// TypingCode.cpp : Defines the entry point for the console application.
// by Jeff Fisher
// 7/30/2012
// This is a simple typing practice application.
// Data entry is not timed and speed is not measured.
#include "stdafx.h"
#include <iostream>
#include <string>
#include <time.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string goalStr; // The string we want to type
string typedStr; // The string we do type
const int numSymb = 122; // The total number of symbols in the array
string symbStr[numSymb] = {"\"", "\'",
"*", "-", "--","-=","_", "+", "+", "+=", "=", ",",
".", "?", "/", "<","<<","<=", ">", ">>",">=","->",
"\\", "@","!","||", "]", "}", "}", "}", ")", ")", ")",
"(","(", "(", "{", "{", "{", "[", ";", ":", "~", "`",
"1", "1", "2", "2", "3", "3", "4", "4", "5", "5",
"6", "6", "7", "7", "8", "8", "9", "9", "0", "0",
"a", "A", "b", "B", "c", "C", "d", "D", "e", "E",
"f", "F", "g", "G", "h", "H", "i", "I", "j", "J",
"k", "K", "l", "L", "m", "M", "n", "N", "o", "O",
"p", "P", "q", "Q", "r", "R", "s", "S", "T", "t",
"u", "U", "v", "V", "x", "X", "y", "Y", "z", "Z"};
// All of the symbols that initialize the numSymb array
float score = 0; // Tracks the net number of correct words
int strLength = 2; // The starting length of the string we need to type
srand(time(NULL)); // Seeds the RAND function
// Main game loop using do-while
do{
// for loop builds the string for the user to type
for( int i=0; i<strLength; i++ ){
goalStr += symbStr[ rand() % numSymb ];
}
cout << goalStr << endl; // Gives the user the goal
cin >> typedStr; // User input
// Checks if the typed string is correct
if(typedStr==goalStr){
cout << endl << "WIN!" << endl << endl; // Lets the user know
score = score + 1; // Increments the score
strLength = sqrt(score)+2; // Updates the length based on the current score
goalStr = ""; // Clears the goal string
} // If the string is not correct
else{
cout << endl << "FAIL!" << endl << endl; // Lets the user know
score = score - 1; // Lowers the score
strLength = sqrt(score)+2; // Updates the length based on the current score
goalStr = ""; // Clears the goal string
}
}
while( strLength < 12 ); // If the string length gets to 12 the game ends
cout << endl << "Good job. I need to make this harder!"; // Lets the user know
system("pause"); // Gives them a chance to revel in their glory
return 0;
}
No comments:
Post a Comment