Guest User

Untitled

a guest
Nov 26th, 2011
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.47 KB | None | 0 0
  1. // Author:
  2. // Uniqname:
  3. // Partner Name:
  4. // Partner uniqname:
  5. // Date:
  6. // GSI: Wen Jia
  7. // Description: Project 5
  8. #include "ioutil.h"
  9. #include "towers.h"
  10.  
  11. #include <iostream>
  12. #include <fstream>
  13. #include <string>
  14. using namespace std;
  15.  
  16. void playGame(Cell board[SIZE][SIZE], int numTowers)
  17. {
  18. char c; //I CHANGEd THIS?
  19. switch(c) // I CHANGED THIS
  20. {
  21. case 'Q': ; break;
  22. case 'P': ; break;
  23. case 'D': ; break;
  24. case 'I': ; break;
  25. case 'T': SetColor::toggleColor(); break;
  26. default: clearInput();
  27. }
  28.  
  29. }
  30.  
  31.  
  32.  
  33. void printCommands()
  34. {
  35. cout << "Commands:" << endl;
  36. cout << " (P)lace a value: P <row> <col> <value>" << endl;
  37. cout << " (D)elete a value: D <row> <col>" << endl;
  38. cout << " (I)nput a row: I <row> <value> ..." << endl;
  39. cout << " (T)oggle color" << endl;
  40. cout << " (Q)uit" << endl;
  41. }
  42.  
  43.  
  44.  
  45. void printBoard(const Cell board[SIZE][SIZE], int numTowers)
  46. {
  47. // print the numbers at the top of the board
  48. cout << " ";
  49. for(int y = 0; y < numTowers+2; y ++) {
  50. if (y < 9)
  51. cout << "| " << SetColor(INDEX_COLOR) << y + 1 << ' ';
  52. else
  53. cout << "| " << SetColor(INDEX_COLOR) << y + 1 ;
  54. }
  55. cout << '|' << endl;
  56.  
  57. for(int x = 0; x < numTowers+2; x ++) {
  58. cout << " -";
  59.  
  60. // print a line above the cell
  61. for(int y = 0; y < numTowers+2; y ++) {
  62. if(x==0 || x==1 || x==numTowers+1) {
  63. cout << SetColor(WHITE, BACK) << "+---";
  64. }else {
  65. if(y==0 || y==1 || y==numTowers+1) {
  66. cout << SetColor(WHITE, BACK) << '+';
  67. } else {
  68. cout << '+';
  69. }
  70.  
  71. cout << "---";
  72. }
  73. }
  74.  
  75. cout << SetColor(WHITE, BACK) << '+' << '-' << endl;
  76. cout << " " << SetColor(INDEX_COLOR) << char(x + 'A') << " ";
  77.  
  78. // print the contents of the cell
  79. for(int y = 0; y < numTowers+2; y ++)
  80. {
  81. if(y==0 || y==1 || y==numTowers+1)
  82. {
  83. cout << SetColor(WHITE, BACK) << '|';
  84. }
  85. else
  86. {
  87. cout << '|';
  88. }
  89. if(board[x][y].permanent)
  90. {
  91. if (board[x][y].number == 0) {
  92. cout << " ";
  93. } else {
  94. cout << ' ' << SetColor(PERMANENT_NUMBER_COLOR) << board[x][y].number;
  95. }
  96. }
  97. else
  98. {
  99. cout << ' ';
  100. if (board[x][y].number == 0) {
  101. cout << ' ';
  102. } else {
  103. cout << board[x][y].number;
  104. }
  105. }
  106. if (board[x][y].number < 10) {
  107. cout << ' ';
  108. }
  109. }
  110. cout << SetColor(WHITE, BACK) << '|' << " " << SetColor(INDEX_COLOR) << char(x + 'A') << endl;
  111. }
  112.  
  113. cout << " -";
  114.  
  115. // print the final line
  116. for(int y = 0; y < numTowers+2; y ++)
  117. {
  118. cout << SetColor(WHITE, BACK) << "+---";
  119. }
  120. cout << SetColor(WHITE, BACK) << '+' << '-' << endl;
  121.  
  122. // print the numbers at the bottom of the board
  123. cout << " ";
  124. for(int y = 0; y < numTowers+2; y ++)
  125. {
  126. if (y < 9)
  127. cout << "| " << SetColor(INDEX_COLOR) << y + 1 << ' ';
  128. else
  129. cout << "| " << SetColor(INDEX_COLOR) << y + 1 ;
  130. }
  131. cout << '|' << endl;
  132. cout << endl << endl;
  133. }
  134.  
  135. void clearInput()
  136. {
  137. }
  138.  
  139. void initBoard(Cell board[SIZE][SIZE])
  140. {
  141. for(int i = 0; i < SIZE; i++)
  142. {
  143. for (int j = 0; j < SIZE; j++)
  144. {
  145. board[i][j] = 0;
  146. }
  147. }
  148. }
  149.  
  150. bool openFile(ifstream& ins)
  151. {
  152. string fileName;
  153. cout << "Enter board filename: ";
  154. cin >> fileName;
  155. ins.open(fileName.c_str());
  156. if(!ins)
  157. {
  158. cout << "Error in opening file" << endl;
  159. return false;
  160. }
  161. else
  162. return true;
  163. }
  164.  
  165. // REQUIRES: ins is already open
  166. // MODIFIES: ins, board, numTower
  167. // EFFECTS: will read the values within the file and fill board
  168. // all values are int's
  169. // see the spec for the format of the file
  170. // NOTE: numTowers should hold the number of rows/cols inside grid,
  171. // not including the permanent border
  172. // You may set permanent within this function or within loadBoard
  173. // Further NOTE: for this project, you may assume that all info on the datafile is correct
  174. void readFile(ifstream& ins, Cell board[SIZE][SIZE], int& numTowers)
  175. {
  176. int a;
  177. openFile(ins);
  178. while(ins >> a)
  179. {
  180. }
  181.  
  182. }
  183.  
  184. // REQUIRES: board has been loaded
  185. // MODIFIES: nothing
  186. // EFFECTS: returns true if all spots have an entry
  187. bool boardFull(const Cell board[SIZE][SIZE], int numTowers)
  188. {
  189. int holder = 0;
  190. for(int i = 0; i < SIZE; i++)
  191. {
  192. for (int j = 0; j < SIZE; j++)
  193. {
  194. if(board[i][j] = 0 || board[i][j] = ' ');
  195. {
  196. holder = 0;
  197. }
  198. }
  199. }
  200. if (holder = 0)
  201. {
  202. return false;
  203. }
  204. else
  205. return true;
  206. }
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
Advertisement
Add Comment
Please, Sign In to add comment