public static List <BattleshipPlayer> CreatePlayers() { List <BattleshipPlayer> lista = new List <BattleshipPlayer>(); for (int i = 0; i < NumberOfPlayer; i++) { if (i == 0) { Player1 = new BattleshipPlayer(i + 1); lista.Add(Player1); } if (i == 1) { Player2 = new BattleshipPlayer(i + 1); lista.Add(Player2); } if (i == 2) { Player3 = new BattleshipPlayer(i + 1); lista.Add(Player3); } if (i == 3) { Player4 = new BattleshipPlayer(i + 1); lista.Add(Player4); } } return(lista); }
public static void PlayBattleShip() { while (playAgain) { playAgain = false; Console.Clear(); BattleShipIntro(); Console.Clear(); TextBattleShip(); BattlechipBoard.SizeOfBoardX = BattlechipBoard.DecideXSizeOnBoard(); BattlechipBoard.SizeOfBoardY = BattlechipBoard.DecideYSizeOnBoard(); Console.Clear(); TextBattleShip(); PlayersDone = 0; NumberOfPlayer = BattleshipPlayer.HowManyPlayers(); Players = CreatePlayers(); Console.Clear(); //tillfälligt - kolla så de hamnar rätt! //TryPrint(Player1.BoatsOnBoard); //Console.ReadLine(); while (NumberOfPlayer != PlayersDone) { foreach (var player in Players) { if (player.AllFound == false) { Console.Clear(); TextBattleShip(); YourTurn(player); player.PrintBoard(); player.GuessXAndY(); player.UpdateBoardWithGuess(); Console.Clear(); TextBattleShip(); YourResult(player); player.PrintBoard(); Console.WriteLine(); player.CheckIfDone(); Console.ReadLine(); } } } PlayAgain(); int choice = InputNumber(0, 1); if (choice == 1) { playAgain = true; } } }
public static void YourResult(BattleshipPlayer player) { Console.WriteLine($"\n\t\t\tSPELARE {Players.IndexOf(player) + 1}: {player.Name}, din gissning visade:"); Console.WriteLine("\t\t\t---------------------------------------"); }
public static void YourTurn(BattleshipPlayer player) { Console.WriteLine($"\n\t\t\tSPELARE {Players.IndexOf(player) + 1}: {player.Name}, din tur!"); Console.WriteLine("\t\t\t---------------------------------------"); }