using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GameEdition3
{
class Program
{
static void Main(string[] args)
{
Data classData = new Data();
Console.WriteLine("{0}", classData.TitleMenu());
while (true)
{
ConsoleKeyInfo PressKey;
PressKey = Console.ReadKey();
while (PressKey.Key == ConsoleKey.Backspace)
{
Console.Clear();
Console.WriteLine("{0}", classData.TitleMenu());
PressKey = Console.ReadKey();
}
while (PressKey.Key == ConsoleKey.I)
{
Console.Clear();
Console.WriteLine("{0}", classData.Information());
PressKey =Console.ReadKey();
}
while (PressKey.Key == ConsoleKey.D1)
{
Console.Clear();
Console.Write("Please type in the Item you want. Warhammer, Heavy Armor, Boots, or Sword: ");
Console.WriteLine("{0}", classData.myFunction());
Console.WriteLine("\nPress Backspace to go back to the menu and you can view your item in the Display all Items tab");
PressKey = Console.ReadKey();
}
while (PressKey.Key == ConsoleKey.D2)
{
Console.Clear();
Console.WriteLine("{0}", classData.result);
PressKey = Console.ReadKey();
}
while (PressKey.Key == ConsoleKey.D3)
{
Console.Clear();
PressKey = Console.ReadKey();
}
if (PressKey.Key == ConsoleKey.D4)
{
return;
}
Console.Read();
}
}
}
}
**/鏈接鍵與循環? C#
您好。我做了這個noob遊戲,你按下一個鍵來獲得不同的菜單和一組方向。問題是,一旦我按了一個鍵並轉到那個特定的方法,我就不能回去了。我希望PressedKey保持循環,這樣我就可以按下鍵進入程序的不同部分。我希望我解釋得很好。
例如:我按下按鍵I.按鍵我轉到一組方向。我需要回退到主菜單。退格不起作用。我如何使這些ConsoleKeys工作?
PS:我試過同時,if語句,做一段時間,而(真)。
下面是如果有人想嘗試一下它的類: http://pastebin.com/GivANrwC 命名類Data.cs.
謝謝。
驚喜!我從來沒有想過這件事。我一直認爲你需要Console.Read();最後。現在我知道更好。你解釋過,所以像我這樣的菜鳥能理解。 – Sarah