示例#1
0
        private static void Move(GameClientBattlecity gcb)
        {
            var r    = new Random();
            var done = false;

            switch (r.Next(5))
            {
            case 0:
                if (!gcb.IsBarrierAt(gcb.PlayerX, gcb.PlayerY - 1))
                {
                    gcb.SendActions(gcb.Up());
                    done = true;
                }
                break;

            case 1:
                if (!gcb.IsBarrierAt(gcb.PlayerX + 1, gcb.PlayerY))
                {
                    gcb.SendActions(gcb.Right());
                    done = true;
                }
                break;

            case 2:
                if (!gcb.IsBarrierAt(gcb.PlayerX, gcb.PlayerY + 1))
                {
                    gcb.SendActions(gcb.Down());
                    done = true;
                }
                break;

            case 3:
                if (!gcb.IsBarrierAt(gcb.PlayerX - 1, gcb.PlayerY))
                {
                    gcb.SendActions(gcb.Left());
                    done = true;
                }
                break;

            case 4:
                gcb.SendActions(gcb.Act());
                done = true;
                break;
            }
            if (done == false)
            {
                gcb.SendActions(gcb.Blank());
            }
        }
示例#2
0
        static bool Dodge()
        {
            const int maxObserveLen = Configuration.DodgeLen;

            // right line
            for (int x = G.PlayerX + 1; x < Math.Min(G.Map.GetLength(0), G.PlayerX + maxObserveLen); x++)
            {
                if (G.IsAnyOfAt(x, G.PlayerY, new[] { Elements.BULLET }))
                {
                    if (!G.IsBarrierAt(x, G.PlayerY - 1))
                    {
                        G.SendActions(G.Up());
                        S.DodgeUp++;
                        return(true);
                    }
                    else
                    {
                        G.SendActions(G.Down());
                        S.DodgeDown++;
                        return(true);
                    }
                }
            }
            // left line
            for (int x = G.PlayerX - 1; x >= Math.Max(0, G.PlayerX - maxObserveLen); x--)
            {
                if (G.IsAnyOfAt(x, G.PlayerY, new[] { Elements.BULLET }))
                {
                    if (!G.IsBarrierAt(x, G.PlayerY - 1))
                    {
                        G.SendActions(G.Up());
                        S.DodgeUp++;
                        return(true);
                    }
                    else
                    {
                        G.SendActions(G.Down());
                        S.DodgeDown++;
                        return(true);
                    }
                }
            }
            // down line
            for (int y = G.PlayerY + 1; y < Math.Min(G.Map.GetLength(1), G.PlayerY + maxObserveLen); y++)
            {
                if (G.IsAnyOfAt(G.PlayerX, y, new[] { Elements.BULLET }))
                {
                    if (!G.IsBarrierAt(G.PlayerX + 1, y))
                    {
                        G.SendActions(G.Right());
                        S.DodgeRight++;
                        return(true);
                    }
                    else
                    {
                        G.SendActions(G.Left());
                        S.DodgeLeft++;
                        return(true);
                    }
                }
            }
            // up line
            for (int y = G.PlayerY - 1; y >= Math.Max(0, G.PlayerY - maxObserveLen); y--)
            {
                if (G.IsAnyOfAt(G.PlayerX, y, new[] { Elements.BULLET }))
                {
                    if (!G.IsBarrierAt(G.PlayerX + 1, y))
                    {
                        G.SendActions(G.Right());
                        S.DodgeRight++;
                        return(true);
                    }
                    else
                    {
                        G.SendActions(G.Left());
                        S.DodgeLeft++;
                        return(true);
                    }
                }
            }

            return(false);
        }