コード例 #1
0
 private void executeAction(UsableKeys keyPressed)
 {
     int? num = null;
     if (this.shortcutDictionary.TryGetValue(keyPressed, out num))
     {
         switch (num)
         {
             case 1:
                 attack();
                 break;
             case 2:
                 defend();
                 break;
             case 3:
                 hide();
                 break;
             case 4:
                 dance();
                 break;
             default:
                 Console.WriteLine("Key not bounded");
                 break;
         }
     }
 }
コード例 #2
0
 private void Form1_KeyDown(object sender, KeyEventArgs e)
 {
     UsableKeys keyPressed = (UsableKeys)e.KeyCode;
     if (this.shortcutDictionary.ContainsKey(keyPressed))
     {
         executeAction(keyPressed);
         e.Handled = true;
         e.SuppressKeyPress = true;
     }
     else if (e.KeyCode == Keys.L)
     {
         switch (this.shortcutDictionary[UsableKeys.A])
         {
             case 1:
                 this.shortcutDictionary[UsableKeys.A] = 4;
                 this.shortcutDictionary[UsableKeys.B] = 3;
                 this.shortcutDictionary[UsableKeys.C] = 2;
                 this.shortcutDictionary[UsableKeys.D] = 1;
                 break;
             case null:
                 this.shortcutDictionary[UsableKeys.A] = 1;
                 this.shortcutDictionary[UsableKeys.B] = 2;
                 this.shortcutDictionary[UsableKeys.C] = 3;
                 this.shortcutDictionary[UsableKeys.D] = 4;
                 break;
             case 4:
                 this.shortcutDictionary[UsableKeys.A] = null;
                 this.shortcutDictionary[UsableKeys.B] = null;
                 this.shortcutDictionary[UsableKeys.C] = null;
                 this.shortcutDictionary[UsableKeys.D] = null;
                 break;
         }
         e.Handled = true;
         e.SuppressKeyPress = true;
     }
 }
コード例 #3
0
ファイル: Game.cs プロジェクト: Palid/Simon-Says
 private Key getShinyKey(UsableKeys key)
 {
     var re = Enum.Parse(typeof(Key), key.ToString().ToUpper());
     return (Key)re;
 }