public void AssignPosition(intPos2 pos) { _column = pos.Column; _row = pos.Row; _s = -(_column + _row); AssignedPos = true; }
//Damage public void TakeDamage(float damage, intPos2 collisionPoint) { Parts hitpart = GetPartAtPosition(collisionPoint.Column, collisionPoint.Row); //TODO: can i do this better? :S _shipParts[_shipParts.IndexOf(hitpart)].TakeDamage(damage); CheckShipDestroyCriteria(); }
//ShipBuilding private intPos2 BuildShip(Parts part) { //TODO: this needs alot of work. function is to long, needs splitting and optimization. Dictionary <intPos2, int> emptyNeighbours = new Dictionary <intPos2, int>(new Utilities.intPos2EqualityComparer()); List <intPos2> exspantionPoints_2plus = new List <intPos2>(); //each hex foreach (Parts shipPart in _shipParts) { //check each neighbour to see if its null. //north 0 , -1 if (GetPartAtPosition(shipPart.Column, shipPart.Row - 1) == null) { //found an empty! intPos2 colRow = new intPos2(shipPart.Column, shipPart.Row - 1); if (emptyNeighbours.ContainsKey(colRow)) { emptyNeighbours[colRow] += 1; } else { emptyNeighbours.Add(colRow, 1); } } //north-East +1 , -1 if (GetPartAtPosition(shipPart.Column + 1, shipPart.Row - 1) == null) { //found an empty! intPos2 colRow = new intPos2(shipPart.Column + 1, shipPart.Row - 1); //has it been found before? if (emptyNeighbours.ContainsKey(colRow)) { emptyNeighbours[colRow] += 1; } else { emptyNeighbours.Add(colRow, 1); } } //north-West -1 , 0 if (GetPartAtPosition(shipPart.Column - 1, shipPart.Row) == null) { //found an empty! intPos2 colRow = new intPos2(shipPart.Column - 1, shipPart.Row); if (emptyNeighbours.ContainsKey(colRow)) { emptyNeighbours[colRow] += 1; } else { emptyNeighbours.Add(colRow, 1); } } //south 0 , +1 if (GetPartAtPosition(shipPart.Column, shipPart.Row + 1) == null) { //found an empty! intPos2 colRow = new intPos2(shipPart.Column, shipPart.Row + 1); if (emptyNeighbours.ContainsKey(colRow)) { emptyNeighbours[colRow] += 1; } else { emptyNeighbours.Add(colRow, 1); } } //south-East +1 , 0 if (GetPartAtPosition(shipPart.Column + 1, shipPart.Row) == null) { //found an empty! intPos2 colRow = new intPos2(shipPart.Column + 1, shipPart.Row); if (emptyNeighbours.ContainsKey(colRow)) { emptyNeighbours[colRow] += 1; } else { emptyNeighbours.Add(colRow, 1); } } //south-West -1 , +1 if (GetPartAtPosition(shipPart.Column - 1, shipPart.Row + 1) == null) { //found an empty! intPos2 colRow = new intPos2(shipPart.Column - 1, shipPart.Row + 1); if (emptyNeighbours.ContainsKey(colRow)) { emptyNeighbours[colRow] += 1; } else { emptyNeighbours.Add(colRow, 1); } } } /* * foreach (intPos2 item in emptyNeighbours.Keys) * { * Debug.Log(item.Column.ToString() + " " + item.Row.ToString() + ". seen:" + emptyNeighbours[item].ToString()); * } */ //if a possible location only has 1 neighbour then its not a valid exspantion point. foreach (intPos2 colRow in emptyNeighbours.Keys) { if (emptyNeighbours[colRow] > 1) { exspantionPoints_2plus.Add(colRow); } } //Debug.Log("All Valid Exspantion Points Complete. " + exspantionPoints_2plus.Count.ToString() + " possible points were found."); int sausages = rnd.Next(0, exspantionPoints_2plus.Count); return(exspantionPoints_2plus[sausages]); }