Ejemplo n.º 1
0
        //todo change to return whole state
        private List <Line> GetState()
        {
            var state = new BoardStateBase(new List <Line>(), new List <Line>(), type, board);

            for (int i = 0; i < board.GetLength(0); i++)
            {
                for (int j = 0; j < board.GetLength(1); j++)
                {
                    var cell = CellManager.Get(i, j);
                    if (board[i, j] != type || usedCells.Contains(cell))
                    {
                        continue;
                    }
                    var factory = new LineModifier(cell, state, GetBackwardsDirections());
                    factory.AddCellToLines();
                    foreach (var lineCell in state.MyLines.SelectMany(l => l))
                    {
                        usedCells.Add(lineCell);
                    }
                }
            }
            state.MyLines.Sort();
            state.OppLines.Sort();
            return(state.MyLines);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Applies the handlers to all board cells
 /// </summary>
 /// <param name="cellClickHandler"></param>
 /// <param name="cellHoverHandler"></param>
 public void SetHandlers(MouseButtonEventHandler cellClickHandler)
 {
     for (int i = 0; i < boardCells.GetLength(0); i++)
     {
         for (int j = 0; j < boardCells.GetLength(1); j++)
         {
             boardCells[i, j].SetHandlers(cellClickHandler);
         }
     }
 }
Ejemplo n.º 3
0
        internal void InitializeBoard()
        {
            int size = r_GameBoard.GetLength(0);

            for (int row = 0; row < size; row++)
            {
                for (int col = 0; col < size; col++)
                {
                    r_GameBoard[row, col] = new BoardCell();
                }
            }
        }
Ejemplo n.º 4
0
 public static void Export(BoardCell[,] board, string fileName)
 {
     using (var sw = new StreamWriter(fileName))
     {
         for (int x = 0; x < board.GetLength(0); x++)
         {
             for (int y = 0; y < board.GetLength(1); y++)
             {
                 sw.Write(board[x, y].GetCellText());
             }
             sw.WriteLine();
         }
     }
 }
Ejemplo n.º 5
0
 void SetupMap(int xsize, int ysize)
 {
     if (cell_map == null || cell_map.GetLength(0) != xsize || cell_map.GetLength(1) != ysize)
     {
         Clear();
         cell_map = new BoardCell[xsize, ysize];
         for (int i = 0; i < ysize; i++)
         {
             for (int o = 0; o < xsize; o++)
             {
                 //obj
                 GameObject new_obj = Instantiate(cell_prefab, transform.position, Quaternion.identity);
                 new_obj.transform.position = new Vector3(o * 1, i * 1, 0);
                 new_obj.transform.parent   = map_container;
                 //cell
                 BoardCell new_cell = new_obj.GetComponent <BoardCell>();
                 new_cell.coordinates = new Vector2(o, i);
                 cell_map[o, i]       = new_cell;
                 new_obj.SetActive(true);
             }
         }
     }
 }
Ejemplo n.º 6
0
    private void AdjustCameraSizeToBoardSize()
    {
        BoardCell[,] boardCells = GameBoard.Instance.Generator.BoardCells;

        if (boardCells == null || boardCells.Length == 0)
        {
            return;
        }

        float minX = boardCells[0, 0].transform.position.x;
        float maxX = boardCells[boardCells.GetLength(0) - 1, 0].transform.position.x;

        float boardWidth = Mathf.Abs(maxX - minX) + 1.5f;

        camera.orthographicSize = boardWidth * Screen.height / Screen.width * 0.5f;
    }
Ejemplo n.º 7
0
 private bool IsInBoardBounds(int x, int y)
 {
     return(y >= 0 && y < board.GetLength(1) && x >= 0 && x < board.GetLength(0));
 }