Exemple #1
0
        public BoggleClone()
        {
            InitializeComponent();

            // initialize the library, first run always uses a tree library for efficiency sake.
            lib = new TreeLibrary();
            lib.BuildLibrary("lexicon.txt");

            // initialize the dice
            dice = new Dice();
            dice.rollDice();

            // add the controls & buttons
            loader = new LibraryLoader();
            this.Controls.Add(loader);
            //loader.loadTimeL.Text = ts.Milliseconds.ToString();
            gameStatusController = new GameStatus();
            this.Controls.Add(gameStatusController);
            // add the library loader button listener
            loader.libLoadB.Click += new System.EventHandler(this.libLoadB_Click);
            loader.resizeB.Click += new System.EventHandler(this.resizeB_Click);
            gameStatusController.submitB.Click += new EventHandler(this.submitB_Click);
            gameStatusController.solveB.Click += new EventHandler(solveB_Click);
            setupBoard();

            // roll the dice
            //this.gameStatusController.startGame();
        }
Exemple #2
0
        /// <summary>
        /// Add buttons to the board, set the width/height of the window to accommodate the layout, set the width of the timer to the width of the window
        /// </summary>
        void setupBoard()
        {
            if (buttons != null)
            {
                foreach (Button button in buttons)
                {
                    this.Controls.Remove(button);
                }
            }

            // set up the buttons
            buttons = new Button[boardWidth, boardHeight];
            //set up the visited map
            visited = new bool[boardWidth, boardHeight];

            for (int row = 0; row < boardHeight; row++)
            {
                for (int col = 0; col < boardWidth; col++)
                {
                    visited[col, row] = false;
                    buttons[col, row] = new Button();
                    buttons[col, row].Location = new Point(col * BUTTON_WIDTH, loader.Height + row * BUTTON_WIDTH);
                    buttons[col, row].Name = col.ToString() + "-" + row.ToString();
                    buttons[col, row].Size = new System.Drawing.Size(BUTTON_WIDTH, BUTTON_WIDTH);
                    buttons[col, row].TabIndex = col * boardWidth + row;
                    buttons[col, row].UseVisualStyleBackColor = true;
                    buttons[col, row].Click += new EventHandler(Die_Click);
                    buttons[col, row].Enabled = false;
                    this.Controls.Add(buttons[col, row]);
                }
            }

            // setup the width/height of the window
            if (loader.Location.X + loader.Width >= buttons[buttons.GetLength(0) - 1, 0].Location.X + buttons[buttons.GetLength(0) - 1, 0].Width)
                this.Width = loader.Location.X + loader.Width + 20;
            else
                this.Width = buttons[buttons.GetLength(0) - 1, 0].Location.X + buttons[buttons.GetLength(0) - 1, 0].Width + 20;

            this.gameStatusController.Width = this.Width;
            this.gameStatusController.Location = new Point(0, buttons[0, buttons.GetLength(1) - 1].Location.Y + buttons[0, buttons.GetLength(1) - 1].Height + 10);
            this.Height = this.gameStatusController.Location.Y + this.gameStatusController.Height + 30;

            // set the location of the begin button's center to the center of the board
            this.beginB.Location = new Point((buttons[0, 0].Location.X + buttons[boardWidth - 1, 0].Location.X + BUTTON_WIDTH) / 2 - this.beginB.Width / 2, (buttons[0, 0].Location.Y + buttons[0, boardHeight - 1].Location.Y + BUTTON_WIDTH) / 2 - this.beginB.Height / 2);

            //set the width of the timer
            // initialize the dice
            dice = new Dice(boardWidth * boardHeight);
            dice.rollDice();
        }