本文整理汇总了C#中ConsoleKey类的典型用法代码示例。如果您正苦于以下问题:C# ConsoleKey类的具体用法?C# ConsoleKey怎么用?C# ConsoleKey使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConsoleKey类属于命名空间,在下文中一共展示了ConsoleKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: KeysPressed
public override void KeysPressed(ConsoleKey _key, EKeyModifiers _modifiers)
{
switch (_key)
{
case ConsoleKey.A:
Constants.WORLD_MAP_SIZE = 32;
Constants.WORLD_SEED = new Random().Next(10000);
//Constants.WORLD_SEED = 2;
m_game.Run();
break;
case ConsoleKey.B:
Constants.WORLD_MAP_SIZE = 100;
Constants.WORLD_SEED = new Random().Next(10000);
m_game.Run();
break;
case ConsoleKey.C:
Constants.WORLD_MAP_SIZE = 1;
Constants.WORLD_SEED = 1;
m_game.Run();
break;
case ConsoleKey.D:
Constants.WORLD_MAP_SIZE = 1;
Constants.WORLD_SEED = 2;
m_game.Run();
break;
case ConsoleKey.E:
Constants.WORLD_MAP_SIZE = 1;
Constants.WORLD_SEED = 0;
m_game.Run();
break;
}
}
示例2: Action
public void Action(ConsoleKey key)
{
Console.Clear();
switch (key)
{
case ConsoleKey.D0:
break;
case ConsoleKey.D1:
break;
case ConsoleKey.D2:
break;
case ConsoleKey.D3:
break;
case ConsoleKey.D4:
break;
case ConsoleKey.D5:
break;
case ConsoleKey.D6:
break;
case ConsoleKey.D7:
break;
case ConsoleKey.D8:
break;
case ConsoleKey.D9:
break;
default:
break;
}
}
示例3: ChangeBoard
public void ChangeBoard(ConsoleKey moveKey)
{
_snake.ChangeDirection(moveKey);
_snake.MoveSnake ();
_snake.CheckForCollision(_apple);
ReplaceApple();
}
示例4: GetCharFromConsoleKey
internal static char GetCharFromConsoleKey(ConsoleKey key, ConsoleModifiers modifiers)
{
// default for unprintables and unhandled
char keyChar = '\u0000';
// emulate GetKeyboardState bitmap - set high order bit for relevant modifier virtual keys
var state = new byte[256];
state[NativeMethods.VK_SHIFT] = (byte)(((modifiers & ConsoleModifiers.Shift) != 0) ? 0x80 : 0);
state[NativeMethods.VK_CONTROL] = (byte)(((modifiers & ConsoleModifiers.Control) != 0) ? 0x80 : 0);
state[NativeMethods.VK_ALT] = (byte)(((modifiers & ConsoleModifiers.Alt) != 0) ? 0x80 : 0);
// a ConsoleKey enum's value is a virtual key code
uint virtualKey = (uint)key;
// get corresponding scan code
uint scanCode = NativeMethods.MapVirtualKey(virtualKey, NativeMethods.MAPVK_VK_TO_VSC);
// get corresponding character - maybe be 0, 1 or 2 in length (diacriticals)
var chars = new char[2];
int charCount = NativeMethods.ToUnicode(
virtualKey, scanCode, state, chars, chars.Length, NativeMethods.MENU_IS_INACTIVE);
// TODO: support diacriticals (charCount == 2)
if (charCount == 1)
{
keyChar = chars[0];
}
return keyChar;
}
示例5: PlayGame
static void PlayGame() {
Dungeon dungeon = new Dungeon();
player.X = dungeon.SpawnPoint[0];
player.Y = dungeon.SpawnPoint[1];
Cell currentRoom;
ConsoleKey key = new ConsoleKey();
do {
IO.CleanConsole();
//Console.WriteLine(player.X + ", " + player.Y);
dungeon.Print(player);
currentRoom = dungeon.Cells[player.X, player.Y];
if (IO.PickUp(key)) {
player.Loot(currentRoom);
}
else {
if (currentRoom.HasItem) {
IO.PlayFoundItem();
currentRoom.Item.WriteFoundItem();
} else {
IO.PadLines(2);
}
}
key = Console.ReadKey().Key;
player.Move(dungeon, key);
} while (player.Health > 0);
}
示例6:
internal ConsoleKeyInfo
(char keyChar, ConsoleKey key, ConsoleModifiers modifiers)
{
this.keyChar = keyChar;
this.key = key;
this.modifiers = modifiers;
}
示例7: Update
public void Update(ConsoleKey key)
{
switch (key)
{
//This is grim. Needs a better method.
case ConsoleKey.W:
this._messenger.AddMessage("Up");
Console.SetCursorPosition(this._player.PosX, this._player.PosY);
this._map.map2[this._player.PosY, this._player.PosX].Draw();
this._player.Move(Direction.Up);
break;
case ConsoleKey.A:
this._messenger.AddMessage("Left");
Console.SetCursorPosition(this._player.PosX, this._player.PosY);
this._map.map2[this._player.PosY, this._player.PosX].Draw();
this._player.Move(Direction.Left);
break;
case ConsoleKey.S:
this._messenger.AddMessage("Down");
Console.SetCursorPosition(this._player.PosX, this._player.PosY);
this._map.map2[this._player.PosY, this._player.PosX].Draw();
this._player.Move(Direction.Down);
break;
case ConsoleKey.D:
this._messenger.AddMessage("Right");
Console.SetCursorPosition(this._player.PosX, this._player.PosY);
this._map.map2[this._player.PosY, this._player.PosX].Draw();
this._player.Move(Direction.Right);
break;
default:
break;
}
}
示例8: GetDirection
public static Point GetDirection(ConsoleKey _key)
{
if (!MoveKeys.Contains(_key))
{
return null;
}
var dx = (_key == ConsoleKey.LeftArrow ? -1 : 0) + (_key == ConsoleKey.RightArrow ? 1 : 0);
var dy = (_key == ConsoleKey.UpArrow ? -1 : 0) + (_key == ConsoleKey.DownArrow ? 1 : 0);
dx += (_key == ConsoleKey.NumPad4 ? -1 : 0) + (_key == ConsoleKey.NumPad6 ? 1 : 0);
dx += (_key == ConsoleKey.NumPad7 ? -1 : 0) + (_key == ConsoleKey.NumPad9 ? 1 : 0);
dx += (_key == ConsoleKey.NumPad1 ? -1 : 0) + (_key == ConsoleKey.NumPad3 ? 1 : 0);
dx += (_key == ConsoleKey.Home ? -1 : 0) + (_key == ConsoleKey.PageUp ? 1 : 0);
dx += (_key == ConsoleKey.End ? -1 : 0) + (_key == ConsoleKey.PageDown ? 1 : 0);
dy += (_key == ConsoleKey.NumPad8 ? -1 : 0) + (_key == ConsoleKey.NumPad2 ? 1 : 0);
dy += (_key == ConsoleKey.NumPad7 ? -1 : 0) + (_key == ConsoleKey.NumPad1 ? 1 : 0);
dy += (_key == ConsoleKey.NumPad9 ? -1 : 0) + (_key == ConsoleKey.NumPad3 ? 1 : 0);
dy += (_key == ConsoleKey.Home ? -1 : 0) + (_key == ConsoleKey.End ? 1 : 0);
dy += (_key == ConsoleKey.PageUp ? -1 : 0) + (_key == ConsoleKey.PageDown ? 1 : 0);
return new Point(dx, dy);
}
示例9: Move
public void Move(ConsoleKey direction)
{
this.Clear();
switch (direction)
{
case ConsoleKey.RightArrow:
case ConsoleKey.D:
if (this.X < Console.WindowWidth - 4)
{
this.X++;
}
break;
case ConsoleKey.LeftArrow:
case ConsoleKey.A:
if (this.X > 0)
{
this.X--;
}
break;
}
this.Print();
}
示例10: Trigger
static void Trigger(ConsoleKey key)
{
if (key == ConsoleKey.X)
HandleX(null, ConsoleKey.X);
if (key == ConsoleKey.Spacebar)
HandleSpace(null, ConsoleKey.Spacebar);
}
示例11: ConsoleKeyInfo
public ConsoleKeyInfo (char keyChar, ConsoleKey key, bool shift, bool alt, bool control)
{
_key = key;
_keyChar = keyChar;
_mods = 0;
SetModifiers (shift, alt, control);
}
示例12: CaptureKeyPressed
static void CaptureKeyPressed(ConsoleKey key)
{
if (key == ConsoleKey.Enter)
{
HandleEnter(null, ConsoleKey.Enter);
}
}
示例13: PushUnmanaged
public Subscription PushUnmanaged(ConsoleKey key, ConsoleModifiers? modifier, Action<ConsoleKeyInfo> handler)
{
Dictionary<ConsoleKey, Stack<Action<ConsoleKeyInfo>>> target;
if (modifier.HasValue == false) target = nakedHandlers;
else if (modifier.Value.HasFlag(ConsoleModifiers.Alt)) target = altHandlers;
else if (modifier.Value.HasFlag(ConsoleModifiers.Shift)) target = shiftHandlers;
else if (modifier.Value.HasFlag(ConsoleModifiers.Control)) target = controlHandlers;
else throw new ArgumentException("Unsupported modifier: "+modifier.Value);
Stack<Action<ConsoleKeyInfo>> targetStack;
if(target.TryGetValue(key, out targetStack) == false)
{
targetStack = new Stack<Action<ConsoleKeyInfo>>();
target.Add(key, targetStack);
}
targetStack.Push(handler);
var sub = new Subscription(() =>
{
targetStack.Pop();
if(targetStack.Count == 0)
{
target.Remove(key);
}
});
return sub;
}
示例14: SpecialInputs
protected override Object SpecialInputs(ConsoleKey cki, EDirection currentDirection, EGameState gameState) {
switch (cki) {
case ConsoleKey.Escape:
if (gameState == EGameState.Running)
return gameState == EGameState.Running ? EGameState.Over : EGameState.Running;
if (gameState == EGameState.Over || gameState == EGameState.Init)
Environment.Exit(0);
break;
case ConsoleKey.Spacebar:
return gameState == EGameState.Running ? EGameState.Paused : EGameState.Running;
case ConsoleKey.Q:
if (gameState == EGameState.Init)
Environment.Exit(0);
if (gameState == EGameState.Over)
StartupManager.Reset();
break;
case ConsoleKey.P:
if (gameState == EGameState.Init)
return EGameState.Running;
break;
}
if (cki == ConsoleKey.UpArrow && currentDirection != EDirection.South)
return EDirection.North;
if (cki == ConsoleKey.RightArrow && currentDirection != EDirection.West)
return EDirection.East;
if (cki == ConsoleKey.DownArrow && currentDirection != EDirection.North)
return EDirection.South;
if (cki == ConsoleKey.LeftArrow && currentDirection != EDirection.East)
return EDirection.West;
return cki;
}
示例15: MenuItem
public MenuItem(Sub method,
string description)
{
this.Method = method;
this.Description = description;
this.Key = ConsoleKey.NoName;
}