示例#1
0
    bool FindPenteWin(BoardSpace[,] grid, int startRow, int startCol, BoardSpace.eSpaceState value, int matchAmount)
    {
        // <-> Horizontal <->
        if (FindLinearMatch(grid, startRow, startCol, value, 0, 1, matchAmount))
        {
            return(true);
        }
        //  | Vertical |
        if (FindLinearMatch(grid, startRow, startCol, value, 1, 0, matchAmount))
        {
            return(true);
        }
        //  / Diagnol-up /
        if (FindLinearMatch(grid, startRow, startCol, value, -1, 1, matchAmount))
        {
            return(true);
        }
        //  \ Diagnol-down \
        if (FindLinearMatch(grid, startRow, startCol, value, 1, 1, matchAmount))
        {
            return(true);
        }

        return(false);
    }
示例#2
0
    private GameBoard(GameBoard other)
    {
        this.board = new BoardSpace[GRIDSIZE, GRIDSIZE];
        bool faceup;

        for (int y = 0; y < GRIDSIZE; y++)
        {
            for (int x = 0; x < GRIDSIZE; x++)
            {
                faceup      = (x + y) % 2 == 0;
                board[x, y] = new BoardSpace(x, y, faceup);
                if (other.board[x, y].getCard() != null)
                {
                    board[x, y].setCard(other.board[x, y].getCard().CopyCard());
                }
            }
        }
        int max = GRIDSIZE;

        player1KnownCards = new bool[max][];
        player2KnownCards = new bool[max][];

        for (int x = 0; x < max; x++)
        {
            player1KnownCards[x] = new bool[max];
            player2KnownCards[x] = new bool[max];
            for (int y = 0; y < max; y++)
            {
                player1KnownCards[x][y] = other.player1KnownCards[x][y];
                player2KnownCards[x][y] = other.player2KnownCards[x][y];
            }
        }
    }
示例#3
0
        public void CreateGameBoard()
        {
            int numChildren = gameObject.transform.childCount;

            for (int i = 0; i < numChildren; i++)
            {
                Destroy(gameObject.transform.GetChild(i).gameObject);
            }

            _spaceGameObjects = new BoardSpace[_board.Size, _board.Size];

            for (int i = 0; i < _board.Size; i++)
            {
                for (int j = 0; j < _board.Size; j++)
                {
                    float x = j - (float)_board.Size / 2;
                    float y = (float)_board.Size / 2 - i;

                    //create a board space at x, y

                    _spaceGameObjects[i, j] = Instantiate(boardSpacePrefab,
                                                          transform.localToWorldMatrix * (transform.localPosition + new Vector3(x, y, 0)),
                                                          transform.rotation * Quaternion.Euler(0, 180, 0), transform);

                    _spaceGameObjects[i, j].Coordinates = new Vector2Int(i, j);
                }
            }

            _boardBounds = Vector2.one * ((float)_board.Size / 2);
        }
示例#4
0
 private void ChangeBoardSizeInLevelHelper(int size, int prevSize)
 {
     BoardSpace[,] newBoard = new BoardSpace[size, size];
     if (size == 6)
     {
         /*for (int i = 0; i < prevSize; i++){
          *  for (int j = 0; j < prevSize; j++){
          *      board[i,j].gameObject.layer = LayerMask.NameToLayer("Default");
          *  }
          * }*/
         for (int c = 0; c < size; ++c)
         {
             for (int r = 0; r < size; ++r)
             {
                 if (IsEdge(c, size) || IsEdge(r, size))
                 {
                     int spaceColor;
                     if ((c + r) % 2 == 0)
                     {
                         spaceColor = 1;
                     }
                     else
                     {
                         spaceColor = 2;
                     }
                     CreateBoardSpace(c, r, spaceColor, newBoard);
                 }
                 else
                 {
                     newBoard[c, r] = board[c - 1, r - 1];
                 }
             }
         }
     }
     else if (size == 4)
     {
         for (int c = 0; c < prevSize; ++c)
         {
             for (int r = 0; r < prevSize; ++r)
             {
                 if (IsEdge(c, prevSize) || IsEdge(r, prevSize))
                 {
                     for (int t = 0; t < board[c, r].tileStack.Count; ++t)
                     {
                         Object.Destroy(board[c, r].tileStack[t].gameObject);
                     }
                     Object.Destroy(board[c, r].gameObject);
                 }
                 else
                 {
                     newBoard[c - 1, r - 1] = board[c, r];
                 }
             }
         }
     }
     board = newBoard;
 }
示例#5
0
 private void MakeBoardSpaces(BoardData bd)
 {
     spaces = new BoardSpace[NumCols, NumRows];
     for (int i = 0; i < NumCols; i++)
     {
         for (int j = 0; j < NumRows; j++)
         {
             spaces[i, j] = new BoardSpace(bd.spaceDatas[i, j]);
         }
     }
 }
示例#6
0
        //sets up a new game with size specified in the textboxes
        private void newGame()
        {
            //clears previous board
            if (this.boardInitialized)
            {
                foreach (BoardSpace bs in board)
                {
                    this.Controls.Remove(bs);
                }
            }

            this.boardInitialized = false;

            //creates new board
            this.boardWidth  = int.Parse(this.textBoxBoardWidth.Text);
            this.boardHeight = int.Parse(this.textBoxBoardHeight.Text);
            this.board       = new BoardSpace[this.boardWidth, this.boardHeight];
            for (int i = 0; i < this.boardWidth; i++)
            {
                for (int j = 0; j < this.boardHeight; j++)
                {
                    this.board[i, j] = new BoardSpace()
                    {
                        x = i, y = j,
                    };
                    this.board[i, j].Click += this.makeMove;
                    this.Controls.Add(this.board[i, j]);
                }
            }

            //creates the first 4 tokens
            this.board[boardWidth / 2 - 1, this.boardHeight / 2 - 1].state = BoardSpace.blue;
            this.board[boardWidth / 2 - 1, this.boardHeight / 2].state     = BoardSpace.red;
            this.board[boardWidth / 2, this.boardHeight / 2 - 1].state     = BoardSpace.red;
            this.board[boardWidth / 2, this.boardHeight / 2].state         = BoardSpace.blue;



            //resets basic variables
            this.score[0]  = 2; this.score[1] = 2;
            this.canUndo   = false;
            this.turn      = 1;
            this.gameState = playerBlue;
            this.checkMoves();



            //displays the new board
            this.updateBoardSize();
            boardInitialized = true;
            this.Invalidate();
        }
示例#7
0
        private void createBoard()
        {
            spaces = new BoardSpace[row_W, row_W];
            int size = 60;

            for (int k = 0; k < row_W; k++)
            {
                for (int i = 0; i < row_W; i++)
                {
                    spaces[k, i] = new BoardSpace(k, i, size, ((i + k) % 2 == 0) ? Sand : Brown, null);
                    mainCanvas.Children.Add(spaces[k, i].getRect());
                }
            }
        }
示例#8
0
        private int m_BlkPieceCount;          // Number of black pieces on the board

        public GameBoard()
            : base()
        {
            // double buffer the game board to prevent the control from flickering on resize
            this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true);

            // go ahead and initialize an 8 by 8 array of board spaces
            m_Spaces = new BoardSpace[8, 8];

            // at the present time, the board is uninitalized and its not valid, the paint event cant interact with it
            m_isValid = false;

            // set the current selection to nothing
            m_sel_col = -1;
            m_sel_row = -1;
        }
示例#9
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="cards"> an Array of 5 cards, in order from top left to bottom right to add to the board</param>
    public GameBoard(ICard[] cards)
    {
        board = new BoardSpace[GRIDSIZE, GRIDSIZE];
        bool faceup;

        for (int y = 0; y < GRIDSIZE; y++)
        {
            for (int x = 0; x < GRIDSIZE; x++)
            {
                faceup      = (x + y) % 2 == 0;
                board[x, y] = new BoardSpace(x, y, faceup);
            }
        }

        int centerpoint = GRIDSIZE / 2;

        board[0, 0].setCard(cards[0]);
        board[0, GRIDSIZE - 1].setCard(cards[1]);
        board[centerpoint, centerpoint].setCard(cards[2]);
        board[GRIDSIZE - 1, 0].setCard(cards[3]);
        board[GRIDSIZE - 1, GRIDSIZE - 1].setCard(cards[4]);


        int max = GRIDSIZE;

        player1KnownCards = new bool[max][];
        player2KnownCards = new bool[max][];
        for (int x = 0; x < max; x++)
        {
            player1KnownCards[x] = new bool[max];
            player2KnownCards[x] = new bool[max];
            for (int y = 0; y < max; y++)
            {
                if (isStartingZone(x, y))
                {
                    player1KnownCards[x][y] = true;
                    player2KnownCards[x][y] = true;
                }
                else
                {
                    player1KnownCards[x][y] = false;
                    player2KnownCards[x][y] = false;
                }
            }
        }
    }
示例#10
0
    // Use this for initialization
    void Start()
    {
        boardSpaces = GameObject.FindGameObjectsWithTag("BoardSpace");

        gameBoard       = new GameObject[MAX_ROW, MAX_COLUMN];
        gameBoardSpaces = new BoardSpace[MAX_ROW, MAX_COLUMN];
        TotalFreeSpaces = 0;
        foreach (GameObject boardSpot in boardSpaces)
        {
            BoardSpace boardSpace = boardSpot.GetComponent <BoardSpace>();
            if (boardSpace.row < MAX_ROW && boardSpace.row >= 0 && boardSpace.column >= 0 && boardSpace.column < MAX_COLUMN)
            {
                int i = boardSpace.row;
                int j = boardSpace.column;

                //set neighbours
                boardSpace.SetTopNeighbours(i - 1, j);
                boardSpace.SetBottomNeighbours(i + 1, j);
                boardSpace.SetLeftNeighbours(i, j - 1);
                boardSpace.SetRightNeighbours(i, j + 1);

                gameBoardSpaces[i, j] = boardSpace;
                gameBoard[i, j]       = boardSpot;
                if (boardSpace.hasFood)
                {
                    TotalFoodAvailable++;
                }
                if (boardSpace.hasPowerUp)
                {
                    TotalPowerUps++;
                }
                if (boardSpace.isSpaceFree)
                {
                    TotalFreeSpaces++;
                }
            }
        }

        //set the initial current position of player on board
        playerCurrentSpace = gameBoard[10, 10].GetComponent <BoardSpace>();
    }
示例#11
0
    private void CreateBoardSpace(int colNum, int rowNum, int color, BoardSpace[,] givenBoard)
    {
        Vector3    location   = new Vector3(colNum - numCols / 2 + 0.5f, 0, rowNum - numRows / 2 + 0.5f);
        GameObject boardSpace = Object.Instantiate(Services.Prefabs.BoardSpace, location, Quaternion.identity) as GameObject;

        boardSpace.transform.SetParent(mainBoard.transform);
        boardSpace.GetComponent <MeshRenderer>().material = Services.Materials.BoardMats[color];

        boardSpace.GetComponent <BoardSpace>().SetBoardSpace(color, colNum, rowNum);

        if (Services.BoardManager.IsCentered(colNum, numCols) && Services.BoardManager.IsCentered(rowNum, numRows))
        {
            boardSpace.GetComponent <BoardSpace>().isCenterSpace = true;
            centerSpaces.Add(boardSpace.GetComponent <BoardSpace>());
        }
        else
        {
            boardSpace.GetComponent <BoardSpace>().isCenterSpace = false;
        }
        boardSpace.layer           = LayerMask.NameToLayer("TopTiles");
        givenBoard[colNum, rowNum] = boardSpace.GetComponent <BoardSpace>();
    }
示例#12
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="cards"> an Array of 5 cards, in order from top left to bottom right to add to the board</param>
    public GameBoard(ICard[] cards)
    {
        board = new BoardSpace[GRIDSIZE, GRIDSIZE];
        bool faceup;

        for (int y = 0; y < GRIDSIZE; y++)
        {
            for (int x = 0; x < GRIDSIZE; x++)
            {
                faceup      = (x + y) % 2 == 0;
                board[x, y] = new BoardSpace(x, y, faceup);
            }
        }

        int centerpoint = GRIDSIZE / 2;

        board[0, 0].setCard(cards[0]);
        board[0, GRIDSIZE - 1].setCard(cards[1]);
        board[centerpoint, centerpoint].setCard(cards[2]);
        board[GRIDSIZE - 1, 0].setCard(cards[3]);
        board[GRIDSIZE - 1, GRIDSIZE - 1].setCard(cards[4]);
    }
示例#13
0
        public Board(Boundaries boundaries, int boardSpaceSize)
        {
            this.boardSpaceSize = boardSpaceSize;
            this.Boundaries     = boundaries;
            var width  = boundaries.Right - boundaries.Left;
            var height = boundaries.Bottom - boundaries.Top;

            var horizontalSpaces = width / boardSpaceSize;
            var verticalSpaces   = height / boardSpaceSize;

            this.BoardSpaces = new BoardSpace[verticalSpaces, horizontalSpaces];

            for (var i = 0; i < horizontalSpaces; i++)
            {
                for (var j = 0; j < verticalSpaces; j++)
                {
                    var position = new Vector2(i * boardSpaceSize, j * boardSpaceSize);
                    this.BoardSpaces[j, i] = new BoardSpace(position, boardSpaceSize, boardSpaceSize);
                }
            }

            Transform = new Transform(boundaries.Left, boundaries.Top, width, height);
        }
示例#14
0
    public void Generate()
    {
        spaces = new BoardSpace[size.x, size.y];
        List <BoardSpace> activeSpaces = new List <BoardSpace>();

        DoFirstGenerationStep(activeSpaces);
        while (activeSpaces.Count > 0)
        {
            DoNextGenerationStep(activeSpaces);
        }

        //Update wall visuals
        for (int y = 0; y < size.y; y++)
        {
            for (int x = 0; x < size.x; x++)
            {
                if (spaces[x, y])
                {
                    spaces[x, y].RefreshWalls();
                }
            }
        }
    }
示例#15
0
    private void CreateBoard()
    {
        centerSpaces = new List <BoardSpace>();

        /*numRows = Services.BoardData.numRows;*/
        if (boardSize == 0)
        {
            numCols = 6;
        }
        else if (boardSize == 1)
        {
            numCols = 4;
        }
        numRows = numCols;
        board   = new BoardSpace[numCols, numRows];
        for (int i = 0; i < numCols; i++)
        {
            for (int j = 0; j < numRows; j++)
            {
                int spaceColor;
                if (Services.BoardManager.IsCentered(i, numCols) && Services.BoardManager.IsCentered(j, numRows))
                {
                    spaceColor = 0;
                }
                else if ((i + j) % 2 == 0)
                {
                    spaceColor = 1;
                }
                else
                {
                    spaceColor = 2;
                }
                CreateBoardSpace(i, j, spaceColor, board);
            }
        }
    }
示例#16
0
 void CreateBoard()
 {
     board = new BoardSpace[numCols, numRows];
     for (int i = 0; i < numCols; i++)
     {
         for (int j = 0; j < numRows; j++)
         {
             int spaceColor;
             if (IsCentered(i, numCols) && IsCentered(j, numRows))
             {
                 spaceColor = 2;
             }
             else if ((i + j) % 2 == 0)
             {
                 spaceColor = 0;
             }
             else
             {
                 spaceColor = 1;
             }
             CreateBoardSpace(i, j, spaceColor);
         }
     }
 }
 public GameBoard()
 {
     _board = new BoardSpace[BOARD_WIDTH, BOARD_HEIGHT];
     _winningSpots = new BoardSpace[4];
 }
示例#18
0
 /// <summary>
 /// Private Constructor
 /// </summary>
 private GameBoard()
 {
     _boardMatrix = new BoardSpace[BoardSpaceDimension, BoardSpaceDimension];
     ClearBoard();
 }
 private void createBoard()
 {
     spaces = new BoardSpace[row_W, row_W];
     int size = 60;
     for (int k = 0; k < row_W; k++)
     {
         for (int i = 0; i < row_W; i++)
         {
             spaces[k, i] = new BoardSpace(k, i, size, ((i + k) % 2 == 0) ? Sand : Brown, null);
             mainCanvas.Children.Add(spaces[k, i].getRect());
         }
     }
 }
示例#20
0
    bool FindLinearMatch(BoardSpace[,] grid, int startRow, int startCol, BoardSpace.eSpaceState value, int rowShift, int colShift, int matchAmount, bool reverse = true)
    {
        //variable to count matching values
        int matchCount = 0;

        int row = startRow;
        int col = startCol;

        //for loop that will run twice, flipping the sign on the second loop
        for (int flip = 1; flip >= -1; flip -= 2)
        {
            for (int i = 0; i <= matchAmount; i++)
            {
                if (flip == -1)
                {
                    //Set i to 1 if its been flipped and not checking the starter piece
                    i = 1;
                }

                //Determine if row or col are out of bounds, break if so
                if (row >= grid.GetLength(0) || row < 0)
                {
                    break;
                }
                if (col >= grid.GetLength(1) || col < 0)
                {
                    break;
                }

                //If piece of grid equals the value passed in, increment count
                if (grid[row, col].state == value)
                {
                    matchCount++;
                }
                else if (i != 0)
                {
                    break;
                }

                // flip: 1 on first loop, -1 on second loop
                row += rowShift * flip;
                col += colShift * flip;
            }

            //IF reverse is false, break out of loop
            if (!reverse)
            {
                break;
            }

            //Restart row and col AND shift so it doesn't count starter piece twice
            row = startRow + (rowShift * flip * -1);
            col = startCol + (colShift * flip * -1);
        }

        if (matchCount == 3)
        {
            Debug.Log("Tria");
        }
        if (matchCount == 4)
        {
            Debug.Log("Tessera");
        }
        return(matchCount >= matchAmount);
    }
示例#21
0
 /// <summary>
 /// Private Constructor
 /// </summary>
 private GameBoard()
 {
     _boardMatrix = new BoardSpace[BoardSpaceDimension, BoardSpaceDimension];
     ClearBoard();
 }