private void UpdateShipsLabels(Ships ships) { CurrentShip1Label.Text = ships.LengthCountShipsArray[4].ToString(); CurrentShip2Label.Text = ships.LengthCountShipsArray[3].ToString(); CurrentShip3Label.Text = ships.LengthCountShipsArray[2].ToString(); CurrentShip4Label.Text = ships.LengthCountShipsArray[1].ToString(); }
private void UpdateShipsLabels(Ships ships) { CurrentShip1Label.Text = ships.LengthCountShipsArray[4].ToString(); CurrentShip2Label.Text = ships.LengthCountShipsArray[3].ToString(); CurrentShip3Label.Text = ships.LengthCountShipsArray[2].ToString(); CurrentShip4Label.Text = ships.LengthCountShipsArray[1].ToString(); }
//ships logic /// <summary> /// Метод для подсчета количества кораблей у игрока /// при расставлении кораблей перед игрой /// </summary> /// <param name="cells"></param> /// <param name="s"></param> RecountStatus RecountReadyShips(Cell[][] cells, out Ships s) { s = new Ships(); //по умолчанию стоит максимальное количество кораблей каждого ранга, сравняем с реальным int nextShipLength = 0; //проходим по всем столбцам и строкам, так можно посчитать корабли длиннее 1 //по строкам for (int i = 0; i < cells.Length; i++) { for (int j = 0; j < cells[0].Length; j++) { if (i != 0 && j == 0) { if (nextShipLength > 4) { return(RecountStatus.MoreThanFourLengthShip); } if (nextShipLength > 1) { s.LengthCountShipsArray[nextShipLength]--; } nextShipLength = 0; } if (cells[i][j] == Cell.Life) { nextShipLength++; } if ((cells[i][j] != Cell.Life)) { if (nextShipLength > 4) { return(RecountStatus.MoreThanFourLengthShip); } if (nextShipLength > 1) { s.LengthCountShipsArray[nextShipLength]--; } nextShipLength = 0; } } } if (nextShipLength > 1) { s.LengthCountShipsArray[nextShipLength]--; } nextShipLength = 0; //по столбцам for (int i = 0; i < cells.Length; i++) { for (int j = 0; j < cells[0].Length; j++) { if (i != 0 && j == 0) { if (nextShipLength > 4) { return(RecountStatus.MoreThanFourLengthShip); } if (nextShipLength > 1) { s.LengthCountShipsArray[nextShipLength]--; } nextShipLength = 0; } if (cells[j][i] == Cell.Life) { nextShipLength++; } if (cells[j][i] != Cell.Life) { if (nextShipLength > 4) { return(RecountStatus.MoreThanFourLengthShip); } if (nextShipLength > 1) { s.LengthCountShipsArray[nextShipLength]--; } nextShipLength = 0; } } } if (nextShipLength > 1) { s.LengthCountShipsArray[nextShipLength]--; } for (int i = 0; i < cells.Length; i++) { for (int j = 0; j < cells[0].Length; j++) { if (cells[i][j] == Cell.Life && GetShipCells(cells, i, j).Count == 1) { //если корабль жив и его длина 1 ячейка.. s.LengthCountShipsArray[1]--; } } } return(RecountStatus.Success); }
//ships logic /// <summary> /// Метод для подсчета количества кораблей у игрока /// при расставлении кораблей перед игрой /// </summary> /// <param name="cells"></param> /// <param name="s"></param> RecountStatus RecountReadyShips(Cell[][] cells, out Ships s) { s = new Ships(); //по умолчанию стоит максимальное количество кораблей каждого ранга, сравняем с реальным int nextShipLength = 0; //проходим по всем столбцам и строкам, так можно посчитать корабли длиннее 1 //по строкам for (int i = 0; i < cells.Length; i++) { for (int j = 0; j < cells[0].Length; j++) { if (i != 0 && j == 0) { if (nextShipLength > 4) return RecountStatus.MoreThanFourLengthShip; if (nextShipLength > 1) s.LengthCountShipsArray[nextShipLength]--; nextShipLength = 0; } if (cells[i][j] == Cell.Life) nextShipLength++; if ((cells[i][j] != Cell.Life)) { if (nextShipLength > 4) return RecountStatus.MoreThanFourLengthShip; if (nextShipLength > 1) s.LengthCountShipsArray[nextShipLength]--; nextShipLength = 0; } } } if (nextShipLength > 1) s.LengthCountShipsArray[nextShipLength]--; nextShipLength = 0; //по столбцам for (int i = 0; i < cells.Length; i++) { for (int j = 0; j < cells[0].Length; j++) { if (i != 0 && j == 0) { if (nextShipLength > 4) return RecountStatus.MoreThanFourLengthShip; if (nextShipLength > 1) s.LengthCountShipsArray[nextShipLength]--; nextShipLength = 0; } if (cells[j][i] == Cell.Life) nextShipLength++; if (cells[j][i] != Cell.Life) { if (nextShipLength > 4) return RecountStatus.MoreThanFourLengthShip; if (nextShipLength > 1) s.LengthCountShipsArray[nextShipLength]--; nextShipLength = 0; } } } if (nextShipLength > 1) s.LengthCountShipsArray[nextShipLength]--; for (int i = 0; i < cells.Length; i++) { for (int j = 0; j < cells[0].Length; j++) { if (cells[i][j] == Cell.Life && GetShipCells(cells, i, j).Count == 1) //если корабль жив и его длина 1 ячейка.. s.LengthCountShipsArray[1]--; } } return RecountStatus.Success; }