bool SprawdzWygrana() { bool bk = false; bool ck = false; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { Figura figura = plansza.PobierzFigure(i, j); if (figura != null) { if (figura.PobierzSymbol() == 'K' && figura.PobierzDruzyne() == 'B') { bk = true; } if (figura.PobierzSymbol() == 'K' && figura.PobierzDruzyne() == 'C') { ck = true; } } } } if (!bk) { wygrana = true; winner = 'C'; } if (!ck) { wygrana = true; winner = 'B'; } return(wygrana); }
void Wyswietl(Figura figura, int y, int x, System.Windows.Forms.PaintEventArgs e) { if (figura.PobierzDruzyne() == 'B') { if (figura.PobierzSymbol() == 'P') { e.Graphics.DrawImage(im_bp, x * w_pola, y * h_pola, w_pola, h_pola); } if (figura.PobierzSymbol() == 'W') { e.Graphics.DrawImage(im_bw, x * w_pola, y * h_pola, w_pola, h_pola); } if (figura.PobierzSymbol() == 'S') { e.Graphics.DrawImage(im_bs, x * w_pola, y * h_pola, w_pola, h_pola); } if (figura.PobierzSymbol() == 'G') { e.Graphics.DrawImage(im_bg, x * w_pola, y * h_pola, w_pola, h_pola); } if (figura.PobierzSymbol() == 'H') { e.Graphics.DrawImage(im_bh, x * w_pola, y * h_pola, w_pola, h_pola); } if (figura.PobierzSymbol() == 'K') { e.Graphics.DrawImage(im_bk, x * w_pola, y * h_pola, w_pola, h_pola); } } if (figura.PobierzDruzyne() == 'C') { if (figura.PobierzSymbol() == 'P') { e.Graphics.DrawImage(im_cp, x * w_pola, y * h_pola, w_pola, h_pola); } if (figura.PobierzSymbol() == 'W') { e.Graphics.DrawImage(im_cw, x * w_pola, y * h_pola, w_pola, h_pola); } if (figura.PobierzSymbol() == 'S') { e.Graphics.DrawImage(im_cs, x * w_pola, y * h_pola, w_pola, h_pola); } if (figura.PobierzSymbol() == 'G') { e.Graphics.DrawImage(im_cg, x * w_pola, y * h_pola, w_pola, h_pola); } if (figura.PobierzSymbol() == 'H') { e.Graphics.DrawImage(im_ch, x * w_pola, y * h_pola, w_pola, h_pola); } if (figura.PobierzSymbol() == 'K') { e.Graphics.DrawImage(im_ck, x * w_pola, y * h_pola, w_pola, h_pola); } } }
public void WykonajRuch(Figura figura, int x, int y, int new_x, int new_y) { if (figura.Weryfikuj(this.szachownica, x, y, new_x, new_y)) { if (szachownica[new_x, new_y] != null) { if (szachownica[new_x, new_y].PobierzDruzyne() != szachownica[x, y].PobierzDruzyne()) { Zbij(new_x, new_y); } } this.OproznijPole(x, y); this.Przypisz(figura, new_x, new_y); } }
private void Form1_Paint(System.Object sender, System.Windows.Forms.PaintEventArgs e) { if (wygrana) { //operacja jezeli ktos juz wygral if (winner == 'B') { e.Graphics.DrawImage(win_white, 0, 0, 8 * w_pola, 8 * h_pola); } else { e.Graphics.DrawImage(win_black, 0, 0, 8 * w_pola, 8 * h_pola); } } else { //standardowa operacja for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if ((i % 2 == 0 && j % 2 == 0) || (i % 2 == 1 && j % 2 == 1)) { e.Graphics.DrawImage(white, i * w_pola, j * h_pola, w_pola, h_pola); } else { e.Graphics.DrawImage(black, i * w_pola, j * h_pola, w_pola, h_pola); } } } for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { Figura figura = plansza.PobierzFigure(i, j); if (plansza.PobierzFigure(i, j) != null) { Wyswietl(figura, i, j, e); } } } if (tura) { e.Graphics.DrawImage(pods, i_pods * w_pola, j_pods * h_pola, w_pola, h_pola); //podswietla pole } } }
public void Przypisz(Figura figura, int x, int y) { szachownica[x, y] = figura; }
private void Form1_Click(System.Object sender, System.EventArgs e) { if (wygrana) { //operacja jezeli ktos juz wygral // delete plansza; Close(); } else { //standardowa operacja Point p = this.PointToClient(MousePosition); int x = p.X; int y = p.Y; int i = x / w_pola; int j = y / h_pola; if (!tura) { //pierwsza faza tury if (SprawdzGracza(j, i)) { h_pocz = j; w_pocz = i; i_pods = i; j_pods = j; tura = true; this.Refresh(); } } else { //druga faza tury h_nowe = j; w_nowe = i; if (h_nowe == h_pocz && w_nowe == w_pocz) { tura = false; this.Refresh(); } else { Figura figura = plansza.PobierzFigure(h_pocz, w_pocz); plansza.WykonajRuch(figura, h_pocz, w_pocz, h_nowe, w_nowe); Figura figura2 = plansza.PobierzFigure(h_nowe, w_nowe); if (figura2 == figura) { //sprawdza czy ruch zostal wykonany SprawdzWygrana(); if (!wygrana) { tura = false; ZmianaGracza(); } this.Refresh(); } else { tura = false; this.Refresh(); } } } } }