示例#1
0
        public List <Field> selectTargets(Battlefield battlefield, Field source, int SkillRange, int MaxTargets, bool targetSelf)
        {
            List <Field> targets = new List <Field>();

            for (int x = -SkillRange; x <= SkillRange; x++)
            {
                for (int y = -SkillRange; y <= SkillRange; y++)
                {
                    if (!(x == 0 && y == 0 && !targetSelf))
                    {
                        try
                        {
                            if (battlefield.GetField(source.x + x, source.y + y).GetHero() != null)
                            {
                                targets.Add(battlefield.GetField(source.x + x, source.y + y));
                            }
                        }
                        catch (Exception e)
                        {
                        }
                    }
                }
            }

            return(targets);
        }
        public List <Field> selectTargets(Battlefield battlefield, Field source, int SkillRange, int MaxTargets, bool targetSelf)
        {
            List <FieldDistance> potencionalTargets = new List <FieldDistance>();
            List <Field>         targets            = new List <Field>();

            for (int x = -SkillRange; x <= SkillRange; x++)
            {
                for (int y = -SkillRange; y <= SkillRange; y++)
                {
                    if (!(x == 0 && y == 0 && !targetSelf))
                    {
                        try
                        {
                            if (battlefield.GetField(source.x + x, source.y + y).GetHero() != null)
                            {
                                potencionalTargets.Add(new FieldDistance(battlefield.GetField(source.x + x, source.y + y),
                                                                         CalculateRange(x, y, source.x, source.y)));
                            }
                        }
                        catch
                        {
                        }
                    }
                }
            }

            potencionalTargets.OrderBy(potencionalTargets => potencionalTargets.distanceFromSource).ToList();

            for (int i = 0; i < MaxTargets - 1; i++)
            {
                //Console.WriteLine(target.field.Hero.GetHeroName());
                try
                {
                    targets.Add(potencionalTargets[i].field);
                }
                catch
                {
                }
            }

            return(targets);
        }
示例#3
0
        public override bool Execute(Battlefield Battlefield)
        {
            if (this.GatheringHero == null)
            {
                return(false);
            }

            Field Field = Battlefield.GetField(GatheringHero.GetCoordinates()[0], GatheringHero.GetCoordinates()[1]);

            if (Field == null)
            {
                return(false);
            }

            Resource Resource = Field.GatherResource(GatheringHero.GetHarvestPower());

            if (Resource.Type == ResourceType.None)
            {
                return(false);
            }

            if (!GatheringHero.PayActionCost(HarvestActionCost))
            {
                if (Field.Resource == null)
                {
                    Field.Resource = Resource;
                }
                else
                {
                    Field.Resource.Add(Resource);
                }
                return(false);
            }

            if (!GatheringHero.AddResource(Resource))
            {
                if (Field.Resource == null)
                {
                    Field.Resource = Resource;
                }
                else
                {
                    Field.Resource.Add(Resource);
                }
                GatheringHero.BoostActionPoints(HarvestActionCost);
                return(false);
            }

            return(true);
        }
        public List <Field> selectTargets(Battlefield battlefield, Field source, int SkillRange, int MaxTargets, bool targetSelf)
        {
            List <Field> targets = new List <Field>();

            Console.WriteLine("You are standing in " + source.x + "," + source.y + " Skill range: " + SkillRange);

            while (true)
            {
                try {
                    Console.WriteLine("Select target coordinates (x,y):");
                    string   coordinates = Console.ReadLine();
                    string[] c           = coordinates.Split(',');
                    int      x           = Convert.ToInt32(c[0]);
                    int      y           = Convert.ToInt32(c[1]);

                    if (x > -1 && y > -1 && CalculateRange(x, y, source.x, source.y, SkillRange) == true) //ak nie som mimo mapy a range skillu sedi
                    {
                        /* if (battlefield.GetField(x, y).Hero == null)
                         * {
                         *   Console.WriteLine("No hero on selected coordinates!");
                         * }
                         * else
                         * {*/
                        Console.WriteLine("Adding selected coordinates " + x + "," + y + " to targets list!");
                        targets.Add(battlefield.GetField(x, y));
                        break;
                        //}
                    }
                    else
                    {
                        Console.WriteLine("Insuficient skill range!");
                    }
                }
                catch
                {
                    Console.WriteLine("Incorrect input!");
                }
            }

            return(targets);
        }
示例#5
0
        private void ReceiveCommands()
        {
            this.HeroQueue = this.Battlefield.GetAllHeroes();
            this.CommandStackNormal.Push(this.Battlefield.CreateMemento());
            this.RenderBattleField();

            String CommandInput;

            String[] Tokens;

            while (true)
            {
                CommandInput = Console.ReadLine();
                Tokens       = CommandInput.Split(' ');
                switch (Tokens[0])
                {
                case "move":
                    if (Tokens.Length != 2)
                    {
                        Console.WriteLine("Invalid syntax");
                        continue;
                    }
                    List <(int, int)> Coordinates = new List <(int, int)>();
                    int start_x = this.HeroQueue.First().GetCoordinates()[0];
                    int start_y = this.HeroQueue.First().GetCoordinates()[1];

                    if (Tokens[1].Split(',').Count() != 2)
                    {
                        Console.WriteLine("Invalid syntax");
                        continue;
                    }
                    int end_x = int.Parse(Tokens[1].Split(',')[0]);
                    int end_y = int.Parse(Tokens[1].Split(',')[1]);

                    int x_incerement = start_x < end_x ? 1 : -1;
                    int y_incerement = start_y < end_y ? 1 : -1;

                    int i = start_x;
                    int j = start_y;
                    while (i != end_x)
                    {
                        Coordinates.Add((i, j));
                        i += x_incerement;
                    }
                    while (j != end_y)
                    {
                        Coordinates.Add((i, j));
                        j += y_incerement;
                    }
                    Coordinates.Add((i, j));
                    Console.WriteLine(Coordinates.Count + " coordinates");

                    Command MoveCommand = new CommandMove(Coordinates);

                    lock (Refreshlock)
                    {
                        RefreshBattleField = true;
                        Monitor.PulseAll(Refreshlock);
                    }
                    this.ExecuteCommand(MoveCommand);
                    lock (Refreshlock)
                    {
                        RefreshBattleField = false;
                    }
                    Thread.Sleep(500);
                    this.RenderBattleField();
                    break;

                case "skill":
                    if (Tokens.Length != 3)
                    {
                        Console.WriteLine("Invalid syntax - need 3 params");
                        continue;
                    }

                    int SkillID = -1;
                    if (!int.TryParse(Tokens[1], out SkillID))
                    {
                        Console.WriteLine("Invalid syntax - param 1 must be integer");
                        continue;
                    }

                    Skill Skill = HeroQueue.First().GetSkill(SkillID);
                    if (Skill == null)
                    {
                        Console.WriteLine("Skill with id " + SkillID + " does not exist");
                        continue;
                    }

                    if (Skill.Passive)
                    {
                        Console.WriteLine("Cannot actively use passive skill");
                        continue;
                    }

                    ITriggerBehaviour TargetingStrategy = null;
                    switch (Tokens[2])
                    {
                    case "one":
                        TargetingStrategy = SelectOneTarget.GetInstance();
                        break;

                    case "auto":
                        TargetingStrategy = SelectAutoTarget.GetInstance();
                        break;

                    case "area":
                        TargetingStrategy = SelectArea.GetInstance();
                        break;

                    case "self":
                        TargetingStrategy = SelectSelf.GetInstance();
                        break;

                    default:
                        break;
                    }
                    if (TargetingStrategy == null)
                    {
                        Console.WriteLine("Invalid target strategy option");
                        continue;
                    }

                    Command UseSkillCommand = new CommandUseSkill(Skill, Battlefield.GetField(HeroQueue.First().GetCoordinates()[0], HeroQueue.First().GetCoordinates()[1]), TargetingStrategy);
                    this.ExecuteCommand(UseSkillCommand);
                    this.RenderBattleField();
                    break;

                case "gather":
                    Command GatherCommand = new CommandGather(this.HeroQueue.First());
                    this.ExecuteCommand(GatherCommand);
                    this.RenderBattleField();
                    break;

                case "end":
                    this.CommandStackNormal.Clear();
                    this.CommandStackNormal.Push(this.Battlefield.CreateMemento());
                    this.CommandStackReverse.Clear();

                    HeroInterface Temp = this.HeroQueue.First();
                    Temp.RestoreTurn();
                    this.HeroQueue.RemoveFirst();
                    this.HeroQueue.AddLast(Temp);

                    this.RenderBattleField();

                    break;

                case "undo":
                    if (this.CommandStackNormal.Count > 1)
                    {
                        this.CommandStackReverse.Push(this.CommandStackNormal.Pop());
                        this.Battlefield.Restore(this.CommandStackNormal.Peek());
                        this.RenderBattleField();
                    }
                    break;

                case "redo":
                    if (this.CommandStackReverse.Any())
                    {
                        this.CommandStackNormal.Push(this.CommandStackReverse.Pop());
                        this.Battlefield.Restore(this.CommandStackNormal.Peek());
                        this.RenderBattleField();
                    }
                    break;

                case "refresh":
                    this.RenderBattleField();
                    break;

                case "exit":
                    this.Over = true;
                    break;

                default:
                    Console.WriteLine("Unknown command");
                    break;
                }

                if (Over)
                {
                    lock (Refreshlock)
                    {
                        Monitor.PulseAll(Refreshlock);
                    }
                    break;
                }
            }

            ObserverFactory.GetInstance().Finish();
        }