コード例 #1
0
        public static CommandKey Merge(CommandKey k1, CommandKey k2)
        {
            CommandKey result;

            if (k1.Code == "4" && k2.Code == "2" || k1.Code == "2" && k2.Code == "4")
            {
                result = Commands.D1;
            }
            else if (k1.Code == "6" && k2.Code == "2" || k1.Code == "2" && k2.Code == "6")
            {
                result = Commands.D3;
            }
            else if (k1.Code == "6" && k2.Code == "8" || k1.Code == "8" && k2.Code == "6")
            {
                result = Commands.D9;
            }
            else if (k1.Code == "4" && k2.Code == "8" || k1.Code == "8" && k2.Code == "4")
            {
                result = Commands.D7;
            }
            else
            {
                result = Commands.DEFAULT;
            }
            return(result);
        }
コード例 #2
0
        public static string Down(CommandKey key)
        {
            var elapsedTime = stopwatch.ElapsedMilliseconds;

            //debugStopwatch.Restart();
            if (elapsedTime > 500)
            {
                keyBuffer.Clear();
            }

            if (keyBuffer.Count() == 0)
            {
                keyBuffer.Add(key);
            }
            else
            {
                var waitKey = new CommandKey("WT");
                waitKey.SetWaitMillis(elapsedTime);

                if ((int)waitKey.WaitFrame <= 1)
                {
                    var lastKey = keyBuffer.Last();

                    if (lastKey.IsMoveKey() && key.IsMoveKey())
                    {
                        if (Commands.CanMerge(lastKey, key))
                        {
                            keyBuffer.RemoveAt(keyBuffer.Count() - 1);
                            keyBuffer.Add(Commands.Merge(lastKey, key));
                        }
                        else
                        {
                            keyBuffer.Add(key);
                        }
                    }
                    else
                    {
                        //keyBuffer.Add(Commands.PLUS);
                        keyBuffer.Add(waitKey);
                        keyBuffer.Add(key);
                    }
                }
                else
                {
                    keyBuffer.Add(waitKey);
                    keyBuffer.Add(key);
                }
            }

            var log = string.Join("", keyBuffer);

            stopwatch.Restart();

            //Console.WriteLine(string.Join("", keyBuffer));

            //debugStopwatch.Stop();
            //Console.WriteLine(debugStopwatch.ElapsedMilliseconds);
            return(log);
        }
コード例 #3
0
        public static CommandKey Find(Key key)
        {
            CommandKey commandKey = Commands.DEFAULT;

            switch (key.ToString())
            {
            case "W":
                commandKey = Commands.D8;
                break;

            case "A":
                commandKey = Commands.D4;
                break;

            case "S":
                commandKey = Commands.D2;
                break;

            case "D":
                commandKey = Commands.D6;
                break;

            case "G":
                commandKey = Commands.LP;
                break;

            case "H":
                commandKey = Commands.MP;
                break;

            case "J":
                commandKey = Commands.HP;
                break;

            case "B":
                commandKey = Commands.LK;
                break;

            case "N":
                commandKey = Commands.MK;
                break;

            case "M":
                commandKey = Commands.HK;
                break;

            default:
                break;
            }

            return(commandKey);
        }
コード例 #4
0
        public static List <CommandKey> CreateCommandKeys(string line)
        {
            var commandKeyList = new List <CommandKey>();
            var commandSplit   = splitPattern.Split(line.Trim()).Where(str => str.Length > 0);

            foreach (var s in commandSplit)
            {
                var m = waitPattern.Match(s);
                if (m.Success)
                {
                    var    waitKey = new CommandKey("WT");
                    int    waitNum = int.Parse(m.Groups[1].Value);
                    string degree  = m.Groups[2].Value.ToUpper();

                    if (degree.Equals("F"))
                    {
                        waitKey.SetWaitFrame(waitNum);
                    }
                    else
                    {
                        waitKey.SetWaitMillis(waitNum);
                    }
                    commandKeyList.Add(waitKey);
                }
                else
                {
                    var chars  = s.ToCharArray();
                    var inputs = new StringBuilder();

                    for (int i = 0; i < s.Length; i++)
                    {
                        if (Commands.GetAvailableChars().Contains(chars[i]))
                        {
                            inputs.Append(chars[i]);

                            var chain = inputs.ToString();
                            if (Commands.GetDefinedKeyCodes().Contains(chain))
                            {
                                commandKeyList.Add(Commands.Find(chain));
                                inputs.Clear();
                            }
                        }
                    }
                }
            }
            return(commandKeyList);
        }
コード例 #5
0
 public Command With(CommandKey key)
 {
     keys.Add(key);
     return(this);
 }
コード例 #6
0
 public void Add(CommandKey key)
 {
     keys.Add(key);
 }
コード例 #7
0
 public static bool CanMerge(CommandKey k1, CommandKey k2)
 {
     return((k1.Code == "4" && k2.Code == "2" || k1.Code == "2" && k2.Code == "4") || (k1.Code == "6" && k2.Code == "2" || k1.Code == "2" && k2.Code == "6") || (k1.Code == "6" && k2.Code == "8" || k1.Code == "8" && k2.Code == "6") || (k1.Code == "4" && k2.Code == "8" || k1.Code == "8" && k2.Code == "4"));
 }