Пример #1
0
        private void drawRobotBody(Robot robot, Pen pen, Graphics g)
        {
            PointF[] spike         = DrawerUtils.Rotate(AngleUtils.ToRads(robot.ANGLE), PointF.Empty, DefaultDrawer.spike);
            PointF[] bottom        = DrawerUtils.Rotate(AngleUtils.ToRads(robot.ANGLE), PointF.Empty, DefaultDrawer.bottom);
            PointF   robotPosition = robot.GetPosition();
            Pen      teamPen       = DefaultDrawer.GetTeamPen(robot.TEAM_ID);


            lock (g) {
                lock (teamPen) {
                    float oldTeamPenWidth = teamPen.Width;
                    teamPen.Width = 5;
                    g.DrawLines(teamPen, DrawerUtils.Translate(robotPosition, spike));
                    teamPen.Width = oldTeamPenWidth;
                }

                lock (pen) {
                    pen.Width = 5;
                    g.DrawLines(pen, DrawerUtils.Translate(robotPosition, bottom));
                }
                lock (Brushes.Red) {
                    g.FillEllipse(Brushes.Red, robotPosition.X - 1, robotPosition.Y - 1, 2, 2);
                }
            }
        }
        private ACommand shootProcess(ShootCommand command, Battlefield.RobotAndBattlefield robotAndBattlefield)
        {
            BattlefieldRobot robot       = robotAndBattlefield.ROBOT;
            Battlefield      battlefield = robotAndBattlefield.BATTLEFIELD;

            Tank tank = robot as Tank;

            if (tank == null)
            {
                return(new ErrorCommand(robot.ROBOT_TYPE + " cannot use shot command."));
            }

            if (tank.GunsToLoad < tank.Gun.BARREL_NUMBER && tank.HitPoints > 0)
            {
                double range = command.RANGE;
                if (range > tank.Gun.MAX_RANGE)
                {
                    range = tank.Gun.MAX_RANGE;
                }
                double toX = range * Math.Cos(AngleUtils.ToRads(command.ANGLE)) + tank.X;
                double toY = range * Math.Sin(AngleUtils.ToRads(command.ANGLE)) + tank.Y;
                battlefield.obstacleManager.ShotChange(battlefield.turn, tank.X, tank.Y, ref toX, ref toY);
                int toLap = (int)Math.Ceiling(range / tank.Gun.SHOT_SPEED) + battlefield.turn;
                lock (battlefield.heapBullet) {
                    if (!battlefield.heapBullet.TryGetValue(toLap, out List <Bullet> bulletList))
                    {
                        bulletList = new List <Bullet>();
                        battlefield.heapBullet.Add(toLap, bulletList);
                    }

                    bulletList.Add(new Bullet(battlefield.turn, toLap, toX, toY, tank));
                }
                int loadAtTurn = battlefield.turn + RELOAD_TIME;
                lock (battlefield.gunLoaded) {
                    if (!battlefield.gunLoaded.TryGetValue(loadAtTurn, out List <Tank> list))
                    {
                        list = new List <Tank>();
                        battlefield.gunLoaded.Add(loadAtTurn, list);
                    }
                    list.Add(tank);
                }

                tank.GunsToLoad++;
                return(new ShootAnswerCommand(true));
            }
            else
            {
                return(new ShootAnswerCommand(false));
            }
        }
Пример #3
0
        /// <inheritdoc />
        public void DrawScan(Scan scan, Graphics g, int turn)
        {
            int    index      = turn;
            Pen    pen        = scannerPen[index];
            double startAngle = scan.ANGLE - scan.PRECISION + 360;
            double stopAngle  = scan.ANGLE + scan.PRECISION + 360;

            if (turn == 0)
            {
                PointF scanPosition = scan.GetPosition();
                PointF endScan1     = DrawerUtils.Translate(scanPosition,
                                                            DrawerUtils.Rotate(AngleUtils.ToRads(startAngle), PointF.Empty,
                                                                               new PointF((float)scan.DISTANCE, 0F)));
                PointF endScan2 = DrawerUtils.Translate(scanPosition,
                                                        DrawerUtils.Rotate(AngleUtils.ToRads(stopAngle), PointF.Empty,
                                                                           new PointF((float)scan.DISTANCE, 0F)));
                lock (g) {
                    lock (pen) {
                        pen.Width = 2;
                        g.DrawLine(pen, scanPosition, endScan1);
                        g.DrawLine(pen, scanPosition, endScan2);
                    }
                }
            }
            RectangleF circle = new RectangleF(
                (float)(scan.X - scan.DISTANCE),
                (float)(scan.Y - scan.DISTANCE),
                (float)scan.DISTANCE * 2,
                (float)scan.DISTANCE * 2
                );

            if (scan.PRECISION > 0 && scan.DISTANCE > 0)
            {
                lock (g) {
                    lock (pen) {
                        g.DrawArc(pen, circle, (float)startAngle, (float)scan.PRECISION * 2);
                    }
                }
            }
        }