コード例 #1
0
ファイル: ttt.c プロジェクト: johnjones4/DinoDOS
/*
 * Start the game play. This function is terminated when the board is filled, or
 * when a player has won.
 */
void play()
{
	//X goes first
	char turn = 'X';
	//current number of moves
	int moves = 0;
	
	//draw the board
	initializeGame();
	//go until we find a winner or the board is filled
	while(!winner() && moves < 9) {
		//the current user input
		char c;
		int row, col;
		//wait until we get a valid charter
		while(!validChar(c = getchar()));
		
		//map the character to a row and column
		if(c == 'q' || c == 'w' || c == 'e') {
			//first row
			row = 0;
		} else if(c == 'a' || c == 's' || c == 'd') {
			//second row
			row = 1;
		} else {
			//third row
			row = 2;
		}
		//column check
		if(c == 'q' || c == 'a' || c == 'z') {
			//first col
			col = 0;
		} else if(c == 'w' || c == 's' || c == 'x') {
			//second col
			col = 1;
		} else {
			//third col
			col = 2;
		}
		
		//check if that space is free, otherwise loop goes again
		if (grid[row][col] == '\0') {
			//mark that spot
			grid[row][col] = turn;
			//draw it an change turns
			if (turn == 'X') {
				drawX(row,col);
				turn = 'O';
			} else if (turn == 'O') {
				drawO(row,col);
				turn = 'X';
			}
			//add the the move count
			moves++;
		}
	}
	//after the game is over, wait for the user to press any key to end
	getchar();
}
コード例 #2
0
ファイル: tic_tac_toe.cpp プロジェクト: chunkyan/DirectX
void drawGamePiece(Move mv,gamePiece playPiece)
{
	if (playPiece==OPEN)
		return;
	if (playPiece==X)
		drawX(getPointFromSlot(mv));
	else
		drawO(getPointFromSlot(mv));
}
コード例 #3
0
ファイル: Render.cpp プロジェクト: PekkaCoder/m_n_kGame
void Render::drawPosition(DrawVariables* dw)
{
	if (m_engine == nullptr)
		return;
	int rows, cols;
	rows = m_engine->getBoard().getRows();
	cols = m_engine->getBoard().getCols();

	for (int i = 0; i < rows; ++i)
	{
		for (int j = 0; j < cols; ++j)
		{
			if (m_engine->getBoard().getSquareValue({ i, j }) == Player::X)
				drawX(dw, { i, j });
			else if (m_engine->getBoard().getSquareValue({ i, j }) == Player::O)
				drawO(dw, { i, j });
		}
	}
}