public CellsView(Board i_Board) { r_TempDisabledCells = new List<CellButton>(); r_Cells = new CellButton[i_Board.Lines, i_Board.Cols]; initializeComponent(); initializeCells(i_Board); }
public void ForgetCellThatIsAlreadyVisibleOnBoard(Board.Cell i_Cell) { if (i_Cell != null) { r_AlreadyVisibleCellsOnBoard.Add(new Board.Cell(i_Cell)); removeLetterFromMemory(i_Cell); } }
public static Board CreateNewBoard(int i_Lines, int i_Cols) { var theBoardToBuild = new Board(i_Lines, i_Cols); List<char> alphaBetLetters = createAlphabetList(); shuffle(alphaBetLetters); int numUniqueLettersNeeded = i_Lines * i_Cols / 2; List<char> uniqueLetters = alphaBetLetters.GetRange(0, numUniqueLettersNeeded); uniqueLetters.AddRange(uniqueLetters); shuffle(uniqueLetters); fillBoardMatrixWithLetters(theBoardToBuild, uniqueLetters); return theBoardToBuild; }
public BoardForm(Board i_Board, string i_FirstName, string i_SecondName) { InitializeComponent(); FlowLayoutPanel mainLayout = new FlowLayoutPanel(); mainLayout.FlowDirection = FlowDirection.TopDown; mainLayout.Padding = new Padding(15, 5, 5, 5); mainLayout.AutoSize = true; mainLayout.AutoSizeMode = AutoSizeMode.GrowAndShrink; r_CellsView = new CellsView(i_Board); r_NamesView = new NamesView(i_FirstName, i_SecondName); mainLayout.Controls.AddRange(new Control[] { r_CellsView, r_NamesView }); Controls.Add(mainLayout); AutoSize = true; AutoSizeMode = AutoSizeMode.GrowAndShrink; Padding = new Padding(0, 0, 0, 0); Closed += BoardForm_Closed; }
private void initializeCells(Board i_Board) { const int spacing = 10; int lines = i_Board.Lines; int cols = i_Board.Cols; int startX = Left; int startY = Top; for (int x = 0; x < lines; ++x) { for (int y = 0; y < cols; ++y) { char letter = i_Board.GetCellAt(x, y).Letter; r_Cells[x, y] = new CellButton(x, y, letter); int xPosition = startX + ((spacing + r_Cells[x, y].Width) * x); int yPosition = startY + ((spacing + r_Cells[x, y].Height) * y); r_Cells[x, y].Location = new Point(xPosition, yPosition); r_Cells[x, y].Click += cellButton_Click; Controls.Add(r_Cells[x, y]); } } }
private static void fillBoardMatrixWithLetters(Board io_Board, IList<char> i_UniqueLetters) { int numberOfLines = io_Board.r_NumOfLines; int numberOfCols = io_Board.r_NumOfCols; Cell[,] cellMatrix = io_Board.r_CellsMatrix; int readIndex = 0; for (int i = 0; i < numberOfLines; ++i) { for (int j = 0; j < numberOfCols; ++j) { cellMatrix[i, j] = new Cell(i_UniqueLetters[readIndex++], i, j); } } }
private void createBoard(int i_BoardLines, int i_BoardCols) { m_Board = Board.CreateNewBoard(i_BoardLines, i_BoardCols); }
public void RememberCell(Board.Cell i_Cell) { if (i_Cell != null) { if (actualMemoryInUse() >= r_MaxMemory) { removeFirstCellFromActiveMemory(); } if (isInActiveMemory(i_Cell)) { return; } if (!r_ActiveCellsMemory.ContainsKey(i_Cell.Letter)) { r_ActiveCellsMemory.Add(i_Cell.Letter, new List<Board.Cell>()); } r_ActiveCellsMemory[i_Cell.Letter].Add(new Board.Cell(i_Cell)); } }
private void removeLetterFromMemory(Board.Cell i_Cell) { if (i_Cell != null) { r_ActiveCellsMemory.Remove(i_Cell.Letter); } }
private bool isInActiveMemory(Board.Cell i_Cell) { bool result; if (i_Cell != null) { result = isInActiveMemory(i_Cell.Line, i_Cell.Col); } else { result = false; } return result; }