Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Author:
- // Uniqname:
- // Partner Name:
- // Partner uniqname:
- // Date:
- // GSI: Wen Jia
- // Description: Project 5
- #include "ioutil.h"
- #include "towers.h"
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- void playGame(Cell board[SIZE][SIZE], int numTowers)
- {
- char c; //I CHANGEd THIS?
- switch(c) // I CHANGED THIS
- {
- case 'Q': ; break;
- case 'P': ; break;
- case 'D': ; break;
- case 'I': ; break;
- case 'T': SetColor::toggleColor(); break;
- default: clearInput();
- }
- }
- void printCommands()
- {
- cout << "Commands:" << endl;
- cout << " (P)lace a value: P <row> <col> <value>" << endl;
- cout << " (D)elete a value: D <row> <col>" << endl;
- cout << " (I)nput a row: I <row> <value> ..." << endl;
- cout << " (T)oggle color" << endl;
- cout << " (Q)uit" << endl;
- }
- void printBoard(const Cell board[SIZE][SIZE], int numTowers)
- {
- // print the numbers at the top of the board
- cout << " ";
- for(int y = 0; y < numTowers+2; y ++) {
- if (y < 9)
- cout << "| " << SetColor(INDEX_COLOR) << y + 1 << ' ';
- else
- cout << "| " << SetColor(INDEX_COLOR) << y + 1 ;
- }
- cout << '|' << endl;
- for(int x = 0; x < numTowers+2; x ++) {
- cout << " -";
- // print a line above the cell
- for(int y = 0; y < numTowers+2; y ++) {
- if(x==0 || x==1 || x==numTowers+1) {
- cout << SetColor(WHITE, BACK) << "+---";
- }else {
- if(y==0 || y==1 || y==numTowers+1) {
- cout << SetColor(WHITE, BACK) << '+';
- } else {
- cout << '+';
- }
- cout << "---";
- }
- }
- cout << SetColor(WHITE, BACK) << '+' << '-' << endl;
- cout << " " << SetColor(INDEX_COLOR) << char(x + 'A') << " ";
- // print the contents of the cell
- for(int y = 0; y < numTowers+2; y ++)
- {
- if(y==0 || y==1 || y==numTowers+1)
- {
- cout << SetColor(WHITE, BACK) << '|';
- }
- else
- {
- cout << '|';
- }
- if(board[x][y].permanent)
- {
- if (board[x][y].number == 0) {
- cout << " ";
- } else {
- cout << ' ' << SetColor(PERMANENT_NUMBER_COLOR) << board[x][y].number;
- }
- }
- else
- {
- cout << ' ';
- if (board[x][y].number == 0) {
- cout << ' ';
- } else {
- cout << board[x][y].number;
- }
- }
- if (board[x][y].number < 10) {
- cout << ' ';
- }
- }
- cout << SetColor(WHITE, BACK) << '|' << " " << SetColor(INDEX_COLOR) << char(x + 'A') << endl;
- }
- cout << " -";
- // print the final line
- for(int y = 0; y < numTowers+2; y ++)
- {
- cout << SetColor(WHITE, BACK) << "+---";
- }
- cout << SetColor(WHITE, BACK) << '+' << '-' << endl;
- // print the numbers at the bottom of the board
- cout << " ";
- for(int y = 0; y < numTowers+2; y ++)
- {
- if (y < 9)
- cout << "| " << SetColor(INDEX_COLOR) << y + 1 << ' ';
- else
- cout << "| " << SetColor(INDEX_COLOR) << y + 1 ;
- }
- cout << '|' << endl;
- cout << endl << endl;
- }
- void clearInput()
- {
- }
- void initBoard(Cell board[SIZE][SIZE])
- {
- for(int i = 0; i < SIZE; i++)
- {
- for (int j = 0; j < SIZE; j++)
- {
- board[i][j] = 0;
- }
- }
- }
- bool openFile(ifstream& ins)
- {
- string fileName;
- cout << "Enter board filename: ";
- cin >> fileName;
- ins.open(fileName.c_str());
- if(!ins)
- {
- cout << "Error in opening file" << endl;
- return false;
- }
- else
- return true;
- }
- // REQUIRES: ins is already open
- // MODIFIES: ins, board, numTower
- // EFFECTS: will read the values within the file and fill board
- // all values are int's
- // see the spec for the format of the file
- // NOTE: numTowers should hold the number of rows/cols inside grid,
- // not including the permanent border
- // You may set permanent within this function or within loadBoard
- // Further NOTE: for this project, you may assume that all info on the datafile is correct
- void readFile(ifstream& ins, Cell board[SIZE][SIZE], int& numTowers)
- {
- int a;
- openFile(ins);
- while(ins >> a)
- {
- }
- }
- // REQUIRES: board has been loaded
- // MODIFIES: nothing
- // EFFECTS: returns true if all spots have an entry
- bool boardFull(const Cell board[SIZE][SIZE], int numTowers)
- {
- int holder = 0;
- for(int i = 0; i < SIZE; i++)
- {
- for (int j = 0; j < SIZE; j++)
- {
- if(board[i][j] = 0 || board[i][j] = ' ');
- {
- holder = 0;
- }
- }
- }
- if (holder = 0)
- {
- return false;
- }
- else
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment