Пример #1
0
        public void Kill(Pirate pir)
        {
            pir.Alive = false;
            var newpos = new Point();

            switch (pir.Team)
            {
            case (Player.red):
                newpos = new Point(0, 12);
                break;

            case (Player.white):
                newpos = new Point(12, 12);
                break;

            case (Player.yellow):
                newpos = new Point(12, 0);
                break;
            }
            pir.Pos = newpos;
        }
Пример #2
0
        public int Swim(Point pTo, Pirate pir)
        {
            if (pTo.X < 0 || pTo.Y < 0 || pTo.X > 12 || pTo.Y > 12)
            {
                return(-1); //выход за пределы диапазона поля
            }
            var pFrom    = pir.Pos;
            var from     = GetIndex(pFrom);
            var to       = GetIndex(pTo);
            var fromTile = TilesColl[from];
            var toTile   = TilesColl[to];
            Point newpos = new Point();

            switch (toTile.Type)
            {
            case (TileType.water):
                newpos = pTo;
                break;

            case (TileType.ship):
                if (toTile.Team == pir.Team)
                {
                    newpos = pTo;
                }
                else
                {
                    Kill(pir);
                }
                break;

            default:
                newpos = pFrom;
                break;
            }
            Open(newpos);
            pir.Pos = newpos;
            return(0);
        }
Пример #3
0
 public PlayerPanel()
 {
     InitializeComponent();
     try { P = PiratesColl[0]; } catch { }
 }
Пример #4
0
        public int Move(Point pTo, Pirate pir, bool arrow = false, bool force = false)
        {
            if (pir.Alive == false)
            {
                return(-6);                    //пират мёртв
            }
            if (pTo.X < 0 || pTo.Y < 0 || pTo.X > 12 || pTo.Y > 12)
            {
                return(-1); //выход за пределы диапазона поля
            }
            if (pir.Drunkc > 0)
            {
                return(-2); //пират пьян
            }
            if (pir.Trapped == true)
            {
                var pirates = PiratesColl.Where(X => X.Pos == pir.Pos);
                if (pirates.Count() > 1)
                {
                    foreach (Pirate p in pirates)
                    {
                        p.Trapped = false;
                        Move(pTo, p);
                    }
                }
                return(-4); //пират в ловушке
            }
            if (pir.Lab > 0)
            {
                pir.Lab--;
                return(FinishStep(1, pir));
            }

            var pFrom    = pir.Pos;
            var from     = GetIndex(pFrom);
            var to       = GetIndex(pTo);
            var fromTile = TilesColl[from];
            var toTile   = TilesColl[to];
            Point newpos = new Point();
            Point dir    = new Point(pTo.X - pFrom.X, pTo.Y - pFrom.Y);

            if (arrow && !Tile.IsRightDir(fromTile, dir))
            {
                return(-3); //поворот не туда
            }
            bool drink = false;

            if (!arrow)
            {
                switch (fromTile.Type)
                {
                case (TileType.astr1):
                case (TileType.astr2):
                case (TileType.astr4):
                case (TileType.adiag1):
                case (TileType.adiag2):
                case (TileType.adiag4):
                case (TileType.a3):
                    return(Move(pTo, pir, true, true));
                }
            }

            if (fromTile.Type == TileType.water)
            {
                return(FinishStep(Swim(pTo, pir), pir));
            }

            Open(pTo);
            switch (toTile.Type)
            {
            case (TileType.water):
                if (force)
                {
                    newpos = pTo;
                }
                else
                {
                    newpos = pFrom;
                }
                break;

            case (TileType.graveyard):
                newpos = pFrom;
                break;

            case (TileType.gfort):
                var pirsThere      = PiratesColl.Where(X => X.Pos == pTo);
                var enemyPirsThere = pirsThere.Where(X => X.Team != pir.Team);
                if (enemyPirsThere.Count() == 0)
                {
                    newpos = pTo;
                    var deadpirs = PiratesColl.Where(X => X.Alive == false);
                    foreach (Pirate p in deadpirs)
                    {
                        p.Alive = true;
                        p.Pos   = pTo;
                    }
                }
                else
                {
                    return(-5);     //пират идёт в занятый форт
                }
                break;

            case (TileType.fort):
                var pirates      = PiratesColl.Where(X => X.Pos == pTo);
                var enemypirates = pirates.Where(X => X.Team != pir.Team);
                if (enemypirates.Count() == 0)
                {
                    newpos = pTo;
                }
                else
                {
                    return(-5);     //пират идёт в занятый форт
                }
                break;

            case (TileType.hole):
                pir.Trapped = true;
                newpos      = pTo;
                break;

            case (TileType.lab2):
                pir.Lab = 1;
                newpos  = pTo;
                break;

            case (TileType.lab3):
                pir.Lab = 2;
                newpos  = pTo;
                break;

            case (TileType.lab4):
                pir.Lab = 3;
                newpos  = pTo;
                break;

            case (TileType.lab5):
                pir.Lab = 4;
                newpos  = pTo;
                break;

            case (TileType.cannibal):
                Kill(pir);
                break;

            case (TileType.grass1):
            case (TileType.grass2):
            case (TileType.grass3):
            case (TileType.grass4):
            case (TileType.coins1):
            case (TileType.coins2):
            case (TileType.coins3):
            case (TileType.coins4):
            case (TileType.coins5):
                newpos = pTo;
                break;

            case (TileType.cannon):
                Open(pTo);
                switch (TilesColl[to].Direction)
                {
                case (TileDirection.up):
                    newpos = new Point(pTo.X, 0);
                    break;

                case (TileDirection.left):
                    newpos = new Point(0, pTo.Y);
                    break;

                case (TileDirection.down):
                    newpos = new Point(pTo.X, 12);
                    break;

                case (TileDirection.right):
                    newpos = new Point(12, pTo.Y);
                    break;
                }
                Open(newpos);
                pir.Pos = pTo;
                return(FinishStep(Move(newpos, pir, false, true), pir));

            case (TileType.ice):
                pir.Pos = pTo;
                return(Move(pTo + new Size(dir), pir));

            case (TileType.croc):
                newpos  = pir.Pos;
                pir.Pos = pTo;
                break;

            case (TileType.rum):
                drink  = true;
                newpos = pTo;
                break;

            case (TileType.balloon):
                newpos = GetShipPos(pir.Team);
                break;

            case (TileType.ship):
                return(FinishStep(MoveToShip(pTo, pir), pir));

            default:
                newpos = pTo;
                break;
            }
            Open(newpos);
            var pirs = PiratesColl.Where(X => X.Pos == newpos && X.Team != pir.Team);

            if (pirs.Count() == 1)
            {
                var victim = pirs.ElementAt(0);
                if (victim.Gold == true)
                {
                    victim.Gold = false;
                    TilesColl[GetIndex(victim.Pos)].Gold++;
                }
                victim.Pos = GetShipPos(victim.Team);
            }
            else if (pirs.Count() > 1)
            {
                if (pir.Gold == true)
                {
                    pir.Gold = false;
                    TilesColl[GetIndex(newpos)].Gold++;
                }
                newpos = GetShipPos(pir.Team);
            }
            pir.Pos = newpos;
            return(FinishStep(0, pir, drink));
        }
Пример #5
0
 public bool IsEnemyShip(Tile tile, Pirate pir)
 {
     return(!(tile.Team == pir.Team));
 }
Пример #6
0
        private void Step(TilePosition target, Pirate pirate, Ship ship, Team team)
        {
            //var moves = _availableMoves;
            //var actions = _actions;

            Tile targetTile = Board.Map[target.Position];

            var  source     = pirate.Position.Position;
            Tile sourceTile = Board.Map[source];

            bool onShip = (ship.Position == pirate.Position.Position);

            Direction direction = new Direction(pirate.Position, target);

            switch (targetTile.Type)
            {
            case TileType.Unknown:
            {
                // exploration
                if (onShip)
                {
                    if (CanLanding(pirate, target))
                    {
                        // landing
                        AddMoveAndActions(new Move(pirate.Position.Position, target),
                                          GameActionList.Create(
                                              new Explore(target, pirate, direction),
                                              new Landing(pirate, ship),
                                              new Moving(pirate, target)));
                    }
                }
                else
                {
                    AddMoveAndActions(new Move(pirate.Position.Position, target),
                                      GameActionList.Create(
                                          new Explore(target, pirate, direction),
                                          new Moving(pirate, target)));
                }

                break;
            }

            case TileType.Water:
            {
                if (target == ship.Position)     //на свой корабль
                {
                    if (sourceTile.Coins > 0)
                    {
                        // shipping with coins
                        AddMoveAndActions(new Move(pirate.Position.Position, target, MoveType.WithCoin),
                                          GameActionList.Create(
                                              new TakeCoinToShip(pirate, ship),
                                              new Shipping(pirate, ship)));
                    }

                    // shipping without coins
                    AddMoveAndActions(new Move(pirate.Position.Position, target),
                                      GameActionList.Create(
                                          //new DropCoin(pirate),
                                          new Shipping(pirate, ship)));
                }
                else if (pirate.Position.Position == ship.Position)     //двигаем корабль
                {
                    if (((ship.Position.X == 0 || ship.Position.X == Board.Size - 1) &&
                         (target.Y <= 1 || target.Y >= Board.Size - 2))
                        ||
                        ((ship.Position.Y == 0 || ship.Position.Y == Board.Size - 1) &&
                         (target.X <= 1 || target.X >= Board.Size - 2)))
                    {
                        break;     // enemy water territories
                    }

                    // navigation
                    AddMoveAndActions(new Move(pirate.Position.Position, target),
                                      GameActionList.Create(
                                          new Navigation(ship, target)));
                }
                else if (Board.Teams.Where(x => x.Id != CurrentTeamId).Select(x => x.Ship.Position).Contains(target))
                {
                    //столкновение с чужим кораблем
                    AddMoveAndActions(new Move(pirate.Position.Position, target),
                                      GameActionList.Create(
                                          new Dying(pirate)));
                }
                else     //падение пирата в воду и плавание в воде
                {
                    AddMoveAndActions(new Move(pirate.Position.Position, target),
                                      GameActionList.Create(
                                          new Moving(pirate, target)));
                }
                break;
            }

            case TileType.Chest1:
            case TileType.Chest2:
            case TileType.Chest3:
            case TileType.Chest4:
            case TileType.Chest5:
            case TileType.Grass:
            case TileType.Fort:
            case TileType.RespawnFort:
            case TileType.RumBarrel:
            case TileType.Canibal:
            case TileType.Spinning:
            case TileType.Trap:
            {
                var  attack       = targetTile.OccupationTeamId.HasValue && targetTile.OccupationTeamId.Value != pirate.TeamId;
                bool targetIsFort = targetTile.Type.IsFort();

                //Respawn
                if (targetTile.Type == TileType.RespawnFort && sourceTile.Type == TileType.RespawnFort)
                {
                    if (team.Pirates.Count() < 3)
                    {
                        AddMoveAndActions(new Move(pirate.Position.Position, target, MoveType.WithRespawn),
                                          GameActionList.Create(
                                              new Respawn(team, target)));
                    }
                }

                if (attack)
                {
                    if (targetIsFort == false)
                    {
                        // attack
                        if (onShip)
                        {
                            if (CanLanding(pirate, target))
                            {
                                AddMoveAndActions(new Move(pirate.Position.Position, target),
                                                  GameActionList.Create(
                                                      new Attack(target),
                                                      new Landing(pirate, ship),
                                                      new Moving(pirate, target)));
                            }
                        }
                        else
                        {
                            AddMoveAndActions(new Move(pirate.Position.Position, target),
                                              GameActionList.Create(
                                                  new Attack(target),
                                                  new Moving(pirate, target)));
                        }
                    }
                }
                else
                {
                    if (onShip)
                    {
                        if (CanLanding(pirate, target))
                        {
                            AddMoveAndActions(new Move(pirate.Position.Position, target),
                                              GameActionList.Create(
                                                  new Landing(pirate, ship),
                                                  new Moving(pirate, target)));
                        }
                    }
                    else
                    {
                        AddMoveAndActions(new Move(pirate.Position.Position, target),
                                          GameActionList.Create(
                                              new Moving(pirate, target)));

                        if (sourceTile.Coins > 0 && targetIsFort == false)
                        {
                            AddMoveAndActions(new Move(pirate.Position.Position, target, MoveType.WithCoin),
                                              GameActionList.Create(
                                                  new Moving(pirate, target, true)));
                        }
                    }
                }
                break;
            }
            }
        }