예제 #1
0
파일: Game.cs 프로젝트: rewin123/Vesteros
 public void MoveUnit(Place to, Unit unit)
 {
 }
예제 #2
0
파일: Game.cs 프로젝트: rewin123/Vesteros
        /// <summary>
        /// Производит ход атаки юнитами на область
        /// </summary>
        /// <param name="to"></param>
        /// <param name="units"></param>
        public void Attack(Place to, List <Unit> units)
        {
            if (to.units.Count == 0)
            {
                to.units.AddRange(units);
            }
            else if (to.units[0].player == units[0].player)
            {
                to.units.AddRange(units);
            }
            else
            {
                int attack_power  = 0;
                int defence_power = 0;

                int castle_attribute = to.castleLevel > 0 ? 4 : 0;

                for (int i = 0; i < units.Count; i++)
                {
                    switch (units[i].type)
                    {
                    case UnitType.Horse:
                        attack_power += 2;
                        break;

                    case UnitType.Siege:
                        attack_power += castle_attribute;
                        break;

                    default:
                        attack_power += 1;
                        break;
                    }
                }

                List <Unit> defended_unit = to.units;
                for (int i = 0; i < defended_unit.Count; i++)
                {
                    if (!defended_unit[i].isLying)
                    {
                        switch (defended_unit[i].type)
                        {
                        case UnitType.Horse:
                            defence_power += 2;
                            break;

                        case UnitType.Siege:
                            defence_power += castle_attribute;
                            break;

                        default:
                            defence_power += 1;
                            break;
                        }
                    }
                }

                if (attack_power > defence_power)
                {
                    for (int i = 0; i < to.units.Count; i++)
                    {
                        if (to.units[i].isLying)
                        {
                            to.units.RemoveAt(i);
                            i--;
                        }
                        else
                        {
                            to.units[i].isLying = true;
                        }
                    }

                    List <Unit> active = GetToActive(to);
                    if (active.Count > 0)
                    {
                        PlayerType p_type  = active[0].player;
                        int        p_index = players.FindIndex((player) => player.type == p_type);
                        Player     p       = players[p_index];
                        Move       move    = new Move
                        {
                            player       = p,
                            playerState  = PlayerState.RetreatMove,
                            active_units = active,
                            active_place = to
                        };

                        inMoveActions.Add(move);
                    }

                    to.units = units;
                }
                else
                {
                    for (int i = 0; i < units.Count; i++)
                    {
                        units[i].isLying = true;
                    }
                    PlayerType p_type = units[0].player;
                    Player     p      = players.Find((player) => player.type == p_type);

                    Move move = new Move
                    {
                        player       = p,
                        playerState  = PlayerState.RetreatMove,
                        active_units = units,
                        active_place = to
                    };

                    inMoveActions.Add(move);
                }
            }
        }
예제 #3
0
파일: Game.cs 프로젝트: rewin123/Vesteros
        /// <summary>
        /// Копирует игру
        /// </summary>
        /// <returns></returns>
        public Game CopyRandom()
        {
            Game game = new Game();

            game.gamePhase  = gamePhase;
            game.orderCount = orderCount;
            game.moveIndex  = moveIndex;

            for (int i = 0; i < players.Count; i++)
            {
                Player p = new RandomPlayer();
                p.type = players[i].type;
                game.players.Add(p);
            }


            for (int i = 0; i < places.Count; i++)
            {
                game.places.Add(places[i].CopyUnlinked());
            }

            for (int i = 0; i < places.Count; i++)
            {
                Place p = game.places[i];
                for (int j = 0; j < p.names.Count; j++)
                {
                    game.places.AddLink(p.name, p.names[j]);
                }
            }

            for (int i = 0; i < players.Count; i++)
            {
                Player       p      = game.players[i];
                List <Order> orders = players[i].orders;
                for (int j = 0; j < orders.Count; j++)
                {
                    OrderData data = orders[j].CopyUnlinked();
                    p.orders.Add(new Order
                    {
                        type  = data.type,
                        power = data.power,
                        place = game.places.Find((place) => place.name == data.place)
                    });
                    p.orders.Last().place.placed_order = p.orders.Last();
                }
            }

            for (int i = 0; i < inMoveActions.Count; i++)
            {
                MoveData data = inMoveActions[i].CopyUnlinked();
                Move     m    = new Move();
                m.active_units = data.active_units;
                m.modifier     = data.modifier;
                m.playerState  = data.playerState;
                m.active_place = game.places.Find((place) => place.name == data.active_place);
                m.player       = game.players.Find((player) => player.type == data.player);

                game.inMoveActions.Add(m);
            }

            return(game);
        }