1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
#include <iostream>
#include "Grid.h"
#include "DUPoint.h"
#include <vector>
#include <sstream>
#include <fstream>
using namespace std;
//constructors
//initializes Grid object
Grid::Grid() { }
Grid::Grid(DUPoint start, DUPoint end)
{
startPos_ = start;
endPos_ = end;
}
//Grid::Grid( const Grid & a )
//{
// startPos_ = a.getStart ;
// endPos_ = a.getEnd ;
//}
//inspectors
//gets start position
DUPoint Grid::getStart(DUPoint start) const
{
return startPos_;
}
//gets end position
DUPoint Grid::getEnd(DUPoint end) const
{
return endPos_;
}
//mutators
//sets start position
void Grid::setStart(DUPoint start)
{
startPos_ = start;
}
//sets end position
void Grid::setEnd(DUPoint end)
{
endPos_ = end;
}
//checks if userMove is legal
bool Grid::isLegalMove(int startPosRow, int startPosColumn,int endPosRow,int endPosColumn)
{
if ( startPosRow < 0 || startPosRow > 3
|| startPosColumn < 0 || startPosColumn > 3
|| endPosRow < 0 || endPosRow > 3 )
return false;
else
return true;
}
//apply userMove
void Grid::applyMove(int startPosRow, int startPosColumn, int endPosRow, int endPosColumn)
{
if (isLegalMove(startPosRow, startPosColumn, endPosRow, endPosColumn)) {
grid_[startPosRow][startPosColumn];
grid_[endPosRow][endPosColumn];
}else
exit(1);
}
//sets startPosition Row n Column, endposition Row n Column
void Grid::setGrids(int startPosRow, int startPosColumn, int endPosRow, int endPosColumn)
{
startPosR_ = startPosRow;
startPosC_ = startPosColumn;
endPosC_ = endPosColumn;
endPosR_ = endPosRow;
}
//facilitators
//Displays grid
void Grid::output(ostream & out) {
vector<vector<int>> grid(4);
int rows, columns;
out << " 0 1 2 3 " << endl;
out << " +---------+" << endl;
for( rows=0; rows< grid.size(); ++rows ) // make each row
{
out << rows << " | ";
for( columns=0; columns< grid.size(); ++columns ) //make each column
{
if(grid.empty())
out << "X" << " ";
else
out << "X" << " ";
}
out << "| ";
out << endl;
}
out << " +---------+" << endl;
}
//overloads << operator
ostream & operator << ( ostream & out, Grid & p)
{
p.output(out);
return out;
}
|