/// <summary> /// Apresenta um menu e pergunta ao jogador se quer sair do jogo, ou se quer guardar o jogo. /// </summary> /// <returns> true - o jogo continua, false- o jogo e encesserado </returns> public static bool ExitGameMenu(Game game) { string msg = null; while (true) { GameCli.ExitSaveGame(msg); ExitGameOptions?option = getExitGameOption(); if (option == null) { msg = Settings.MsgApp["Erro_InputInvalid"]; } else { switch (option) { case ExitGameOptions.SaveGame: game.SaveGameJson(); msg = Settings.MsgApp["Success_Save"]; break; case ExitGameOptions.Return: return(true); case ExitGameOptions.Exit: return(false); } } } }
/// <summary> /// Pogica do menu de carregamento de jogos /// Permite selecionar um dos ficheiros de json a carregar /// </summary> /// <param name="files"> Lista de ficheiros de saves</param> /// <param name="pag_start"> Index inical da lista de saves </param> /// <param name="n_lines"> Numero de ficheiros apresentados por pagina</param> /// <returns></returns> public static int LoadGameMenu(string[] files, int pag_start, int n_lines) { string msg = null; Boolean loop = true; if (pag_start < 0) { pag_start = 0; } while (loop) { GameCli.LoadGameMenuCli(files, pag_start, n_lines); var result = getLoadGameOption(); if (result.option == null) { msg = Settings.MsgApp["Erro_InputInvalid"]; } else { switch (result.option) { case LoadGameOptions.PreviousPage: if ((pag_start - n_lines) > 0) { pag_start = pag_start - n_lines; } else { pag_start = 0; } break; case LoadGameOptions.NextPage: if ((pag_start + n_lines) < files.Length) { pag_start = pag_start + n_lines; } break; case LoadGameOptions.File: return(result.file - 1); case LoadGameOptions.Exit: loop = false; break; } } } return(-1); }
/// <summary> /// Logica do menu inical /// </summary> public static void StartGameMenu() { string msg = null; Boolean loop = true; while (loop) { GameCli.StartMenu(msg); StartMenuOptions?option = getStartMenuOption(); if (option == null) { msg = Settings.MsgApp["Erro_InputInvalid"]; } else { switch (option) { case StartMenuOptions.NewGame: Menus.NewGameMenu(); break; case StartMenuOptions.LoadGame: String[] files = Tools.ProcessDirectory("Saves"); int file = Menus.LoadGameMenu(files, 0, 10); if (file >= 0 && file < files.Length) { Game.LoadSavedFile(files[file]); } break; case StartMenuOptions.Instructions: GameCli.Intrucoes(); break; case StartMenuOptions.Exit: loop = false; break; } msg = null; } } }
/// <summary> /// Logica do Menu de de inserir navios /// apresenta o tabuleiro onde os navios são inseridos e pergunta ao utilizador qual ação quer tomar /// </summary> /// <param name="ships"> Lista de navios do jogador</param> public void MenuCreatShips(List <Ship> ships) { bool loop = true; bool isAdded = false; String msg = null; List <int> listSizeShips = new List <int>(Settings.ListShipsToInsert); do { GameCli.CreatBoard(this, listSizeShips.Count, msg); CreateBoardOptions?option = Menus.getCreateBoardOption(); if (option == null) { msg = Settings.MsgApp["Erro_InputInvalid"]; } else { switch (option) { case CreateBoardOptions.AddShip: if (0 < listSizeShips.Count) { Console.WriteLine("Tamanho do navio a inserir:" + listSizeShips[0]); Console.WriteLine("Insira a cordenada do Navio:"); isAdded = AddByListShips(ships, listSizeShips[0]); if (isAdded) { listSizeShips.RemoveAt(0); msg = Settings.MsgApp["Success_InsertShip"]; } else { msg = Settings.MsgApp["Erro_InsertShip"]; } } else { Console.WriteLine("Todos os Navios foram inseridos!"); } break; case CreateBoardOptions.RemoveShip: if (ships.Count > 0) { Console.WriteLine("Insira a cordenada do Navio a Remover:"); var IsRemove = RemoveByListShips(ships); if (IsRemove.Item1) { listSizeShips.Insert(0, IsRemove.Item2); Console.WriteLine("Navio removido"); } else { Console.WriteLine("Navio não removido"); } } else { Console.WriteLine("Não existem navios para remover!"); } break; case CreateBoardOptions.Exit: loop = false; break; } } } while (loop); }
/// <summary> /// Apresenta as ações que o jogador pode tomar durante o jogo /// </summary> /// <param name="attakOn">se o jogador pode atacar ou não</param> /// <param name="shot"> estado do ataque 0-não atacou 1-falhou 2-acertou 3-afundou navio 4-venceu jogo </param> /// <param name="name"> Nome do vencedor</param> public static void GamingActions(bool attakOn, int shot, string name, string msg) { string info = null; if (attakOn) { Console.WriteLine("╠══════════════╦══════════════════╬════════════════════╦═══════════════╣"); Console.WriteLine("║ A - Atacar ║ B - Passar turno ║ S - Guardar ║ Q - Sair ║"); Console.WriteLine("╚══════════════╩══════════════════╩════════════════════╩═══════════════╝"); } else { switch (shot) { case 1: info = "║ " + Settings.MsgApp["Info_ShipHitFail"]; break; case 2: info = "║ " + Settings.MsgApp["Info_ShipHitSuccess"]; break; case 3: info = "║ " + Settings.MsgApp["Info_ShipSink"]; break; case 4: info = GameCli.Won(name); break; case 5: info = "║ " + Settings.MsgApp["Info_AttackInvalid"]; break; case 6: info = "║ " + Settings.MsgApp["Info_Welcome"]; break; case 0: info = "║ " + Settings.MsgApp["Erro_InputInvalid"]; break; default: info = "║ Não é valido"; break; } Console.WriteLine("╠═════════════════════════════════╩════════════════════════════════════╣"); Console.WriteLine(info); if (shot != 4) { Console.WriteLine("╠════════════════════════╦═════════════════════════╦═══════════════════╣"); Console.WriteLine("║ B - Passar turno ║ S - Guardar Jogo ║ Q - Sair ║"); Console.WriteLine("╚════════════════════════╩═════════════════════════╩═══════════════════╝"); } else { Console.WriteLine("╠══════════════════════════════════════════════════════════════════════╣"); Console.WriteLine("║ Q - Sair do jogo ║"); Console.WriteLine("╚══════════════════════════════════════════════════════════════════════╝"); } } Console.WriteLine(msg); }
/// <summary> /// Apresenta o tabuleiro de ataque e defesa do jogador e algumas ações /// O jogador pode atacar ou passar e sair /// Esta função tambem troca o turno do jogador /// </summary> /// <param name="PA">Player que ataca</param> /// <param name="PD">Player que defende</param> public void Gamming(Player PA, Player PD) { bool loop = true; int shot = 6; string msg = null; while (loop) { bool attakOn = true; if (this.State == GameState.P1_Only_View || this.State == GameState.P2_Only_View) { attakOn = false; } GameCli.GameCliGame(PA.Attack, PA.Defend, PA.Name, PA.Ships.Count, PD.Ships.Count, Turn); GameCli.GamingActions(attakOn, shot, PA.Name, msg); var option = getGamingOptions(); if (option == null) { msg = Settings.MsgApp["Erro_InputInvalid"]; } else { switch (option) { case GamingOptions.Attack: if (attakOn) { Console.WriteLine(" Insira a cordenada [ex: A3]:"); var cords = Tools.ConvertToCord(Console.ReadLine()); if (cords.valid) { shot = PD.Defend.Shot(cords.cord[0], cords.cord[1], PA.Attack, PD.Ships); var fw = FindWinner(); if (fw.Item1) { shot = 4; } ; } } if (shot != 5) { attakOn = false; if (State == GameState.P1_Turn_Attack) { State = GameState.P1_Only_View; } else if (State == GameState.P2_Turn_Attack) { State = GameState.P2_Only_View; } } break; case GamingOptions.NextTurn: if (shot != 4) { if (State == GameState.P1_Turn_Attack || State == GameState.P1_Only_View) { State = GameState.P2_Turn_Attack; } else { State = GameState.P1_Turn_Attack; Turn++; } GameCli.NextTurn(PD.Name); var Aux = PD; PD = PA; PA = Aux; } break; case GamingOptions.Save: this.SaveGameJson(); msg = Settings.MsgApp["Success_Save"]; break; case GamingOptions.Exit: loop = Menus.ExitGameMenu(this); break; } } } }
/// <summary> /// Logica do menu Novo jogo /// </summary> public static void NewGameMenu() { Player P1 = null; Player P2 = null; Game G = null; string msg = null; Boolean loop = true; while (loop) { GameCli.MenuGame(P1, P2, msg); NewGameOptions?option = getNewGameOption(); if (option == null) { msg = Settings.MsgApp["Erro_InputInvalid"]; } else { switch (option) { case NewGameOptions.CreatePlayer1: if (P1 == null) { Console.WriteLine("| Insira o nome do Player 1! |"); Console.Write("| Nome:"); string Name = Console.ReadLine(); if (Name.Length > 1) { P1 = new Player(Name); P1.CreatBoard(); P1.Defend.MenuCreatShips(P1.Ships); } else { msg = Settings.MsgApp["Erro_PlayerSizeName"]; } } else { P1.Defend.MenuCreatShips(P1.Ships); } break; case NewGameOptions.CreatePlayer2: if (P2 == null) { Console.WriteLine("| Insira o nome do Player 2! |"); Console.Write("| Nome:"); string Name = Console.ReadLine(); if (Name.Length > 1) { P2 = new Player(Name); P2.CreatBoard(); P2.Defend.MenuCreatShips(P2.Ships); } else { msg = Settings.MsgApp["Erro_PlayerSizeName"]; } } else { P2.Defend.MenuCreatShips(P1.Ships); } break; case NewGameOptions.StartGame: if (P1 != null && P2 != null) { G = new Game(P1, P2, 0, 1); G.Gamming(P1, P2); } else { msg = Settings.MsgApp["Erro_StartGame"]; } break; case NewGameOptions.Exit: loop = false; break; } } } }