private void GetField(int idField, TetrisGameBoard board) { BoardPoint[,] result = new BoardPoint[board.Width, board.Height]; SqlCommand comm = GetCommand("GetPoints"); comm.Parameters.Add(new SqlParameter() { ParameterName = "@idField", DbType = DbType.Int32, Value = idField }); DataTable table = new DataTable(); table.Load(comm.ExecuteReader()); if (table.Rows.Count != 0) { for (int i = 0; i < table.Rows.Count; i++) { var row = table.Rows[i]; TColor col = (TColor)row[0]; byte x = (byte)row[1]; byte y = (byte)row[2]; result[x, y] = new BoardPoint(col); } board.Field = result; } }
private void GetFigure(int idSavePoint, TetrisGameBoard board) { GetIdFigWithType(idSavePoint, out int idCurrF, out int idNextF, out int idCurrFType, out int idNextFType); int[,] bodyCurrF = GetFigurePoint(idCurrF, out int colorCurrFig); int[,] bodyNextF = GetFigurePoint(idNextF, out int colorNextFig); board.CurrentFigure = DataBaseLogic.CreateFigure(bodyCurrF, (TColor)colorCurrFig, (FiguresTypes)idCurrFType, board); board.NextFigure = DataBaseLogic.CreateFigure(bodyNextF, (TColor)colorNextFig, (FiguresTypes)idNextFType, board); }
public static bool SaveGame(TetrisGameBoard board, SqlConnectionStringBuilder conn) { bool result; using (var connection = new TetrisConnection(conn)) { result = connection.SaveGamePoint(board); } return(result); }
public bool OpenGamePoint(TetrisGameBoard board, int idSavePoint, int idField) { try { GetFigure(idSavePoint, board); GetField(idField, board); return(true); } catch (SqlException e) { Console.WriteLine(e); return(false); } finally { Dispose(); } }
public bool SaveGamePoint(TetrisGameBoard board) { try { AddSavePoint(board, out int idSaveP, out int idFld, out int idCurrF, out int idNextF); AddPointsField(board, idFld); AddPointsFigure(board.CurrentFigure, idCurrF); AddPointsFigure(board.NextFigure, idNextF); return(true); } catch (SqlException e) { Console.WriteLine(e); return(false); } finally { Dispose(); } }
private void AddSavePoint(TetrisGameBoard board, out int idSaveP, out int idFld, out int idCurrF, out int idNextF) { SqlCommand comm = GetCommand("AddSavePoint"); AddInputParameter(board, comm); SqlParameter idSavePoint = new SqlParameter() { ParameterName = "@IdSaveP", DbType = DbType.Int32, Direction = ParameterDirection.Output }; SqlParameter idField = new SqlParameter() { ParameterName = "@IdFld", DbType = DbType.Int32, Direction = ParameterDirection.Output }; SqlParameter idCurrFig = new SqlParameter() { ParameterName = "@IdCurrFigure", DbType = DbType.Int32, Direction = ParameterDirection.Output }; SqlParameter idNextFig = new SqlParameter() { ParameterName = "@IdNextFigure", DbType = DbType.Int32, Direction = ParameterDirection.Output }; comm.Parameters.Add(idSavePoint); comm.Parameters.Add(idField); comm.Parameters.Add(idCurrFig); comm.Parameters.Add(idNextFig); comm.ExecuteNonQuery(); idSaveP = (int)idSavePoint.Value; idFld = (int)idField.Value; idCurrF = (int)idCurrFig.Value; idNextF = (int)idNextFig.Value; }
private static void AddInputParameter(TetrisGameBoard board, SqlCommand comm) { comm.Parameters.Add(new SqlParameter() { ParameterName = "@Level", DbType = DbType.Int32, Value = board.Level + 1 }); comm.Parameters.Add(new SqlParameter() { ParameterName = "@BurLine", DbType = DbType.Int32, Value = board.BurnedLine }); comm.Parameters.Add(new SqlParameter() { ParameterName = "@Score", DbType = DbType.Int32, Value = board.Score }); comm.Parameters.Add(new SqlParameter() { ParameterName = "@idCurrFigType", DbType = DbType.Int32, Value = (int)board.CurrentFigure.GetFigureType() }); comm.Parameters.Add(new SqlParameter() { ParameterName = "@idNextFigType", DbType = DbType.Int32, Value = (int)board.NextFigure.GetFigureType() }); }
private void AddPointsField(TetrisGameBoard board, int idFld) { SqlCommand comm = GetSqlCommandForAddPoint(out SqlParameter color, out SqlParameter x, out SqlParameter y); comm.Parameters.Add(new SqlParameter() { ParameterName = "@idField", DbType = DbType.Int32, Value = idFld }); for (byte i = 0; i < board.Field.GetLength(1); i++) { for (byte j = 0; j < board.Field.GetLength(0); j++) { if (board.Field[j, i] != null) { color.Value = (int)board.Field[j, i].Col; x.Value = j; y.Value = i; comm.ExecuteNonQuery(); } } } }
public static Figure GetFigure(TetrisGameBoard board) { Figure fig; int choseFigure = Rnd.Next(0, NumberOfFigures); TColor color = (TColor)Rnd.Next(1, NumberOfColors + 1); int[,] body; switch (choseFigure) { case 0: body = new int[, ] { { 1, 0 }, { 2, 0 }, { 2, 1 }, { 2, 2 } }; fig = new LeftG(color, (int[, ])body.Clone(), board); break; case 1: body = new int[, ] { { 2, 0 }, { 2, 1 }, { 1, 2 }, { 2, 2 } }; fig = new RightG(color, (int[, ])body.Clone(), board); break; case 2: body = new int[, ] { { 1, 0 }, { 1, 1 }, { 2, 1 }, { 2, 2 } }; fig = new LeftZigzag(color, (int[, ])body.Clone(), board); break; case 3: body = new int[, ] { { 2, 0 }, { 1, 1 }, { 2, 1 }, { 1, 2 } }; fig = new RightZigzag(color, (int[, ])body.Clone(), board); break; case 4: body = new int[, ] { { 1, 1 }, { 2, 1 }, { 3, 1 }, { 2, 2 } }; fig = new LetterT(color, (int[, ])body.Clone(), board); break; case 5: body = new int[, ] { { 1, 1 }, { 2, 1 }, { 1, 2 }, { 2, 2 } }; fig = new Square(color, (int[, ])body.Clone(), board); break; case 6: body = new int[, ] { { 2, 0 }, { 2, 1 }, { 2, 2 }, { 2, 3 } }; fig = new Stick(color, (int[, ])body.Clone(), board); break; default: body = new int[, ] { { 1, 1 }, { 2, 1 }, { 1, 2 }, { 2, 2 } }; fig = new Square(color, (int[, ])body.Clone(), board); break; } return(fig); }
public static Figure CreateFigure(int[,] bodyCurrF, TColor colorCurrFig, FiguresTypes idCurrFigType, TetrisGameBoard board) { Figure fig = null; switch (idCurrFigType) { case FiguresTypes.LeftG: fig = new LeftG(colorCurrFig, bodyCurrF, board); break; case FiguresTypes.LeftZigzag: fig = new LeftZigzag(colorCurrFig, bodyCurrF, board); break; case FiguresTypes.LetterT: fig = new LetterT(colorCurrFig, bodyCurrF, board); break; case FiguresTypes.RightG: fig = new RightG(colorCurrFig, bodyCurrF, board); break; case FiguresTypes.RightZigzag: fig = new RightZigzag(colorCurrFig, bodyCurrF, board); break; case FiguresTypes.Square: fig = new Square(colorCurrFig, bodyCurrF, board); break; case FiguresTypes.Stick: fig = new Stick(colorCurrFig, bodyCurrF, board); break; } return(fig); }