我有一個從遊戲中實時返回CS:GO統計數據的庫。我正在製作一個存儲統計數據並對其進行分析的程序。我該如何改進這一邏輯? C#
我有這樣的功能:
private void UpdateKills(GameState gs)
{
int currentKills = -1;
if (lastKills == -1) // first time getting player info
{
int temp = gs.Player.MatchStats.Kills;
currentKills = temp;
lastKills = temp;
}
else
{
currentKills = gs.Player.MatchStats.Kills;
int dif = currentKills - lastKills;
if (currentKills == 0 && lastKills != 0) // maybe changed server/map/whatever
{
lastKills = -1;
}
else
{
if (dif != 0 && dif > 0) // player killed someone AND it was not teamkill
{
ps.Kills += dif; // add the kills to the main variable
lastKills = currentKills;
dif = 0;
playSimpleSound();
}
}
}
}
這是我的函數處理殺死。大多數情況下,它工作得很好,但有時它只是嚇壞了,我不知道問題是我的邏輯還是圖書館問題。
注:我使用這個庫:github.com/rakijah/CSGSI
我的邏輯是:
- 獲取玩家殺死
- 增量在PlayerStats那些殺害對象。
我的代碼在邏輯上是正確的嗎?我的代碼可以更「正確」嗎?
你從哪裏得到最後的殺敵? – Eulogy
ps.Kills也來自哪裏?這些靜態變量是什麼? –
你有變量'lastKills'和'ps',這些變量可能被修改,誰知道還有什麼地方。你有奇怪的表達式,如果(dif!= 0 && dif> 0)//玩家殺死了某人並且它不是teamkill',其中'dif!= 0'部分是毫無意義的,因爲'dif> 0'也必須匹配第一部分,完全不清楚這是如何與「玩家殺了某人,而不是團隊技能」有關的。因此,我建議「怪胎」是由於你的邏輯。 –