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
|
#include <cstdlib>
#include <iostream>
#include <windows.h> // for COLOR!
#include <vector>
#include "Header.h"
#define PIVOT -1 // used to mark the pivot spot (blank area) on the puzzle
#define PIVOT_SYMBOL "*" // used to show the pivot location when drawing the board
#define COLOR_DEFAULT 7
#define COLOR_RED 12
#define COLOR_GREEN 10
bool Tile::setColumns(int myCols)
{
bool accepted = false;
if (myCols <= 0) {
accepted = false;
cout << "Invalid Column Count.\n";
}
else
{
accepted = true;
NUM_COLS = myCols;
}
return accepted;
}
bool Tile::setRows(int myRows)
{
bool accepted = false;
if (myRows <= 0) {
accepted = false;
cout << "Invalid Column Count.\n";
}
else
{
accepted = true;
NUM_ROWS = myRows;
}
return accepted;
}
bool Tile::setPivot(vector< vector<int> > theBoard)
{
int accepted = false;
int pivotnum = NUM_COLS * NUM_ROWS;
for (int x = 0; x < NUM_ROWS; x++)
{
for (int z = 0; z < NUM_COLS; z++)
{
if (theBoard[x][z] == pivotnum)
{
accepted = true;
theBoard[x][z] = PIVOT;
}
}
}
return accepted;
}
void Tile::InitializeBoard(vector< vector<int> > theBoard)
{
// x is first counter, z is second counter.
int enterno = 1; // enterno is declared as int initialized at 1. // enterno means the number entered into the array
for (int x = 0; x < NUM_ROWS; x++) // for x is declared as int initialized as 0, while x < NUM_ROWS, x goes up 1 when function loops
{
vector<int> row;
for (int z = 0; z < NUM_COLS; z++) // for z is declared as int initialized as 0, while z < NUM_COLS, z goes up 1 when function loops
{
row.push_back(enterno); // array[x][z] will equal enterno.
enterno++; //enterno counts up 1
cout << " " << theBoard[x][z];
}
theBoard.push_back(row);
}
setPivot(theBoard);
// in the future, -1, or PIVOT, will equal PIVOT_SYMBOL
}
void Tile::PrintBoard(vector< vector<int> > theBoard)
{
//print whatever
// 1 2 3
// 4 5 6
// 7 8 *
HANDLE hConsole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
vector< vector<int> > origBoard;
InitializeBoard(origBoard);
for (int x = 0; x < NUM_ROWS; x++) // for x is declare as int intitialized as 0, while x < NUM_ROWS, x goes up 1 when function loops
{
for (int z = 0; z < NUM_COLS; z++) // for z is declare as int intitialized as 0, while z < NUM_COLS, z goes up 1 when function loops
{
if (theBoard[x][z] == PIVOT) // if number is equal to PIVOT, then give color number as COLOR_DEFAULT
{
SetConsoleTextAttribute(hConsole, COLOR_DEFAULT); // sets to gray
cout << " " << PIVOT_SYMBOL; // outputs pivot
}
else if (theBoard[x][z] == origBoard[x][z]) // if a number is in correct position like above, then give color number as COLOR_GREEN
{
SetConsoleTextAttribute(hConsole, COLOR_GREEN); // sets to green
cout << " " << theBoard[x][z]; // outputs correct number
}
else if (theBoard[x][z] != origBoard[x][z]) // if a number is in an incorrect position, then give color number as COLOR_RED
{
SetConsoleTextAttribute(hConsole, COLOR_RED); // sets to red
cout << " " << theBoard[x][z]; // outputs wrong number
}
}
cout << "\n";
}
SetConsoleTextAttribute(hConsole, COLOR_DEFAULT);
}
| |