Пример #1
0
void Timer(int a)
{
    if(!change) //checks to see if we are dealing with the same shape
    {
        x = generatePart(board); // if the shape has set, generate a new shape
        change = true; // set change to true to not generate a new shape until the one we just generated sets
    }
    
    if( x == NULL)
    {
        char choice =' ';
        boardDraw();
        cout << "Game over" << endl;
        cout << "Wish to play again?" << endl;
        cin >> choice;
        
        if( choice == 'Y')
        {
            for(int i = 1; i < 21; i++)
            {
                for(int j = 1; j < 11; j++)
                {
                    board[i][j] = 0;
                }
            }
            
            boardDraw();
            x = generatePart(board);
            change = true;
            speed = 1000;
        }
        
        else if (choice == 'N')
            exit(0);
    }
Пример #2
0
//this function takes in our keyboard inputs
void keys(int key, int w, int y) //movements need to be about the
{
    //Remember to add option to quit which is the esc key
    if(key == GLUT_KEY_UP)
    {
        //rotate method
        x->rotate(board);// rotate our shape
        //x->ghost(board);
        x->draw(board); //draw our shape to the array
        boardDraw();  //draw our shape to the screen
    }
    
    if(key == GLUT_KEY_LEFT)
    {
        //left directional key
        x->moveLeft(board); //moves our shape to the left
        //x->ghost(board);
        x->draw(board);
        boardDraw(); //draw our shape to the screen
    }
    
    if(key == GLUT_KEY_RIGHT)
    {
        //Right directional key
        x->moveRight(board); //moves our shape to the right
        //x->ghost(board);
        x->draw(board); //draw our shape to the array
        boardDraw(); //draw our shape to the screen
    }
    
    if(key == GLUT_KEY_DOWN)
    {
        //Down directional key
        x->moveDown(board); //moves the shape down
        x->draw(board); //draw our shape to the array
        boardDraw(); //draw our shape to the screen
    }
    
    if(key == 32) //space key
    {
        //set piece immediately
        x->dropSet(board); // this is wonky. when there is space beneath tiles it runs forever??
        x->draw(board);
        boardDraw(); // draw shape to screen window
    }
    
    if(key == 27) //esc key
    {
        exit(0);
    }
}
Пример #3
0
int main() {
	Board board = newBoard();
	Player player = newPlayer(1, PLAYER, board),
		   current;
	AI ai = newAI(board);
	WINDOW *status;
	bool isRunning = TRUE;
	int key;

	initscr();				/* Start curses mode */
	start_color();			/* Color mode */
	cbreak();				/* Disable line-break mode */
	keypad(stdscr, TRUE);	/* Enable getch for function keys */
	curs_set(0);			/* Remove cursor */
	noecho();				/* Disable echo */
	init_pair(1, COLOR_YELLOW, COLOR_BLACK);
	init_pair(2, COLOR_RED, COLOR_BLACK);
	init_pair(3, COLOR_YELLOW, COLOR_YELLOW);
	init_pair(4, COLOR_RED, COLOR_RED);

	status = newwin(25, 20, 0, 0);
	current = player;

	boardDraw(board);
	statusDraw(status, current, ai);
	ungetch('a');	/* Skip first getch() */

	while(isRunning) {
		if((key = getch()) == KEY_F(1)) {
			isRunning = FALSE;
			break;
		}
		
		if(current == player) {
			if(player->doMove(player, key)) {
				/* Pass turn to AI */
				current = ai->player;
				ungetch('a'); /* Skip the next keystroke and instantly go to the AI */
			}
		} else {
			ai->doAIMove(ai);
			if(ai->player->doMove(ai->player, key)) {
				/* Pass turn to AI */
				current = player;
				ungetch('a'); /* Skip the next keystroke and instantly go to the AI */
			}
		}

		boardDraw(board);
		statusDraw(status, current, ai);

		if(board->isBoardFull(board)) {
			getch();
			wmove(status, 13, 1); wclrtoeol(status);
			wattron(status, A_BOLD);
			wprintw(status, "Draw Game!");
			wattroff(status, A_BOLD);
			wrefresh(status);

			isRunning = FALSE;
			getch();
		}
		if(board->checkForWin(board, current->getID(current))) {
			int pid = current->getID(current);

			getch();
			wmove(status, 13, 1); wclrtoeol(status);
			wattron(status, A_BOLD | COLOR_PAIR(pid));
			wprintw(status, "%s", (pid == 1)?"Player":"AI");
			wattroff(status, A_BOLD | COLOR_PAIR(pid));
			wprintw(status, " won!");
			wrefresh(status);

			isRunning = FALSE;
			getch();
		}
	}

	board->destroyBoard(board);
	free(player);
	free(ai);
	endwin();
	return 0;
}
Пример #4
0
void gameDraw()
{
    boardDraw();
    gameGuiDraw();
}
Пример #5
0
void Timer(int a)
{
    /*
     some where along the line if I drop the line block on top of a square, if the right block is the one touching it will
     not recreate a part...
     */

    if(!change) //checks to see if we are dealing with the same shape
    {
        x = generatePart(board); // if the shape has set, generate a new shape
        change = true; // set change to true to not generate a new shape until the one we just generated sets
    }
    
    //Drop variable to set to true so that we cannot move once we drop set
    //if this is not here it will not work for some reason
    x->DROP = true;
    
    //display board to console for testing
    print(board);
    x->draw(board); //draw shape to board
    print(board);
    boardDraw(); // draw shape to screen window
    
    if(typeid(*x) == typeid(Square)) //if we are dealing with a sqare block (C++ version of java instanceof)
    {
        //board[x->Y4+1][x->X4] == 0 && board[x->Y3+1][x->X3] == 0
        if(x->moveDown(board)) //check if down move is available
        {
            glutDisplayFunc(draw);
            glutSpecialFunc(keys);
            glutTimerFunc(speed, Timer, 0);
            glutPostRedisplay();
        }
        
        //if(board[x->Y4+1][x->X4] != 0 || board[x->Y3+1][x->X3] != 0)
        else if(!x->moveDown(board))// if the cube reached the bottom
        {
            change = false;
            glutDisplayFunc(draw);
            glutTimerFunc(1, Timer, 0);
            glutPostRedisplay();
        }
    }
    
    else if(typeid(*x) == typeid(Line)) //if we are dealing with a line block
    {
        //this will only work for a line right now and square
         //&& board[x->Y4+1][x->X4] == 0 && board[x->Y3+1][x->X3] == 0
        if(x->moveDown(board))
        {
            glutTimerFunc(speed, Timer, 0);
            glutDisplayFunc(draw);
            glutSpecialFunc(keys);
            glutPostRedisplay();
        }
        
        // generate and draw soon after
        else if(!x->moveDown(board))
        {
            change = false;
            glutTimerFunc(1, Timer, 0);
            glutDisplayFunc(draw);
            glutPostRedisplay();
        }
    }
}