Ejemplo n.º 1
0
        public void CannotDrillWithInsufficientDrillers()
        {
            DrillMineEvent drillMine = new DrillMineEvent(_model1);

            _tm.AddEvent(drillMine);
            _tm.Advance(10);
            Assert.IsFalse(drillMine.WasEventSuccessful());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new game using the provided GameConfiguration. Calling this constructor will trigger
        /// map generation and generate the map based on the GameConfiguration that was passed into the game.
        /// </summary>
        /// <param name="gameConfiguration">Settings that determine how the game should be configured during generation.</param>
        public Game(GameConfiguration gameConfiguration)
        {
            SeededRandom = new SeededRandom(gameConfiguration.MapConfiguration.Seed);

            // Creates a new game state and makes a time machine to reference the state
            GameState.GameState state = new GameState.GameState(gameConfiguration);
            TimeMachine = new TimeMachine(state);

            // Creates the map generator with a random seed
            MapGenerator mapGenerator = new MapGenerator(gameConfiguration.MapConfiguration, state.GetPlayers());

            // Generate the map
            List <Outpost> generatedOutposts = mapGenerator.GenerateMap();

            // Add the outposts to the map
            state.GetOutposts().AddRange(generatedOutposts);

            // Populate the specialist pool
            SpecialistPool = new SpecialistPool(SeededRandom, gameConfiguration.GameSettings.AllowedSpecialists.ToList());

            // All owned factories should start producing drillers
            foreach (Outpost o in generatedOutposts)
            {
                if (o is Factory && o.GetComponent <DrillerCarrier>().GetOwner() != null)
                {
                    Factory f = (Factory)o;
                    TimeMachine.AddEvent(new FactoryProduction(f, f.GetTicksToFirstProduction()));
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a new game using the provided GameConfiguration. Calling this constructor will trigger
        /// map generation and generate the map based on the GameConfiguration that was passed into the game.
        /// </summary>
        /// <param name="gameConfiguration">Settings that determine how the game should be configured during generation.</param>
        public Game(GameConfiguration gameConfiguration)
        {
            // Creates a new game state and makes a time machine to reference the state
            GameState state = new GameState(gameConfiguration);

            TimeMachine = new TimeMachine(state);

            // Creates the map generator with a random seed
            MapGenerator mapGenerator = new MapGenerator(gameConfiguration);

            // Generate the map
            List <Outpost> outpostsToGenerate = mapGenerator.GenerateMap();

            // Add factory driller production events to the time machine.
            // TODO: Make this better.
            foreach (Outpost o in outpostsToGenerate)
            {
                if (o.GetOutpostType() == OutpostType.Factory)
                {
                    TimeMachine.AddEvent(new FactoryProduceDrillersEvent(o, state.GetCurrentTick().Advance(36)));
                }
            }

            // Add the outposts to the map
            state.GetOutposts().AddRange(outpostsToGenerate);
        }
        public override bool ForwardAction(TimeMachine timeMachine, GameState.GameState state)
        {
            Entity drillLocation = state.GetEntity(GetEventData().SourceId);

            if (drillLocation != null && drillLocation is Outpost && !(drillLocation is Mine) && !((Outpost)drillLocation).GetComponent <DrillerCarrier>().IsDestroyed())
            {
                _original = (Outpost)drillLocation;
                var drillerCarrier = drillLocation.GetComponent <DrillerCarrier>();
                if (state.GetOutposts().Contains(_original) && !drillerCarrier.GetOwner().IsEliminated() && drillerCarrier.GetDrillerCount() >= drillerCarrier.GetOwner().GetRequiredDrillersToMine())
                {
                    _drilledMine = new Mine(_original);
                    if (state.ReplaceOutpost(_original, _drilledMine))
                    {
                        drillerCarrier.RemoveDrillers(drillerCarrier.GetOwner().GetRequiredDrillersToMine());
                        drillerCarrier.GetOwner().AlterMinesDrilled(1);
                        timeMachine.AddEvent(new NeptuniumProductionEvent(_drilledMine, GetOccursAt().Advance(Mine.TICKS_PER_PRODUCTION_PER_MINE / state.GetPlayerOutposts(drillerCarrier.GetOwner()).Count)));
                        EventSuccess = true;
                    }
                }
            }
            else
            {
                EventSuccess = false;
            }
            return(EventSuccess);
        }
Ejemplo n.º 5
0
 public override bool ForwardAction(TimeMachine timeMachine, GameState.GameState state)
 {
     if (!_mine.GetComponent <DrillerCarrier>().GetOwner().IsEliminated() && state.GetOutposts().Contains(_mine) && !_mine.GetComponent <DrillerCarrier>().IsDestroyed())
     {
         _mine.GetComponent <DrillerCarrier>().GetOwner().AlterNeptunium(1);
         this._nextProduction = new NeptuniumProductionEvent(_mine, GetOccursAt().Advance(Mine.TICKS_PER_PRODUCTION_PER_MINE / state.GetPlayerOutposts(_mine.GetComponent <DrillerCarrier>().GetOwner()).Count));
         timeMachine.AddEvent(this._nextProduction);
         EventSuccess = true;
     }
     else
     {
         EventSuccess = false;
     }
     return(EventSuccess);
 }
Ejemplo n.º 6
0
 public override bool ForwardAction(TimeMachine timemachine, GameState.GameState state)
 {
     _productionAmount = this._producingFactory.GetDrillerProduction(state);
     if (state.OutpostExists(_producingFactory) && this._productionAmount > 0 && !this._producingFactory.GetComponent <DrillerCarrier>().IsDestroyed())
     {
         _producingFactory.GetComponent <DrillerCarrier>().AddDrillers(this._productionAmount);
         EventSuccess = true;
         if (_nextProduction == null)
         {
             _nextProduction = new FactoryProduction(_producingFactory, base.GetOccursAt().Advance(this._producingFactory.GetTicksPerProduction()));
             timemachine.AddEvent(this._nextProduction);
         }
     }
     else
     {
         EventSuccess = false;
     }
     return(EventSuccess);
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Performs the forward event
        /// </summary>
        public override bool ForwardAction(TimeMachine timeMachine, GameState state)
        {
            this._launchedSub = state.GetCombatableById(GetEventData().SourceId).LaunchSub(state, this);
            if (_launchedSub != null && _launchedSub is Sub)
            {
                combatEvents.AddRange(CreateCombatEvents(_launchedSub as Sub, state));
                foreach (GameEvent e in combatEvents)
                {
                    timeMachine.AddEvent(e);
                }
                this.EventSuccess = true;
            }
            else
            {
                this.EventSuccess = false;
            }

            return(this.EventSuccess);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Performs the forward event
        /// </summary>
        public override bool ForwardAction(TimeMachine timeMachine, GameState.GameState state)
        {
            this._launchedSub = state.GetEntity(GetEventData().SourceId).GetComponent <SubLauncher>().LaunchSub(state, this);
            if (_launchedSub != null && !_launchedSub.GetComponent <DrillerCarrier>().GetOwner().IsEliminated())
            {
                _combatEvents.AddRange(CreateCombatEvents(_launchedSub, state));
                foreach (GameEvent e in _combatEvents)
                {
                    timeMachine.AddEvent(e);
                }
                this.EventSuccess = true;
            }
            else
            {
                this.EventSuccess = false;
            }

            return(this.EventSuccess);
        }
Ejemplo n.º 9
0
 public void LoadGameEvents(List <GameEventModel> gameEvents)
 {
     gameEvents
     .ConvertAll <GameEvent>(m => GameEventFactory.ParseGameEvent(m))
     .ForEach(parsedEvent => TimeMachine.AddEvent(parsedEvent));
 }