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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cctype>
using namespace std;
void getFileName(char fileName[])
{
cout << "Where is your board located? ";
//cin.ignore();
cin.getline(fileName, 256);
}
void readFile(char fileName[], int board[][9])
{
ifstream fin(fileName);
//ERROR CHECK
if (fin.fail())
{
cout << "ERROR Reading File\n";
exit(1);
}
for (int r = 0; r < 9; r++)
{
for (int c = 0; c < 9; c++)
fin >> board[r][c];
}
fin.close();
}
void displayMenu()
{
cout << "Options:\n"
<< " ? Show these instructions\n"
<< " D Display the board\n"
<< " E Edit one square\n"
<< " S Show the possible values for a square\n"
<< " Q Save and Quit\n"
<< endl;
return;
}
void displayBoard(int board[][9])
{
//header
cout << " A B C D E F G H I" << endl;
//row = i / 9 and Column = i % 9
for (int r = 0; r < 9; r++)
{
cout << r + 1 << " ";
for (int c = 0; c < 9; c++)
{
if (board [r][c] == 0)
cout << " ";
else
cout << board [r][c];
if (c == 2 || c == 5)
cout << '|';
else if (c != 8)
cout << " ";
}
cout << endl;
if (r == 2 or r == 5)
{
cout << " -----+-----+-----\n";
}
}
}
void mainBoard(char cord[], int arraycord[])
{
}
void editSquare(int board[][9], char cord[], int arraycord[], bool possible[])
{
}
void writeBoard(int board[][9])
{
}
void interact(int board[][9])
{
bool done;
bool possible[10];
char cord[3];
int arraycord[2];
char getOption;
//Interactive Menu
do
{
cout << "\n> ";
cin >> getOption;
switch (getOption)
{
case '?'://Display menu
displayMenu();
break;
case 'd'://Display board
case 'D':
displayBoard(board);
break;
case 'e'://Edit square
case'E':
mainBoard(cord, arraycord);
editSquare(board, cord, arraycord, possible);
break;
case 'S': //clear the board
case 's':
mainBoard(cord, arraycord);
editSquare(board, cord, arraycord, possible);
break;
case 'Q':
case 'q': //quit
done = true;
break;
writeBoard(board);
return;
default:
cout << "ERROR: Invalid command" << endl;
displayMenu();
}
}
while (getOption != 'Q' or getOption != 'q');
}
/**********************************************************************
*
***********************************************************************/
int main(int argc,char *argv[])
{
char fileName[256];
char newfile[256];
int board[9][9];
getFileName(fileName);
readFile(fileName, board);
displayMenu();
displayBoard(board);
interact(board);
return 0;
}
|