// --------------------------------------------------------------------------------------------- private static void SetLife(ref user_game score, string change) { var maxLife = Int32.Parse(ConfigurationManager.AppSettings["maxLife"]); var lifeChange = Double.Parse(change); // shield reduces loss of life if (lifeChange < 0) { double shieldFactor = (double)(1 - Math.Floor(score.shield / 10) / 10); lifeChange = lifeChange * shieldFactor; } // life in database counts from 0 to "maxLife" as set in Web.config (now: 1000) score.life += (int)(lifeChange / 100 * maxLife); // death if (score.life < 0) { score.life = 0; score.shield = 0; score.rank = 0; } else if (score.life > maxLife) { score.life = maxLife; } }
// --------------------------------------------------------------------------------------------- private static void SetShield(ref user_game score, string change) { score.shield += (Decimal)Double.Parse(change); // keep the shield within proper boudaries var maxShield = Int32.Parse(ConfigurationManager.AppSettings["maxShield"]); if (score.shield > maxShield) { score.shield = maxShield; } else if (score.shield < 0) { score.shield = 0; } }