コード例 #1
0
    private void CheckSides(Vector2Int position, Vector2Int heading, Vector2Int rightDir, ref int side, int frontFree, int sizeX, int sizeY)
    {
        Vector2Int testDir       = Vector2Int.zero;
        SquareData dataAtTest    = SquareData.NULL;
        int        checkDistance = side;
        bool       done          = false;

        while (!done)
        {
            checkDistance++;
            for (int i = 1; i <= frontFree; i++)
            {
                testDir = position + checkDistance * rightDir + i * heading;
                if ((testDir.x < 0) || (testDir.y < 0) || (testDir.x >= sizeX) || (testDir.y >= sizeY))
                {
                    side = checkDistance - 1;
                    done = true;
                    break;
                }
                else
                {
                    dataAtTest = map.GetMapData(testDir.x, testDir.y);
                }
                if ((dataAtTest != SquareData.CLOSED) && (dataAtTest != SquareData.NJ_CLOSED))
                {
                    side = checkDistance - 1;
                    done = true;
                    break;
                }
            }
        }
    }
コード例 #2
0
ファイル: ArenaManager.cs プロジェクト: bpinzone/SnakeV2
 public void catchUp()
 {
     // Go through every square data and send claims/frees/foods...
     for (int colsDone = 0; colsDone < width; ++colsDone)
     {
         for (int rowsDone = 0; rowsDone < height; ++rowsDone)
         {
             SquareData sd = squareData[colsDone, rowsDone];
             if (sd.state == SquareManager.OPEN)
             {
                 continue;
             }
             // Debug.Log("Catching up...");
             if (sd.state >= 0)
             {
                 Color c = players[sd.state].GetComponent <PlayerManager>().myColor;
                 Rpc_ReceiveClaim(sd.state, c, colsDone, rowsDone, sd.lastCommandID);
             }
             else if (sd.state == SquareManager.FOOD)
             {
                 Rpc_ReceiveFood(colsDone, rowsDone, sd.lastCommandID);
             }
         }
     }
 }
コード例 #3
0
 public RectFill(int _startX, int _startY, int _endX, int _endY, SquareData _type)
 {
     startX = _startX;
     startY = _startY;
     endX   = _endX;
     endY   = _endY;
     type   = _type;
 }
コード例 #4
0
ファイル: ArenaManager.cs プロジェクト: bpinzone/SnakeV2
    // ==== LOW LEVEL LOCAL METHODS ====
    private void setupBoard()
    {
        //set up all object container.
        all = new GameObject("All Squares");
        all.transform.position = Vector2.zero;

        //set up row managers.
        cols = new GameObject[width];
        for (int colsDone = 0; colsDone < width; ++colsDone)
        {
            cols[colsDone] = new GameObject("Col" + colsDone.ToString());
            cols[colsDone].transform.SetParent(all.transform);
            cols[colsDone].transform.position = Vector2.zero;
        }

        //set up individuals
        squareData = new SquareData[width, height];
        for (int colsDone = 0; colsDone < width; ++colsDone)
        {
            for (int rowsDone = 0; rowsDone < height; ++rowsDone)
            {
                // Debug.Log("Setting up tile");
                //create with a parent.
                GameObject currObject = Instantiate(squarePrefab, cols[colsDone].transform) as GameObject;
                //position.
                currObject.transform.position = new Vector2(colsDone, rowsDone);

                //rename
                currObject.name = "c" + colsDone.ToString() + "r" + rowsDone;

                // Init server data
                squareData[colsDone, rowsDone] = new SquareData();
                SquareData currSD = squareData[colsDone, rowsDone];
                currSD.square        = currObject;
                currSD.lastCommandID = -1;

                //state
                currObject.GetComponent <SquareManager>().initOpen();
                currSD.state = SquareManager.OPEN;

                //init server data
                //border colors
                if (colsDone == 0 || colsDone == width - 1 ||
                    rowsDone == 0 || rowsDone == height - 1)
                {
                    // state
                    currObject.GetComponent <SquareManager>().initWall();
                    currSD.state = SquareManager.WALL;
                }
            }
        }
        // Back in setup board base.
        finishedSetup = true;
    }
コード例 #5
0
ファイル: GridBoard.cs プロジェクト: rakansu/ThePathfinder
 private void ProcessDrawingPoint(TileView tilePoint, TileView newTile, SquareData data)
 {
     if (tilePoint != null)
     {
         tilePoint.GetSquare().SetData(SquareData.Empty);
     }
     newTile.GetSquare().SetData(data);
     onUpdateTile?.Invoke(tilePoint);
     onUpdateTile?.Invoke(newTile);
     current_drawstate = DrawState.None;
 }
コード例 #6
0
ファイル: MainWindow.xaml.cs プロジェクト: KScl/FortuneAvenue
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            var board = ((BoardFile)this.DataContext);

            if (board == null)
            {
                return;
            }

            board.BoardData.Squares.Add(SquareData.LoadDefault((byte)board.BoardData.Squares.Count));
        }
コード例 #7
0
    public void Save(List <Square> _squareList, Vector2Int _mapSize)
    {
        squaresList = new List <SquareData>();
        mapSize     = _mapSize;

        foreach (Square s in _squareList)
        {
            SquareData data = new SquareData();
            data.Type = s.SquareType;
            data.Team = s.Team;

            squaresList.Add(data);
        }
    }
コード例 #8
0
    private void CheckSides(Vector2Int position, Vector2Int heading, Vector2Int rightDir, ref int side, int frontFree, int sizeX, int sizeY, int factor)
    {
        Vector2Int testDir       = Vector2Int.zero;
        SquareData dataAtTest    = SquareData.NULL;
        int        checkDistance = side;
        bool       done          = false;

        while (!done)
        {
            checkDistance++;
            for (int i = 1; i <= frontFree; i++)
            {
                testDir = position + (checkDistance * factor) * rightDir + i * heading;
                if ((testDir.x < 0) || (testDir.y < 0) || (testDir.x >= sizeX) || (testDir.y >= sizeY))
                {
                    side = checkDistance - 1;
                    done = true;
                    break;
                }
                else
                {
                    dataAtTest = map.GetMapData(testDir.x, testDir.y);
                }
                if (map.CrawlersInTunnels && map.CrawlersInAnterooms)
                {
                    if ((dataAtTest != SquareData.OPEN) && (dataAtTest != SquareData.NJ_OPEN) && (dataAtTest != SquareData.G_OPEN) && (dataAtTest != SquareData.IT_OPEN) && (dataAtTest != SquareData.IA_OPEN) && (dataAtTest != SquareData.NJ_G_OPEN))
                    {
                        side = checkDistance - 1;
                        done = true;
                        break;
                    }
                }
                else if (map.CrawlersInTunnels)
                {
                    if ((dataAtTest != SquareData.OPEN) && (dataAtTest != SquareData.NJ_OPEN) && (dataAtTest != SquareData.G_OPEN) && (dataAtTest != SquareData.IT_OPEN) && (dataAtTest != SquareData.NJ_G_OPEN))
                    {
                        side = checkDistance - 1;
                        done = true;
                        break;
                    }
                }
                else if ((dataAtTest != SquareData.OPEN) && (dataAtTest != SquareData.NJ_OPEN) && (dataAtTest != SquareData.G_OPEN) && (dataAtTest != SquareData.NJ_G_OPEN))
                {
                    side = checkDistance - 1;
                    done = true;
                    break;
                }
            }
        }
    }
コード例 #9
0
        public SquareInformation(int fieldWidth, int fieldHeight)
        {
            FieldWidth      = fieldWidth;
            FieldHeight     = fieldHeight;
            PushbackSquares = new List <Types.PushbackSquare>();
            TrackNumbers    = new List <Types.TrackNumber>();
            MoveSquares     = new List <Types.MoveSquare>();

            squareData = new SquareData[FieldWidth * FieldHeight];

            for (int i = 0; i < squareData.Length; i++)
            {
                squareData[i] = new SquareData();
            }
        }
コード例 #10
0
 private void InitSquareData()
 {
     _squareDataList = new List <SquareData>();
     for (int i = 0; i < SudokuUtility.PUZZLE_LENGTH; i++)
     {
         SquareData squareData = new SquareData();
         squareData.Index        = i;
         squareData.SlotDataList = new List <SlotData>();
         int squareStartIndex = (i % SudokuUtility.SQUARE_LENGTH) * SudokuUtility.SQUARE_LENGTH + (i / SudokuUtility.SQUARE_LENGTH) * SudokuUtility.PUZZLE_LENGTH * SudokuUtility.SQUARE_LENGTH;             // 該九宮格的起始點(左上)的 Slot 的 Index, 用 0 ~ 80 表示
         for (int j = 0; j < SudokuUtility.PUZZLE_LENGTH; j++)
         {
             int slotIndex = squareStartIndex + (j % SudokuUtility.SQUARE_LENGTH) + ((j / SudokuUtility.SQUARE_LENGTH) * SudokuUtility.PUZZLE_LENGTH);                 // 該九宮格的目標點位置, 用 0 ~ 80 表示
             squareData.SlotDataList.Add(_slotDataList[slotIndex]);
         }
         _squareDataList.Add(squareData);
     }
 }
コード例 #11
0
        public static SquareState MapSquareDataToSquareState(SquareData squareData)
        {
            var squareState = SquareState.Covered;

            if (squareData.IsUncovered)
            {
                if (squareData.IsMine)
                {
                    squareState = SquareState.Exploded;
                }
                else
                {
                    squareState = (squareData.NumNeighouringMines == 0)
                        ? SquareState.UncoveredWithNoSurroundingMines
                        : SquareState.UncoveredWithSurroundingMines;
                }
            }
            else if (squareData.IsFlagged)
            {
                squareState = SquareState.Flagged;
            }

            return(squareState);
        }
コード例 #12
0
        public static SquareViewModel MapSquareDataToSquareViewModel(SquareData squareData, Coords coords)
        {
            var squareState = MapSquareDataToSquareState(squareData);

            return(new SquareViewModel(squareState, coords, squareData.NumNeighouringMines ?? -1, squareData.IsMine));
        }
コード例 #13
0
ファイル: Square.cs プロジェクト: rakansu/ThePathfinder
 public void SetData(SquareData data) => this.data = data;
コード例 #14
0
    public int FrontFree(Vector2Int position, Vector2Int heading, ref int leftFree, ref int rightFree)
    {
        Debug.Assert((leftFree >= 1) && (rightFree >= 1));
        int sizeX = map.SizeX;
        int sizeY = map.SizeY;

        Debug.Assert((position.x >= 0) && (position.y >= 0) && (position.x < sizeX) && (position.y < sizeY));
        int        frontFree = -1;
        Vector2Int rightDir  = Vector2Int.zero;
        Vector2Int testDir;

        if (heading.x == 0)
        {
            rightDir = new Vector2Int(heading.y, 0);
        }
        else if (heading.y == 0)
        {
            rightDir = new Vector2Int(0, -heading.x);
        }
        else
        {
            Debug.Assert(false);
        }
        int        checkDistance = 0;
        SquareData dataAtTest    = SquareData.NULL;

        while (frontFree == -1)
        {
            checkDistance++;
            for (int i = -leftFree; i <= rightFree; ++i)
            {
                testDir = position + i * rightDir + checkDistance * heading;
                if ((testDir.x < 0) || (testDir.y < 0) || (testDir.x >= sizeX) || (testDir.y >= sizeY))
                {
                    frontFree = checkDistance - 1;
                    break;
                }
                else
                {
                    dataAtTest = map.GetMapData(testDir.x, testDir.y);
                }
                if (map.CrawlersInTunnels && map.CrawlersInAnterooms)
                {
                    if (((i == 0) && (dataAtTest != SquareData.OPEN) && (dataAtTest != SquareData.NJ_OPEN) && (dataAtTest != SquareData.IT_OPEN) && (dataAtTest != SquareData.IA_OPEN)) || //we are blocked
                        ((dataAtTest != SquareData.OPEN) && (dataAtTest != SquareData.NJ_OPEN) && (dataAtTest != SquareData.IT_OPEN) && (dataAtTest != SquareData.IA_OPEN) && (dataAtTest != SquareData.G_OPEN) && (dataAtTest != SquareData.NJ_G_OPEN)))
                    {
                        frontFree = checkDistance - 1;
                        break;
                    }
                }
                else if (map.CrawlersInTunnels)
                {
                    if (((i == 0) && (dataAtTest != SquareData.OPEN) && (dataAtTest != SquareData.NJ_OPEN) && (dataAtTest != SquareData.IT_OPEN)) || //we are blocked
                        ((dataAtTest != SquareData.OPEN) && (dataAtTest != SquareData.NJ_OPEN) && (dataAtTest != SquareData.IT_OPEN) && (dataAtTest != SquareData.G_OPEN) && (dataAtTest != SquareData.NJ_G_OPEN)))
                    {
                        frontFree = checkDistance - 1;
                        break;
                    }
                }
                else
                {
                    if (((i == 0) && (dataAtTest != SquareData.OPEN) && (dataAtTest != SquareData.NJ_OPEN)) || //we are blocked
                        ((dataAtTest != SquareData.OPEN) && (dataAtTest != SquareData.NJ_OPEN) && (dataAtTest != SquareData.G_OPEN) && (dataAtTest != SquareData.NJ_G_OPEN)))
                    {
                        frontFree = checkDistance - 1;
                        break;
                    }
                }
            }
        }
        Debug.Assert(frontFree >= 0);

        if (frontFree > 0)
        {
            CheckSides(position, heading, rightDir, ref leftFree, frontFree, sizeX, sizeY, -1);
            CheckSides(position, heading, rightDir, ref rightFree, frontFree, sizeX, sizeY, 1);
        }

        return(frontFree);
    }
コード例 #15
0
    private bool Join(int frontFree)
    {
        Vector2Int right = Vector2Int.zero;
        Vector2Int test  = Vector2Int.zero;

        if (forward.x == 0)
        {
            right = new Vector2Int(forward.y, 0);
        }
        else if (forward.y == 0)
        {
            right = new Vector2Int(0, -forward.x);
        }
        else
        {
            Debug.Assert(false);
        }

        test = location + (frontFree + 1) * forward;
        if (test.x < 0 || test.y < 0 || test.x > map.SizeX || test.y > map.SizeY)
        {
            return(false);
        }

        SquareData squareType = map.GetMapData(test);

        if (squareType == SquareData.CLOSED || squareType == SquareData.G_CLOSED)
        {
            for (int i = 1; i <= frontFree; i++)
            {
                test = location + i * forward;
                if (test.x < 0 || test.y < 0 || test.x > map.SizeX || test.y > map.SizeY)
                {
                    return(false);
                }
                map.SetMapData(test, SquareData.NJ_CLOSED);
            }
            return(true);
        }
        else if (squareType == SquareData.NJ_CLOSED || squareType == SquareData.NJ_G_CLOSED)
        {
            return(false);
        }

        Vector2Int wall     = Vector2Int.zero;
        int        sideStep = 0;

        for (int i = 0; i <= corridorWidth; ++i)
        {
            test = location + (i * right) + (frontFree + 1) * forward;
            if (test.x < 0 || test.y < 0 || test.x > map.SizeX || test.y > map.SizeY)
            {
                return(false);
            }
            squareType = map.GetMapData(test);
            if (squareType == SquareData.CLOSED || squareType == SquareData.G_CLOSED || squareType == SquareData.NJ_CLOSED || squareType == SquareData.NJ_G_CLOSED)
            {
                wall     = test;
                sideStep = i;
                break;
            }

            test = location - (i * right) + (frontFree + 1) * forward;
            if (test.x < 0 || test.y < 0 || test.x > map.SizeX || test.y > map.SizeY)
            {
                return(false);
            }
            squareType = map.GetMapData(test);
            if (squareType == SquareData.CLOSED || squareType == SquareData.G_CLOSED || squareType == SquareData.NJ_CLOSED || squareType == SquareData.NJ_G_CLOSED)
            {
                wall     = test;
                sideStep = -i;
                break;
            }
        }

        /*
         * if (wall.x != 0 || wall.y != 0)
         *  return false;
         * if (sideStep != 0)
         *  return false;*/
        if (squareType == SquareData.NJ_CLOSED || squareType == SquareData.NJ_G_CLOSED)
        {
            return(false);
        }

        int absSidestep = Mathf.Abs(sideStep);
        int factorSidestep;

        if (sideStep < 0)
        {
            test           = right;
            factorSidestep = -1;
        }
        else
        {
            test           = -right;
            factorSidestep = 1;
        }

        int leftF  = 1;
        int rightF = 1;
        int free   = FrontFree(wall, test, ref leftF, ref rightF);

        if (free < absSidestep + 1)
        {
            return(false);
        }

        for (int i = 1; i <= frontFree + 1; ++i)
        {
            test = location + i * forward;
            if (test.x < 0 || test.y < 0 || test.x > map.SizeX || test.y > map.SizeY)
            {
                return(false);
            }
            map.SetMapData(test, SquareData.NJ_CLOSED);
        }

        for (int i = 1; i < absSidestep; ++i)
        {
            test = location + (i * factorSidestep) * right + (frontFree + 1) * forward;
            if (test.x < 0 || test.y < 0 || test.x > map.SizeX || test.y > map.SizeY)
            {
                return(false);
            }
            map.SetMapData(test, SquareData.NJ_CLOSED);
        }
        return(true);
    }
コード例 #16
0
    public int FrontFree(Vector2Int position, Vector2Int heading, ref int leftFree, ref int rightFree)
    {
        Debug.Assert(leftFree >= 1 && rightFree >= 1);

        int dX = map.SizeX;
        int dY = map.SizeY;

        Debug.Assert((position.x >= 0 && position.y >= 0) && (position.x < dX && position.y <= dY));

        Debug.Assert(((heading.x == 0) && (heading.y == -1 || heading.y == 1)) ||
                     ((heading.y == 0) && (heading.x == -1 || heading.x == 1)));

        int frontFree = -1;

        Vector2Int right = Vector2Int.zero;
        Vector2Int left  = Vector2Int.zero;
        Vector2Int test  = Vector2Int.zero;

        if (heading.x == 0)
        {
            right = new Vector2Int(heading.y, 0);
        }
        else if (heading.y == 0)
        {
            right = new Vector2Int(0, -heading.x);
        }

        left = -right;

        int        checkDistance = 0;
        SquareData dataAtTest    = SquareData.NULL;

        while (frontFree == -1)
        {
            checkDistance++;
            for (int i = -leftFree; i <= rightFree; ++i)
            {
                test = position + i * right + checkDistance * heading;
                if (test.x < 0 || test.y < 0 || test.x >= dX || test.y >= dY)
                {
                    frontFree = checkDistance - 1;
                    break;
                }
                else
                {
                    dataAtTest = map.GetMapData(test);
                }
                if (dataAtTest != SquareData.CLOSED && dataAtTest != SquareData.NJ_CLOSED)
                {
                    frontFree = checkDistance - 1;
                    break;
                }
            }
        }
        Debug.Assert(frontFree >= 0);

        if (frontFree > 0)
        {
            CheckSides(position, heading, left, ref leftFree, frontFree, dX, dY);
            CheckSides(position, heading, right, ref rightFree, frontFree, dX, dY);
        }
        return(frontFree);
    }
コード例 #17
0
 SpawnInfo(int x = 0, int y = 0, SquareData t = SquareData.NULL)
 {
     xCoord = x;
     yCoord = y;
     type   = t;
 }
コード例 #18
0
 public void SetSquare(ref SquareInfo rhs)
 {
     xCoord = rhs.xCoord;
     yCoord = rhs.yCoord;
     type   = rhs.type;
 }
コード例 #19
0
 public SquareInfo(ref SquareInfo data)
 {
     xCoord = data.xCoord;
     yCoord = data.yCoord;
     type   = data.type;
 }
コード例 #20
0
 public SquareInfo(int x, int y, SquareData _type)
 {
     xCoord = x;
     yCoord = y;
     type   = _type;
 }