private void StartButton_Click(object sender, EventArgs e) { tableLayoutPanel.Visible = false; Game_Panel game = new Game_Panel(); Game g = new Game(game, Int16.Parse(boardSizeCombo.Text),FirstComputerHeuristic.Text,SecondComputerHeuristic.Text,testMode.Checked); game.Dock = DockStyle.Fill; this.Controls.Add(game); }
public Game(Game_Panel gamePanel, int boardSize, string FuncW, string FuncB, bool test_mode) { WhiteSemaphore = new Semaphore(0, 1); BlackSemaphore = new Semaphore(1, 1); whitePlayer = new Player(FuncW, "W",boardSize); blackPlayer = new Player(FuncB, "B",boardSize); whitePlayer.setOpponent(blackPlayer); blackPlayer.setOpponent(whitePlayer); this.gamePanel = gamePanel; this.boardSize = boardSize; this.test_mode = test_mode; ///z zasad gry: Czarny zawsze zaczyna gre! turn = Turn.B; int squareSize = boardSize / 3; tileSize = (gamePanel.gameBoard.Width) / boardSize; int gridSize = boardSize; int half = gridSize / 2; // inicjalizacja planszy Tiles = new Panel[gridSize, gridSize]; for (var n = 0; n < gridSize; n++) { for (var m = 0; m < gridSize; m++) { var newPanel = new Panel { Size = new Size(tileSize, tileSize), Location = new Point(tileSize * n, tileSize * m) }; Tiles[n, m] = newPanel; // color the backgrounds if (n % 2 == 0) { newPanel.BackgroundImage = (System.Drawing.Image)(Image.FromFile("GreenField.png")); newPanel.Tag = "G"; } else { newPanel.BackgroundImage = (System.Drawing.Image)(Image.FromFile("GreenField.png")); newPanel.Tag = "G"; } newPanel.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; if ((n < squareSize && m < squareSize) || (n >= 2 * squareSize && m >= 2 * squareSize) || (n < squareSize && m >= 2 * squareSize) || (m < squareSize && n >= 2 * squareSize)) { newPanel.BackgroundImage = (System.Drawing.Image)(Image.FromFile("EmptyField.png")); newPanel.Tag = "E"; } gamePanel.gameBoard.Controls.Add(newPanel); } } ///ustawienie 4 pionkow na srodku planszy Panel p = Tiles[half, half]; p.BackgroundImage = (System.Drawing.Image)(Image.FromFile("WField.png")); p.Tag = "W"; p = Tiles[half - 1, half - 1]; whitePlayer.Points++; p.BackgroundImage = (System.Drawing.Image)(Image.FromFile("WField.png")); p.Tag = "W"; whitePlayer.Points++; p = Tiles[half, half - 1]; p.BackgroundImage = (System.Drawing.Image)(Image.FromFile("BlackField.png")); p.Tag = "B"; blackPlayer.Points++; p = Tiles[half - 1, half]; p.BackgroundImage = (System.Drawing.Image)(Image.FromFile("BlackField.png")); p.Tag = "B"; blackPlayer.Points++; //TEST MODE - testowanie interakcji GUI z logiką gry (naprzemienne klikanie myszką pol) if (test_mode) { for (var n = 0; n < gridSize; n++) { for (var m = 0; m < gridSize; m++) { if (Tiles[n, m].Tag.ToString() == "G") { this.Tiles[n, m].Click += new System.EventHandler(this.Tile_Click); this.Tiles[n, m].MouseEnter += new System.EventHandler(this.Tile_Enter); this.Tiles[n, m].MouseLeave += new System.EventHandler(this.Tile_Leave); } } } } //w przeciwnym przypadku naprzemienne uruchamianie graczy else { searcher = new Searcher(tileSize, boardSize); Start(); } }