private Boolean check_piece(piece piece) { index = prilipania_index(MousePosition.X, MousePosition.Y); try { for (int i = index[0] - index_piece[1]; i < index[0] - index_piece[1] + 5; i++) { for (int j = index[1] - index_piece[2]; j < index[1] - index_piece[2] + 5; j++) { if (piece.form[i - (index[0] - index_piece[1])][j - (index[1] - index_piece[2])] == '1') { if (table[i, j] != 0) { return(false); } } } } } catch { return(false); } return(true); }
private Boolean game_over_f(piece piece, int index1, int index2) { try { for (int r = 0; r < 5; r++) { for (int h = 0; h < 5; h++) { if (piece.form[r][h] == '1' && table[index1 + r - 2, index2 + h - 2] == 1) { return(false); } } } } catch { return(false); } return(true); }
private void piece_location(piece piece) { for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { switch (name.Name[0]) { case '1': picturePanel1[i, j].Visible = false; k.visible = false; break; case '2': picturePanel2[i, j].Visible = false; k1.visible = false; break; case '3': picturePanel3[i, j].Visible = false; k2.visible = false; break; } } } for (int i = index[0] - index_piece[1]; i < index[0] - index_piece[1] + 5; i++) { for (int j = index[1] - index_piece[2]; j < index[1] - index_piece[2] + 5; j++) { if (piece.form[i - (index[0] - index_piece[1])][j - (index[1] - index_piece[2])] == '1') { table[i, j] = 1; myBoxes[i, j].Visible = true; myBoxes[i, j].BackgroundImage = piece.color; Score++; } } } label2.Text = Score.ToString(); if (Score > HighScore) { HighScore = Score; label1.Text = HighScore.ToString(); System.IO.StreamWriter sr = new System.IO.StreamWriter(System.IO.File.Open("score.txt", System.IO.FileMode.Create, System.IO.FileAccess.Write)); { sr.WriteLine(HighScore.ToString()); sr.Close(); } label2.Text = Score.ToString(); label2.Left = pictureBox3.Left - 20 - label2.Width; } v++; if (v == 3) { v = 0; next_pieces(); } delete_row(); if (game_over() == true) { if (voice == true) { sound.play("2.wav"); } int f = -1, k = 0; string line; string[] ss = new string[1]; System.IO.StreamReader sr2 = new System.IO.StreamReader(System.IO.File.Open("champions.txt", System.IO.FileMode.Open)); { line = sr2.ReadLine(); while (line != null) { ss[k] = line; Array.Resize(ref ss, ss.Length + 1); if (line.Split(' ')[0] == name_player) { f = k; } k++; line = sr2.ReadLine(); } sr2.Close(); } System.IO.StreamWriter sr1 = new System.IO.StreamWriter(System.IO.File.Open("champions.txt", System.IO.FileMode.Create, System.IO.FileAccess.Write)); { if (f != -1) { for (int i = 0; i < k; i++) { if (i == f && Score > Convert.ToInt16(ss[i].Split(' ')[1])) { sr1.WriteLine(ss[i].Split(' ')[0] + " " + Score); } else { sr1.WriteLine(ss[i]); } } } else { for (int i = 0; i < k; i++) { sr1.WriteLine(ss[i]); } sr1.WriteLine(name_player + " " + Score.ToString()); } sr1.Close(); } MessageBox.Show("Game over!"); v = 0; complexity = 6; Score = 0; label2.Text = "0"; next_pieces(); for (int i = 0; i < a; i++) { for (int j = 0; j < a; j++) { table[i, j] = 0; myBoxes[i, j].BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\0.png"); } } } }