public static void WriteBoardImage(this State state, string pathname, Location select1, Location select2) { if (File.Exists(pathname)) { return; } var boardImage = BoardPainter.DrawBoard(state, select1, select2, null, false, Point.Empty); var scaledImage = ResizeImage(boardImage, boardImage.Width / 2, boardImage.Height / 2); scaledImage.Save(pathname, ImageFormat.Png); }
private void AsyncPlayGame(object cancellationToken) { TellBoardPainterThereIsANewGeneration(); do { Thread.Sleep(DelayBetweenGenerationsInMs); _gameRules.NextGeneration(); GenerationNumber++; TellBoardPainterThereIsANewGeneration(); } while (!_cancellationToken.IsCancellationRequested); _cancellationToken.Dispose(); _cancellationToken = null; BoardPainter.Dispose(); }
private void MainForm_Load(object sender, EventArgs e) { //options options = Options.Load(); switch (options.Level) { case GameLevel.Easy: menuEasy.Checked = true; break; case GameLevel.Medium: menuMedium.Checked = true; break; case GameLevel.Hard: menuHard.Checked = true; break; case GameLevel.Expert: menuExpert.Checked = true; break; case GameLevel.Crazy: menuCrazy.Checked = true; break; default: break; } switch (options.Mode) { case GameMode.HumanVsComputer: pvsCToolStripMenuItem.Checked = true; break; case GameMode.ComputerVsHuman: cvsPToolStripMenuItem.Checked = true; break; default: break; } //board boardPainter = new BoardPainter(board, bufferBoard); game = new Game(board); game.UpdatePlay = (player, square) => { Safe(() => { UpdateBoard(); if (player == PlayerType.Human) { AddMoveItem(square); } }); }; game.UpdateResult = r => { Safe(() => { DisplaySearchResult(r); if (r.Process == 1) { AddMoveItem(r.Move, r.Score); } }); }; game.UpdateMessage = msg => { Safe(() => { ShowMessage(msg); }); }; game.NewGame(); }
private void TellBoardPainterThereIsANewGeneration() { BoardPainter.GenerationHasChanged(GenerationNumber, _gameRules.Board); }