Example #1
0
 public override void Update(GameTime gameTime)
 {
     GameCollection.Update(gameTime);
     if (queue.Size == 0)
     {
         Random rnd = new Random();
         Game.GetService <GameFieldService>().GameField.coolNoise();
         Game.GetService <GameFieldService>().GameField.calculateNoise();
         GameCollection.GlobalUpdate();
         List <Submarine> list = GameCollection.getSubmarines();
         foreach (Submarine submarine in list)
         {
             submarine.detectNoise();
         }
         Submarine sub = list[rnd.Next(list.Count)];
         ((Team)sub.Parent).AI.NextAction(sub, Game.GetService <GameFieldService>().GameField).execute(sub, queue);
         foreach (Marker marker in sub.Team.AI.Markers)
         {
             marker.Parent = GameCollection;
             GameCollection.addToCollection(marker);
         }
     }
     else
     {
         queue.nextAction(gameTime);
     }
     base.Update(gameTime);
 }
Example #2
0
        public override void Update(GameTime gameTime)
        {
            if (!pause)
            {
                if (IsFirst)
                {
                    gameCollection = (EntityCollection)rm.ReadInitPos(Game.GetService <GameFieldService>().GameField).Copy(null);
                    stepList       = rm.ReadGame(Game.GetService <GameFieldService>().GameField);
                    gameCollection = (EntityCollection)stepList.Find(x => x.stepNumb == k).collection.Copy(null);
                    queue          = new ActionsQueue(gameCollection, Game.GetService <GameFieldService>().GameField);

                    IsFirst = false;
                }
                else
                {
                    gameCollection.Update(gameTime);
                    if (queue.Size == 0)
                    {
                        if (k <= stepList.Count)
                        {
                            gameCollection.GlobalUpdate();
                            ReplayStep step = stepList.Find(x => x.stepNumb == k);
                            k++;
                            if (step.action != null)
                            {
                                step.action.action.execute(gameCollection.getSubmarines().Find(x => x.Number == step.action.subNumb), queue);
                            }
                        }
                    }
                    else
                    {
                        queue.nextAction(gameTime);
                        if (queue.Size == 0)
                        {
                            Game.GetService <GameFieldService>().GameField.coolNoise();
                            Game.GetService <GameFieldService>().GameField.calculateNoise();
                        }
                    }
                }
            }
            base.Update(gameTime);
        }
Example #3
0
        public override void Update(GameTime gameTime)
        {
            this.gameTime = gameTime.Total.TotalSeconds;
            if (stepCount < Config.MaxStepCount)
            {
                if (!_isPaused)
                {
                    GameCollection.Update(gameTime);
                    if ((GameCollection.Winner != null) && (!weHaveAWinner))
                    {
                        weHaveAWinner = true;
                        printResults();
                    }
                    if (!weHaveAWinner)
                    {
                        if (queue.Size == 0)
                        {
                            if (_isStepByStep)
                            {
                                if (_waitNextStep)
                                {
                                    _nextStep = false;
                                }
                            }
                            else
                            {
                                _nextStep = true;
                            }

                            _waitNextStep = false;

                            if (_nextStep)
                            {
                                GameCollection.GlobalUpdate();
                                _waitNextStep = true;
                                stepCount++;
                                List <Submarine> list     = GameCollection.getSubmarines();
                                Submarine        sub      = list[rnd.Next(list.Count)];
                                AIAction         aiAction = sub.Team.AI.NextAction(sub, Game.GetService <GameFieldService>().GameField);
                                foreach (Marker marker in sub.Team.AI.Markers)
                                {
                                    if (marker != null)
                                    {
                                        marker.Parent = GameCollection;
                                        GameCollection.addToCollection(marker);
                                    }
                                }
                                if (aiAction != null)
                                {
                                    rm.saveStep(GameCollection, aiAction, sub);
                                    aiAction.execute(sub, queue);
                                }
                            }
                        }
                        else
                        {
                            queue.nextAction(gameTime);
                            if (queue.Size == 0)
                            {
                                Game.GetService <GameFieldService>().GameField.coolNoise();
                                Game.GetService <GameFieldService>().GameField.calculateNoise();
                            }
                        }
                    }
                }
                base.Update(gameTime);
            }
            else
            {
                if (!resultsPrinted)
                {
                    printResults();
                    resultsPrinted = true;
                }
            }
        }