Пример #1
0
/**
 * Runs user turn
 */
int userTurn(ticTacToeBoard* selector, unsigned short int win, char* charPtr, unsigned short int aiPlay)
{
    int i = 0;
    int playSpace = 0;

    renderBoard(charPtr, win);

    while(i == 0)
    {
        if(aiPlay == 1)
            printf("                       Please choose a space to play.\n");
        else printf("                Player %c: Please choose a space to play.\n", charPtr[40]);

        printf("\n                                0  1  2");
        printf("\n                                3  4  5");
        printf("\n                                6  7  8\n\n");

        printf("Selection: ");
        scanf("%i", &playSpace);
        printf("\n");

        if(((int)playSpace >= 0) && ((int)playSpace <= 8))
        {
            if(charPtr[30 + playSpace] == ' ')
            {
                charPtr[30 + playSpace] = charPtr[40];
                i++;
            }
            else
            {
                printf("               This space is already occupied. Try again.\n");
                renderBoard(charPtr, win);
            }
        }
        else
        {
            printf("                      *Invalid input. Try again*\n");
            renderBoard(charPtr, win);
        }
    }

    // Checks if winning position
    if(winPositionInfo(selector, charPtr))
        return 1;

    // Switches player
    switchPlayer(charPtr);
    printf("\n\n");

    return 0;
}
Пример #2
0
void MainWindow::renderBoard(QString inFile, QString outFile, int removeLast, bool renderOpenTiles, bool renderFrames, bool renderPlayers, bool renderNextTile)
{
	auto && history = Game::loadFromFile(inFile);
	if (history.size() == 0)
		return;
	return renderBoard(history, outFile, removeLast, renderOpenTiles, renderFrames, renderPlayers, renderNextTile);
}
Пример #3
0
void Game::updatePVP()
{
	cout << "|=                                                                          =|" << endl;
	cout << "|============================================================================|" << endl;
	cout << "|=                              Player VS Player                            =|" << endl;
	cout << "|============================================================================|" << endl;
	cout << "|=                                                                          =|" << endl;

	renderBoard();

	if (_error) {
		cout << "|= ERROR: Incorrect user input or block already taken.                      =|" << endl;
		_error = false;
	}
	else {
		cout << "|=                                                                          =|" << endl;
	}
		
	cout << "|= Please select a row    : ";
	cin >> rowSelection;
	cout << "|= Please select a column : ";
	cin >> colSelection;

	processInput();
}
Пример #4
0
void moveleft(){
    xpos = xpos + (velocity*time);

//    xvel = -1;
//    yvel = 1/time;
    renderBoard();
}
Пример #5
0
void moveright(){
    xpos = xpos - (velocity*time); 

//    xvel = 1;
//    yvel = 1/time;
    renderBoard();
}
Пример #6
0
SDL_Texture* VsGameRenderer::renderGame() {

	SDL_Texture* gbq = _gbqr0.renderQueue();
	SDL_Texture* gbq2 = _gbqr1.renderQueue();

	SDL_SetRenderTarget(_SDLRenderer, _texture);
	SDL_SetRenderDrawColor(_SDLRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
	SDL_RenderClear(_SDLRenderer);

	SDL_RenderCopy(_SDLRenderer, _bg, NULL, NULL);
	SDL_RenderCopy(_SDLRenderer, _2pbg, NULL, NULL);

	if (!_game.isPaused()) {

		renderBoard(0);
		renderBoard(1);
		SDL_Rect gbqp = { 258, 307, 38, 120 };
		SDL_RenderCopy(_SDLRenderer, gbq, NULL, &gbqp);
		gbqp.x = 344;
		SDL_RenderCopy(_SDLRenderer, gbq2, NULL, &gbqp);
		renderParticles();

	}
	renderStatsText();
	renderMatchPoints();

	if (_game.isPaused()) {
		SDL_SetTextureColorMod(_texture, 0x50, 0x50, 0x50);
		SDL_RenderCopy(_SDLRenderer, _texture, NULL, NULL);
		SDL_SetTextureColorMod(_texture, 0xFF, 0xFF, 0xFF);
		_game.getPauseMenu().render();
	} else {
		SDL_SetTextureColorMod(_texture, 0xFF, 0xFF, 0xFF);
	}

	//TODO: make this state more fancy
	if (_game.getState() == Game::State::ENDED
			&& SDL_GetTicks() % 1000 >= 500) {
		_SDLContext.renderText("PUSH START", { 255, 255, 255 },
				_SDLContext._fontSquare, 134, 342);
	}

	return _texture;
}
Пример #7
0
void hangman() {
	char *toguess;
	int i;
	char correct[128];
	char guess[4];
	unsigned int len = 0;
	int right;
	int correctcount = 0;
	unsigned int wagered = 0;

	bzero(correct, 128);
	toguess = pickaword(state);
	len = cgc_strlen(toguess);
	state->hangmanguess = 0;

	wagered = getBet(state);
	if(wagered == -1)
		return;

	while(state->hangmanguess < 5)
	{
		right = 0;
		bzero(guess, 4);
		put(renderBoard(state));
		for(i=0;i<len;i++)
		{
			if(correct[i] == 0)
				put("_");
			else {
				put(&correct[i]);
				i+= cgc_strlen(&correct[i])-1;
			}
		}

		put("\n");
		put("Please enter a guess: ");
		recvUntil(0, guess, 3, '\n');
		for(i=0;i<len;i++)
		{
			if(guess[0] == toguess[i])
			{
				correct[i] = guess[0];
				right = 1;
				correctcount++;
			}
		}
		if(right == 0)
			state->hangmanguess++;
		if(cgc_strlen(correct) == cgc_strlen(toguess))
		{
			handleOutcome(state, 1, wagered);
			return;
		}
	}
	handleOutcome(state, 0, wagered);
}
Пример #8
0
Board makeAndRenderMoveIfLegal(Board b, int moveIndex, int player)
{
	if ( moveIsLegal(b, moveIndex, player) ) {
		b = makeMove(b, moveIndex, player);
		renderBoard(b);
	}
	else {
		printf("move %i is NOT legal.\n", moveIndex);
	}
	return b;
}
Пример #9
0
void Game::endMenu(int &id)
{
	_gameOver = true;

	if (id == 3) _playerT = 'D';
	
	cout << "|=                                                                          =|" << endl;
	cout << "|============================================================================|" << endl;
	cout << "|=                                  Results                                 =|" << endl;
	cout << "|============================================================================|" << endl;
	cout << "|=                                                                          =|" << endl;

	renderBoard();

	cout << "|= [1] Return to Main Menu";
	cin >> _menuSelection;
	
	_looping = false;
}
Пример #10
0
void MainWindow::on_actionRender_to_file_triggered()
{
	QString path = QFileDialog::getSaveFileName(this, tr("Render Board"));
	if (path.isEmpty())
		return;

	RenderOptionsDialog renderOptions(this);
	if (renderOptions.exec() != QDialog::Accepted)
		return;

	renderBoard(
	            game->getMoveHistory(),
	            path,
	            renderOptions.getRemoveLast(),
	            renderOptions.getRenderOpenTiles(),
	            renderOptions.getRenderFrames(),
	            renderOptions.getRenderPlayers(),
	            renderOptions.getRenderNextTile()
	            );
}
Пример #11
0
void ChessBoard::paintEvent(QPaintEvent * /*e*/)
{
    QImage img( size, QImage::Format_RGB32 );
    QPainter p( &img );
    p.setRenderHint(QPainter::Antialiasing, 1);

	p.setPen(QColor(128, 128, 128));
	p.setBrush(QBrush( QColor(128, 128, 128) ));
    QRect full(0, 0, size.width(), size.height());
	p.drawRect( full );

    // render p
    // render board
//    QRectF rc(0, 0, 128, 128);
//    pieceSet->pieces[0][0]->renderer()->render(&p, rc);

    renderBoard( p, QRectF(full), flipped );

    QPainter p2( this );
    p2.drawImage( 0, 0, img);
}
Пример #12
0
Файл: main.c Проект: zx96/xt3ds
int main(int argc, char *argv[])
{
	cellState gameBoard[3][3][3][3];
	u8 player;
	screen scrTop, scrBot;

	gfxInitDefault();

	//Reset the game state
	memset(gameBoard, EMPTY, 81);
	player = 0;

	while (aptMainLoop())
	{
		//Clear the screens
		scrTop = getScreen(GFX_TOP);
		scrBot = getScreen(GFX_BOTTOM);
		clearScreen(scrTop);
		clearScreen(scrBot);
		
		//Check keypresses
		hidScanInput();
		u32 kDown = hidKeysDown();

		if (kDown & KEY_START) break;

		//Render the main board
		renderBoard(scrTop, gameBoard, RGBA(0x3f48ccff), RGBA(0x232b83ff), 
				WHITE, NULL, NULL);
		renderZoomedSubgrid(scrBot, gameBoard[0][0], WHITE, NULL, NULL);

		gfxFlushBuffers();
		gfxSwapBuffers();
		gspWaitForVBlank();
	}
	
	gfxExit();
	return 0;
}
Пример #13
0
void Game::updatePVCEasy()
{
	cout << "|=                                                                          =|" << endl;
	cout << "|============================================================================|" << endl;
	cout << "|=                             Player VS Computer                           =|" << endl;
	cout << "|============================================================================|" << endl;
	cout << "|=                                                                          =|" << endl;

	renderBoard();

	if (_error) {
		cout << "|= ERROR: Incorrect user input or block already taken.                      =|" << endl;
		_error = false;
	}
	else {
		cout << "|=                                                                          =|" << endl;
	}

	if (_playerT == _player1) {
		cout << "|= Please select a row    : ";
		cin >> rowSelection;
		cout << "|= Please select a column : ";
		cin >> colSelection;
	}
Пример #14
0
void movedown(){
    steps = 0;
    snake.xdir[head] = 0;
    snake.ydir[head] = 1;
    renderBoard();
}
Пример #15
0
void moveup(){
    steps = 0;
    snake.xdir[head] = 0;
    snake.ydir[head] = -1;
    renderBoard();
}
Пример #16
0
void moveright(){
    steps = 0;
    snake.xdir[head] = 1;
    snake.ydir[head] = 0;
    renderBoard();
}
Пример #17
0
int main (void)
{
	int player = 0;
	int winner = 0;
	int choice = 0;
	int row = 0;
	int column = 0;
	int line = 0;

	char board [3][3] = {
				 {'1','2','3'},
				 {'4','5','6'},
				 {'7','8','9'}
						};

	void renderBoard(char** bd){
		/*todo add somelogic*/
	}
	
	void getMove(char&& bd){
		/*to do add some logic*/
		
	}

	for (int i = 0; i<9 && winner==0; i++)
	{
		renderBoard(board);
		player = i%2 + 1;
		
		getMove(board);

		do
		{
			printf("\nPlayer %d, please enter the number of the square "
				"where you want to place your %c: ",
				player,(player==1)?'X':'O');
			scanf("%d", &choice);


			row = --choice/3;
			column = choice%3;
		}while(choice<0 || choice>9 || board [row][column]>'9');

		board[row][column] = (player == 1) ? 'X' : 'O';


		if((board[0][0]==board[1][1] && board[0][0]==board[2][2]) ||
		   (board[0][2]==board[1][1] && board[0][2]==board[2][0]))
		   winner = player;
		else
			for(line = 0; line <=2; line++)
				if((board[line][0]==board[line][1] && board[line][0]==board[line][2])||
					(board[0][line]==board[1][line] && board[0][line]==board[2][line]))
					winner = player;
	

	}

	renderBoard(board);
	

		if(winner==0)
			printf("The game is a draw\n");
		else
			printf("Player %d has won\n", winner);

	return 0;
}
Пример #18
0
/**
 * Runs all main game functions
 */
int runGame(ticTacToeBoard* selector, unsigned short int* corners, unsigned short int* sides, unsigned short int center, char* charPtr, unsigned short int* intPtr)
{
    unsigned short int aiPlay;
    unsigned short int win = 0;

    //Checks if AI is playing and sets respective character value
    if(intPtr[1] == 1)
        aiPlay = 1;
    else aiPlay=0;


    if(aiPlay == 1){
        // Sets user and AI character values
        if(charPtr[41] == 'X')
            charPtr[42] = 'O';
        else charPtr[42]= 'X';

    }

    switch(aiPlay)
    {
        //Runs game without AI
        case 0:
            while(win == 0)
            {
                // Runs user turn and returns a win of 0 or 1
                win = userTurn(selector, win, charPtr, aiPlay);

                // Increases turn by 1
                intPtr[0] = intPtr[0] + 1;
            }
            break;
        // Runs game with AI
        case 1:
            while(win == 0)
            {
                if(charPtr[42] == charPtr[40])
                {
                    // Runs AI turn
                    win = aiTurn(selector, corners, sides, center, win, charPtr, intPtr);

                    // Increases turn by 1
                    intPtr[0] = intPtr[0] + 1;
                    if(win == 1)
                        break;
                }
                win = userTurn(selector, win, charPtr, aiPlay);

                // Increases turn by 1
                intPtr[0] = intPtr[0] + 1;
            }
            break;
        default:
            displayError();
            break;
    }

    // Print board to console
    renderBoard(charPtr, win);

    return 0;
}
Пример #19
0
void gameLoop() {
    col_s = getColumns();
    row_s = getRows();
    initRenderBuffer();
    int sx = col_s * 32;
    int sy = row_s * 32;
    win = SDL_CreateWindow("ProxySweep", 100, 100, sx, sy, SDL_WINDOW_SHOWN);
    SDL_PTR_ERR(__LINE__, win);
    ren = NULL;
    ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
    SDL_PTR_ERR(__LINE__, ren);
    SDL_SetRenderDrawColor(ren, 0, 127, 127, 255);
    initTextures();
    SDL_Event e;
    int quit = 0;
    Uint32 ticks = 0;
    int game_state = ONGOING;
    board = getPointer();
    while (!quit) {
        while (SDL_PollEvent(&e)) {
            if (e.type == SDL_QUIT)
                quit = true;
            if (e.type == SDL_MOUSEBUTTONDOWN) {
                int x, y;
                Uint32 s = SDL_GetMouseState(&x, &y);
                int col = x/32;
                int row = y/32;
                if (s & SDL_BUTTON(1)) {
                    if (SDL_GetTicks() - ticks < CLICK_DELAY)
                        game_state = doubleClick(col, row);
                    else {
                        game_state = buttonPressed(col, row, LEFT);
                    }
                    ticks = SDL_GetTicks();
                }
                else if (s & SDL_BUTTON(3)) {
                    //right button
                    game_state = buttonPressed(col, row, RIGHT);
                }
            }
        }
        board = getPointer();
        renderBoard();
        switch (game_state) {
            case GAME_END_SUCCESS:
                printf("You won :)\n");
                showMessage("YOU WIN!!!", "Congratulations");
                quit = 1;
                break;
            case GAME_END_FAIL:
                printf("You lost :(\n");
                showMessage("YOU LOSE!!!", "I'm Sorry...");
                quit = 1;
                break;
            case ONGOING:
                //printf("Ongoing..\n");
                break;
        }
    }
    while (SDL_PollEvent(&e));
    freeRenderBuffer();
    SDL_DestroyWindow(win);
}
Пример #20
0
void Window::renderAll(Cell board[], const int amoutOfCells) {
    renderBoard(board, amoutOfCells);
    renderUI();
}