コード例 #1
0
ファイル: View-guiTiles.cs プロジェクト: pushyka/draughts-all
        // clears all tiles
        private void clearGuiTiles(Board modelBoard)
        {
            // use gui=true tiles from modelBoard.internalBoard
            // find the corresponding panels in guiTileRefs
            // ADD OR REMOVE THE CONTAINING PIECE ACCORDINGLY
            // mark the modelBoard tiles as gui=false

            int size = modelBoard.Size;

            for (int row = 0; row < size; row++)
            {
                Tile[] rowOfTiles = modelBoard.InternalBoard[row];
                for (int col = 0; col < size; col++)
                {
                    Tile tile = rowOfTiles[col];
                    if (tile.GuiMustBeUpdated)
                    {
                        try
                        {
                            System.Windows.Forms.Panel guiTile = guiTileRefs[row][col];
                            guiTile.Controls.Clear();
                            // finally mark the tile as gui=false, this is LOGIC CODE
                        }
                        catch (NullReferenceException e)
                        {
                            System.Console.Error.WriteLine("resetting board before its created");
                            // it is better practise to not have this type of error handled here
                            // it is better to have the option to click reset disabled while the
                            // board has not been created yet
                        }

                    }
                }
            }
        }
コード例 #2
0
ファイル: View.cs プロジェクト: pushyka/draughts-all
 public View(Board board)
 {
     this.DoubleBuffered = true;
     this.data = new Data();
     this.board = board; //model
     InitializeComponent(); //view
     renderTiles(board);
 }
コード例 #3
0
ファイル: Logic.cs プロジェクト: pushyka/draughts-all
 public void test()
 {
     Console.WriteLine("test1");
     Board b = new Board();
     b.populateGameBoard();
     Coord c = new Coord(2, 2); //this piece
     List<Move> vm = b.getValidAvailableMoves(c);
     Console.WriteLine("board created and populated");
     Console.WriteLine(">: NUM OF VALID MOVES FOR THIS PIECE {0}", vm.Count); //this piece
 }
コード例 #4
0
ファイル: Program.cs プロジェクト: pushyka/draughts-all
        static void Main(string[] args)
        {
            Board board = new Board();           // model
            Gui gui = new Gui();                 // view
            Controller logic = new Controller(board, gui); // controller - model, view goes in here

            logic.test();

            /*
             * board b contains internal board
             * puplic generateboard, clearboard, populateBoard, addPiecestorows, getTile (ref), getPiecesValidAMoves,
             * getTilesWithPieceMoves, isCoordTileOnBoard, isPieceOnKingRow, movePiece
             * */
        }
コード例 #5
0
ファイル: Logic.cs プロジェクト: pushyka/draughts-all
 public Controller(Board board, Gui gui)
 {
     this.board = board;
     this.gui = gui;
 }
コード例 #6
0
ファイル: View-guiTiles.cs プロジェクト: pushyka/draughts-all
        // go through the model board, find those with gui needs to be
        // updated set to true, and use the refs array to obtain the gui tile
        // finally set the model back to guineedsupdate=false
        // used only for initially adding the pieces
        private void renderAllPieces(Board modelBoard)
        {
            // use gui=true tiles from modelBoard.internalBoard
            // find the corresponding panels in guiTileRefs
            // ADD OR REMOVE THE CONTAINING PIECE ACCORDINGLY
            // mark the modelBoard tiles as gui=false

            int size = modelBoard.Size;

            for (int row = 0; row < size; row ++)
            {
                Tile[] rowOfTiles = modelBoard.InternalBoard[row];
                for (int col = 0; col < size; col ++)
                {
                    Tile tile = rowOfTiles[col];

                    try
                    {
                        System.Windows.Forms.Panel guiTile = guiTileRefs[row][col];

                        if (tile.IsOccupied)
                        {
                            string player = tile.OccupyingPiece.Player;
                            CirclePanel guiPiece = new CirclePanel(player);

                            guiPiece.BackColor = Color.Transparent; // this set in the current main thread for visual priority
                            guiPiece.Size = new System.Drawing.Size(20, 20);
                            guiPiece.Location = new System.Drawing.Point(10, 10);
                            guiPiece.Click += (sender, eventArgs) => { tileClickedHandler(sender, tile.TileCoord); };
                            guiPiece.Name = "guiPiece"; //
                            guiTile.Controls.Add(guiPiece);
                        }
                        else // remove the corresponding gui piece
                            // since this means guineedsupdating=true, and there are NO pieces on the logic tile
                        {
                            // so remove the guiPiece which should currently be on PiecePanel
                            guiTile.Controls.Clear();
                        }
                    // finally mark the tile as gui=false, this is LOGIC CODE
                    }
                    catch (NullReferenceException e)
                    {
                        System.Console.Error.WriteLine("resetting board before its created");
                        // it is better practise to not have this type of error handled here
                        // it is better to have the option to click reset disabled while the
                        // board has not been created yet
                    }

                }
            }
        }
コード例 #7
0
ファイル: View-guiTiles.cs プロジェクト: pushyka/draughts-all
 /* null the guiTileRefs, clear the tilePanel controls */
 private void undrawTiles(Board board)
 {
     guiTileRefs = null;
     tilePanel.Controls.Clear();
 }
コード例 #8
0
ファイル: View-guiTiles.cs プロジェクト: pushyka/draughts-all
        /* Event response to the vs Computer game option clicked, firstly the board tiles should be drawn
         * the method will need to get the size of the board from the settings (logic/model)
         * it will use the same .py loop method for generating the physical placement of the gui components
         * ADDITIONALLY, it will place a referene of the compontents in an easy to access array. So when the
         * logic needs to access the tiles it can do so without having to resort to the expensive find_withtag
         * gui method such was used in the .py version */
        private void renderTiles(Board modelBoard)
        {
            // get the size of the board from the logic
            //int size = logic.getSize();
            int size = modelBoard.Size;
            // initialise the refs array
            guiTileRefs = new System.Windows.Forms.Panel[size][];

            int tilePanelDimension = this.tilePanel.Size.Height; // height==width
            int tileSize = this.tilePanel.Size.Height / size;
            // tilePanel dimensions are 322*322,
            // 8x40p-wide tiles with 1 pixel outermost border

            // starting board position relative to tilePanel == 1,1
            int baseLocationX = 1;
            int baseLocationY = 1;
            for (int row = 0; row < size; row ++) // multi by
            {

                System.Windows.Forms.Panel[] listOfPanels = new System.Windows.Forms.Panel[size];

                for (int col = 0; col < size; col ++)
                {
                    // create the control
                    System.Windows.Forms.Panel tile = new System.Windows.Forms.Panel();

                    // add control to 'this' form
                    // NOT TIMES PLUS ?=
                    //
                    int newLocationX = baseLocationX + (col * tileSize); // col * size(tile)
                    int newLocationY = baseLocationY + (row * tileSize);
                    tile.Location = new System.Drawing.Point(newLocationX, newLocationY);
                    tile.Size = new System.Drawing.Size(tileSize, tileSize);
                    // get the tileIcon/color from the logical tile
                    // modelBoard obj already made previously
                    Coord coord = new Coord(col, row);
                    Tile modelTile = modelBoard.getTile(coord);
                    //string strColor = modelBoard.getTile(coord).TileIcon;
                    //tile.BackColor = System.Drawing.Color.FromName(strColor);
                    if (modelTile.TileIcon == "white")
                    {
                        tile.BackgroundImage = checkers_wf.Properties.Resources.off_white_micro_fiber_cloth_fabric_texture_190x190;
                    }
                    if (modelTile.TileIcon == "black")
                    {
                        tile.BackgroundImage = checkers_wf.Properties.Resources.Indian_Premium_Black_Slab_464x464;
                    }
                    // add the event handler
                    tile.Click += (sender, eventArgs) => { tileClickedHandler(sender, coord); };

                    tilePanel.Controls.Add(tile);
                    // now add the reference to the gui array
                    listOfPanels[col] = tile;

                }
                guiTileRefs[row] = listOfPanels;
            }
        }