private void button1_Click(object sender, EventArgs e) { ConnDatabase bd = new ConnDatabase(); string id_piece = ""; List <string> game = new List <string>(); try { game = bd.selectAllAboutGameByLoginAndIdPuzzle(login, id_puzzle); if (game.Count != 0) { bd.deleteGameByIdPuzzleAndLogin(id_puzzle, login); for (int i = 0; i < serial_number.Count; i++) { id_piece = bd.selectIDPiece(serial_number[i].ToString(), id_puzzle); bd.deletePiecePuzzleByIdPuzzleAndOrIdPuzzle(id_puzzle, id_piece); } bd.deleteSaveByIdPuzzleAndLogin(id_puzzle, login); saveGame(record); } else { saveGame(record); } } catch { } }
private void button2_Click_1(object sender, EventArgs e) { string bildOfPuzzle = ""; string modeGame = ""; if (button2.Text.Equals("Начать заново")) { ConnDatabase bd = new ConnDatabase(); bd.deleteSaveByIdPuzzleAndLogin(id_puzzle_curr, login); bd.deleteGameByIdPuzzleAndLogin(id_puzzle_curr, login); } if ((radioButton1.Checked) || (radioButton2.Checked) || (radioButton3.Checked)) { if (radioButton1.Checked) { bildOfPuzzle = "На поле"; } else if (radioButton2.Checked) { bildOfPuzzle = "В куче"; } else if (radioButton3.Checked) { bildOfPuzzle = "На ленте"; } if ((radioButton7.Checked) || (radioButton8.Checked)) { if (radioButton7.Checked) { modeGame = "На время"; } else if (radioButton8.Checked) { modeGame = "На очки"; } GameOnField gameOnFieldForm = new GameOnField(id_puzzle_curr, bildOfPuzzle, modeGame, login, forma, false); gameOnFieldForm.Show(); exit = false; this.Close(); } else { MessageBox.Show("Выберите режим игры!"); } } else { MessageBox.Show("Выберите режим сборки!"); } }
public void setPieceIfOnRightLocation(object pic) { if (first_move) { timer1.Enabled = true; stopWatch.Start(); first_move = false; } currentmoves++; PicBox picture = (PicBox)pic; bool is_moved_top_piece = true; bool is_this_top_piece = true; char place = (char)((object[])picture.Tag)[1]; Point rightxy = (Point)((object[])picture.Tag)[0]; bool need_to_update_strip = false; ConnDatabase bd = new ConnDatabase(); string id_piece = ""; List <string> game = new List <string>(); picture.Invalidate(); if (triangle) { Color iii = ((Bitmap)picture.Image).GetPixel(5, 5); is_moved_top_piece = !(iii.ToArgb() == Color.Transparent.ToArgb()); } if ((picture.Location.X < (rightxy.X + (btm1[0].Width / 2))) && (picture.Location.X > (rightxy.X - (btm1[0].Width / 2))) && (picture.Location.Y < (rightxy.Y + (btm1[0].Height / 2))) && (picture.Location.Y > (rightxy.Y - (btm1[0].Height / 2)))) { picture.Location = rightxy; picture.Invalidate(); picture.Enabled = false; picture.BorderStyle = BorderStyle.Fixed3D; if (game_mode.Equals("На ленте")) { object[] o = new object[2]; o[0] = rightxy; o[1] = 'f'; picture.Tag = o; if (place == 's') { need_to_update_strip = true; } } } if (game_mode.Equals("На поле")) { //найти ячейку на которую стал пазл int r = 0; int old_num = 0; bool www = false; int l = verticalCountOfPieces * horisontalCountOfPieces; if (triangle) { l *= 2; } //как-то не проверить себя самого while ((old_num < l) && !((char)(((object[])pb[old_num].Tag)[1]) == 'o')) { old_num++; } while ((r < l) && (!www)) { Color iii = ((Bitmap)pb[r].Image).GetPixel(5, 5); is_this_top_piece = !(iii.ToArgb() == Color.Transparent.ToArgb()); if (r != old_num) { if ((picture.Location.X > (pb[r].Location.X - (btm1[0].Width / 2))) && (picture.Location.X < (pb[r].Location.X + (btm1[0].Width / 2))) && (picture.Location.Y < pb[r].Location.Y + (btm1[0].Height / 2)) && (picture.Location.Y > (pb[r].Location.Y - (btm1[0].Height / 2)))) { if (pb[r].Enabled) { if (is_this_top_piece == is_moved_top_piece) { www = true; //устанавливаю туда, куда он стал picture.Location = pb[r].Location; picture.BringToFront(); picture.Invalidate(); pb[r].Location = oldLocation; pb[r].BringToFront(); pb[r].Invalidate(); if (pb[r].Location.X == ((Point)((object[])pb[r].Tag)[0]).X) { if (pb[r].Location.Y == ((Point)((object[])pb[r].Tag)[0]).Y) { pb[r].Enabled = false; pb[r].BorderStyle = BorderStyle.Fixed3D; } } } } } } r++; } if (!www) { picture.Location = oldLocation; picture.Invalidate(); } object[] o = new object[2]; o[0] = (Point)(((object[])picture.Tag)[0]); o[1] = ' '; picture.Tag = o; } //лента if (game_mode.Equals("На ленте")) { if ((currentLocationOfStripZoneTopLeft.X < picture.Location.X) && (picture.Location.X < currentLocationOfStripZoneBottomRight.X)) { if ((currentLocationOfStripZoneTopLeft.Y < picture.Location.Y) && (picture.Location.Y < currentLocationOfStripZoneBottomRight.Y)) { //значит в зоне ленты if (!(place == 's')) { need_to_update_strip = true; object[] o = new object[2]; o[0] = rightxy; o[1] = 'n'; picture.Tag = o; } } } if (place == 's') { need_to_update_strip = true; object[] o = new object[2]; o[0] = rightxy; o[1] = 'f'; picture.Tag = o; } } if (need_to_update_strip) { updateStrip(); } int i = 0; while ((i < pb.Count) && (pb[i].Enabled == false)) { i++; } if (i == pb.Count) { string res = ""; double points = 0; int l = verticalCountOfPieces * horisontalCountOfPieces; if (triangle) { l *= 2; } TimeSpan ts = stopWatch.Elapsed; ts.Add(fromSave); int sec = ts.Hours * 60 * 60 + ts.Minutes * 60 + ts.Seconds; if (record.Equals("На очки")) { points = currentmoves / (l); } else { points = sec / (l); } if (points < betweenGreatAndNormal) { points = GREAT / points; } else if (points > betweenNormalAndBad) { points = BAD / points; } else { points = NORMAL / points; } points *= complexityKoeff; res = ((int)points).ToString(); //проверка сохраненной игры game = bd.selectAllAboutGameByLoginAndIdPuzzle(login, id_puzzle); if (game.Count != 0) { bd.deleteGameByIdPuzzleAndLogin(id_puzzle, login); for (int k = 0; k < l; k++) { id_piece = bd.selectIDPiece(k.ToString(), id_puzzle); bd.deletePiecePuzzleByIdPuzzleAndOrIdPuzzle(id_puzzle, id_piece); } bd.deleteSaveByIdPuzzleAndLogin(id_puzzle, login); } string result = bd.selectResults(login); try { points += Int32.Parse(result); } catch { points += 0; } bd.setResults(login, ((int)points).ToString()); if (MessageBox.Show("Победа!Ваш результат: " + res) == DialogResult.OK) { stopWatch.Stop(); timer1.Enabled = false; close_without_ask = true; hhh.Close(); this.Close(); } } }