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 saveGame(string rec) { ConnDatabase bd = new ConnDatabase(); string id_piece = ""; int l = verticalCountOfPieces * horisontalCountOfPieces; if (triangle) { l *= 2; } if (rec == "На время") { TimeSpan ts = stopWatch.Elapsed.Add(fromSave); string formatts = ts.ToString(@"hh\:mm\:ss"); bd.insertInGame(id_puzzle, login, game_mode, record, formatts); for (int i = 0; i < l; i++) { bd.insertInPuzzlePiece(serial_number[i].ToString(), ((Point)((object[])pb[i].Tag)[0]).X.ToString(), ((Point)((object[])pb[i].Tag)[0]).Y.ToString(), id_puzzle); id_piece = bd.selectIDPiece(serial_number[i].ToString(), id_puzzle); if ((game_mode.Equals("На ленте")) && (((char)((object[])pb[i].Tag)[1] == 'n') || ((char)((object[])pb[i].Tag)[1] == 's'))) { bd.insertInSave(id_piece, id_puzzle, login, (55).ToString(), (this.Size.Height - h - buttonLeft.Height - 38 + 5).ToString()); } else { bd.insertInSave(id_piece, id_puzzle, login, pb[i].Location.X.ToString(), pb[i].Location.Y.ToString()); } } MessageBox.Show("Игра успешно сохранена!"); } else { bd.insertInGame(id_puzzle, login, game_mode, record, currentmoves.ToString()); for (int i = 0; i < l; i++) { bd.insertInPuzzlePiece(i.ToString(), ((Point)((object[])pb[i].Tag)[1]).X.ToString(), ((Point)((object[])pb[i].Tag)[1]).Y.ToString(), id_puzzle); id_piece = bd.selectIDPiece(i.ToString(), id_puzzle); bd.insertInSave(id_piece, id_puzzle, login, pb[i].Location.X.ToString(), pb[i].Location.Y.ToString()); } 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(); } } }