コード例 #1
0
ファイル: WildmenGame.cs プロジェクト: arcticnw/Wildmen
    public void MakeMap(int width, int height, int players, int unitCap)
    {
      UnitCap = unitCap;
      if (Map != null)
      {
        if (NaturePlayer != null)
        {
          NaturePlayer.Dispose();
        }
        Map.Dispose();
        Effects.Clear();
      }
      NaturePlayer = new Player(-1, this, "Nature");

      Map = new MapBoard(this, width, height);
      Map.Initialize();
      Map.Generate(random, players);

      NaturePlayer.Initialize();
    }
コード例 #2
0
ファイル: WildmenGame.cs プロジェクト: arcticnw/Wildmen
    /// <summary>
    /// Method that deserializes the data from the line starting at given position in given context depending on the MessageType
    /// </summary>
    /// <param id="mt">MessageType defining the extend of deserialization which is to be performed</param>
    /// <param id="line">String array containing the serialized data</param>
    /// <param id="position">Current position in the array</param>
    /// <param id="context">Context of the serialized data, game where this INetworkSerializable object is in</param>
    public void Deserialize(MessageType mt, string[] line, ref int position, WildmenGame context)
    {
      int n;
      switch (mt)
      {
        case MessageType.GameTransfer:
          Map = new MapBoard(context, int.Parse(line[position + 0]), int.Parse(line[position + 1]));
          Map.Initialize();
          Map.Deserialize(mt, line, ref position, context);
          Map.LoadContent();

          int evCount = int.Parse(line[position++]);
          for (int i = 0; i < evCount; i++)
          {
            Effects.Add(GameEffect.Create(line, ref position, context));
          }


          UnitCap = int.Parse(line[position++]);
          n = int.Parse(line[position++]);
          for (int i = 0; i < n; i++)
          {
            var p = new Player(i, context, null);
            Players.Add(p);
            p.Initialize();
          }
          for (int i = 0; i < n; i++)
          {
            Players[i].Deserialize(mt, line, ref position, context);
          }
          NaturePlayer = new Player(-1, context, null);
          NaturePlayer.Initialize();
          NaturePlayer.Deserialize(mt, line, ref position, context);
          List<Player> tempPlayers = new List<Player>(Players);
          tempPlayers.Add(NaturePlayer);
          foreach (var player in tempPlayers)
          {
            foreach (var unit in player.Units)
            {
              unit.ResolveReferences(GetGameObjectById);
            }
            foreach (var bldg in player.Buildings)
            {
              bldg.ResolveReferences(GetGameObjectById);
            }
          }
          NextUID = int.Parse(line[position++]);
          break;
        default:
          throw new Exception("WildmenGame deserialization error");
      }
    }