public void DrawField(Ship[] ships, FrontendField field, bool?areShipsHidden) { int[] shipStates = TransformShipStatesInArray(ships); int[][] shipCoords = TransformShipCoordInInts(ships); int numberToChar = 63; int number = 47; int f = 0; for (int y = 0; y < Constants.height - 1; y++) { number++; for (int x = 0; x < Constants.width; x++) { numberToChar++; symbol = field.field[y, x]; if (y == 0 && x >= 1) { symbol = (char)numberToChar; } if (y >= 1 && x == 0) { symbol = (char)number; } if ((bool)!areShipsHidden) { for (int i = 0; i < ships.Length; i++) { if (shipCoords[i][0] == x && shipCoords[i][1] == y) { if (shipStates[i] == 0) { symbol = '!'; } if (shipStates[i] == 1) { symbol = '#'; } if (shipStates[i] == 2) { symbol = '.'; } } } } if (symbol == '.' || symbol == '^') { field.field[y, x] = symbol; } Console.Write(symbol); } Console.WriteLine(); } }
private void CheckForHit(Ship[] ships, FrontendField field, int x, int y) { for (int i = 0; i < ships.Length; i++) { if (ships[i].xCoord == x && ships[i].yCoord == y) { ships[i].state = ShipState.destroyed; field.field[y, x] = '#'; uiReference.WriteASentence(ConsoleColor.Cyan, "Hit!"); if (counter == 1) { counter = 2; } else //Making counter +1 or -1 to start playerCycle/aiCycle again when hit { counter = -1; } return; } } uiReference.WriteASentence(ConsoleColor.Cyan, "Miss!"); field.field[y, x] = '^'; }