Пример #1
0
        public bool StartTraining(WarriorType warriortoTrain)
        {
            if (warriortoTrain.FoodCost <= resources.food &&
                 warriortoTrain.StoneCost <= resources.stone &&
                 warriortoTrain.WoodCost <= resources.wood &&
                 warriortoTrain.GoldCost <= resources.gold
                )
            {

                if (warriortoTrain.kind==WarriorType.Kind.Worker)
                {
                    int workers = (from w in warriors where w.type.kind == WarriorType.Kind.Worker select w).Count();
                    if (workers>resources.maxWorkers)
                    {
                        Debug.WriteLine("Not enough houses to create worker.");
                        return false;
                    }
                }

                resources.food -= warriortoTrain.FoodCost;
                resources.stone -= warriortoTrain.StoneCost;
                resources.wood -= warriortoTrain.WoodCost;
                resources.gold -= warriortoTrain.GoldCost;

                warriors.Add(new Warrior(warriortoTrain));

                return true;

            }

            return false;
        }
Пример #2
0
        public JsonResult Train(WarriorType.Kind kind)
        {
            WarriorType warriortoTrain = RunningGame.WarriorTypes.Where(e => e.kind.Equals(kind)).First();

            bool trainingStarted = PlayerVik.StartTraining(warriortoTrain);

            var response = new ClientResponseModels.CreateModel();
            response.Ok = trainingStarted;
            response.TrainingTicks = warriortoTrain.TrainingTime;
            return Json(response, JsonRequestBehavior.AllowGet);
        }