public void Drawwinnerline() { Graphics g = Graphics.FromHwnd(this.pictureBox1.Handle); Pen pn = new Pen(Color.DarkGreen, 2); wl = AutoGamer.Drawwinline(GameFld); g.DrawLine(pn, wl.Winp1, wl.Winp2); }
public void Step() { if (GameFld.Winner != 0) { return; } progressBar1.Visible = true; Rectangle rec = new Rectangle(); for (int i = 0; i <= 2; i++) { for (int j = 0; j <= 2; j++) { rec = (Rectangle)ListRect[i, j]; if (rec.Contains(pxd)) { if (GameFld.field[i, j] != 0) { return; } GameFld.field[i, j] = 2; } } } if (this.нормаToolStripMenuItem.CheckState == CheckState.Checked) { GameFld.diffic = 1; } if (this.жестьToolStripMenuItem.CheckState == CheckState.Checked) { GameFld.diffic = 2; } GameFld = AutoGamer.NextStep(GameFld); this.Fillfield(GameFld.field); this.Labeldraw(); }
public static Gamefield NextStep(Gamefield fld) { bool Winplayer = false; bool WinAuto = false; // PlacePoint[] PlPoint = new PlacePoint[9]; double[,] PlPoint = new double[3, 3]; for (int i = 0; i <= 2; i++) { for (int j = 0; j <= 2; j++) { PlPoint[i, j] = 0; } } //столбцы int CX = 0; for (int i = 0; i <= 2; i++) { int cnt0 = 0; int cntx = 0; double rat = 0; int X = 0; for (int j = 0; j <= 2; j++) { if (fld.field[i, j] == 1) { cnt0 = cnt0 + 1; } if (fld.field[i, j] == 2) { cntx = cntx + 1; X = j; CX = CX + 1; } } rat = cntx + cnt0; if (cntx == 2) { rat = 2 + 3; } if (cnt0 == 2) { rat = 2 + 6; if (cntx == 0) { WinAuto = true; } } if (cnt0 == 1 && cntx == 1) { rat = 0; } if (cnt0 == 1 && cntx == 1) { rat = 0; } if (cntx == 3) { Winplayer = true; } for (int j = 0; j <= 2; j++) { if (fld.field[i, j] == 0) { PlPoint[i, j] = PlPoint[i, j] + rat; if (Math.Abs(X - j) == 1 && CX > 1 && fld.diffic == 2) { PlPoint[i, j] = PlPoint[i, j] + 1.5; } } } } //строки for (int j = 0; j <= 2; j++) { int cnt0 = 0; int cntx = 0; double rat = 0; int Y = 0; for (int i = 0; i <= 2; i++) { if (fld.field[i, j] == 1) { cnt0 = cnt0 + 1; } if (fld.field[i, j] == 2) { cntx = cntx + 1; Y = i; } } rat = cntx + cnt0; if (cntx == 2) { rat = 2 + 3; } if (cnt0 == 2) { rat = 2 + 6; if (cntx == 0) { WinAuto = true; } } if (cnt0 == 1 && cntx == 1) { rat = 0; } if (cntx == 3) { Winplayer = true; } for (int i = 0; i <= 2; i++) { if (fld.field[i, j] == 0) { PlPoint[i, j] = PlPoint[i, j] + rat; if (Math.Abs(Y - i) == 1 && CX > 1 && fld.diffic == 2) { PlPoint[i, j] = PlPoint[i, j] + 1.5; } } } } //диагон int cnt0d = 0; int cntxd = 0; double ratd = 0; for (int j = 0; j <= 2; j++) { int i = j; if (fld.field[i, j] == 1) { cnt0d = cnt0d + 1; } if (fld.field[i, j] == 2) { cntxd = cntxd + 1; } } ratd = cntxd + cnt0d; if (cntxd == 2) { ratd = 2 + 6; } if (cnt0d == 2) { ratd = 2 + 1; if (cntxd == 0) { WinAuto = true; } } if (cntxd == 1) { ratd = 2; } if (cntxd == 3) { Winplayer = true; } // } for (int j = 0; j <= 2; j++) { int i = j; if (fld.field[i, j] == 0) { PlPoint[i, j] = PlPoint[i, j] + ratd; } } //diag2 cnt0d = 0; cntxd = 0; ratd = 0; for (int j = 2; j >= 0; j--) { int i = 2 - j; if (fld.field[i, j] == 1) { cnt0d = cnt0d + 1; } if (fld.field[i, j] == 2) { cntxd = cntxd + 1; } } ratd = cntxd + cnt0d; if (cntxd == 2) { ratd = 2 + 6; } if (cnt0d == 2) { ratd = 2 + 1; if (cntxd == 0) { WinAuto = true; } } if (cnt0d == 1 && cntxd == 1) { ratd = 0; } if (cntxd == 1) { ratd = 2; } if (cntxd == 3) { Winplayer = true; } // } if (WinAuto) { fld.Winner = 1;// "Вы проиграли! Деньги на бочку!"; } if (Winplayer) { fld.Winner = 2;// "Вы выиграли, поздравляю!"; } if (Winplayer) { return(fld); } for (int j = 2; j >= 0; j--) { int i = 2 - j; if (fld.field[i, j] == 0) { PlPoint[i, j] = PlPoint[i, j] + ratd; } } PlacePoint Point = AutoGamer.FindPoint(PlPoint); if (Point.Rate > 0) { fld.field[Point.Numstr, Point.Numcol] = 1; } return(fld); }
private void pictureBox1_MouseClick(object sender, MouseEventArgs e) { if (GameFld.Winner != 0) { return; } Point p = new Point(e.X, e.Y); Rectangle rec = new Rectangle(); for (int i = 0; i <= 2; i++) { for (int j = 0; j <= 2; j++) { rec = (Rectangle)ListRect[i, j]; if (rec.Contains(p)) { if (GameFld.field[i, j] != 0) { return; } GameFld.field[i, j] = 2; } } } if (this.нормаToolStripMenuItem.CheckState == CheckState.Checked) { GameFld.diffic = 1; } if (this.жестьToolStripMenuItem.CheckState == CheckState.Checked) { GameFld.diffic = 2; } GameFld = AutoGamer.NextStep(GameFld); this.Fillfield(GameFld.field); switch (GameFld.Winner) { case 1: txtNote.Text = "Вы проиграли! Деньги на бочку!"; txtNote.ForeColor = Color.Red; break; case 2: txtNote.Text = "Вы выиграли, поздравляю!";; txtNote.ForeColor = Color.Green; break; case 0: txtNote.Text = "Ваш ход..."; txtNote.ForeColor = Color.Blue; int busycell = 0; for (int i = 0; i <= 2; i++) { for (int j = 0; j <= 2; j++) { if (GameFld.field[i, j] != 0) { busycell++; } } } if (busycell == 9) { txtNote.Text = "Ничья вышла..."; txtNote.ForeColor = Color.Blue; } break; } //g.DrawImage(bitKreiz, rec); //this.pictureBox1.Invalidate(); }