public void EnableShipType(eShipType shipType, int count) { if (!_shipTypes.ContainsKey(shipType)) { _shipTypes.Add(shipType, count); } }
public Ship(eShipType shipType, eShipOrientation shipOrientation, int id) { _shipType = shipType; _shipOrientation = shipOrientation; _length = (int)_shipType; _health = _length; _shipId = id; _cells = new List <ICell>(); }
public bool PlaceShip(eShipType shipType, eShipOrientation shipOrientation, int startX, int startY) { if (_shipTypes.ContainsKey(shipType) && _ships.Count(x => x.GetShipType() == shipType) < _shipTypes[shipType]) { var shipid = _randomizer.Next(1, 100); var ship = new Ship(shipType, shipOrientation, shipid); var shipTempCells = new List <ICell>(); for (int i = 0; i < ship.GetShipLenght(); i++) { ICell startingCell = null; if (shipOrientation == eShipOrientation.Horizontal) { startingCell = _cells.FirstOrDefault(x => x.GetX() == startX + i && x.GetY() == startY); } else { startingCell = _cells.FirstOrDefault(x => x.GetX() == startX && x.GetY() == startY + i); } if (startingCell != null && startingCell.GetCellType() != eCellType.Ship) { shipTempCells.Add(startingCell); } else { return(false); } } foreach (var tempCell in shipTempCells) { tempCell.SetCellType(eCellType.Ship); } ship.SetCells(shipTempCells); _ships.Add(ship); return(true); } else { return(false); } }
void RpcSetShipType2(int aShipType, int aTeam, int aShipID, float aAngle, Vector3 aPosition, float aRespawnTime, Vector3[] aPath, float aPathSpeed) { m_team = aTeam; m_startPosition = aPosition; m_startAngle = aAngle; m_respawnTime = aRespawnTime; transform.position = m_startPosition; transform.rotation = Quaternion.Euler(0, 0, m_startAngle); GameObject.Find("GameManager").GetComponent<GameManager>().AddSpawnedShip(this); m_shipType = (eShipType)aShipType; m_shipTargets = new List<ShipTarget>(); m_shipID = aShipID; int index = 1; GameObject graphic = null; string path = ""; switch (m_shipType) { case eShipType.SHIP_TYPE_CARRIER: path = "Carrier0" + aTeam; break; case eShipType.SHIP_TYPE_BATTLESHIP: path = "Battleship0" + aTeam; break; case eShipType.SHIP_TYPE_CRUISER: path = "Cruiser0" + aTeam; break; case eShipType.SHIP_TYPE_PATROLBOAT: path = "PatrolBoat0" + aTeam; break; case eShipType.SHIP_TYPE_DESTROYER: path = "Destroyer0" + aTeam; break; } m_shipPrefab = (GameObject)Resources.Load(path); graphic = (GameObject)Instantiate(m_shipPrefab, transform.FindChild("ShipGraphic").position, transform.FindChild("ShipGraphic").rotation); graphic.transform.parent = transform.FindChild("ShipGraphic"); if (aTeam == 1) { graphic.transform.FindChild("Graphic").gameObject.layer = 16; } else { graphic.transform.FindChild("Graphic").gameObject.layer = 17; } bool done = false; path = ""; while (!done) { path = "TargetPosition" + index; Transform target = graphic.transform.FindChild(path); if (target != null) { GameObject targetGraphic = (GameObject)Instantiate((GameObject)Resources.Load("TargetPosition"), target.position, target.rotation); m_shipTargets.Add(new ShipTarget(targetGraphic, target, m_shipID, index - 1)); } else { done = true; break; } index++; } }
void RpcSetShipType1(int aShipType, int aTeam, int aShipID) { if (m_startPosition == new Vector3(-1, -1, -1)) { m_startPosition = transform.position; m_startAngle = transform.eulerAngles.z; m_respawnTime = -1; m_team = aTeam; GameObject.Find("GameManager").GetComponent<GameManager>().AddSpawnedShip(this); m_shipType = (eShipType)aShipType; m_shipTargets = new List<ShipTarget>(); m_shipID = aShipID; int index = 1; GameObject graphic = null; string path = ""; switch (m_shipType) { case eShipType.SHIP_TYPE_CARRIER: path = "Carrier0" + aTeam; break; case eShipType.SHIP_TYPE_BATTLESHIP: path = "Battleship0" + aTeam; break; case eShipType.SHIP_TYPE_CRUISER: path = "Cruiser0" + aTeam; break; case eShipType.SHIP_TYPE_PATROLBOAT: path = "PatrolBoat0" + aTeam; break; case eShipType.SHIP_TYPE_DESTROYER: path = "Destroyer0" + aTeam; break; } m_shipPrefab = (GameObject)Resources.Load(path); graphic = (GameObject)Instantiate(m_shipPrefab, transform.FindChild("ShipGraphic").position, transform.FindChild("ShipGraphic").rotation); graphic.transform.parent = transform.FindChild("ShipGraphic"); if (aTeam == 1) { graphic.transform.FindChild("Graphic").gameObject.layer = 16; } else { graphic.transform.FindChild("Graphic").gameObject.layer = 17; } bool done = false; path = ""; while (!done) { path = "TargetPosition" + index; Transform target = graphic.transform.FindChild(path); if (target != null) { GameObject targetGraphic = (GameObject)Instantiate((GameObject)Resources.Load("TargetPosition"), target.position, target.rotation); m_shipTargets.Add(new ShipTarget(targetGraphic, target, m_shipID, index - 1)); } else { done = true; break; } index++; } } else { m_team = aTeam; transform.position = m_startPosition; transform.rotation = Quaternion.Euler(0, 0, m_startAngle); GameObject.Find("GameManager").GetComponent<GameManager>().AddSpawnedShip(this); m_shipType = (eShipType)aShipType; m_shipTargets = new List<ShipTarget>(); m_shipID = aShipID; int index = 1; GameObject graphic = transform.GetChild(0).GetChild(0).gameObject; m_shipTargets.Clear(); bool done = false; string path = ""; while (!done) { path = "TargetPosition" + index; Transform target = graphic.transform.FindChild(path); if (target != null) { GameObject targetGraphic = (GameObject)Instantiate((GameObject)Resources.Load("TargetPosition"), target.position, target.rotation); m_shipTargets.Add(new ShipTarget(targetGraphic, target, m_shipID, index - 1)); } else { done = true; break; } index++; } ParticleSystem[] effects = transform.GetComponentsInChildren<ParticleSystem>(); for (int i = 0; i < effects.Length; i++) { Destroy(effects[i].gameObject); } } }
public void SetShipType(eShipType aShipType, int aTeam, int aShipID, float aAngle, Vector3 aPosition, float aRespawnTime, Vector3[] aPath, float aPathSpeed) { RpcSetShipType2((int)aShipType, aTeam, aShipID, aAngle, aPosition, aRespawnTime, aPath, aPathSpeed); CmdSetShipType2((int)aShipType, aTeam, aShipID, aAngle, aPosition, aRespawnTime, aPath, aPathSpeed); }
public void SetShipType(eShipType aShipType, int aTeam, int aShipID) { RpcSetShipType1((int)aShipType, aTeam, aShipID); CmdSetShipType1((int)aShipType, aTeam, aShipID); }
public void SetShipType(eShipType aShipType, int aTeam, int aShipID, float aAngle, Vector3 aPosition, float aRespawnTime, Vector3[] aPath, float aPathSpeed) { RpcSetShipType2((int)aShipType, aTeam, aShipID, aAngle, aPosition, aRespawnTime, aPath, aPathSpeed); }
public void SetShipType(eShipType aShipType, int aTeam, int aShipID) { RpcSetShipType1((int)aShipType, aTeam, aShipID); }
//[ClientRpc] void RpcSetShipType2(int aShipType, int aTeam, int aShipID, float aAngle, Vector3 aPosition, float aRespawnTime, Vector3[] aPath, float aPathSpeed) { m_team = aTeam; m_startPosition = aPosition; m_startAngle = aAngle; m_respawnTime = aRespawnTime; transform.position = m_startPosition; transform.rotation = Quaternion.Euler(0, 0, m_startAngle); GameObject.Find("GameManager").GetComponent <GameManager>().AddSpawnedShip(this); m_shipType = (eShipType)aShipType; m_shipTargets = new List <ShipTarget>(); m_shipID = aShipID; int index = 1; GameObject graphic = null; string path = ""; switch (m_shipType) { case eShipType.SHIP_TYPE_CARRIER: path = "Carrier0" + aTeam; break; case eShipType.SHIP_TYPE_BATTLESHIP: path = "Battleship0" + aTeam; break; case eShipType.SHIP_TYPE_CRUISER: path = "Cruiser0" + aTeam; break; case eShipType.SHIP_TYPE_PATROLBOAT: path = "PatrolBoat0" + aTeam; break; case eShipType.SHIP_TYPE_DESTROYER: path = "Destroyer0" + aTeam; break; } m_shipPrefab = (GameObject)Resources.Load("Prefabs/Game/" + path); graphic = (GameObject)Instantiate(m_shipPrefab, transform.Find("ShipGraphic").position, transform.Find("ShipGraphic").rotation); graphic.transform.parent = transform.Find("ShipGraphic"); if (aTeam == 1) { graphic.transform.Find("Graphic").gameObject.layer = 16; } else { graphic.transform.Find("Graphic").gameObject.layer = 17; } bool done = false; path = ""; while (!done) { path = "TargetPosition" + index; Transform target = graphic.transform.Find(path); if (target != null) { GameObject targetGraphic = (GameObject)Instantiate((GameObject)Resources.Load("Prefabs/Game/" + "TargetPosition"), target.position, target.rotation); m_shipTargets.Add(new ShipTarget(targetGraphic, target, m_shipID, index - 1)); } else { done = true; break; } index++; } }
//[ClientRpc] void RpcSetShipType1(int aShipType, int aTeam, int aShipID) { if (m_startPosition == new Vector3(-1, -1, -1)) { m_startPosition = transform.position; m_startAngle = transform.eulerAngles.z; transform.rotation = Quaternion.Euler(0, 0, m_startAngle); m_respawnTime = -1; m_team = aTeam; GameObject.Find("GameManager").GetComponent <GameManager>().AddSpawnedShip(this); m_shipType = (eShipType)aShipType; m_shipTargets = new List <ShipTarget>(); m_shipID = aShipID; int index = 1; GameObject graphic = null; string path = ""; switch (m_shipType) { case eShipType.SHIP_TYPE_CARRIER: path = "Carrier0" + aTeam; break; case eShipType.SHIP_TYPE_BATTLESHIP: path = "Battleship0" + aTeam; break; case eShipType.SHIP_TYPE_CRUISER: path = "Cruiser0" + aTeam; break; case eShipType.SHIP_TYPE_PATROLBOAT: path = "PatrolBoat0" + aTeam; break; case eShipType.SHIP_TYPE_DESTROYER: path = "Destroyer0" + aTeam; break; } m_shipPrefab = (GameObject)Resources.Load("Prefabs/Game/" + path); graphic = (GameObject)Instantiate(m_shipPrefab, transform.Find("ShipGraphic").position, transform.Find("ShipGraphic").rotation); graphic.transform.parent = transform.Find("ShipGraphic"); if (aTeam == 1) { graphic.transform.Find("Graphic").gameObject.layer = 16; } else { graphic.transform.Find("Graphic").gameObject.layer = 17; } bool done = false; path = ""; while (!done) { path = "TargetPosition" + index; Transform target = graphic.transform.Find(path); if (target != null) { GameObject targetGraphic = (GameObject)Instantiate((GameObject)Resources.Load("Prefabs/Game/" + "TargetPosition"), target.position, target.rotation); m_shipTargets.Add(new ShipTarget(targetGraphic, target, m_shipID, index - 1)); } else { done = true; break; } index++; } } else { m_team = aTeam; transform.position = m_startPosition; transform.rotation = Quaternion.Euler(0, 0, m_startAngle); GameObject.Find("GameManager").GetComponent <GameManager>().AddSpawnedShip(this); m_shipType = (eShipType)aShipType; m_shipTargets = new List <ShipTarget>(); m_shipID = aShipID; int index = 1; GameObject graphic = transform.GetChild(0).GetChild(0).gameObject; m_shipTargets.Clear(); bool done = false; string path = ""; while (!done) { path = "TargetPosition" + index; Transform target = graphic.transform.Find(path); if (target != null) { GameObject targetGraphic = (GameObject)Instantiate((GameObject)Resources.Load("Prefabs/Game/" + "TargetPosition"), target.position, target.rotation); m_shipTargets.Add(new ShipTarget(targetGraphic, target, m_shipID, index - 1)); } else { done = true; break; } index++; } ParticleSystem[] effects = transform.GetComponentsInChildren <ParticleSystem>(); for (int i = 0; i < effects.Length; i++) { Destroy(effects[i].gameObject); } } }
public void SetShipType(eShipType aShipType, int aTeam, int aShipID, float aAngle, Vector3 aPosition, float aRespawnTime, Vector3[] aPath, float aPathSpeed) { GetComponent <PhotonView>().RPC("SetShipTypeRPC", PhotonTargets.AllBuffered, (int)aShipType, aTeam, aShipID, aAngle, aPosition, aRespawnTime, aPath, aPathSpeed); }
public void SetShipType(eShipType aShipType, int aTeam, int aShipID) { GetComponent <PhotonView>().RPC("SetShipTypeRPC", PhotonTargets.AllBuffered, (int)aShipType, aTeam, aShipID); }