public bool IsBetterRecord(GameRecord record) { if (records.Count() < RECORD_AMOUNT) { return(true); } else { GameRecord worstRecord = records.First(); return(record.CompareTo(worstRecord) > 0); } }
public bool IsBetterRecordAchieved(int snakeLength) { GameRecord currentResult = new GameRecord("", snakeLength, DateTime.Now); string selectedMap = ReadGameProperties(); if (selectedMap == "Yellow Stone") { return(yellowStoneMapRecord.IsBetterRecord(currentResult)); } else { return(grandCanyonMapRecord.IsBetterRecord(currentResult)); } }
void PopulateRecords(SortedSet <GameRecord> records) { GameRecord r1 = null, r2 = null, r3 = null; foreach (GameRecord r in records) { if (r1 == null) { r1 = r; } else if (r2 == null) { r2 = r1; r1 = r; } else { r3 = r2; r2 = r1; r1 = r; } } if (r1 != null) { name1.Text = r1.Name; length1.Text = r1.SnakeLength.ToString(); date1.Text = r1.Date.ToString(); } if (r2 != null) { name2.Text = r2.Name; length2.Text = r2.SnakeLength.ToString(); date2.Text = r2.Date.ToString(); } if (r3 != null) { name3.Text = r3.Name; length3.Text = r3.SnakeLength.ToString(); date3.Text = r3.Date.ToString(); } }
public void ShowNewRecordForm() { GameRecord currentResult = new GameRecord("", snake.GetLength(), DateTime.Now); string selectedMap = ReadGameProperties(); if (selectedMap == "Yellow Stone") { currentResult.TargetGroup = yellowStoneMapRecord; } else { currentResult.TargetGroup = grandCanyonMapRecord; } if (this.InvokeRequired) { ShowNewRecordFormCallback callback = new ShowNewRecordFormCallback(ShowNewRecordForm); Invoke(callback); } else { new NewRecordForm(currentResult).Show(this); } }
public bool WriteRecordsToFile(string fileName) { string[] serializedRecord = new string[RECORD_AMOUNT]; try { int index = 0; while (records.Count() != 0) { GameRecord r = records.First(); serializedRecord[index++] = SerializeGameRecord(r); records.Remove(r); } File.WriteAllLines(fileName + ".txt", serializedRecord); } catch (Exception e) { Debug.WriteLine(e.Message); return(false); } return(true); }
public NewRecordForm(GameRecord currentResult) { InitializeComponent(); this.currentResult = currentResult; }
public string SerializeGameRecord(GameRecord record) { return(record.Name + "|" + record.SnakeLength + "|" + record.Date); }