コード例 #1
0
        public int Step(string token, Maze.Direction direction)
        {
            var pro = _context.MazeProcesses.FirstOrDefault(p => string.Equals(p.Token, token));

            if (pro == null)
            {
                return(Maze.Map[0][0]);
            }
            else
            {
                Maze.Edges edges = (Maze.Edges)Maze.Map[pro.x][pro.y];
                switch (direction)
                {
                case Maze.Direction.UP:
                    if (!edges.HasFlag(Maze.Edges.UP))
                    {
                        pro.y = pro.y + 1;
                    }
                    break;

                case Maze.Direction.DOWN:
                    if (!edges.HasFlag(Maze.Edges.DOWN))
                    {
                        pro.y = pro.y - 1;
                    }
                    break;

                case Maze.Direction.LEFT:
                    if (!edges.HasFlag(Maze.Edges.LEFT))
                    {
                        pro.x = pro.x - 1;
                    }
                    break;

                case Maze.Direction.RIGHT:
                    if (!edges.HasFlag(Maze.Edges.RIGHT))
                    {
                        pro.x = pro.x + 1;
                    }
                    break;

                default:
                    break;
                }
                _context.SaveChanges();
                return(Maze.Map[pro.x][pro.y]);
            }
        }
コード例 #2
0
        public IActionResult MazeStep(string drc)
        {
            if (!_levelProcessRepository.CheckAuthority(Request.Cookies["token"], 10) ||
                (drc != "n" && drc != "s" && drc != "w" && drc != "e"))
            {
                return(new JsonResult(new { status = "Fail" }));
            }

            Maze.Direction direction = Maze.Direction.Unknown;
            switch (drc)
            {
            case "n": direction = Maze.Direction.UP; break;

            case "s": direction = Maze.Direction.DOWN; break;

            case "w": direction = Maze.Direction.LEFT; break;

            case "e": direction = Maze.Direction.RIGHT; break;
            }

            Maze.Edges edges = (Maze.Edges)_mazeProcessRepository.GetCurState(Request.Cookies["token"]).walls;

            if (direction.HasFlag(Maze.Direction.Unknown) || edges.HasFlag((Maze.Edges)(int) direction))
            {
                return(new JsonResult(new { status = "Fail" }));
            }

            int newedges = _mazeProcessRepository.Step(Request.Cookies["token"], direction);

            return(new JsonResult(new { status = "Success", newedges }));
        }