示例#1
0
        public override async Task UpdateGameData(OsianPlayer you, OsianPlayer opponent, MapData mapData)
        {
            if (_subProcess.HasExited)
            {
                return;
            }
            StringBuilder builder = new StringBuilder();

            builder.AppendLine("1");
            builder.AppendFormat("{0} {1} {2} {3}\n", you.Cost, opponent.Cost, you.Base, opponent.Base);
            List <string>[,] temps = new List <string> [OsianLogic.LEN_X, OsianLogic.LEN_Y];
            for (int i = 0; i < OsianLogic.LEN_X; i++)
            {
                for (int j = 0; j < OsianLogic.LEN_Y; j++)
                {
                    temps[i, j] = new List <string> ();
                    List <string> temp = temps[i, j];
                    if (mapData.Map[i, j] is BarrackMapObject barrack)
                    {
                        temp.Add(_composeString(4, _composeOwner(barrack.Owner, you), 0, barrack.BreakingPoints, 0));
                    }
                    else if (mapData.Map[i, j] is ObstacleMapObject obstacle)
                    {
                        temp.Add(_composeString(5, _composeOwner(obstacle.Owner, you), 0, obstacle.BreakingPoints, obstacle.CostBonus));
                    }
                }
            }
            foreach (var item in mapData.Army)
            {
                List <string> temp = temps[item.PosX, item.PosY];
                if (item is Archer archer)
                {
                    temp.Add(_composeString(0, _composeOwner(archer.Owner, you), archer.HP, 0, 0));
                }
                else if (item is Buster buster)
                {
                    temp.Add(_composeString(1, _composeOwner(buster.Owner, you), buster.HP, 0, 0));
                }
                else if (item is Castle castle)
                {
                    temp.Add(_composeString(2, _composeOwner(castle.Owner, you), castle.HP, 0, 0));
                }
                else if (item is Dragon dragon)
                {
                    temp.Add(_composeString(3, _composeOwner(dragon.Owner, you), dragon.HP, 0, 0));
                }
            }
            for (int i = 0; i < OsianLogic.LEN_X; i++)
            {
                for (int j = 0; j < OsianLogic.LEN_Y; j++)
                {
                    List <string> temp = temps[i, Math.Abs(you.BasePosY - j)];
                    builder.Append(temp.Count);
                    builder.Append(" ");
                    builder.Append(string.Join(" ", temp));
                    builder.Append(" ");
                }
            }
            await _subProcess.StandardInput.WriteLineAsync(builder.ToString());
        }
示例#2
0
 public Dragon(OsianPlayer owner, int px, int py) : base(owner, px, py)
 {
     HP            = 4;
     Speed         = 1;
     BreakingPower = 2;
     Attack        = 5;
     AttackRange   = 2;
 }
示例#3
0
 public Archer(OsianPlayer owner, int px, int py) : base(owner, px, py)
 {
     Attack        = 2;
     HP            = 1;
     Speed         = 1;
     BreakingPower = 1;
     AttackRange   = 1;
 }
示例#4
0
        public ArmyBase(OsianPlayer owner, int px, int py)
        {
            Owner = owner;
            PosX  = px;
            PosY  = py;

            Timestamp = NextTimestamp++;
        }
示例#5
0
        public void Invoke(OsianPlayer player, Map.MapData mapData)
        {
            int x = Px;
            int y = Math.Abs(player.BasePosY - Py);

            x.XRangeCheck(); y.YRangeCheck();
            player.Cost -= Cost;
            Action(player, mapData, x, y);
        }
示例#6
0
 public override void Action(OsianPlayer player, MapData mapData, int px, int py)
 {
     if (mapData.Map[px, py] is EmptyMapObject && py != 0 && py != OsianLogic.LEN_Y - 1 && mapData.Army.Count((army) => army.PosX == px && army.PosY == py) == 0)
     {
         mapData.Map[px, py] = new ObstacleMapObject()
         {
             InitialPoints  = 5,
             BreakingPoints = 5,
             CostBonus      = 0,
             Owner          = player
         };
     }
 }
示例#7
0
 public override void Action(OsianPlayer player, MapData mapData, int px, int py)
 {
     if (mapData.Map[px, py] is BarrackMapObject barrack)
     {
         if (player != barrack.Owner)
         {
             throw new InvalidGameOperationException("The barrack is not yours.");
         }
     }
     else if (py != player.BasePosY)
     {
         throw new InvalidGameOperationException("Not placing army on barracks or bases.");
     }
     mapData.Army.Add((TArmy)Activator.CreateInstance(typeof(TArmy), player, px, py));
 }
示例#8
0
 public abstract void Action(OsianPlayer player, Map.MapData mapData, int px, int py);
示例#9
0
 public Buster(OsianPlayer owner, int px, int py) : base(owner, px, py)
 {
     HP            = 2;
     Speed         = 3;
     BreakingPower = 1;
 }
示例#10
0
 public override MapObjectBase OnBroken(OsianPlayer source)
 {
     source.Cost += CostBonus;
     return(new EmptyMapObject());
 }
示例#11
0
 public override void Action(OsianPlayer player, MapData mapData, int px, int py)
 {
 }
示例#12
0
 public MeleeArmyBase(OsianPlayer owner, int px, int py) : base(owner, px, py)
 {
 }
示例#13
0
 public Castle(OsianPlayer owner, int px, int py) : base(owner, px, py)
 {
     HP            = 6;
     Speed         = 2;
     BreakingPower = 1;
 }
示例#14
0
 private int _composeOwner(OsianPlayer target, OsianPlayer you)
 {
     return(target == null ? 0 : target == you ? 1 : 2);
 }
示例#15
0
 public virtual MapObjectBase OnBroken(OsianPlayer source)
 {
     return(this);
 }
示例#16
0
 public override MapObjectBase OnBroken(OsianPlayer source)
 {
     Owner          = source;
     BreakingPoints = InitialPoints;
     return(this);
 }
示例#17
0
 public RangedArmyBase(OsianPlayer owner, int px, int py) : base(owner, px, py)
 {
 }