Jump to content
  • Advertisement
Sign in to follow this  
Ovicior

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

This topic is 1333 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
Advertisement
Please show the code that you're actually having trouble with. This code looks reasonable but of course it doesn't do much. It's very difficult to assist without seeing the actual issue you're running into.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!