Exemplo n.º 1
0
 // Define a world's size
 private void CreateWorld()
 {
     if (_listOfEvents.Count != 0)
     {
         WarSpotEvent wsEvent = _listOfEvents.First();
         if (wsEvent.EventType == EventTypes.SystemEventWorldCreated)
         {
             var tmp = wsEvent as SystemEventWorldCreated;
             SetWorldSize(tmp.Width, tmp.Height);
             _listOfEvents.Remove(tmp);
         }
     }
 }
Exemplo n.º 2
0
        public override void Update(GameTime gameTime)
        {
            if (!_globalPause)
            {
                if (!_localPause)
                {
                    WarSpotEvent wsEvent = _listOfEvents.First();

                    switch (wsEvent.EventType)
                    {
                    case EventTypes.GameEventHealthChange:
                    {
                        var tmpEvent = wsEvent as GameEventHealthChange;
                        var tmp      = _listOfCreatures.First(creature => creature.Id == tmpEvent.SubjectId);
                        tmp.CurrentHealth = tmpEvent.Health;
                        _listOfEvents.Remove(wsEvent);
                        break;
                    }

                    case EventTypes.GameEventCiChange:
                    {
                        var tmpEvent = wsEvent as GameEventCiChange;
                        var tmp      = _listOfCreatures.First(creture => creture.Id == tmpEvent.SubjectId);
                        tmp.CurrentCi = tmpEvent.Ci;
                        _listOfEvents.Remove(wsEvent);
                        break;
                    }

                    case EventTypes.GameEventMove:
                    {
                        _localPause = true;
                        var tmpEvent = wsEvent as GameEventMove;
                        var tmp      = _listOfCreatures.First(creture => creture.Id == tmpEvent.SubjectId);
                        tmp.X = (tmp.X + tmpEvent.ShiftX + _worldWidth) % _worldWidth;
                        tmp.Y = (tmp.Y + tmpEvent.ShiftY + _wordlHeight) % _wordlHeight;
                        _listOfEvents.Remove(wsEvent);
                        break;
                    }

                    case EventTypes.GameEventDeath:
                    {
                        _localPause = true;
                        var tmpEvent = wsEvent as GameEventDeath;
                        var tmp      = _listOfCreatures.First(creture => creture.Id == tmpEvent.SubjectId);
                        _listOfCreatures.Remove(tmp);
                        _listOfEvents.Remove(wsEvent);
                        break;
                    }

                    case EventTypes.GameEventBirth:
                    {
                        var tmp = wsEvent as GameEventBirth;
                        _listOfCreatures.Add(new Creature(tmp.SubjectId, tmp.Newborn.X, tmp.Newborn.Y,
                                                          tmp.Newborn.Team, tmp.Newborn.MaxHealth, tmp.Newborn.Health, tmp.Newborn.Ci));
                        _localPause = true;
                        _listOfEvents.Remove(tmp);
                        break;
                    }

                    case EventTypes.GameEventWorldCiChanged:
                    {
                        var tmp = wsEvent as GameEventWorldCiChanged;
                        _worldMap[tmp.Y][tmp.X].changeCi(tmp.Ci);
                        _listOfEvents.Remove(tmp);
                        break;
                    }

                    case EventTypes.SystemEventTurnStarted:
                    {
                        var tmp = wsEvent as SystemEventTurnStarted;
                        _turnLabel.Text = "Turn " + tmp.Number.ToString() + " / " + size.ToString();
                        _listOfEvents.Remove(tmp);
                        break;
                    }

                    case EventTypes.SystemEventCommandWin:
                    {
                        var tmp = wsEvent as SystemEventCommandWin;
                        _listOfEvents.Remove(tmp);
                        break;
                    }

                    case EventTypes.SystemEventCommandDead:
                    {
                        var tmp = wsEvent as SystemEventCommandDead;
                        _listOfEvents.Remove(tmp);
                        break;
                    }

                    case EventTypes.SystemEventMatchEnd:
                    {
                        var tmp = wsEvent as SystemEventMatchEnd;
                        ExitReplay();
                        break;
                    }

                    default:
                        _listOfEvents.RemoveAt(0);
                        break;
                    }
                }
                else
                {
                    // Checks time per unit game action
                    _timeSinceLastTurn += gameTime.ElapsedGameTime.Milliseconds;
                    // 1000 - delay between game actions
                    if (_timeSinceLastTurn > 200)
                    {
                        _localPause        = false;
                        _timeSinceLastTurn = 0;
                    }
                }
            }
        }