private void NovaIgra() { if (matricaDugme != null) { foreach (Button dugme in matricaDugme) { this.Controls.Remove(dugme); } } matricaDugme = new Button[6, 7]; igracnapotezu = 2; tabla = new Tabla(); gameOver = false; for (int i = 0; i < 6; i++) { for (int j = 0; j < 7; j++) { Button button1 = new Button(); button1.ForeColor = Color.Transparent; button1.BackColor = Color.Transparent; button1.FlatAppearance.MouseOverBackColor = Color.Transparent; button1.FlatAppearance.MouseDownBackColor = Color.Transparent; button1.FlatStyle = FlatStyle.Flat; button1.FlatAppearance.BorderSize = 0; button1.Height = 60; button1.Width = 60; button1.Location = new Point(j * 69 + 49, i * 70 + 47); //button1.BackgroundImage = Image.FromFile("belizeton.png"); button1.BackgroundImageLayout = ImageLayout.Stretch; button1.Click += FormIgra_Click; matricaDugme[i, j] = button1; this.Controls.Add(button1); } } }
void Proveri(ref bool gameOver, Tabla tabla, Label label1, Label label2) { int stanjeTable = tabla.ishod(); if (stanjeTable == 1) { gameOver = true; label1.Text = (Convert.ToInt32(label1.Text) + 1).ToString(); MessageBox.Show("Pobednik je igrac 1"); } else if (stanjeTable == 2) { gameOver = true; label2.Text = (Convert.ToInt32(label2.Text) + 1).ToString(); MessageBox.Show("Pobednik je igrac 2"); } else if (stanjeTable == 0) { gameOver = true; MessageBox.Show("Nereseno"); } else { gameOver = false; } }
public bool Klik(Button[,] matricaDugme, ref int igracnapotezu, System.Drawing.Point relative, Tabla tabla, Label label1, Label label2) { bool gameOver = false; if (relative.X > 42 && relative.X < 530) { int zetonKolona = (relative.X - 50) / 70; int odigrajpotez = tabla.OdigrajPotez(zetonKolona, igracnapotezu); if (odigrajpotez != -1) { matricaDugme[odigrajpotez, zetonKolona].BackgroundImage = Image.FromFile(igracnapotezu + ".png"); igracnapotezu = (igracnapotezu % 2) + 1; int stanjeTable = tabla.ishod(); if (stanjeTable == 1) { gameOver = true; label1.Text = (Convert.ToInt32(label1.Text) + 1).ToString(); MessageBox.Show("Pobednik je igrac 1"); } else if (stanjeTable == 2) { gameOver = true; label2.Text = (Convert.ToInt32(label2.Text) + 1).ToString(); MessageBox.Show("Pobednik je igrac 2"); } else if (stanjeTable == 0) { gameOver = true; MessageBox.Show("Nereseno"); } else { gameOver = false; } } } return(gameOver); }
public int evaluacija(Tabla b) { ////////// int aiScore = 1; int score = 0; int praznine = 0; int k = 0, josPoteza = 0; for (int i = 5; i >= 0; --i) { for (int j = 0; j <= 6; ++j) { if (b.board[i, j] == 0 || b.board[i, j] == 2) { continue; } if (j <= 3) { for (k = 1; k < 4; ++k) { if (b.board[i, j + k] == 1) { aiScore++; } else if (b.board[i, j + k] == 2) { aiScore = 0; praznine = 0; break; } else { praznine++; } } josPoteza = 0; if (praznine > 0) { for (int c = 1; c < 4; ++c) { int column = j + c; for (int m = i; m <= 5; m++) { if (b.board[m, column] == 0) { josPoteza++; } else { break; } } } } if (josPoteza != 0) { score += izracunajScore(aiScore, josPoteza); } aiScore = 1; praznine = 0; } if (i >= 3) { for (k = 1; k < 4; ++k) { if (b.board[i - k, j] == 1) { aiScore++; } else if (b.board[i - k, j] == 2) { aiScore = 0; break; } } josPoteza = 0; if (aiScore > 0) { int column = j; for (int m = i - k + 1; m <= i - 1; m++) { if (b.board[m, column] == 0) { josPoteza++; } else { break; } } } if (josPoteza != 0) { score += izracunajScore(aiScore, josPoteza); } aiScore = 1; praznine = 0; } if (j >= 3) { for (k = 1; k < 4; ++k) { if (b.board[i, j - k] == 1) { aiScore++; } else if (b.board[i, j - k] == 2) { aiScore = 0; praznine = 0; break; } else { praznine++; } } josPoteza = 0; if (praznine > 0) { for (int c = 1; c < 4; ++c) { int column = j - c; for (int m = i; m <= 5; m++) { if (b.board[m, column] == 0) { josPoteza++; } else { break; } } } } if (josPoteza != 0) { score += izracunajScore(aiScore, josPoteza); } aiScore = 1; praznine = 0; } if (j <= 3 && i >= 3) { for (k = 1; k < 4; ++k) { if (b.board[i - k, j + k] == 1) { aiScore++; } else if (b.board[i - k, j + k] == 2) { aiScore = 0; praznine = 0; break; } else { praznine++; } } josPoteza = 0; if (praznine > 0) { for (int c = 1; c < 4; ++c) { int column = j + c, row = i - c; for (int m = row; m <= 5; ++m) { if (b.board[m, column] == 0) { josPoteza++; } else if (b.board[m, column] == 1) { ; } else { break; } } } if (josPoteza != 0) { score += izracunajScore(aiScore, josPoteza); } aiScore = 1; praznine = 0; } } if (i >= 3 && j >= 3) { for (k = 1; k < 4; ++k) { if (b.board[i - k, j - k] == 1) { aiScore++; } else if (b.board[i - k, j - k] == 2) { aiScore = 0; praznine = 0; break; } else { praznine++; } } josPoteza = 0; if (praznine > 0) { for (int c = 1; c < 4; ++c) { int column = j - c, row = i - c; for (int m = row; m <= 5; ++m) { if (b.board[m, column] == 0) { josPoteza++; } else if (b.board[m, column] == 1) { ; } else { break; } } } if (josPoteza != 0) { score += izracunajScore(aiScore, josPoteza); } aiScore = 1; praznine = 0; } } } } return(score); }
public bool Klik(Button[,] matricaDugme, ref int igracnapotezu, Point relative, Tabla tabla, Label label1, Label label2) { bool gameOver = false; if (relative.X > 42 && relative.X < 530) { bool pom = true; for (int i = 0; i < 2; i++) { int zetonKolona; int odigrajpotez; if (pom) { zetonKolona = (relative.X - 50) / 70; pom = false; } else { AI.b = tabla; zetonKolona = AI.GenerisiPotez(); //zetonKolona = 3; odigrajpotez = 1; } odigrajpotez = tabla.OdigrajPotez(zetonKolona, igracnapotezu); if (odigrajpotez != -1) { matricaDugme[odigrajpotez, zetonKolona].BackgroundImage = Image.FromFile(igracnapotezu + ".png"); FormIgra.igra.Refresh(); igracnapotezu = (igracnapotezu % 2) + 1; int stanjeTable = tabla.ishod(); if (stanjeTable == 1) { gameOver = true; label2.Text = (Convert.ToInt32(label2.Text) + 1).ToString(); MessageBox.Show("Pobednik je igrac 2"); //AIClass.Serialize(AI.transpozicija, File.Open("data.bin", FileMode.Create)); break; } else if (stanjeTable == 2) { gameOver = true; label1.Text = (Convert.ToInt32(label1.Text) + 1).ToString(); MessageBox.Show("Pobednik je igrac 1"); //AIClass.Serialize(AI.transpozicija, File.Open("data.bin", FileMode.Create)); break; } else if (stanjeTable == 0) { gameOver = true; MessageBox.Show("Nereseno"); //AIClass.Serialize(AI.transpozicija, File.Open("data.bin", FileMode.Create)); break; } else { gameOver = false; } } } } return(gameOver); }