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

Started by
1 comment, last by markypooch 9 years, 5 months ago

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.
What will you make?
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.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

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

This topic is closed to new replies.

Advertisement