Пример #1
0
        private void findNewTarget(GameMap gameMap, SectorHolder sectors)
        {
            stepToTarget = 0;
            target       = null;

            sectors.solveSectorToMove(this);

            float attraction;
            float maxAttraction = int.MinValue;
            int   currentPriority;

            foreach (Unit point in gameMap.getMap())
            {
                if (point != this && !point.getIsDeleted())
                {
                    if (isVisibleUnit(point) && radius > point.getRadius())
                    {
                        currentPriority = sectors.getPriorityForUnit(point);
                        float distance       = Math.Abs(x - point.getX()) + Math.Abs(y - point.getY());//not real distance use only for choice
                        float feedByDistance = point.getFeed() / distance;
                        attraction = feedByDistance - currentPriority * Settings.PriorityValue;
                        if (attraction > maxAttraction)
                        {
                            maxAttraction = attraction;
                            target        = point;
                        }
                    }
                }
            }
        }
Пример #2
0
 public void updateState(GameMap gameMap, SectorHolder sectors)
 {
     if (stepToTarget == Settings.EnemyMaxStepToTarget || target == null) //update null
     {
         findNewTarget(gameMap, sectors);
     }
     if (target == null)
     {
         target = gameMap.getAnyUnit();
     }
     if (moveToTarget())
     {
         findNewTarget(gameMap, sectors);
         stepToTarget = 0;
     }
     else
     {
         stepToTarget++;
     }
 }
Пример #3
0
        public GameManager(Canvas canvas, Canvas Container, Ellipse mainBulk, TextBlock timeUI, TextBlock pointUI, float actualPageWidth, float actualPageHeight)
        {
            this.canvas           = canvas;
            this.mainBulk         = mainBulk;
            this.actualPageWidth  = actualPageWidth;
            this.actualPageHeight = actualPageHeight;
            this.timeUI           = timeUI;
            this.pointUI          = pointUI;
            mousePositionPoint    = new Point();
            dispatcherTimer       = new DispatcherTimer();
            start = DateTime.Now;

            Container.Background = new SolidColorBrush(Settings.GameFieldColor);
            dX          = 0;
            dY          = 0;
            usersRadius = Settings.UserStartSize;
            float centerX = actualPageWidth / 2;
            float centerY = actualPageHeight / 2;

            usersX = centerX - usersRadius / 2;
            usersY = centerY - usersRadius / 2;

            user      = new User(centerX, centerY, Settings.UserStartSize);
            bulkesMap = new List <Bulk>();
            bulkesMap.Add(user);
            bulkesMap.Add(new Enemy(0, 200, 95));
            bulkesMap.Add(new Enemy(500, 0, 80));

            gameMap = new GameMap();
            gameMap.generateSmartMap(bulkesMap);
            unitMap = gameMap.getMap();
            gameMap.addUnit(user);
            gameMap.addUnit(bulkesMap[1]);
            gameMap.addUnit(bulkesMap[2]);

            sectors = new SectorHolder();
            sectors.setOffsets(-gameMap.getOffsetTopLeftX(), -gameMap.getOffsetTopLeftY());
            startGame();
        }