Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- #include <string>
- #include <cstdlib>
- #include <ctime>
- #include <vector>
- #include <fstream>
- #include "color.h"
- #include "Position.h"
- #include "Bomb.h"
- #include "Ship.h"
- #include "Board.h"
- #include "Player.h"
- using namespace std;
- //A assume o caractere 219 da tabela ASCII que é um espaço completo
- const char A = 219;
- //Função do ecrã de abertura
- void intro()
- {
- clrscr();
- // Colorir e centrar a mensagem de boas vindas
- setcolor(14, 0);
- gotoxy(36, 2);
- cout << "Welcome!";
- setcolor(1, 0);
- gotoxy(0, 6);
- // Primeira barra azul
- for (int i = 0; i < 80; i++){
- cout << A;
- }
- cout << endl;
- setcolor(14, 0);
- //Representação gráfica do nome do jogo
- cout << " " << A << A << A << A << A << " " << A << A << " " << A << A << A << A << A << A << " " << A << A << A << A << A << A << " " << A << A << " " << A << A << A << A << A << A << " " << A << A << A << A << A << A << " " << A << A << " " << A << A << " " << A << A << A << A << A << A << " " << A << A << A << A << A << " " << endl;
- cout << " " << A << A << " " << A << A << " " << A << A << A << A << " " << A << A << A << A << A << A << " " << A << A << A << A << A << A << " " << A << A << " " << A << A << A << A << A << A << " " << A << A << A << A << A << A << " " << A << A << " " << A << A << " " << A << A << A << A << A << A << " " << A << A << " " << A << A << " " << endl;
- cout << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << endl;
- cout << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << endl;
- cout << " " << A << A << A << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << A << A << " " << A << A << A << A << A << A << " " << A << A << A << A << A << A << " " << A << A << " " << A << A << A << A << A << " " << endl;
- cout << " " << A << A << " " << A << A << " " << A << A << A << A << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << A << A << A << A << " " << A << A << A << A << A << A << " " << A << A << " " << A << A << " " << endl;
- cout << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << endl;
- cout << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << A << A << A << A << " " << A << A << A << A << A << A << " " << A << A << A << A << A << A << " " << A << A << " " << A << A << " " << A << A << A << A << A << A << " " << A << A << " " << endl;
- cout << " " << A << A << A << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << " " << A << A << A << A << A << A << " " << A << A << A << A << A << A << " " << A << A << A << A << A << A << " " << A << A << " " << A << A << " " << A << A << A << A << A << A << " " << A << A << " " << endl;
- cout << endl;
- // Segunda barra azul
- setcolor(1, 0);
- for (int i = 0; i < 80; i++){
- cout << A;
- }
- cout << endl;
- // Centrar e colorir a mensagem
- for (int i = 0; i < 28; i++){
- cout << " ";
- }
- setcolor(14, 0);
- cout << "Press Enter to Continue" << endl;
- }
- //Função do menu
- void menu()
- {
- clrscr();
- //Caixilho do menu
- setcolor(1, 0);
- for (unsigned int i = 0; i < 27; i++)
- {
- gotoxy(27 + i, 3);
- cout << A;
- gotoxy(27 + i, 13);
- cout << A;
- }
- for (unsigned i = 0; i < 9; i++)
- {
- gotoxy(27, 4 + i);
- cout << A;
- gotoxy(53, 4 + i);
- cout << A;
- }
- //Opções do menu (Brancos)
- setcolor(15, 0);
- gotoxy(34, 5);
- cout << "Play (2 Players)";
- gotoxy(34, 7);
- cout << "Scores (Time)";
- gotoxy(34, 9);
- cout << "Scores (Round)";
- gotoxy(34, 11);
- cout << "Exit";
- //Números de seleção (Amarelos)
- setcolor(14, 0);
- gotoxy(36, 1);
- cout << "Game Menu" << endl;
- for (unsigned int i = 1; i <= 4; i++)
- {
- gotoxy(31, i * 2 + 3);
- cout << i << ".";
- }
- gotoxy(27, 14);
- cout << "Please enter your choice: ";
- }
- //Função da vitória quando o jogo acaba
- void victory(string const name, bool const scorest, bool const scoresr)
- {
- clrscr();
- setcolor(14, 0);
- gotoxy(32, 0);
- cout << "Congratulations!";
- //Desenho taça
- gotoxy(33, 3);
- cout << " ________ " << endl;
- gotoxy(33, 4);
- cout << "__| |__" << endl;
- gotoxy(33, 5);
- cout << char(92) << " " << char(92) << " / /" << endl;
- gotoxy(33, 6);
- cout << " " << char(92) << "__" << char(92) << " /__/ " << endl;
- gotoxy(33, 7);
- cout << " | | " << endl;
- gotoxy(33, 8);
- cout << " | | " << endl;
- gotoxy(33, 9);
- cout << " || " << endl;
- gotoxy(33, 10);
- cout << " _/ " << char(92) << "_" << endl;
- gotoxy(33, 11);
- cout << " --------" << endl;
- //Informação do vencedor
- setcolor(15, 0);
- gotoxy(35 - (name.length() / 2), 13);
- cout << name << " has won!";
- //Informação se atingiu as 10 melhores pontuações por tempo
- if (scorest)
- {
- gotoxy(22, 15);
- cout << "You are now on top 10 scores by time!";
- }
- //Informação se atingiu as 10 melhores pontuações por número de rondas
- if (scoresr)
- {
- gotoxy(22, 17);
- cout << "You are now on top 10 scores by round!";
- }
- setcolor(14, 0);
- gotoxy(29, 19);
- cout << "Press Enter to go back.";
- }
- //Verifica a existência do ficheiro e as dimensões do tabuleiro
- bool checkFile(string const filename, int &tempLine, int &tempColumn)
- {
- ifstream file(filename);
- string temps;
- if (file)
- {
- file >> tempLine >> temps >> tempColumn;
- return true;
- }
- else
- {
- return false;
- }
- }
- void infoask(string &p1name, string &p1board, string &p2name, string &p2board)
- {
- int p1tempLine = 0, p1tempColumn = 0, p2tempLine = 0, p2tempColumn = 0;
- clrscr();
- setcolor(14, 0);
- gotoxy(0, 1);
- cout << "Player 1 Name: ";
- setcolor(15, 0);
- while (p1name.empty())
- {
- getline(cin, p1name);
- }
- setcolor(14, 0);
- gotoxy(0, 4);
- cout << "Player 1 Board: ";
- setcolor(15, 0);
- getline(cin, p1board);
- while (!checkFile(p1board, p1tempLine, p1tempColumn) || (p1tempLine < 0 || p1tempLine>26) || (p1tempColumn < 0 || p1tempColumn>26))
- {
- cout << "Sorry, the file can't be opened or the dimensions are wrong." << endl;
- getline(cin, p1board);
- }
- clrscr();
- setcolor(14, 0);
- gotoxy(0, 1);
- cout << "Player 2 Name: ";
- setcolor(15, 0);
- while (p2name.empty())
- {
- getline(cin, p2name);
- }
- setcolor(14, 0);
- gotoxy(0, 4);
- cout << "Player 2 Board: ";
- setcolor(15, 0);
- getline(cin, p2board);
- while (!checkFile(p2board, p2tempLine, p2tempColumn) || p2tempLine != p1tempLine || p2tempColumn != p1tempColumn)
- {
- cout << "Sorry, the file can't be opened or the dimensions doesn't match with the Player 1's board." << endl;
- getline(cin, p2board);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement