Exemple #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());
        }
Exemple #2
0
 public Dragon(OsianPlayer owner, int px, int py) : base(owner, px, py)
 {
     HP            = 4;
     Speed         = 1;
     BreakingPower = 2;
     Attack        = 5;
     AttackRange   = 2;
 }
Exemple #3
0
 public Archer(OsianPlayer owner, int px, int py) : base(owner, px, py)
 {
     Attack        = 2;
     HP            = 1;
     Speed         = 1;
     BreakingPower = 1;
     AttackRange   = 1;
 }
Exemple #4
0
        public ArmyBase(OsianPlayer owner, int px, int py)
        {
            Owner = owner;
            PosX  = px;
            PosY  = py;

            Timestamp = NextTimestamp++;
        }
Exemple #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);
        }
Exemple #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
         };
     }
 }
 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));
 }
Exemple #8
0
 public abstract void Action(OsianPlayer player, Map.MapData mapData, int px, int py);
Exemple #9
0
 public Buster(OsianPlayer owner, int px, int py) : base(owner, px, py)
 {
     HP            = 2;
     Speed         = 3;
     BreakingPower = 1;
 }
 public override MapObjectBase OnBroken(OsianPlayer source)
 {
     source.Cost += CostBonus;
     return(new EmptyMapObject());
 }
 public override void Action(OsianPlayer player, MapData mapData, int px, int py)
 {
 }
Exemple #12
0
 public MeleeArmyBase(OsianPlayer owner, int px, int py) : base(owner, px, py)
 {
 }
Exemple #13
0
 public Castle(OsianPlayer owner, int px, int py) : base(owner, px, py)
 {
     HP            = 6;
     Speed         = 2;
     BreakingPower = 1;
 }
Exemple #14
0
 private int _composeOwner(OsianPlayer target, OsianPlayer you)
 {
     return(target == null ? 0 : target == you ? 1 : 2);
 }
 public virtual MapObjectBase OnBroken(OsianPlayer source)
 {
     return(this);
 }
 public override MapObjectBase OnBroken(OsianPlayer source)
 {
     Owner          = source;
     BreakingPoints = InitialPoints;
     return(this);
 }
 public RangedArmyBase(OsianPlayer owner, int px, int py) : base(owner, px, py)
 {
 }