public bool saveNewInstance(SavedInstance si) { string query = "INSERT INTO " + _savedTable + "(`name`, `board`, `score`, `linescleared`)"; query += " VALUES(\'" + si.Name + "\', \'" + si.Board + "\', \'" + si.Score; query += "\', \'" + si.LinesCleared + "\')"; return(execNonQuery(query)); }
private void preview_Click(object sender, RoutedEventArgs e) { if (list.SelectedItems.Count == 0) { return; } SavedInstance si = (SavedInstance)list.SelectedItem; _preview.Reset(); _preview.Load(si.Board); }
public void Load(SavedInstance si) { Reset(); _board.Reset(); _board.Load(si.Board); _block = null; _nextBlock = null; _score = si.Score; _linesCleared = si.LinesCleared; _level = _linesCleared / 10 + 1; _blockMoveTimer.Interval = (int)(500 / (Math.Pow(1.25, _level - 1))); updateScoreBoard(0); _blockMoveTimer.Enabled = true; _gameRunning = true; handleMenuItems(); }
public SavedInstance getSavedInstanceById(int id) { SavedInstance si = new SavedInstance(); string query = "select * from " + _savedTable + " where id=" + id; SQLiteDataReader reader = execReader(query); while (reader.Read()) { si.Id = reader.GetInt32(reader.GetOrdinal("id")); si.Name = (string)reader["name"]; si.Board = (string)reader["board"]; si.Score = reader.GetInt32(reader.GetOrdinal("score")); si.LinesCleared = reader.GetInt32(reader.GetOrdinal("linescleared")); } return(si); }
public ArrayList getAllInstances() { ArrayList list = new ArrayList(); string query = "select * from " + _savedTable; SQLiteDataReader reader = execReader(query); while (reader.Read()) { SavedInstance si = new SavedInstance(); si.Id = reader.GetInt32(reader.GetOrdinal("id")); si.Name = (string)reader["name"]; si.Board = (string)reader["board"]; si.Score = reader.GetInt32(reader.GetOrdinal("score")); si.LinesCleared = reader.GetInt32(reader.GetOrdinal("linescleared")); list.Add(si); } return(list); }
private void SaveMenu_Click(object sender, RoutedEventArgs e) { if (_gameRunning && !_blockMoveTimer.Enabled) { StringBuilder b = new StringBuilder(_board.ToString()); if (_block != null) { foreach (Point p in _block.Shape) { b[(int)(p.Y + _block.Coordinates.Y) * _width + (int)(p.X + _block.Coordinates.X)] = '#'; } } string name = Util.ShowDialog("Choose a name:", "Save as"); Debug.WriteLine(name); SavedInstance si = new SavedInstance(name, b.ToString(), _score, _linesCleared); _database.saveNewInstance(si); } handleMenuItems(); }