コード例 #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");
      }
    }
コード例 #3
0
ファイル: Building.cs プロジェクト: arcticnw/Wildmen
    //

    /// <summary>
    /// Determines whether a building can be placed at given position
    /// </summary>
    /// <param name="map">Map, where the building-placement should be checked</param>
    /// <param name="baseTile">Base tile of the building-check</param>
    /// <param name="ignoreBuilding">Should the existing structures be ignored</param>
    /// <returns>Whether a building can be built at given position</returns>
    public static bool CanPlace(MapBoard map, Tile baseTile, bool ignoreBuilding = false)
    {
      int height = baseTile.Elevation;
      foreach (var d in new Direction[] { Direction.Center, Direction.TopLeft, Direction.Top, Direction.TopRight })
      {
        Tile item = map.GetSurroundingTile(baseTile, d);
        if (item == null) return false;
        if (!ignoreBuilding && item.Building != null) return false;
        if (item.Resource != null) return false;
        if (item.Elevation < MapBoard.SEA_LEVEL) return false;
        if (Math.Abs(item.Elevation - height) > 1) return false;
      }
      return true;
    }
コード例 #4
0
ファイル: MapUI.cs プロジェクト: arcticnw/Wildmen
    /// <summary>
    /// Background-Updates the MapUI, updating the game
    /// </summary>
    /// <param id="c">Screen cursor</param>
    public void BackgroundUpdate(Cursor c)
    {
      // Reset cursor
      c.UseDefault();
      c.UseText("");

      // If no map is present or map is not valid, flush the information and reload the map from the game
      if (this.map == null || !this.map.Valid)
      {
        FlushMapInfo();
        // If game doesn't have valid map, return
        if (this.game.Map == null || !this.game.Map.Valid)
        {
          return;
        }

        this.map = this.game.Map;
      }

      // Don't update if there is no controlling player (we are viewing server game)
      if (controllingPlayer != null)
      {
        // Update the game
        game.Update();

        // Validate our selection (it might have died, etc)
        ValidateSelection();
      }

      lastMouseVector = UI.Instance.MouseVector;
    }
コード例 #5
0
ファイル: MapUI.cs プロジェクト: arcticnw/Wildmen
    // UPDATE

    /// <summary>
    /// Updates the MapUI, handling mouse and keyboard input, cursor, updating the game
    /// </summary>
    /// <param id="c">Screen cursor</param>
    public void Update(Cursor c)
    {
      // If no map is present or map is not valid, flush the information and reload the map from the game
      if (this.map == null || !this.map.Valid)
      {
        FlushMapInfo();
        // If game doesn't have valid map, return
        if (this.game.Map == null || !this.game.Map.Valid)
        {
          return;
        }

        this.map = this.game.Map;
      }

      // If there is no controlling player, the targeting is disabled
      if (controllingPlayer != null)
      {
        UpdateTracking();

        // if autoCursor is enabled, try to guess suitable order
        if (autoCursor)
        {
          SmartCursor();
        }

        // Check the user controls
        cm.Update();
      }

      if (userPanelScrollCooldown > 0) userPanelScrollCooldown--;

      // Don't update mouse when the cursor is above user controls
      if (cm.IsMouseover)
      { }
      // Don't update mouse when the cursor is above menu
      else if ((inGameState == InGameStateEnum.BuildingPlacement || inGameState == InGameStateEnum.Spell) &&
          (UI.Instance.MouseVector.X > UI.Instance.ScreenBounds.X - USER_PANEL_SIZE))
      {
        MenuSelecting();
      }
      else
      {
        // Handle mouse buttons & scroll
        MouseUpdate();
      }
      // Handle keyboard input
      KeyboardUpdate();

      // Don't update if there is no controlling player (we are viewing server game)
      if (controllingPlayer != null)
      {
        // Update the game
        game.Update();

        // Validate our selection (it might have died, etc)
        ValidateSelection();
      }

      // Update mouse-over newText and cursor
      CursorUpdate(c);

      lastMouseVector = UI.Instance.MouseVector;
    }
コード例 #6
0
ファイル: MapUI.cs プロジェクト: arcticnw/Wildmen
    // INITIALIZE

    /// <summary>
    /// Constructor for the MapUI class
    /// </summary>
    /// <param id="game">game, the MapUI will overlook</param>
    public MapUI(WildmenGame game)
    {
      this.game = game;
      this.map = this.game.Map;
      this.inGameState = InGameStateEnum.Default;
    }
コード例 #7
0
ファイル: MapUI.cs プロジェクト: arcticnw/Wildmen
    // DISPOSING

    /// <summary>
    /// Flushes all the information about the map and resets the MapUI (while keeping the Game and ControllingPlayer)
    /// </summary>
    private void FlushMapInfo()
    {
      inGameState = InGameStateEnum.Default;

      mouseoverTile = null;
      mouseoverGameObject = null;
      map = null;

      mouseoverTileTracking = false;
      gameObjectTracking = true;
      mouseSelecting = false;
    }
コード例 #8
0
ファイル: Tile.cs プロジェクト: arcticnw/Wildmen
    /// <summary>
    /// Tile constructor
    /// </summary>
    /// <param id="x">X coordinate of this tile</param>
    /// <param id="y">Y coordinate of this tile</param>
    /// <param id="cpb">Additional tile parameters</param>
    public Tile(int x, int y, ConstructorParamBundle cpb)
    {
      Units = new List<Unit>();

      this.X = x;
      this.Y = y;

      bool oddTile = x % 2 == 1;
      float off = 0f;

      if (oddTile)
      {
        off = 0.5f;
      }

      this.MapPosition = new Vector2((x / 2 + off) * MapBoard.TILE_XSPACING, (y + off) * MapBoard.TILE_YSPACING);

      this.DrawZLevel = this.baseDrawZLevel = cpb.zLevel;
      this.DrawZLevelRange = cpb.zLevelStep;
      this.isBorder = cpb.isBorder;

      this.Elevation = -1;

      this.map = cpb.map;
    }