/// <summary> /// This method paints the board as well the symbols. /// </summary> /// <param name="e"></param> protected override void OnPaint(PaintEventArgs e) { if (IsTopLeft == true) { IsTopLeft = false; this.AutoScrollPosition = new Point(225, 225); } int dx = (AutoScrollPosition.X % CellSize); int dy = (AutoScrollPosition.Y % CellSize); AutoScrollPosition.Offset(AutoScrollPosition.X + dx, AutoScrollPosition.Y + dy); base.OnPaint(e); Matrix mx = new Matrix(1, 0, 0, 1, AutoScrollPosition.X, AutoScrollPosition.Y); e.Graphics.Transform = mx; if (ScreenFlag == Screens.game) { this.AutoScroll = true; this.HScroll = true; this.AutoScrollMinSize = new System.Drawing.Size(CellSize * BoardSize, CellSize * BoardSize); this.VScroll = true; GView.ShowGrid(e.Graphics, BoardSize); } else if (ScreenFlag == Screens.exit) { this.AutoScrollPosition = new Point(0, 0); GoodBye.Visible = true; this.AutoScroll = false; Exit.Visible = true; GameRestart.Visible = true; GameHeading.Location = new Point(160, 10); GameHeading.Visible = true; } }
/// <summary> /// This event will be generated when the user clicks on the playing grid, /// and checks if resize is required, places the user move, selects the best /// move for the computer and places the computer move. /// </summary> /// <param name="e"></param> protected override void OnMouseClick(MouseEventArgs e) { base.OnMouseClick(e); int CoordX = 0; int CoordY = 0; if (e.Button == MouseButtons.Left) { int ScrollX = (AutoScrollPosition.X % CellSize); int ScrollY = (AutoScrollPosition.Y % CellSize); AutoScrollPosition.Offset(ScrollX, ScrollY); CoordX = (int)Math.Round(((-(decimal)AutoScrollPosition.X) / (decimal)CellSize), 0); CoordY = (int)Math.Round(((-(decimal)AutoScrollPosition.Y) / (decimal)CellSize), 0); Point CellCoord = new Point((e.X / CellSize) + CoordX, (e.Y / CellSize) + CoordY); if (GmBoard.GetSymbol(CellCoord) == Symbol.blank) { Logic.MakeMove(CellCoord, UserSymbol); Refresh(); if (Logic.CheckResult(CellCoord, UserSymbol)) { GView.ShowResult(UserSymbol); GmBoard.Clear(); ScreenFlag = Screens.exit; } if (CheckResizeRequired(CellCoord) == 1) { ResizeBoard(); Refresh(); } else if (CheckResizeRequired(CellCoord) == 2) { IsTopLeft = true; ResizeBoard(); Refresh(); } Point ComputerPosition = Logic.SelectBestMove(ComputerSymbol); Logic.MakeMove(ComputerPosition, ComputerSymbol); Refresh(); if (Logic.CheckResult(ComputerPosition, ComputerSymbol)) { GView.ShowResult(ComputerSymbol); GmBoard.Clear(); ScreenFlag = Screens.exit; } Refresh(); } else { MessageBox.Show("Please make a valid move"); } } else { MessageBox.Show("Right Click not allowed"); } }