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); }
Part::Ptr & Brain::part(Part::ID const & id_) { Part::Ptr & ret = _parts[id_]; if(!ret){ ret.reset(generatePart(id_)); } return ret; }
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(); } } }