public virtual void InitSpaceship(string formation, List <CSpot> saveSpots, bool display) { var shipStrs = formation.Split(','); // "index:X:Y" for (int i = 0; i < shipStrs.Length; i++) { // CONFIGS var shipFormat = shipStrs[i].Split(':'); var shipIndex = int.Parse(shipFormat[0]); // INDEX var shipX = int.Parse(shipFormat[1]); // X var shipY = int.Parse(shipFormat[2]); // Y // SAVE var shipData = this.m_Spaceships[shipIndex]; for (int s = 0; s < shipData.spots.Length; s++) { var spot = shipData.spots[s]; var newSpot = new CSpot(shipX + spot.posX, shipY + spot.posY); saveSpots.Add(newSpot); } // DISPLAY if (display) { var ship = Instantiate(shipData); ship.transform.SetParent(this.m_Battlefield.transform); ship.name = String.Format("Ship_{0}", i); ship.SetPositionWithSize(shipX, shipY); } } }
protected virtual string PlaceSpaceship(int index, CSpaceship ship, params CSpot[] spots) { var randomX = UnityEngine.Random.RandomRange(0, this.m_MapColumn); var randomY = UnityEngine.Random.RandomRange(0, this.m_MapColumn); var step = spots.Length + 9999; var resultStr = String.Empty; for (int i = 0; i < spots.Length;) { var spot = spots[i]; var spotX = spot.posX; var spotY = spot.posY; var newSpot = new CSpot(spot.posX + randomX, spot.posY + randomY); if (randomX + spotX >= 0 && // MIN_X randomX + spotX < this.m_MapColumn && // MAX_X randomY + spotY >= 0 && // MIN_Y randomY + spotY < this.m_MapColumn && // MAX_Y this.m_PlayerSpaceshipSpots.Contains(newSpot) == false) { i++; } else { randomX = UnityEngine.Random.RandomRange(0, this.m_MapColumn); randomY = UnityEngine.Random.RandomRange(0, this.m_MapColumn); i = 0; } step--; if (step < 0) { break; } } if (step < 0) { ship.gameObject.SetActive(false); } else { for (int i = 0; i < ship.spots.Length; i++) { var spot = ship.spots[i]; var newSpot = new CSpot(spot.posX + randomX, spot.posY + randomY); this.m_PlayerSpaceshipSpots.Add(newSpot); } ship.SetPositionWithSize(randomX, randomY); resultStr = String.Format("{0}:{1}:{2}", index, randomX, randomY); } return(resultStr); }
protected virtual void OnReceiveChessPosition(SocketIOEvent e) { var currentPos = e.data.GetField("currentPos"); var x = int.Parse(currentPos.GetField("x").ToString()); var y = int.Parse(currentPos.GetField("y").ToString()); var turnIndex = int.Parse(e.data.GetField("turnIndex").ToString()); var chess = this.m_MapChesses[x, y]; this.m_TurnIndex = turnIndex == 1; var newSpot = new CSpot(x, y); if (this.IsLocalTurn()) { var isEnemyContain = this.m_EnemyCheckSpot.Contains(newSpot); chess.SetState(CChess.ESpotState.PLAYER_FIRED, isEnemyContain); if (isEnemyContain) { this.m_EnemyCheckSpot.Remove(newSpot); this.SetResult("Player", x, y, CResult.EResult.EXPLOSIVE); } else { this.SetResult("Player", x, y, CResult.EResult.INACTIVE); } this.ShowResult("Enemy"); } else { var isPlayerContain = this.m_PlayerCheckSpot.Contains(newSpot); chess.SetState(CChess.ESpotState.ENEMY_FIRED, isPlayerContain); if (isPlayerContain) { this.m_PlayerCheckSpot.Remove(newSpot); this.SetResult("Enemy", x, y, CResult.EResult.EXPLOSIVE); } else { this.SetResult("Enemy", x, y, CResult.EResult.INACTIVE); } this.ShowResult("Player"); } this.CheckTurn(); this.ChangeTurn(); }
public CSpot(CSpot value) { this.m_X = value.posX; this.m_Y = value.posY; }
public CResult(CSpot value) : base(value) { this.value = EResult.NONE; }