public static IGameState CreateGameState(GameplayConstants constants) { List <StateItem> items = new List <StateItem>(); StateItemFloat myMaxEnergy = new StateItemFloat(StateItemType.MyMaxEnergy.ToString(), 0, 100, InitValue(constants, StateItemType.MyMaxEnergy), PerMinute(constants, StateItemType.MyMaxEnergy), true); StateItemInt mySalary = new StateItemInt(StateItemType.MySalary.ToString(), InitValue(constants, StateItemType.MySalary)); StateItemInt partnerSalary = new StateItemInt(StateItemType.PartnerSalary.ToString(), InitValue(constants, StateItemType.PartnerSalary)); items.Add(new StateItemFloat(StateItemType.Age.ToString(), 0, 99999, InitValue(constants, StateItemType.Age), PerMinute(constants, StateItemType.Age), true)); items.Add(myMaxEnergy); items.Add(new StateItemFloat(StateItemType.MyEnergy.ToString(), 0, () => myMaxEnergy.GetValue <float>(), InitValue(constants, StateItemType.MyEnergy), PerMinute(constants, StateItemType.MyEnergy), true)); items.Add(new StateItemFloat(StateItemType.MyFood.ToString(), 0, 100, InitValue(constants, StateItemType.MyFood), PerMinute(constants, StateItemType.MyFood), true)); items.Add(new StateItemFloat(StateItemType.MyHappiness.ToString(), 0, 100, InitValue(constants, StateItemType.MyHappiness), PerMinute(constants, StateItemType.MyHappiness), true)); items.Add(new StateItemFloat(StateItemType.MyHealth.ToString(), 0, 100, InitValue(constants, StateItemType.MyHealth), PerMinute(constants, StateItemType.MyHealth), true)); items.Add(new StateItemFloat(StateItemType.FamilyFood.ToString(), 0, 100, InitValue(constants, StateItemType.FamilyFood), PerMinute(constants, StateItemType.FamilyFood), false)); items.Add(new StateItemFloat(StateItemType.FamilyHappiness.ToString(), 0, 100, InitValue(constants, StateItemType.FamilyHappiness), PerMinute(constants, StateItemType.FamilyHappiness), false)); items.Add(new StateItemFloat(StateItemType.FamilyHealth.ToString(), 0, 100, InitValue(constants, StateItemType.FamilyHealth), PerMinute(constants, StateItemType.FamilyHealth), false)); items.Add(new StateItemMoney(StateItemType.Money.ToString(), InitValue(constants, StateItemType.Money), () => mySalary.GetValue <int>(), () => partnerSalary.GetValue <int>())); items.Add(mySalary); items.Add(partnerSalary); items.Add(new StateItemInt(StateItemType.FoodSupplies.ToString(), InitValue(constants, StateItemType.FoodSupplies))); List <StateAction> actions = constants.GetPlayerActions(); return(new GameStateImpl(items, actions)); }
// Update is called once per frame void Update() { if (GameplayConstants.isGameOver) { return; } if (gameMaker.CheckGameOver()) { GameplayConstants.SetGameOver(true); return; } score.text = string.Format(" " + ++scoreCounter); if (!(Input.GetKey(KeyCode.Space))) { foreach (var o in world) { o.transform.position += Vector3.back * GameplayConstants.GameSpeedMultiplier; } } gameMaker.UpdateTheWorld(); }
/** * SETTERS AND CHANGERS */ // defence public void DealDamage(float amount, UnitStats attackerStats, UnitStatsComponent attackerStatsComponent) { if (Invulnerable) { return; } // Check if the target evades the projectile and proceed if it doesn't if (!(EvasionChance > 0f && Random.value < EvasionChance)) { // Check if the thrower crits and increase damage if successful if (attackerStats.critChance > 0f && Random.value < attackerStats.critChance) { // Crit was successful amount *= (1 + attackerStats.critExtraMultiplier); } // Modify damage from target's armor and armor type, and attacker's attack type. amount *= GameplayConstants.ArmorDamageReduction(attackerStats.attackType, ArmorType, Armor); unitStats.health -= amount; if (attackerStatsComponent) { attackerStatsComponent.ApplyOnAttackEffects(amount); } if (IsDead) { // Give gold to killing player (always gives to Client as-of-now) GameObject client = GameObject.Find("Client"); client.GetComponent <GoldContainer>().ChangeGold(gameObject.GetComponent <UnitStatsComponent>().GoldDropped); // Give experience to the killing team (always gives to west team as-of-now) Teams team = Globals.Teams; int teamMembers = team.CountTeam(true); foreach (GameObject hero in team.WestTeam) { if (hero) { // Divide experience between all Heroes on the killing team, calculated from a base value factored by the killed unit's level float experience = GameplayConstants.MonsterLevelOneExpDrop * Mathf.Pow(GameplayConstants.MonsterExpDropIncreaseFactorPerLevel, MonsterLevel) / teamMembers; hero.GetComponent <HeroStatsComponent>().AddExperience(experience); } } // and destroy Destroy(gameObject); } else if (Health > MaxHealth) { unitStats.health = unitStats.maxHealth; } } }
// Use this for initialization void Start() { Debug.Log("init of GenerateBoxes.cs"); //GameplayConstants should be a init class, where I should put all numbers and use the instance gameMaker = new GameMaker(GameplayConstants.rowCount, GameplayConstants.rowWidth, GameplayConstants.groundFrom, GameplayConstants.groundTo, Player, new SimpleLevelGenerator(), new SimpleGameRules(), new InfiniteWorldCreator()); GameplayConstants.SetGameOver(false); gameMaker.LoadTheLevel(); gameMaker.InitializeTheWorld(); world = gameMaker.GetCreatedWorldObjects(); }
private static int PerMinute(GameplayConstants constants, StateItemType type) { return(constants.GetChangePerMinute(type.ToString())); }
private static int InitValue(GameplayConstants constants, StateItemType type) { return(constants.GetInitialValue(type.ToString())); }
public void Test() { // TODO GameStateFactory.CreateGameState(GameplayConstants.CreateEmptyConstants()); }