private static void MovePlayer(List <List <string> > field, SpaceShip player, int newRow, int newCol) { if (newRow == field.Count || newRow < 0 || field[0].Count == newCol || newCol < 0) { field[player.Row][player.Col] = "-"; // player.NeedMoney = 0; MarkHoleZiro(field); player.IsIlive = false; } else { if (field[newRow][newCol] == "O" || field[newRow][newCol] == "o" || field[newRow][newCol] == "0") { field[newRow][newCol] = "-"; field[player.Row][player.Col] = "-"; FindAnotherBlackHole(field, player); } else if (field[newRow][newCol] != "-") { int money = int.Parse(field[newRow][newCol].ToString()); player.NeedMoney += money; field[player.Row][player.Col] = "-"; field[newRow][newCol] = "S"; player.Row = newRow; player.Col = newCol; } else { field[player.Row][player.Col] = "-"; field[newRow][newCol] = "S"; player.Row = newRow; player.Col = newCol; } } }
static void Main(string[] args) { int sizeMatrix = int.Parse(Console.ReadLine()); List <List <string> > field = GreateField(sizeMatrix); SpaceShip player = FindPlayer(field); string command = Console.ReadLine(); while (true) { int newRow = player.Row; int newCol = player.Col; switch (command) { case "up": newRow -= 1; break; case "down": newRow += 1; break; case "left": newCol -= 1; break; case "right": newCol += 1; break; default: break; } MovePlayer(field, player, newRow, newCol); if (!player.IsIlive || player.NeedMoney >= 50) { break; } command = Console.ReadLine(); } if (!player.IsIlive) { Console.WriteLine($"Bad news, the spaceship went to the void."); Console.WriteLine($"Star power collected: {player.NeedMoney}"); } if (player.NeedMoney >= 50) { Console.WriteLine("Good news! Stephen succeeded in collecting enough star power!"); Console.WriteLine($"Star power collected: {player.NeedMoney}"); } PrintMatrix(field); }
private static SpaceShip FindPlayer(List <List <string> > field) { for (int row = 0; row < field.Count; row++) { for (int col = 0; col < field[row].Count; col++) { if (field[row][col] == "S") { SpaceShip player = new SpaceShip(row, col, 0); return(player); } } } return(null); }
private static void FindAnotherBlackHole(List <List <string> > field, SpaceShip player) { for (int row = 0; row < field.Count; row++) { for (int col = 0; col < field[row].Count; col++) { if (field[row][col] == "O") { field[row][col] = "S"; player.Row = row; player.Col = col; break; } } } }