public SPlayer[] GetPlayer(int Round, int numPlayer) { if (NumPlayer == 0) return new SPlayer[1]; if (Round >= NumRounds) return new SPlayer[1]; SPlayer[] player = new SPlayer[numPlayer]; for (int p = 0; p < player.Length; p++) { player[p].Name = _Rounds[Round, p].Name; player[p].Points = _Rounds[Round, p].Points; player[p].PointsGoldenNotes = _Rounds[Round, p].PointsGoldenNotes; player[p].PointsLineBonus = _Rounds[Round, p].PointsLineBonus; player[p].SongID = _Rounds[Round, p].SongID; player[p].LineNr = _Rounds[Round, p].LineNr; player[p].Difficulty = _Rounds[Round, p].Difficulty; player[p].Medley = _Rounds[Round, p].Medley; player[p].Duet = _Rounds[Round, p].Duet; player[p].ShortSong = _Rounds[Round, p].ShortSong; player[p].DateTicks = _Rounds[Round, p].DateTicks; player[p].SongFinished = _Rounds[Round, p].SongFinished; player[p].ProfileID = _Rounds[Round, p].ProfileID; } return player; }
public static int AddScore(SPlayer player) { SQLiteConnection connection = new SQLiteConnection(); connection.ConnectionString = "Data Source=" + _HighscoreFilePath; SQLiteCommand command; try { connection.Open(); } catch (Exception) { return -1; } command = new SQLiteCommand(connection); int DataBaseSongID = GetDataBaseSongID(player, command); int result = AddScore(player, command, DataBaseSongID); connection.Close(); connection.Dispose(); return result; }
public void SetPoints(int Round, int SongID, SPlayer[] Player, bool Medley, bool Duet, bool ShortSong) { long DateTicks = DateTime.Now.Ticks; for (int player = 0; player < Player.Length; player++) { _Rounds[Round, player].SongID = SongID; _Rounds[Round, player].LineNr = Player[player].LineNr; _Rounds[Round, player].Points = Player[player].Points; _Rounds[Round, player].PointsGoldenNotes = Player[player].PointsGoldenNotes; _Rounds[Round, player].PointsLineBonus = Player[player].PointsLineBonus; _Rounds[Round, player].Medley = Medley; _Rounds[Round, player].Duet = Duet; _Rounds[Round, player].ShortSong = ShortSong; _Rounds[Round, player].DateTicks = DateTicks; _Rounds[Round, player].SongFinished = Player[player].SongFinished; } }
public CPoints(int NumRounds, SPlayer[] Player) { _Rounds = new SPlayer[NumRounds, Player.Length]; for (int round = 0; round < NumRounds; round++) { for (int player = 0; player < Player.Length; player++) { _Rounds[round, player].ProfileID = Player[player].ProfileID; _Rounds[round, player].Name = Player[player].Name; _Rounds[round, player].Difficulty = Player[player].Difficulty; _Rounds[round, player].Points = 0f; _Rounds[round, player].PointsGoldenNotes = 0f; _Rounds[round, player].PointsLineBonus = 0f; _Rounds[round, player].Medley = false; _Rounds[round, player].Duet = false; _Rounds[round, player].ShortSong = false; _Rounds[round, player].SongFinished = false; } } }
public static int AddScore(string PlayerName, int Score, int LineNr, long Date, int Medley, int Duet, int ShortSong, int Diff, string Artist, string Title, int NumPlayed, string FilePath) { SPlayer player = new SPlayer(); player.Name = PlayerName; player.Points = Score; player.LineNr = LineNr; player.DateTicks = Date; player.Medley = (Medley == 1); player.Duet = (Duet == 1); player.ShortSong = (ShortSong == 1); player.Difficulty = (EGameDifficulty)Diff; SQLiteConnection connection = new SQLiteConnection(); SQLiteCommand command; connection.ConnectionString = "Data Source=" + FilePath; try { connection.Open(); } catch (Exception) { return -1; } command = new SQLiteCommand(connection); int DataBaseSongID = GetDataBaseSongID(Artist, Title, NumPlayed, command); int result = AddScore(player, command, DataBaseSongID); command.Dispose(); connection.Close(); connection.Dispose(); return result; }
private static int GetDataBaseSongID(SPlayer player, SQLiteCommand command) { CSong song = CSongs.GetSong(player.SongID); if (song == null) return -1; command.CommandText = "SELECT id FROM Songs WHERE [Title] = @title AND [Artist] = @artist"; command.Parameters.Add("@title", System.Data.DbType.String, 0).Value = song.Title; command.Parameters.Add("@artist", System.Data.DbType.String, 0).Value = song.Artist; SQLiteDataReader reader = null; try { reader = command.ExecuteReader(); } catch (Exception) { throw; } if (reader != null && reader.HasRows) { reader.Read(); int id = reader.GetInt32(0); reader.Close(); reader.Dispose(); return id; } else { if (reader != null) reader.Close(); command.CommandText = "INSERT INTO Songs (Title, Artist, NumPlayed) " + "VALUES (@title, @artist, 0)"; command.Parameters.Add("@title", System.Data.DbType.String, 0).Value = song.Title; command.Parameters.Add("@artist", System.Data.DbType.String, 0).Value = song.Artist; command.ExecuteNonQuery(); command.CommandText = "SELECT id FROM Songs WHERE [Title] = @title AND [Artist] = @artist"; command.Parameters.Add("@title", System.Data.DbType.String, 0).Value = song.Title; command.Parameters.Add("@artist", System.Data.DbType.String, 0).Value = song.Artist; reader = null; try { reader = command.ExecuteReader(); } catch (Exception) { throw; } if (reader != null) { reader.Read(); int id = reader.GetInt32(0); reader.Close(); reader.Dispose(); return id; } } if (reader != null) { reader.Close(); reader.Dispose(); } return -1; }
public static void LoadScore(ref List<SScores> Score, SPlayer player) { SQLiteConnection connection = new SQLiteConnection(); connection.ConnectionString = "Data Source=" + _HighscoreFilePath; SQLiteCommand command; Score = new List<SScores>(); try { connection.Open(); } catch (Exception) { return; } command = new SQLiteCommand(connection); int Medley = 0; if (player.Medley) Medley = 1; int Duet = 0; if (player.Duet) Duet = 1; int DataBaseSongID = GetDataBaseSongID(player, command); if (DataBaseSongID >= 0) { command.CommandText = "SELECT PlayerName, Score, Date, Difficulty, LineNr, id FROM Scores " + "WHERE [SongID] = @SongID AND [Medley] = @Medley AND [Duet] = @Duet " + "ORDER BY [Score] DESC"; command.Parameters.Add("@SongID", System.Data.DbType.Int32, 0).Value = DataBaseSongID; command.Parameters.Add("@Medley", System.Data.DbType.Int32, 0).Value = Medley; command.Parameters.Add("@Duet", System.Data.DbType.Int32, 0).Value = Duet; SQLiteDataReader reader = null; try { reader = command.ExecuteReader(); } catch (Exception) { throw; } if (reader != null && reader.HasRows) { while (reader.Read()) { SScores score = new SScores(); score.Name = reader.GetString(0); score.Score = reader.GetInt32(1); score.Date = new DateTime(reader.GetInt64(2)).ToString("dd/MM/yyyy"); score.Difficulty = (EGameDifficulty)reader.GetInt32(3); score.LineNr = reader.GetInt32(4); score.ID = reader.GetInt32(5); Score.Add(score); } reader.Close(); reader.Dispose(); } } command.Dispose(); connection.Close(); connection.Dispose(); }
public static int AddScore(SPlayer player) { int lastInsertID = -1; SQLiteConnection connection = new SQLiteConnection(); connection.ConnectionString = "Data Source=" + _HighscoreFilePath; SQLiteCommand command; try { connection.Open(); } catch (Exception) { return -1; } command = new SQLiteCommand(connection); int DataBaseSongID = GetDataBaseSongID(player, command); if (DataBaseSongID >= 0) { int Medley = 0; if (player.Medley) Medley = 1; int Duet = 0; if (player.Duet) Duet = 1; command.CommandText = "INSERT INTO Scores (SongID, PlayerName, Score, LineNr, Date, Medley, Duet, Difficulty) " + "VALUES (@SongID, @PlayerName, @Score, @LineNr, @Date, @Medley, @Duet, @Difficulty)"; command.Parameters.Add("@SongID", System.Data.DbType.Int32, 0).Value = DataBaseSongID; command.Parameters.Add("@PlayerName", System.Data.DbType.String, 0).Value = player.Name; command.Parameters.Add("@Score", System.Data.DbType.Int32, 0).Value = (int)Math.Round(player.Points); command.Parameters.Add("@LineNr", System.Data.DbType.Int32, 0).Value = (int)player.LineNr; command.Parameters.Add("@Date", System.Data.DbType.Int64, 0).Value = player.DateTicks; command.Parameters.Add("@Medley", System.Data.DbType.Int32, 0).Value = Medley; command.Parameters.Add("@Duet", System.Data.DbType.Int32, 0).Value = Duet; command.Parameters.Add("@Difficulty", System.Data.DbType.Int32, 0).Value = (int)player.Difficulty; command.ExecuteNonQuery(); //Read last insert line command.CommandText = "SELECT id FROM Scores ORDER BY Date DESC LIMIT 0, 1"; SQLiteDataReader reader = null; try { reader = command.ExecuteReader(); } catch (Exception) { throw; } if (reader != null && reader.HasRows) { while (reader.Read()) { lastInsertID = reader.GetInt32(0); } reader.Close(); reader.Dispose(); } } command.Dispose(); connection.Close(); connection.Dispose(); return lastInsertID; }
public static int AddScore(SPlayer player) { return(_HighscoreDB == null ? -1 : _HighscoreDB.AddScore(player)); }
public virtual void NextRound(SPlayer[] Player) { if (_CurrentSong < _SongQueque.Count && _SongQueque.Count > 0) { if (_CurrentSong > -1) { _Points.SetPoints( _CurrentSong, _SongQueque[_CurrentSong].SongID, Player, _SongQueque[_CurrentSong].GameMode == EGameMode.TR_GAMEMODE_MEDLEY, _SongQueque[_CurrentSong].GameMode == EGameMode.TR_GAMEMODE_DUET, _SongQueque[_CurrentSong].GameMode == EGameMode.TR_GAMEMODE_SHORTSONG); } _CurrentSong++; } }
public virtual void Start(SPlayer[] Player) { _Points = new CPoints(_SongQueque.Count, Player); }
private static int GetDataBaseSongID(SPlayer player, SQLiteCommand command) { CSong song = CSongs.GetSong(player.SongID); if (song == null) return -1; return GetDataBaseSongID(song.Artist, song.Title, 0, command); }
private static int AddScore(SPlayer player, SQLiteCommand command, int DataBaseSongID) { int lastInsertID = -1; if (DataBaseSongID >= 0) { int Medley = 0; if (player.Medley) Medley = 1; int Duet = 0; if (player.Duet) Duet = 1; int ShortSong = 0; if (player.ShortSong) ShortSong = 1; command.CommandText = "SELECT id FROM Scores WHERE SongID = @SongID AND PlayerName = @PlayerName AND Score = @Score AND " + "LineNr = @LineNr AND Date = @Date AND Medley = @Medley AND Duet = @Duet AND ShortSong = @ShortSong AND Difficulty = @Difficulty"; command.Parameters.Add("@SongID", System.Data.DbType.Int32, 0).Value = DataBaseSongID; command.Parameters.Add("@PlayerName", System.Data.DbType.String, 0).Value = player.Name; command.Parameters.Add("@Score", System.Data.DbType.Int32, 0).Value = (int)Math.Round(player.Points); command.Parameters.Add("@LineNr", System.Data.DbType.Int32, 0).Value = (int)player.LineNr; command.Parameters.Add("@Date", System.Data.DbType.Int64, 0).Value = player.DateTicks; command.Parameters.Add("@Medley", System.Data.DbType.Int32, 0).Value = Medley; command.Parameters.Add("@Duet", System.Data.DbType.Int32, 0).Value = Duet; command.Parameters.Add("@ShortSong", System.Data.DbType.Int32, 0).Value = ShortSong; command.Parameters.Add("@Difficulty", System.Data.DbType.Int32, 0).Value = (int)player.Difficulty; SQLiteDataReader reader = null; try { reader = command.ExecuteReader(); } catch (Exception) { ; } if (reader != null && reader.HasRows) { if (reader.Read()) return reader.GetInt32(0); } if (reader != null) reader.Close(); command.CommandText = "INSERT INTO Scores (SongID, PlayerName, Score, LineNr, Date, Medley, Duet, ShortSong, Difficulty) " + "VALUES (@SongID, @PlayerName, @Score, @LineNr, @Date, @Medley, @Duet, @ShortSong, @Difficulty)"; command.Parameters.Add("@SongID", System.Data.DbType.Int32, 0).Value = DataBaseSongID; command.Parameters.Add("@PlayerName", System.Data.DbType.String, 0).Value = player.Name; command.Parameters.Add("@Score", System.Data.DbType.Int32, 0).Value = (int)Math.Round(player.Points); command.Parameters.Add("@LineNr", System.Data.DbType.Int32, 0).Value = (int)player.LineNr; command.Parameters.Add("@Date", System.Data.DbType.Int64, 0).Value = player.DateTicks; command.Parameters.Add("@Medley", System.Data.DbType.Int32, 0).Value = Medley; command.Parameters.Add("@Duet", System.Data.DbType.Int32, 0).Value = Duet; command.Parameters.Add("@ShortSong", System.Data.DbType.Int32, 0).Value = ShortSong; command.Parameters.Add("@Difficulty", System.Data.DbType.Int32, 0).Value = (int)player.Difficulty; command.ExecuteNonQuery(); //Read last insert line command.CommandText = "SELECT id FROM Scores ORDER BY id DESC LIMIT 0, 1"; reader = null; try { reader = command.ExecuteReader(); } catch (Exception) { throw; } if (reader != null && reader.HasRows) { while (reader.Read()) { lastInsertID = reader.GetInt32(0); } reader.Close(); reader.Dispose(); } } return lastInsertID; }
private void UpdateRatings() { CSong song = null; SPlayer[] player = new SPlayer[CGame.NumPlayer]; if (_Round != 0) { song = CGame.GetSong(_Round); if (song == null) return; Texts[htTexts(TextSong)].Text = song.Artist + " - " + song.Title; if (_Points.NumRounds > 1) { Texts[htTexts(TextSong)].Text += " (" + _Round + "/" + _Points.NumRounds + ")"; } player = _Points.GetPlayer(_Round - 1, CGame.NumPlayer); } else { Texts[htTexts(TextSong)].Text = "TR_SCREENSCORE_OVERALLSCORE"; for (int i = 0; i < CGame.NumRounds; i++) { SPlayer[] points = _Points.GetPlayer(i, CGame.NumPlayer); for (int p = 0; p < player.Length; p++) { if (i < 1) { player[p].ProfileID = points[p].ProfileID; player[p].Name = points[p].Name; player[p].Difficulty = points[p].Difficulty; } player[p].Points += points[p].Points; } } for (int p = 0; p < player.Length; p++) { player[p].Points = (int)(player[p].Points / CGame.NumRounds); } } for (int p = 0; p < player.Length; p++) { if (song != null) { if (!song.IsDuet) Texts[htTexts(TextNames[p, CGame.NumPlayer - 1])].Text = player[p].Name; else if (player[p].LineNr == 0 && song.DuetPart1 != "Part 1") Texts[htTexts(TextNames[p, CGame.NumPlayer - 1])].Text = player[p].Name + " (" + song.DuetPart1 + ")"; else if (player[p].LineNr == 1 && song.DuetPart2 != "Part 2") Texts[htTexts(TextNames[p, CGame.NumPlayer - 1])].Text = player[p].Name + " (" + song.DuetPart2 + ")"; else Texts[htTexts(TextNames[p, CGame.NumPlayer - 1])].Text = player[p].Name; } else Texts[htTexts(TextNames[p, CGame.NumPlayer - 1])].Text = player[p].Name; Texts[htTexts(TextScores[p, CGame.NumPlayer - 1])].Text = ((int)Math.Round(player[p].Points)).ToString("0000") + " " + CLanguage.Translate("TR_SCREENSCORE_POINTS"); if (CGame.NumPlayer <= 3) { Texts[htTexts(TextRatings[p, CGame.NumPlayer - 1])].Text = CLanguage.Translate("TR_SCREENSCORE_RATING") + ": " + CLanguage.Translate(GetRating((int)Math.Round(player[p].Points))); Texts[htTexts(TextDifficulty[p, CGame.NumPlayer - 1])].Text = CLanguage.Translate("TR_SCREENSCORE_GAMEDIFFICULTY") + ": " + CLanguage.Translate(player[p].Difficulty.ToString()); } else { Texts[htTexts(TextRatings[p, CGame.NumPlayer - 1])].Text = CLanguage.Translate(GetRating((int)Math.Round(player[p].Points))); Texts[htTexts(TextDifficulty[p, CGame.NumPlayer - 1])].Text = CLanguage.Translate(player[p].Difficulty.ToString()); } StaticPointsBarDrawnPoints[p] = 0.0; Statics[htStatics(StaticPointsBar[p, CGame.NumPlayer - 1])].Rect.H = 0; Statics[htStatics(StaticPointsBar[p, CGame.NumPlayer - 1])].Rect.Y = Statics[htStatics(StaticPointsBarBG[p, CGame.NumPlayer - 1])].Rect.H + Statics[htStatics(StaticPointsBarBG[p, CGame.NumPlayer - 1])].Rect.Y - Statics[htStatics(StaticPointsBar[p, CGame.NumPlayer - 1])].Rect.H; if (player[p].ProfileID >= 0 && player[p].ProfileID < CProfiles.NumProfiles) Statics[htStatics(StaticAvatar[p, CGame.NumPlayer - 1])].Texture = CProfiles.Profiles[player[p].ProfileID].Avatar.Texture; } if (CConfig.ScoreAnimationTime < 1) { for (int p = 0; p < CGame.NumPlayer; p++) { Statics[htStatics(StaticPointsBar[p, CGame.NumPlayer - 1])].Rect.H = ((float)player[p].Points) * (Statics[htStatics(StaticPointsBarBG[p, CGame.NumPlayer - 1])].Rect.H / 10000); Statics[htStatics(StaticPointsBar[p, CGame.NumPlayer - 1])].Rect.Y = Statics[htStatics(StaticPointsBarBG[p, CGame.NumPlayer - 1])].Rect.H + Statics[htStatics(StaticPointsBarBG[p, CGame.NumPlayer - 1])].Rect.Y - Statics[htStatics(StaticPointsBar[p, CGame.NumPlayer - 1])].Rect.H; StaticPointsBarDrawnPoints[p] = player[p].Points; } } timer = new Stopwatch(); timer.Start(); }
public override bool UpdateGame() { SPlayer[] player = new SPlayer[CGame.NumPlayer]; if (_Round != 0) player = _Points.GetPlayer(_Round - 1, CGame.NumPlayer); else { for (int i = 0; i < CGame.NumRounds; i++) { SPlayer[] points = _Points.GetPlayer(i, CGame.NumPlayer); for (int p = 0; p < player.Length; p++) { player[p].Points += points[p].Points; } } for (int p = 0; p < player.Length; p++) { player[p].Points = (int)(player[p].Points/CGame.NumRounds); } } for (int p = 0; p < player.Length; p++) { if (StaticPointsBarDrawnPoints[p] < player[p].Points) { if (CConfig.ScoreAnimationTime >= 1) { StaticPointsBarDrawnPoints[p] = (timer.ElapsedMilliseconds / 1000f) / CConfig.ScoreAnimationTime * 10000; if (StaticPointsBarDrawnPoints[p] > player[p].Points) { StaticPointsBarDrawnPoints[p] = player[p].Points; } Statics[htStatics(StaticPointsBar[p, CGame.NumPlayer - 1])].Rect.H = ((float)StaticPointsBarDrawnPoints[p]) * (Statics[htStatics(StaticPointsBarBG[p, CGame.NumPlayer - 1])].Rect.H / 10000); Statics[htStatics(StaticPointsBar[p, CGame.NumPlayer - 1])].Rect.Y = Statics[htStatics(StaticPointsBarBG[p, CGame.NumPlayer - 1])].Rect.H + Statics[htStatics(StaticPointsBarBG[p, CGame.NumPlayer - 1])].Rect.Y - Statics[htStatics(StaticPointsBar[p, CGame.NumPlayer - 1])].Rect.H; } } } return true; }
public virtual void NextRound(SPlayer[] Player) { if (_ActualSong < _SongIDs.Count && _SongIDs.Count > 0) { if (_ActualSong > -1) { _Points.SetPoints(_ActualSong, _SongIDs[_ActualSong], Player, _GameMode == EGameMode.Medley, _GameMode == EGameMode.Duet); } _ActualSong++; } }