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
|
#include <iostream>
#include <ncurses.h>
#include <stdio.h>
#include <assert.h>
using namespace std;
class TicTacToe
{
public:
TicTacToe();
void displayGrid();
void input();
void openLine(int y_cor);
void closedLine(int y_cor);
private:
int turn;
static const int ROWS = 5;
static const int COLS = 6;
char board[ROWS][COLS];
};
TicTacToe::TicTacToe()
{
for(int i = 0; i < ROWS; i++)
for (int j = 0; j < COLS; j++)
board[i][j] = ' ';
turn = 1;
}
/*
void TicTacToe::displayGrid()
{
openLine(10);
closedLine(11);
openLine(12);
closedLine(13);
openLine(14);
}
*/
void TicTacToe::openLine(int y_cor)
{
mvprintw(y_cor, 20, " | | ");
}
void TicTacToe::closedLine(int y_cor)
{
mvprintw(y_cor, 20, "-----");
}
void TicTacToe::input()
{
int x, y;
int x_cor = 3, y_cor = 3;
mvprintw(0, 0, "Your turn.\nInput coordinate x:");
do{
scanf("%d", &x);
}while(x > 3 || x < 1);
if (x = 1)
{
x_cor = 0;
}
else if (x = 2)
{
x_cor = 3;
}
else if (x = 3)
{
x_cor = 5;
}
mvprintw(1, 0, "Input coordiante y: ");
do{
scanf("%d", &y);
}while(y > 3 || y < 1);
if (y = 1)
{
y_cor = 0;
}
else if (y = 2)
{
y_cor = 3;
}
else if (y = 3)
{
y_cor = 5;
}
mvprintw(1, 18, ":");
mvprintw(y_cor + 10, x_cor + 20, "X");
}
int main()
{
TicTacToe game;
WINDOW * wnd;
int row, col;
char yesno;
wnd = initscr();
getmaxyx (wnd, col, row);
//game.displayGrid();
start_color();
init_pair(1, COLOR_RED, COLOR_BLACK);
attron(COLOR_PAIR(1));
mvprintw(9, 20, "1 2 3");
mvprintw(10, 18, "1");
game.openLine(10);
game.closedLine(11);
mvprintw(12, 18, "2");
game.openLine(12);
game.closedLine(13);
mvprintw(14, 18, "3");
game.openLine(14);
game.input();
attroff(COLOR_PAIR(1));
do
{
mvprintw (17, 17, "End program?");
scanf("%c", &yesno);
if (yesno == 'y' || yesno == 'Y')
endwin();
}while (yesno != 'y' && yesno != 'Y');
return 0;
}
|