예제 #1
0
파일: DiceAI.cs 프로젝트: Dolany/DolanyAI
        private static DiceModel ParseDice(string msg)
        {
            var model = new DiceModel();

            if (msg.Contains("+"))
            {
                msg = CheckModify(msg, model);
            }

            return(!msg.Contains("d") ? null : CheckD(msg, model));
        }
예제 #2
0
파일: DiceAI.cs 프로젝트: Dolany/DolanyAI
        private static DiceResultModel ConsoleDice(DiceModel model)
        {
            var result = new DiceResultModel
            {
                Modify = model.Modify,
                Result = new List <int>()
            };

            for (var i = 0; i < model.Count; i++)
            {
                var value = Rander.RandInt(model.Size) + 1;
                result.Result.Add(value);
            }

            return(result);
        }
예제 #3
0
파일: DiceAI.cs 프로젝트: Dolany/DolanyAI
        private static string CheckModify(string msg, DiceModel model)
        {
            if (msg.Count(p => p == '+') > 1)
            {
                return(msg);
            }

            var strs1 = msg.Split(new[] { '+' }, StringSplitOptions.RemoveEmptyEntries);

            if (strs1.Length != 2)
            {
                return(msg);
            }

            if (!int.TryParse(strs1[1], out var modify) || modify <= 0)
            {
                return(msg);
            }
            model.Modify = modify;
            return(strs1[0]);
        }
예제 #4
0
파일: DiceAI.cs 프로젝트: Dolany/DolanyAI
        private static DiceModel CheckD(string msg, DiceModel model)
        {
            if (msg.Count(p => p == 'd') > 1)
            {
                return(null);
            }

            var strs = msg.Split(new[] { 'd' }, StringSplitOptions.RemoveEmptyEntries);

            if (strs.Length != 1 && strs.Length != 2)
            {
                return(null);
            }

            if (strs.Length == 1)
            {
                if (!int.TryParse(strs[0], out var size) || size <= 0)
                {
                    return(null);
                }
                model.Size  = size;
                model.Count = 1;

                return(model);
            }
            else
            {
                if (!int.TryParse(strs[0], out var count) ||
                    !int.TryParse(strs[1], out var size) ||
                    count <= 0 ||
                    size <= 0)
                {
                    return(null);
                }
                model.Size  = size;
                model.Count = count;

                return(model);
            }
        }