Using Gamedemo.utils;
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Namespace Gamedemo
{
Class Program
{
static void Main (string[] args)
{
int total=0;//Timing
Console.WriteLine ("Start Game");
Console.WriteLine ("Ready to start the game?") y/n? ");
if (Console.ReadLine (). Equals ("n")) {
Console.WriteLine ("Game has exited!");
Return
}
Console.WriteLine ("Please enter the number of levels");
int GK = Int32.Parse (Console.ReadLine ());
Console.WriteLine ("Please enter the number of entries per level");
int count = Int32.Parse (Console.ReadLine ());
Console.WriteLine ("Please enter the number of words entered in the entry)";
int size = Int32.Parse (Console.ReadLine ());
for (int i = 0; I <gk; i++)
{
for (int j = 0; J <count; J + +)
{
Console.WriteLine ("This is the first" + (i+1) + "off" + "+" + (j+1) + "Times");
Generate Random letters
String str = new Randomutils (). Createrandomword (size);
Console.WriteLine ("You want to enter the content is:" +str);
Time Calculation
DateTime start = DateTime.Now;
Wait for user input
String Userinput=console.readline ();
DateTime end = DateTime.Now;
int t= (int) (end. Ticks-start. Ticks)/10000000;//single-time timekeeping
Total + = t;//timing
Check that user input is correct
if (userinput. Equals (str))
{
Console.WriteLine ("Congratulations, you entered the right!" +t+ "seconds");
}
else {
Console.WriteLine ("Sorry, you entered the wrong, the game is over!") ");
Return
}
}
if (i = = gk-1) {//run through all levels
Console.WriteLine ("Congratulate you all pass, total time is" +total+ "second");
Return
}
Console.WriteLine ("Ready to go to the next pass y/n");
String comd = Console.ReadLine ();
if (comd. Equals ("n")) {
Console.WriteLine ("Game has exited!");
Return
}
}
}
}
}
Tool class for producing strings
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Namespace Gamedemo.utils
{
Class Randomutils
{
<summary>
An array of characters to load
</summary>
Private char[] chars = new CHAR[50];
<summary>
Initializing an array of data
</summary>
Public Randomutils () {
Get a A-Z character
int idx=0;
for (int i = ' a '; i < ' z ' +1; i++)
{
if (i = = ' O ') {//Remove O-Letter
Continue
}
CHARS[IDX] + = (char) i;
idx++;
}
Get 1-9 of the characters
int idx2=idx;
for (int j = ' 0 '; j < ' 9 ' +1; j + +)
{
chars[idx2++] = (char) j;
}
Re-assemble data
char[] Newchars = new CHAR[IDX2];
for (int m = 0; M <idx2; m++)
{
if (chars[m] = = ' L ') {//Replace lowercase L with l
Chars[m] = ' L ';
}
NEWCHARS[M] = chars[m];
}
Assign a new array to the original array to make it easier for other methods to access the array data
chars = Newchars;
}
<summary>
Randomly generated string
</summary>
<param name= "Size" > Number of strings generated </param>
<returns></returns>
public string Createrandomword (int size) {
StringBuilder builder = new StringBuilder ();
Random r = new Random ();
for (int i = 0; I <size; i++)
{
char C = chars[r.next (chars. Length)];
if (builder. ToString (). Contains (c)) {//Handle string recurrence
i--;
Continue
}
Builder. Append (c);
}
Return builder. ToString ();
}
}
}
C # Implementation of simple Kingsoft typing games (source code)