Пример #1
0
        private void setupBoard()
        {
            movemode = true;
            gameover = false;

            // initialise all tiles as free tiles
            for (int row = 1; row < rowcount + 1; row++)
            {
                for (int col = 1; col < colcount + 1; col++)
                {
                    BoardLoc loc = new BoardLoc(row, col);
                    TileArray[loc.TileNumber()] = new Tile(loc, tokenfree, TileType.free);
                }
            }

            // initialise players
            PlayerArray[0] = new Player('A', 3, 1, 0);
            PlayerArray[1] = new Player('B', rowcount - 2, colcount, 0);
            foreach (Player PlayerRef in PlayerArray)
            {
                int t = PlayerRef.poss.TileNumber();
                TileArray[t].tiletype = TileType.player;
                TileArray[t].token    = PlayerRef.tile;
            }

            // define board size
            this.Size = new Size(colcount * tilesize + 35, rowcount * tilesize + 120);

            int i = 0;

            foreach (Tile tile in TileArray)
            {
                ButtonArray[i]           = new Button();
                ButtonArray[i].Name      = i.ToString();
                ButtonArray[i].Text      = tile.token.ToString();
                ButtonArray[i].Font      = new Font("Berlin Sans FB", 20);
                ButtonArray[i].BackColor = Color.Yellow;
                ButtonArray[i].ForeColor = Color.Black;
                ButtonArray[i].Width     = tilesize - 1;
                ButtonArray[i].Height    = tilesize - 1;
                ButtonArray[i].Location  = new Point((tile.poss.col - 1) * tilesize + 10, (tile.poss.row - 1) * tilesize + 10);
                //ButtonArray[i].Enabled = true;
                //ButtonArray[i].Visible = true;
                ButtonArray[i].Click += btntile_Click;
                this.Controls.Add(ButtonArray[i]);

                i++;
            }

            // position label
            labelAction.Location = new Point(10, rowcount * tilesize + 20);

            // handover control to buttons
            getPlayerAction();
        }
Пример #2
0
        private bool testTileMove(BoardLoc posFrom, BoardLoc posTo)
        {
            // check new position is directly adjacent before checking if valid tile move
            int rowDiff = Math.Abs(posFrom.row - posTo.row);
            int colDiff = Math.Abs(posFrom.col - posTo.col);

            if ((rowDiff > 1 || colDiff > 1) || (rowDiff == 0 && colDiff == 0))
            {
                return(false);
            }
            else
            {
                return(testTileMove(posTo.TileNumber()));
            }
        }