I wanted a routine that would allow me to use the NumPad keys for directional commands. 1-9 for each compass point, - for up and + for down. If one of these keys are not pressed, it would act as a regular readline()
. I threw in a few simple lines to act as timers, obviously this was just to complete it.
This is my solution. It works fairly well, but thinking there is a better way.
string orders;
bool lives = true;
int counter = 0;
char[] delimeterChars = { ' ', ',', '.', ':', '\t' };
Console.Write("What shall I do? ");
do
{
string verb = "";
string noun = "game";
orders = Ask();
Console.WriteLine("You pressed " + orders);
counter = 0;
string[] words = orders.Split(delimeterChars);
verb = words[0].ToLower();
if (words.Length > 1) { noun = words[1].ToLower(); }
Console.WriteLine("verb is " + verb);
Console.WriteLine("noun is " + noun);
if (verb == "q" || verb == "quit") { noun = "game"; lives = false; }
} while (lives == true);
if (lives == false)
{
Console.WriteLine("Game over");
}
}
public static string Ask()
{
do
{
ThirstTimer();
HungerTimer();
ParalysisTimer();
PoisonTimer();
AttackTimer();
SpellTimer();
} while (Console.KeyAvailable == false);
var cki = Console.ReadKey(true);
Console.Write(cki.Key.ToString());
string VeRb = cki.Key.ToString();
switch (VeRb)
{
case "NumPad1":
return "go southwest";
case "NumPad2":
return "go south";
case "NumPad3":
return "go southeast";
case "NumPad4":
return "go west";
case "NumPad6":
return "go east";
case "NumPad7":
return "go northwest";
case "NumPad8":
return "go north";
case "NumPad9":
return "go northeast";
case "Add":
return "go down";
case "Subtract":
return "go up";
// If numpad is not used, get letter pressed and add to input.
default:
string Verbage = Console.ReadLine();
string VERB = cki.Key.ToString() + Verbage;
return VERB;
}
}
public static void ThirstTimer()
{ //Console.WriteLine("You are thirsty."); } // Timers include current Time, target Time, and 30 second display timer
}
public static void HungerTimer()
{ //Console.WriteLine("You are hungry."); }// Timers include current Time, target Time, and 30 second display timer
}
public static void ParalysisTimer()
{ //Console.WriteLine("You are paralysed."); }// Timers include current Time, target Time, a display everytime you attempt to move while active.
}
public static void PoisonTimer()
{ //Console.WriteLine("You have been poisoned."); }// Timers include current Time, target Time, and 30 second display timer
}
public static void AttackTimer()
{ //Console.WriteLine("Checking Attack delay."); }// Timers include current Time, target Time, and 30 second display timer
}
public static void SpellTimer()
{ //Console.WriteLine("Checking Spell Delay."); }// Timers include current Time, target Time, and display timer based on mana usage
}