fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <stdio.h>
  5. #include <math.h>
  6. using namespace std;
  7.  
  8. class MapFrames{
  9. public:
  10. char frame[11];
  11. vector<short> cols;
  12. vector<short> rows;
  13. MapFrames (short a, short b);
  14. };
  15.  
  16. MapFrames::MapFrames (short a, short b){
  17. // Construct a vector "rows" of a certain user defined size
  18. rows.resize(a);
  19. // Construct a vector "cols" of a certain user defined size
  20. cols.resize(b);
  21. //Construct Frames
  22. frame[0]=201; // Top LC
  23. frame[1]=205; // Horizontal
  24. frame[2]=187; // Top RC
  25. frame[3]=186; // Vertical
  26. frame[4]=200; // Bottom LC
  27. frame[5]=188; // Bottom RC
  28.  
  29. //Construct Icons
  30. frame[6]=219; // ICON: Hidden Locations
  31. frame[7]=177; // ICON: Spy Location: Nothing Found
  32. frame[8]=2; // ICON: Spy Location: City Found
  33. frame[9]=127; // ICON: Miss
  34. frame[10]=15; // ICON: Destroyed City
  35. }
  36.  
  37. class Cities : public MapFrames{
  38. public:
  39. //Cords Holds map data. 0 = Unknown, 1 = City Location, 2 = Hit, 3 = Miss, 4 = Spy: Hit Nothing, 5 = Spy: Hit City
  40. vector<short>P1cords;
  41. vector<short>P2cords;
  42. Cities (short a, short b);
  43. };
  44.  
  45. Cities::Cities (short a, short b) : MapFrames (a,b){
  46. //Player 1 (LEFT)
  47. //Resize Vector to number of elements in map
  48. P1cords.resize(a*b);
  49. //set 1st 33% of elements (rounded up) to 1.
  50. for (int i=0; i<ceil((33/100.f)*(a*b)); i++){
  51. P1cords[i] = 1;
  52. }
  53. //Shuffle cords for random city locations.
  54. random_shuffle ( P1cords.begin(), P1cords.end() );
  55.  
  56. //Player 2 (RIGHT)
  57. //Resize Vector to number of elements in map
  58. P2cords.resize(a*b);
  59. //set 1st 33% of elements (rounded up) to 1.
  60. for (int i=0; i<ceil((33/100.f)*(a*b)); i++){
  61. P2cords[i] = 1;
  62. }
  63. //Shuffle cords for random city locations.
  64. random_shuffle ( P2cords.begin(), P2cords.end() );
  65. }
  66.  
  67. class PrintFuncs : public Cities{
  68. public:
  69. PrintFuncs(short a, short b);
  70. void PrintTop();
  71. void PrintMid();
  72. void PrintBot();
  73. void PrintCords();
  74. void PrintGrid();
  75. };
  76. PrintFuncs::PrintFuncs(short a, short b) : Cities (a,b){
  77. }
  78. void PrintFuncs::PrintTop(){
  79. cout<<frame[0]<<frame[1]<<frame[1]<<frame[1]<<frame[2];
  80. }
  81. void PrintFuncs::PrintMid(){
  82. cout<<frame[3]<<" "<<frame[6]<<" "<<frame[3];
  83. }
  84. void PrintFuncs::PrintBot(){
  85. cout<<frame[4]<<frame[1]<<frame[1]<<frame[1]<<frame[5];
  86. }
  87. void PrintFuncs::PrintCords(){
  88. cout<<" ";
  89. for (int i=0; i<cols.size(); ++i){
  90. cout<<" "<<i<<" ";
  91. }
  92. cout<<" ";
  93. for (int i=0; i<cols.size(); ++i){
  94. if (i+cols.size()<10){
  95. cout<<" "<<i+cols.size()<<" ";}
  96. if (i+cols.size()>9){
  97. cout<<" "<<i+cols.size()<<" ";}
  98. }
  99. cout<<"\n";
  100. }
  101.  
  102. void PrintFuncs::PrintGrid(){
  103. for (int j=0; j<rows.size(); ++j){
  104. //Print TopRow
  105. cout<<" ";
  106. for (int i=0; i<cols.size(); ++i){
  107. PrintTop();
  108. }
  109. cout<<" ";
  110. for (int i=0; i<cols.size(); ++i){
  111. PrintTop();
  112. }
  113. cout<<"\n";
  114. //Print Middle Row
  115. cout<<" "<<j<<" ";
  116. for (int i=0; i<cols.size(); ++i){
  117. PrintMid();
  118. }
  119. cout<<" ";
  120. for (int i=0; i<cols.size(); ++i){
  121. PrintMid();
  122. }
  123. cout<<"\n";
  124. //Print Bottom Row
  125. cout<<" ";
  126. for (int i=0; i<cols.size(); ++i){
  127. PrintBot();
  128. }
  129. cout<<" ";
  130. for (int i=0; i<cols.size(); ++i){
  131. PrintBot();
  132. }
  133. cout<<"\n";
  134. }
  135. }
  136.  
  137. class GameBoard : PrintFuncs{
  138. public:
  139. GameBoard (short a, short b);
  140. void display();
  141. };
  142. GameBoard::GameBoard(short a, short b) : PrintFuncs (a,b){}
  143. void GameBoard::display(){
  144. PrintCords();
  145. PrintGrid();
  146. }
  147.  
  148. int main (){
  149.  
  150. short rows = 0;short cols = 0;
  151. cout<<"Enter a value for ROWS - between 2-6: ";cin>>rows;
  152. cout<<"Enter a value for COLS - between 2-7: ";cin>>cols;
  153. cout<<endl<<endl;
  154.  
  155. // short rows = 5;short cols = 5;
  156. GameBoard map(rows, cols);
  157. map.display();
  158.  
  159. // End
  160. std::cout<<std::endl<<std::endl<<std::endl<<"Please Close Console Window"<<std::endl;
  161. std::cin.ignore('\n', 1024);
  162. return(0);
  163. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty