Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static Random newletter = new Random();
        static void Main(string[] args)
        {
            
            string[] alphabet;
            Console.WriteLine("Typing reflex game"); Console.WriteLine(); Console.WriteLine();
            Console.WriteLine("You must type the letter you see as fast as you can");
            Console.WriteLine("Hit enter to start");
            Console.ReadLine();
            Console.WriteLine("The game starts in: 3"); System.Threading.Thread.Sleep(1000);
            Console.WriteLine("The game starts in: 2"); System.Threading.Thread.Sleep(1000);
            Console.WriteLine("The game starts in: 1"); System.Threading.Thread.Sleep(1000);
            ConsoleKeyInfo inputletter; 
            alphabet = new string[26];
            alphabet[0] = "A";
            alphabet[1] = "B";
            alphabet[2] = "C";
            alphabet[3] = "D";
            alphabet[4] = "E";
            alphabet[5] = "F";
            alphabet[6] = "G";
            alphabet[7] = "H";
            alphabet[8] = "I";
            alphabet[9] = "J";
            alphabet[10] = "K";
            alphabet[11] = "L";
            alphabet[12] = "M";
            alphabet[13] = "N";
            alphabet[14] = "O";
            alphabet[15] = "P";
            alphabet[16] = "Q";
            alphabet[17] = "R";
            alphabet[18] = "S";
            alphabet[19] = "T";
            alphabet[20] = "U";
            alphabet[21] = "V";
            alphabet[22] = "W";
            alphabet[23] = "X";
            alphabet[24] = "Y";
            alphabet[25] = "Z";
            do
            {
                Console.Clear();
                int lol = newletter.Next(0, 25);
                Console.WriteLine("Typing reflex game"); Console.WriteLine(); Console.WriteLine();
                Console.WriteLine("                     TYPE THIS LETTER:"); Console.WriteLine();
                Console.Write("                              "+ alphabet[lol]);
                inputletter = Console.ReadKey();
                inputletter = Convert.ToString;
                alphabet[lol].ToString();
                if (inputletter == alphabet[lol])
                {
                   // Add a point, or something
                }
                Console.WriteLine(inputletter.Key.ToString());
             } while (inputletter.Key != ConsoleKey.Escape);
            
            
        }
    }
}


This part:

C#
inputletter = Console.ReadKey();
                inputletter = Convert.ToString;
                alphabet[lol].ToString();
                if (inputletter == alphabet[lol])
                {
                }


I'm practicing for college work and I'm trying to make a app where the user types in the letter shown then it shows how many they got correct out of how ever many attempted (and I will try put in a timer system). I don't know how to make it check if the inputletter (the key input when the letter is shown) is equal to the alphabet[lol] (being a random chosen letter in the alphabet array)

please help :(
and any other help would be greatly appreciated
- first time using this site

I get 2 errors:
Cannot convert method group ToString to non-delegate type System.ConsoleKeyInfo. Did you intend to invoke the method?

and:
Operator == cannot be applied to operands of type System.ConsoleKeyInfo and string
Posted
Updated 15-Dec-11 19:16pm
v4
Comments
Balakrishnan Dhinakaran 16-Dec-11 1:45am    
my vote 5 for your clear scenario..
Balakrishnan Dhinakaran 16-Dec-11 1:48am    
you just copy my code and use I hope it ll work fine

Those errors appears because inputletter is a System.ConsoleKeyInfo[^] and you're trying to compare it with a string.

You should use KeyChar[^] property of inputletter
C#
inputletter = Console.ReadKey();
if (inputletter.KeyChar.ToString() == alphabet[lol])
{
}
 
Share this answer
 
Comments
Balakrishnan Dhinakaran 16-Dec-11 1:41am    
my vote 5
Balakrishnan Dhinakaran 16-Dec-11 1:42am    
if (inputletter.ToString() == alphabet[lol])
{
// Add a point, or something
}

I use this and it works well
Joel Whatley- 16-Dec-11 10:31am    
Thanks everyone :) What an awesome site this is! <3
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static Random newletter = new Random();
        static void Main(string[] args)
        {
            string[] alphabet;
            Console.WriteLine("Typing reflex game"); Console.WriteLine(); Console.WriteLine();
            Console.WriteLine("You must type the letter you see as fast as you can");
            Console.WriteLine("Hit enter to start");
            Console.ReadLine();
            Console.WriteLine("The game starts in: 3"); System.Threading.Thread.Sleep(1000);
            Console.WriteLine("The game starts in: 2"); System.Threading.Thread.Sleep(1000);
            Console.WriteLine("The game starts in: 1"); System.Threading.Thread.Sleep(1000);
            ConsoleKeyInfo inputletter;
            alphabet = new string[26];
            alphabet[0] = "A";
            alphabet[1] = "B";
            alphabet[2] = "C";
            alphabet[3] = "D";
            alphabet[4] = "E";
            alphabet[5] = "F";
            alphabet[6] = "G";
            alphabet[7] = "H";
            alphabet[8] = "I";
            alphabet[9] = "J";
            alphabet[10] = "K";
            alphabet[11] = "L";
            alphabet[12] = "M";
            alphabet[13] = "N";
            alphabet[14] = "O";
            alphabet[15] = "P";
            alphabet[16] = "Q";
            alphabet[17] = "R";
            alphabet[18] = "S";
            alphabet[19] = "T";
            alphabet[20] = "U";
            alphabet[21] = "V";
            alphabet[22] = "W";
            alphabet[23] = "X";
            alphabet[24] = "Y";
            alphabet[25] = "Z";
            do
            {
                Console.Clear();
                int lol = newletter.Next(0, 25);
                Console.WriteLine("Typing reflex game"); Console.WriteLine(); Console.WriteLine();
                Console.WriteLine("                     TYPE THIS LETTER:"); Console.WriteLine();
                Console.Write("                              " + alphabet[lol]);
                inputletter = Console.ReadKey();
                
                alphabet[lol].ToString();
                if (inputletter.ToString() == alphabet[lol])
                {
                    // Add a point, or something
                }
                Console.WriteLine(inputletter.Key.ToString());
            } while (inputletter.Key != ConsoleKey.Escape);
            
        }
    }
}
 
Share this answer
 
Comments
Joel Whatley- 16-Dec-11 10:31am    
Thanks!
Also does anyone know of a way to make the alphabet[lol] more random?
It doesn't seem very random at all :(
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 29-Apr-13 18:44pm    
Not an answer, should be removed. If you want to ask a question, ask a question. Posts like that will only give you down-votes and abuse reports.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900