Exemplo n.º 1
0
    private Coordinate MatchFreeBase(List<Coordinate> coords, WeewarMap wmap, Game g, Faction myFaction)
    {

      //Console.WriteLine("Coords:"+coords );
      foreach (Coordinate c in coords)
      {
        Terrain t = wmap.get(c);
        //Console.WriteLine("type :"+t.Type );
        Faction owner = g.getTerrainOwner(c);
        if (t.Type == TerrainType.Base && (owner == null || owner != myFaction) && g.getUnit(c) == null)
          return c;
      }
      return null;
    }
Exemplo n.º 2
0
 private List<Coordinate> getTargets(Game game, WeewarMap wmap, Faction myFaction)
 {
   List<Coordinate> targets = new List<Coordinate>();
   foreach (Faction faction in game.Factions)
   {
     if (faction == myFaction)
       continue;
     foreach (Unit otherUnit in faction.Units)
       targets.Add(otherUnit.Coordinate);
   }
   return targets;
 }
Exemplo n.º 3
0
 private List<Coordinate> getEnemyCities(Game game, WeewarMap wmap, Faction myFaction)
 {
   List<Coordinate> targets = new List<Coordinate>();
   List<Terrain> bases = wmap.getTerrainsByType(TerrainType.Base);
   foreach (Terrain ter in bases)
     if (game.getTerrainOwner(ter.Coordinate) != myFaction)
       targets.Add(ter.Coordinate);
   return targets;
 }
Exemplo n.º 4
0
    private Game parseGame(XmlElement gameEle)
    {
      Game g = new Game();
      String att = gameEle.GetAttribute("inNeedOfAttention");
      g.IsInNeedOfAttention = att == "true";
      g.Name = gameEle.SelectSingleNode("name").InnerText;
      g.Id = Int32.Parse(gameEle.SelectSingleNode("id").InnerText);
      XmlNode map = gameEle.SelectSingleNode("map");

      if (map != null && map.InnerText != null)
        g.MapId = Int32.Parse(map.InnerText);
      g.Link = gameEle.SelectSingleNode("url").InnerText;
      g.RequiresAnInviteAccept = g.Link.Contains("join");
      if (gameEle.SelectSingleNode("factions") != null)
      {
        XmlNodeList factions = gameEle.SelectNodes("factions/faction");
        foreach (XmlElement faction in factions)
        {
          Faction f = new Faction();
          g.Factions.Add(f);
          f.PlayerName = faction.GetAttribute("playerName");
          f.State = faction.GetAttribute("state");
          if (!String.IsNullOrEmpty(faction.GetAttribute("credits")))
            f.Credits = Int32.Parse(faction.GetAttribute("credits"));
          foreach (XmlElement unit in faction.SelectNodes("unit"))
          {
            Unit u = new Unit();
            u.Coordinate = new Coordinate(Int32.Parse(unit.GetAttribute("x")), Int32.Parse(unit.GetAttribute("y")));
            u.Type = Unit.ToType(unit.GetAttribute("type"));
            u.Finished = "true" == unit.GetAttribute("finished");
            u.Quantity = Int32.Parse(unit.GetAttribute("quantity"));
            f.Units.Add(u);
          }
          foreach (XmlElement unit in faction.SelectNodes("terrain"))
          {
            Terrain t = new Terrain();
            t.Coordinate = new Coordinate(Int32.Parse(unit.GetAttribute("x")), Int32.Parse(unit.GetAttribute("y")));
            t.Type = Terrain.ToType(unit.GetAttribute("type"));
            t.Finished = "true" == unit.GetAttribute("finished");
            f.Terrains.Add(t);
          }
        }
      }
      return g;
    }