private void загрузитьToolStripMenuItem_Click(object sender, EventArgs e) { BinaryFormatter BF = new BinaryFormatter(); FileStream Savestream = File.OpenRead("savegame.gam"); this.GameFld = (Gamefield)BF.Deserialize(Savestream); Savestream.Close(); this.pictureBox1.Invalidate(); }
public void Cleargame() { int dif = 1; GameFld = new Gamefield(dif); txtNote.Text = "Ваш ход..."; txtNote.ForeColor = Color.Blue; pictureBox1.Invalidate(); }
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 GameForm() { InitializeComponent(); CenterToScreen(); this.Paint += new PaintEventHandler(GameForm_Paint); txtNote.Text = "Ваш ход..."; txtNote.ForeColor = Color.Blue; int dif = 1; if (this.нормаToolStripMenuItem.CheckState == CheckState.Checked) { dif = 1; } if (this.жестьToolStripMenuItem.CheckState == CheckState.Checked) { dif = 2; } GameFld = new Gamefield(dif); }
public GameForm() { InitializeComponent(); CenterToScreen(); this.Paint += new PaintEventHandler(GameForm_Paint); txtNote.Text = "Ваш ход..."; txtNote.ForeColor = Color.Blue; int dif = 1; if (this.нормаToolStripMenuItem.CheckState == CheckState.Checked) { dif = 1; } if (this.жестьToolStripMenuItem.CheckState == CheckState.Checked) { dif = 2; } GameFld = new Gamefield(dif); tim.Interval = 10; tim.Tick += new EventHandler(tim_Tick); progressBar1.Visible = false; }
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); }
public static Winline Drawwinline(Gamefield fld) { int wa = 0; int wp = 0; int x1 = 0; int x2 = 0; int y1 = 0; int y2 = 0; x1 = 0; for (int i = 0; i <= 2; i++) { wa = 0; wp = 0; y1 = i; for (int j = 0; j <= 2; j++) { if (fld.field[i, j] == 1) { wa++; } if (fld.field[i, j] == 2) { wp++; } } x2 = 2; y2 = i; if (wa == 3) { return(new Winline(x1, y1, x2, y2)); } if (wp == 3) { return(new Winline(x1, y1, x2, y2)); } } //столб y1 = 0; for (int j = 0; j <= 2; j++) { wa = 0; wp = 0; for (int i = 0; i <= 2; i++) { x1 = j; if (fld.field[i, j] == 1) { wa++; } if (fld.field[i, j] == 2) { wp++; } } x2 = j; y2 = 2; if (wa == 3) { return(new Winline(x1, y1, x2, y2)); } if (wp == 3) { return(new Winline(x1, y1, x2, y2)); } } //диагон wa = 0; wp = 0; x1 = 0; y1 = 0; for (int j = 0; j <= 2; j++) { int i = j; if (fld.field[i, j] == 1) { wa++; } if (fld.field[i, j] == 2) { wp++; } x2 = 2; y2 = 2; } if (wa == 3) { return(new Winline(x1, y1, x2, y2)); } if (wp == 3) { return(new Winline(x1, y1, x2, y2)); } ; //diag2 x1 = 2; y1 = 0; x2 = 0; y2 = 2; wa = 0; wp = 0; for (int j = 2; j >= 0; j--) { int i = 2 - j; if (fld.field[i, j] == 1) { wa++; } if (fld.field[i, j] == 2) { wp++; } } if (wa == 3) { return(new Winline(x1, y1, x2, y2)); } if (wp == 3) { return(new Winline(x1, y1, x2, y2)); } ; return(new Winline()); }
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(); }