/// <summary> /// Builds image for game state /// </summary> /// <param name="gameState">FEN Value of the current game state</param> /// <param name="playerCurrentTurn">Name for the player who's turn it now is</param> /// <param name="playerNowWaiting">Name for player who just went</param> /// <returns>asset path for the new image</returns> public static string processImage(string gameBoardState, string whitePlayerName, string blackPlayerName) { // TODO: Do we need this as defaults Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Setup Objects ChessBoardImageForm cbbForm = new ChessBoardImageForm(); ChessBoardImageGenerator cbbImgGen = new ChessBoardImageGenerator(cbbForm); cbbForm.ImageGenerator = cbbImgGen; // Setup Input Fields cbbImgGen.WhitePlayerLabel = whitePlayerName; cbbImgGen.BlackPlayerLabel = blackPlayerName; // Setup Output Fields cbbImgGen.FileNameImageFormat = ImageFormat.Png; cbbImgGen.ImageFileName = @"..\..\DigitalAssets\ChessBoardImage.png"; // Set "updatedGameBoardState" expected in Forsyth-Edwards Notation cbbForm.ChessBoardStateFEN = gameBoardState; // Generate the game board Application.Run(cbbForm); return cbbImgGen.ImageFileName; }
/// <summary> /// ChessBoardStatic /// </summary> /// <param name="aChessBoardBox"></param> /// <returns></returns> public ChessBoard(ChessBoardImageGenerator aChessBoardImageGenerator, PictureBox aPictureBox) { chessBoardImageGenerator = aChessBoardImageGenerator; if (aPictureBox.Handle == null) { throw new Exception("Bad PictureBox"); } chessBoardBox = aPictureBox; squareList = new ArrayList(); whitePieceList = new ArrayList(); blackPieceList = new ArrayList(); chessPieceFactory = new ChessPieceFactory(); squareFactory = new ChessSquareFactory(); squareLocator = new ChessSquareLocator(); chessBoardInitializer = new ChessBoardInitializer( this, squareList, whitePieceList, blackPieceList, squareFactory, chessPieceFactory, squareLocator); chessBoardInitializer.Initialize(); chessBoardBox.Paint += new PaintEventHandler(paint); chessLocationCalculatorFactory = new ChessLocationCalculatorFactory(this); }
static void MainForDev() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Setup Objects ChessBoardImageForm cbbForm = new ChessBoardImageForm(); ChessBoardImageGenerator cbbImgGen = new ChessBoardImageGenerator(cbbForm); cbbForm.ImageGenerator = cbbImgGen; // Setup Output Fields cbbImgGen.FileNameImageFormat = ImageFormat.Png; cbbImgGen.ImageFileName = @"..\..\DigitalAssets\ChessBoardImage.png"; // Setup Input Fields cbbImgGen.WhitePlayerLabel = "Zach"; cbbImgGen.BlackPlayerLabel = "Joe"; // Expected Chess Board States in Forsyth-Edwards Notation string FENState; int example = 0; // Change this to test various valid string if (false) { int index = cbbImgGen.ImageFileName.IndexOf(".png"); string newFileName = cbbImgGen.ImageFileName.Insert(index, example.ToString()); cbbImgGen.ImageFileName = newFileName; } switch (example) { case 1: FENState = "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1"; // Another state - Black's Turn break; case 2: FENState = "rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 2"; // Another state - White's Turn break; case 3: FENState = "rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2"; // Another state - Black's Turn break; default: FENState = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"; // Initial state - White's Turn break; } cbbForm.ChessBoardStateFEN = FENState; Application.Run(cbbForm); }