public bool IsValid() { if (cells.Count == 0) { return(false); } bool areVert = true; bool areHor = true; eCell firstCell = cells[0]; foreach (eCell cell in cells) { if (cell.Type == eCell.eType.ALIVE || cell.Type == eCell.eType.HITTED) { return(false); } if (firstCell.X != cell.X) { areHor = false; } if (firstCell.Y != cell.Y) { areVert = false; } if (!areVert && !areHor) { break; } } return(areVert || areHor); }
protected string ConsoleCellPrint(bool isOwner, eCell cell) { if (isOwner) { switch (cell.Type) { case eCell.eType.ALIVE: return("B"); case eCell.eType.EMPTY: return("?"); case eCell.eType.HITTED: return("$"); case eCell.eType.MISSED: return("#"); } } switch (cell.Type) { case eCell.eType.ALIVE: case eCell.eType.EMPTY: return("u"); case eCell.eType.HITTED: return("$"); case eCell.eType.MISSED: return("#"); } return(""); }
public override bool Equals(Object _right) { if (_right == null) { return(false); } eCell right = (eCell)_right; return(X == right.X && Y == right.Y); }
protected bool IsCellsAroundEmpty(eCell cell) { List <eCell> cellsAround = cells.FindAll(delegate(eCell item) { return(item.Type != eCell.eType.EMPTY && ((Math.Abs(item.X - cell.X) == 1 && Math.Abs(item.Y - cell.Y) == 0) || (Math.Abs(item.X - cell.X) == 1 && Math.Abs(item.Y - cell.Y) == 1) || (Math.Abs(item.X - cell.X) == 0 && Math.Abs(item.Y - cell.Y) == 1))); }); return(cellsAround.Count == 0); }
public bool IsValid() { if (cells.Count == 0 || cells.Count > 4) { return(false); } bool areVert = true; bool areHor = true; //todo: bug eCell firstCell = cells[0]; eCell minCell = cells[0]; eCell maxCell = cells[0]; foreach (eCell cell in cells) { if (minCell.X > cell.X || minCell.Y > cell.Y) { minCell = cell; } if (maxCell.X < cell.X || maxCell.Y < cell.Y) { maxCell = cell; } if (cell.Type != eCell.eType.ALIVE && cell.Type != eCell.eType.HITTED) { return(false); } if (firstCell.X != cell.X) { areHor = false; } if (firstCell.Y != cell.Y) { areVert = false; } if (!areVert && !areHor) { break; } } return((areVert || areHor) && (cells.Count == maxCell.Y - minCell.Y + 1 || cells.Count == maxCell.X - minCell.X + 1)); }
protected bool AddShip_(eShip ship) { List <eCell> copyShipCells = new List <eCell>(); foreach (eCell cell in ship.Cells()) { eCell copyItem = cells.Find(delegate(eCell item) { return(item.X == cell.X && item.Y == cell.Y); }); if (copyItem == null) { return(false); } copyShipCells.Add(copyItem); } ships.Add(new eShip(copyShipCells)); return(true); }
//to do:kill after working with ui public string ConsolePrint(eUser user = null) { bool isOwner = user == owner; string result; string horDiv = "----------------------"; string vertDiv = "|"; string upTitle = " |A|B|C|D|E|F|G|H|I|J|"; result = horDiv + "\n" + upTitle + "\n" + horDiv; for (int i = 0; i < 10; ++i) { string line = (i).ToString() + vertDiv; for (int j = 0; j < 10; ++j) { eCell cell = cells[10 * i + j]; line += ConsoleCellPrint(isOwner, cell) + vertDiv; } result += "\n" + line + "\n" + horDiv; } return(result); }
public void AddCell(eCell _cell) { _cell.SetShip(this); cells.Add(_cell); }