Sign in to follow this  

3 Choices: Console.ReadKey(); Does Not Work?

This topic is 1118 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello

I am making a text-based game, and need some help with the choice system. Here's my code:

 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Text_Based_Zombie_Survival
{
    class Program
    {
       
        static void Main(string[] args)
        {   
            //Define variables
            ConsoleKeyInfo keyInfo = Console.ReadKey();
            char choice = keyInfo.KeyChar;   //Get char typed
 
            char a;
            char b;
            char c;
            
 
            
            //Instructions
            Console.WriteLine("INSTRUCTIONS:");
            Console.WriteLine("In each scenario, you will be presented with three choices");
            Console.WriteLine("Each choice corresponds to a letter(a,b,c)");
            Console.WriteLine("For example, if you had to choose between a backpack, stick, or golfclub");
            Console.WriteLine("a would be the backpack, b would be the stick, and c would be the golfclub");
            Console.ReadKey();
            Console.WriteLine("Have fun!");
            
            //Introduction
            Console.ReadKey();
            Console.WriteLine("There is a zombie apocalypse");
            Console.ReadKey();
            Console.WriteLine("Will you survive?");
            Console.ReadKey();
            Console.WriteLine("There is only one way to find out. Push any key to continue");
            Console.ReadKey();
 
            //Begin Game
            Console.WriteLine("You wake up");
            Console.ReadKey();
            Console.WriteLine("Looking outside, you see zombies all over your yard");
            Console.ReadKey();
            Console.WriteLine("You open your closet to grab a weapon");
            Console.ReadKey();
            Console.WriteLine("You see a rifle, baseball bat, and tennis racquet");
            Console.ReadKey();
            Console.WriteLine("Which do you pick?");
            
            
 
 
            
            
            
            
            
        }
    }
}
 
 
So what I want to do is make it so the user just has to type in the letters a,b, or c, and it initiates the set response. I keep getting conversion errors, however, and this is the latest method I tried using.

Share this post


Link to post
Share on other sites

Howdie,

 

I'll assume that your attempting to parse out the characters respecitively with some branching not shown in your provided code.

But seeing where you actually perform the branching with your reference to ConsoleKeyInfo is pivotal.

 

P.s. If at all possible, try utilizing source tags. Makes the code a bit more readable.

 

-Marcus

Edited by markypooch

Share this post


Link to post
Share on other sites

This topic is 1118 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this