public void MoveToken(Hex destHex, MoveableToken token) { //remove the ship token from its current location Hex hex = _hexArray[token.HexIndex.X, token.HexIndex.Y]; if (hex != null) { hex.TokenList.RemoveToken(token); } //add the token to its new hex destHex.TokenList.AddToken(token); //change the token's current hex token.HexIndex = destHex.Index; //resets the tokens pixel location destHex.SetPoints(); Console.WriteLine("Token Moved from " + hex.Index + " to " + destHex.Index); }
private MoveableToken CreatePlayerShipToken(Ship ship, int ID) // ID? { switch (ship.Type) { case Ship.ShipType.Colony: { MoveableToken token = new MoveableToken("ShipColony" + ID + ".ico", ship.HexLocation); token.Source = ship; return(token); } case Ship.ShipType.Scout: { MoveableToken token = new MoveableToken("ShipScout" + ID + ".ico", ship.HexLocation); token.Source = ship; return(token);; } case Ship.ShipType.Defender: { MoveableToken token = new MoveableToken("ShipDefender" + ID + ".ico", ship.HexLocation); token.Source = ship; return(token); } case Ship.ShipType.Base: { MoveableToken token = new MoveableToken("ColonyBase" + ID + ".ico", ship.HexLocation); token.Source = ship; return(token); } default: { Console.WriteLine("default moveable ship token created"); return(null); } } }
/// <summary> /// populate TokenList with all visible tokens drawn from /// GameData, compile these in order for re-paint and hit- /// testing purposes: system tokens, non-movable ships /// including players own ships, then moveable /// tokens, i.e. current players fleet /// </summary> public TokenList(PlayerList playerList, SystemList systemList, HexArray hexArray, int playerID) { // // Create token for Worm hole, assign it to its hex and // add it to the token list // Token wormholeToken = new Token("Wormhole.ico", hexArray.Wormhole); hexArray[hexArray.Wormhole.X, hexArray.Wormhole.Y].SystemToken = wormholeToken; _tokenArray.Add(wormholeToken); // Cycle through systemList, creating tokens for // each system, adding them to the list and // assigning them to their home hex. for (int i = 0; i < systemList.Count; i++) { StarSystem system = systemList[i]; Point location = system.MapLocation; //Hex index of system Token token = CreateSystemToken(system, location); _tokenArray.Add(token); hexArray[location.X, location.Y].SystemToken = token; } // // Cycle through playerlist, getting Fleets and creating // Tokens for fleets and adding them to the list // and assigning their to a home hex. Skip this player // and create moveable tokens assigning them. // int count = playerList.Count; for (int i = 0; i < count; i++) { Fleet fleet = playerList[i].Fleet; //skip this players icons for now if (i == playerID) { continue; } for (int j = 0; j < fleet.Count; j++) { Ship ship = fleet[j]; if (ship.Type == Ship.ShipType.Trader) { continue; } Token token = CreateShipToken(ship, i); _tokenArray.Add(token); hexArray[ship.HexLocation.X, ship.HexLocation.Y].TokenList.AddToken(token); } } //if this is the controller view, we're done if (playerID == -1) { return; } //otherwise //create this players fleet tokens //add them to the list and assign them to their hexes for (int i = 0; i < playerList[playerID].Fleet.Count; i++) { Ship ship = playerList[playerID].Fleet[i]; if (ship.Type == Ship.ShipType.Trader) { continue; } MoveableToken token = CreatePlayerShipToken(ship, playerID); _tokenArray.Add(token); hexArray[ship.HexLocation.X, ship.HexLocation.Y].TokenList.AddToken(token); } }