Advertisement
Guest User

Untitled

a guest
May 25th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. #include <string>
  5. #include <cstdlib>
  6. #include <ctime>
  7. #include <vector>
  8. #include <fstream>
  9. #include "color.h"
  10. #include "Position.h"
  11. #include "Bomb.h"
  12. #include "Ship.h"
  13. #include "Board.h"
  14. #include "Player.h"
  15.  
  16. using namespace std;
  17.  
  18. //A assume o caractere 219 da tabela ASCII que é um espaço completo
  19. const char A = 219;
  20.  
  21. //Função do ecrã de abertura
  22. void intro()
  23. {
  24. clrscr();
  25. // Colorir e centrar a mensagem de boas vindas
  26. setcolor(14, 0);
  27. gotoxy(36, 2);
  28. cout << "Welcome!";
  29. setcolor(1, 0);
  30. gotoxy(0, 6);
  31. // Primeira barra azul
  32. for (int i = 0; i < 80; i++){
  33. cout << A;
  34. }
  35. cout << endl;
  36. setcolor(14, 0);
  37. //Representação gráfica do nome do jogo
  38. 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;
  39. 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;
  40. 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;
  41. 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;
  42. 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;
  43. 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;
  44. 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;
  45. 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;
  46. 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;
  47. cout << endl;
  48. // Segunda barra azul
  49. setcolor(1, 0);
  50. for (int i = 0; i < 80; i++){
  51. cout << A;
  52. }
  53. cout << endl;
  54. // Centrar e colorir a mensagem
  55. for (int i = 0; i < 28; i++){
  56. cout << " ";
  57. }
  58. setcolor(14, 0);
  59. cout << "Press Enter to Continue" << endl;
  60. }
  61. //Função do menu
  62. void menu()
  63. {
  64. clrscr();
  65.  
  66. //Caixilho do menu
  67. setcolor(1, 0);
  68. for (unsigned int i = 0; i < 27; i++)
  69. {
  70. gotoxy(27 + i, 3);
  71. cout << A;
  72. gotoxy(27 + i, 13);
  73. cout << A;
  74. }
  75. for (unsigned i = 0; i < 9; i++)
  76. {
  77. gotoxy(27, 4 + i);
  78. cout << A;
  79. gotoxy(53, 4 + i);
  80. cout << A;
  81. }
  82.  
  83. //Opções do menu (Brancos)
  84. setcolor(15, 0);
  85. gotoxy(34, 5);
  86. cout << "Play (2 Players)";
  87. gotoxy(34, 7);
  88. cout << "Scores (Time)";
  89. gotoxy(34, 9);
  90. cout << "Scores (Round)";
  91. gotoxy(34, 11);
  92. cout << "Exit";
  93.  
  94. //Números de seleção (Amarelos)
  95. setcolor(14, 0);
  96. gotoxy(36, 1);
  97. cout << "Game Menu" << endl;
  98. for (unsigned int i = 1; i <= 4; i++)
  99. {
  100. gotoxy(31, i * 2 + 3);
  101. cout << i << ".";
  102. }
  103. gotoxy(27, 14);
  104. cout << "Please enter your choice: ";
  105. }
  106.  
  107. //Função da vitória quando o jogo acaba
  108. void victory(string const name, bool const scorest, bool const scoresr)
  109. {
  110. clrscr();
  111. setcolor(14, 0);
  112. gotoxy(32, 0);
  113. cout << "Congratulations!";
  114.  
  115. //Desenho taça
  116. gotoxy(33, 3);
  117. cout << " ________ " << endl;
  118. gotoxy(33, 4);
  119. cout << "__| |__" << endl;
  120. gotoxy(33, 5);
  121. cout << char(92) << " " << char(92) << " / /" << endl;
  122. gotoxy(33, 6);
  123. cout << " " << char(92) << "__" << char(92) << " /__/ " << endl;
  124. gotoxy(33, 7);
  125. cout << " | | " << endl;
  126. gotoxy(33, 8);
  127. cout << " | | " << endl;
  128. gotoxy(33, 9);
  129. cout << " || " << endl;
  130. gotoxy(33, 10);
  131. cout << " _/ " << char(92) << "_" << endl;
  132. gotoxy(33, 11);
  133. cout << " --------" << endl;
  134.  
  135. //Informação do vencedor
  136. setcolor(15, 0);
  137. gotoxy(35 - (name.length() / 2), 13);
  138. cout << name << " has won!";
  139. //Informação se atingiu as 10 melhores pontuações por tempo
  140. if (scorest)
  141. {
  142. gotoxy(22, 15);
  143. cout << "You are now on top 10 scores by time!";
  144. }
  145. //Informação se atingiu as 10 melhores pontuações por número de rondas
  146. if (scoresr)
  147. {
  148. gotoxy(22, 17);
  149. cout << "You are now on top 10 scores by round!";
  150. }
  151.  
  152. setcolor(14, 0);
  153. gotoxy(29, 19);
  154. cout << "Press Enter to go back.";
  155. }
  156.  
  157. //Verifica a existência do ficheiro e as dimensões do tabuleiro
  158. bool checkFile(string const filename, int &tempLine, int &tempColumn)
  159. {
  160. ifstream file(filename);
  161. string temps;
  162.  
  163. if (file)
  164. {
  165. file >> tempLine >> temps >> tempColumn;
  166. return true;
  167. }
  168. else
  169. {
  170. return false;
  171. }
  172.  
  173. }
  174.  
  175.  
  176. void infoask(string &p1name, string &p1board, string &p2name, string &p2board)
  177. {
  178. int p1tempLine = 0, p1tempColumn = 0, p2tempLine = 0, p2tempColumn = 0;
  179.  
  180. clrscr();
  181. setcolor(14, 0);
  182. gotoxy(0, 1);
  183. cout << "Player 1 Name: ";
  184. setcolor(15, 0);
  185. while (p1name.empty())
  186. {
  187. getline(cin, p1name);
  188. }
  189. setcolor(14, 0);
  190. gotoxy(0, 4);
  191. cout << "Player 1 Board: ";
  192. setcolor(15, 0);
  193. getline(cin, p1board);
  194. while (!checkFile(p1board, p1tempLine, p1tempColumn) || (p1tempLine < 0 || p1tempLine>26) || (p1tempColumn < 0 || p1tempColumn>26))
  195. {
  196. cout << "Sorry, the file can't be opened or the dimensions are wrong." << endl;
  197. getline(cin, p1board);
  198. }
  199. clrscr();
  200. setcolor(14, 0);
  201. gotoxy(0, 1);
  202. cout << "Player 2 Name: ";
  203. setcolor(15, 0);
  204. while (p2name.empty())
  205. {
  206. getline(cin, p2name);
  207. }
  208. setcolor(14, 0);
  209. gotoxy(0, 4);
  210. cout << "Player 2 Board: ";
  211. setcolor(15, 0);
  212. getline(cin, p2board);
  213. while (!checkFile(p2board, p2tempLine, p2tempColumn) || p2tempLine != p1tempLine || p2tempColumn != p1tempColumn)
  214. {
  215. cout << "Sorry, the file can't be opened or the dimensions doesn't match with the Player 1's board." << endl;
  216. getline(cin, p2board);
  217. }
  218. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement