A little trouble

K.I.L.E.R

Retarded moron
Veteran
I'm making a noughts and crosses game.

I got the board set up:
Code:
	cout << "-----|------|-----" << endl;
	cout << "     |      |   " << endl;
	cout << "     |      |   " << endl;
	cout << "-----|------|-----" << endl;
	cout << "     |      |   " << endl;
	cout << "     |      |   " << endl;
	cout << "-----|------|-----" << endl;
	cout << "     |      |   " << endl;
	cout << "     |      |   " << endl;
	cout << "-----|------|-----" << endl;

Well it looks perfect in my program.

Problem is that I can't get the bloody X or O inside the bloody places.
I believe I have to set the cursor position and then display it but there has got to be an esaier way?

I have all the rest of the logic working just can't position the X or O.

Can someone please help me?

Thanks
 
Why not just redisplay the entire board after someone makes a move? It might be easier to setup a 2-dimensional char array, then write the X/O into the array, then dump the modified array to the screen.

Aside from doing something like just outputing the entire board again, you'd probably have to look into the 'curses' / 'ncurses' package. I'm not sure what WinOS has available, but that's the unix-style approach.
 
If this is in a DOS prompt, I think you can use a gotoxy(x, y) function.

#include <console.h> I think.
 
Used to be you had direct access to the text-mode framebuffer. B8000 or somewhere? I don't think gotoxy() is available on MS platforms.

Text mode's just tricky for this sort of thing. Brit's solution may be best, clear the console then rewrite the entire screen including the current positions every update.
 
Thanks guys.

I had to copy/paste the function data for gotoxy. :)
Code:
void gotoxy(int x, int y)
{
	HANDLE hConsoleOutput;
	COORD dwCursorPosition;

	dwCursorPosition.X = x;
	dwCursorPosition.Y = y;
	hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorPosition(hConsoleOutput,dwCursorPosition);
}

It might actually save me a lot of time by just copy/pasting the board with a new state. The problem is when the CPU jots down a random thing I'm going to have a lot of trouble with it.
 
Here is an even more simple board layout I found out for myself.
Can anyone believe that I actually found this?
Code:
#include <iostream>
using namespace std;

char boardPOS[3][3] = {{' '},{' '}};

//prototypes
void board();
void select();

void main(void)
{
	board();
}

void select()
{
	int number;

	cout << "Enter number 1-9(0 to exit):";
	cin >> number;

	switch(number)
	{
	case 1:
	boardPOS[0][0] = 'X';
	//refresh board
	system("cls");
	board();
		break;
	case 2:
	boardPOS[1][0] = 'X';
	system("cls");
	board();
		break;
	case 3:
	boardPOS[2][0] = 'X';
	system("cls");
	board();
		break;
	case 4:
	boardPOS[0][1] = 'X';
	system("cls");
	board();
		break;
	case 5:
	boardPOS[2][1] = 'X';
	system("cls");
	board();
		break;
	case 6:
	boardPOS[3][1] = 'X';
	system("cls");
	board();
		break;
	case 7:
	boardPOS[0][2] = 'X';
	system("cls");
	board();
		break;
	case 8:
	boardPOS[1][2] = 'X';
	system("cls");
	board();
		break;
	case 9:
	boardPOS[2][2] = 'X';
	system("cls");
	board();
		break;
	default:
		select();
	}
}

void board()
{
	cout << "--1--|--2---|--3--" << endl;
	cout << "  " << boardPOS[0][0]
		 << "  "
		 << "|  " << boardPOS[1][0] 
		 << "   |  "
		 << boardPOS[2][0] << endl;
	cout << "--4--|--5---|--6--" << endl;
	cout << "  " << boardPOS[0][1]
		 << "  "
		 << "|  " << boardPOS[2][1] 
		 << "   |  "
		 << boardPOS[3][1] << endl;
	cout << "--7--|--8---|--9--" << endl;
	cout << "  " << boardPOS[0][2]
		 << "  "
		 << "|  " << boardPOS[1][2] 
		 << "   |  "
		 << boardPOS[2][2] << endl;
	cout << "-----|------|-----" << endl;

	select();
}
 
Back
Top