Example #1
0
        protected void OnShown(object sender, EventArgs e)
        {
            board     = new Board(NUM_ROWS);
            algorithm = new IterativeAlgorithm(board);
            // algorithm = new RecursiveYieldAlgorithm(board);
            // algorithm = new RecursiveStepAndContinueAlgorithm(board);
            board.DoHop   += OnHop;
            board.UndoHop += OnUndoHop;

            WebSocketHelpers.ClearCanvas();
            DrawBoard();
            ShowPegs();
        }
Example #2
0
        protected void UpdateUI(int fromIdx, int hopIdx, int toIdx, Color fromColor, Color hoppedColor, Color toColor)
        {
            WebSocketHelpers.UpdateProperty("c" + fromIdx, "FillColor", fromColor.Name);
            WebSocketHelpers.UpdateProperty("c" + hopIdx, "FillColor", hoppedColor.Name);
            WebSocketHelpers.UpdateProperty("c" + toIdx, "FillColor", toColor.Name);

            // We only call DoEvents and delay when the algorithm is running.  If single stepping
            // or perusing the solution, we do NOT want to call DoEvents because additional mouse events
            // could then fire and the state of the game gets messed up.
            if (running)
            {
                lbSolution.DataSource = algorithm.UndoStack.Reverse().ToList();
                tbIterations.Text     = algorithm.Iterations.ToString("#,###,##0");
                Application.DoEvents();
                int delay;

                if (int.TryParse(tbIterateDelay.Text, out delay))
                {
                    System.Threading.Thread.Sleep(delay);
                }
            }
        }
Example #3
0
        protected void DrawBoard()
        {
            int cx = (pnlFlowSharp.Width - 50) / 2;
            int y  = 50;
            int n  = 0;

            Rectangle trect = new Rectangle(cx - NUM_ROWS * 50 + 65, y - 15, NUM_ROWS * 50 + 100, y + NUM_ROWS * 50 + 25);

            WebSocketHelpers.DropShape("UpTriangle", "t", trect, Color.FromArgb(240, 230, 140));

            NUM_ROWS.ForEach(row =>
            {
                row.ForEach(cell =>
                {
                    string name    = "c" + n;
                    Rectangle rect = new Rectangle(cx - 25 * row + 50 * cell, y + row * 50, 30, 30);
                    WebSocketHelpers.DropShape("Ellipse", name, rect, Color.White);
                    WebSocketHelpers.UpdateProperty(name, "Text", n.ToString());
                    ++n;
                });
            }, 1);
        }
Example #4
0
 private void OnFormClosing(object sender, FormClosingEventArgs e)
 {
     WebSocketHelpers.Close();
 }
Example #5
0
 protected void ShowPegs()
 {
     board.NumCells.ForEach(n => WebSocketHelpers.UpdateProperty("c" + n, "FillColor", board.GetPegColor(n).Name));
     WebSocketHelpers.UpdateProperty("c" + startPosition, "FillColor", "White");
 }