예제 #1
0
파일: tetris.c 프로젝트: vichou/tetris
void movePieceY (int mag)
{
    int canMove = 1;
    for (int i = 0; i < 16; i++)
    {
        if (currActivePiece[i].onoff == 1)
        {
            if (currActivePiece[i].y + mag <= 3)
            canMove = 0;
            if (theBoard[currActivePiece[i].x]
            [currActivePiece[i].y + mag].onoff == 1)
            canMove = 0;
        }
    }
    if (canMove == 0)
    {
        fillBoard ();
        needNewPiece = 1;
    }
    if (canMove == 1)
    {
        moveY += mag;
        for (int i = 0; i < 16; i++)
        {
            currActivePiece[i].y += mag;
        }
    }
}
예제 #2
0
/*****************************************************************************
Precondition: Board dimensions are sent in
Postcondition: A boggle board is built to the proper size
*****************************************************************************/
bool BogValidator::readBoard()
{
	int junk = 0;

	cin >> boardSize;
	//catches the second dimension because it is not needed
	cin >> junk;

	//checks validity of dimensions
	if (boardSize != junk){
		return false;
	}
	if (boardSize <= 0){
		return false;
	}

	//builds the board to the proper size
	bogBoard = new Tile*[boardSize];

	//constructs the second dimension
	for (int i = 0; i < boardSize; i++){
		bogBoard[i] = new Tile[boardSize];
	}

	fillBoard();

	return true;
}
예제 #3
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ballsParent = ui->ballsFrame;
    Controller *sth = new Controller(ballsParent);
    sth->init(ballsParent);
    connect(ui->actionNew, SIGNAL(triggered()), Controller::control, SLOT(fillBoard()));
    connect(Controller::control, SIGNAL(newFirstScore(int)), ui->firstScore, SLOT(display(int)));
}
예제 #4
0
int main(){
	initScreen();
	lcdTest();
	while(1){
		fillBoard();
		printBoard();
		for (int i = 0; i < 1000; i++){
			playerStep();
			printBoard();
		}
	}
	closeScreen();

}
예제 #5
0
int main(){
	initializeCoords();
	fillBoard();
#ifdef _DEBUG
	for(int index=0;index<100;index++)
		printf("%d\t",get(coords[index].row,coords[index].col));
	printf("\n");
#endif
	int caseNum;
	scanf("%d",&caseNum);
	while(caseNum--){
		int index;
		scanf("%d",&index);
		printf("%d\n",get(coords[index-1].row,coords[index-1].col));
	}
	return 0;
}
예제 #6
0
int
main(int argc,char **argv)
    {
    int i;
    char **mineBoard = 0;
    char **statusBoard = 0;
    //for(i=0;i<argc;i++)
        //printf("argv[%d] = %s\n",i,argv[i]);
    int rows = atoi(argv[1]) + 1;
    //printf("rows = %d\n",rows);
    int colums = atoi(argv[2]) + 1;
    //printf("cols = %d\n",colums);
    int mines = atoi(argv[3]);
    //printf("mines = %d\n",mines);
    mineBoard = makeEmptyBoard(mineBoard,rows,colums);
    //printf("\n");
    statusBoard = makeEmptyBoard(statusBoard,rows,colums);
    //printf("\n");
    //printf("rows = %d\n",rows);
    //printf("cols = %d\n",colums);
    
    //displayBoard(mineBoard,rows,colums);
    //displayBoard(statusBoard,rows,colums);
    coverBoard(statusBoard,rows,colums);
    displayBoard(statusBoard,rows,colums);
    mineBoard = placeMines(rows,colums,mines,mineBoard);
    mineBoard = fillBoard(mineBoard,rows,colums);
    displayBoard(mineBoard,rows,colums);

    /*int r,c;
    for (r=0;r<rows;r++)
        {
        for (c=0;c<colums;c++)
            {
            printf("[%c] ",mineBoard[r][c]);
            }
        printf("\n");
        }*/
    //free(mineBoard);
    //free(statusBoard);
    return 0;
    }
예제 #7
0
void executeCGOL(int x, int y, int seed) {
  Serial.println("executeCGOL\n");
	b1 = (char*)malloc(sizeof(char)*x*y);
	b2 = (char*)malloc(sizeof(char)*x*y);
	fillBoard((char*)b1, x, y, seed);
	long itercount =0;

	while (itercount<MAX_GEN && aliveCount(b1, x,y)>3) {
		char *artemp = b1;
		b1=generate(b1,b2, x, y);
        b2 = artemp;
         // display board
		displayBoard(b1);
		delay(1000);
		if(!hasChanged(b1, b2, x, y)) {
			delay(60000);
			break;
		}
  	}		
}
예제 #8
0
int main()
{
    byte** board;
    byte i, j;
    time_t t;

    srand((unsigned) time(&t));

    board = malloc(DIMENSION * sizeof(byte*));

    for(i = 0; i < DIMENSION; ++i)
        board[i] = malloc(DIMENSION * sizeof(byte));

    for(i = 0; i < DIMENSION; ++i)
        for(j = 0; j < DIMENSION; ++j)
            board[i][j] = 0;

    fillBoard(board, rand() % DIMENSION, rand() % DIMENSION, DIMENSION);

    for(i = 0; i < DIMENSION; ++i)
    {
        for(j = 0; j < DIMENSION; ++j)
        {
            if(!board[i][j])
            {
                printf("ERROR: empty slot on the board at %d %d!!!\n", i, j);
                return 1;
            }
            else printf("%2d ", board[i][j]);
        }
        printf("\n");
    }

    for(i = 0; i < DIMENSION; ++i)
        free(board[i]);
    free(board);

    return 0;
}
예제 #9
0
int main(){
	initScreen();
	initSound();
	initLedButtons();
	lcdTest();
	while(1){
		fillBoard();
		printBoard();
		
		for (int i = 0; i < 100; i++){
			setLeds((char)i);
			setFrequency(120*(i%20));
			playerStep();
			printBoard();
			playSounds();
			if (readButtons() & 0x01 > 0) break;
		}
	}
	closeLedButtons();
	closeScreen();
	closeSound();

}
예제 #10
0
void boardLoop()
{
    Board b;
    char inputOption;
    Coord source, dest;
    fillBoard(b);
    do {
        do {
            printGameScreen(b);
            inputOption = readValidOption("Ingrese la fila de origen", VALID_OPTIONS);
            if (isProgramOption(inputOption, VALID_PROGRAM_OPTIONS)) {
                break;
            }
            source.row = ctoi(inputOption);

            printGameScreen(b);
            inputOption = readValidOption("Ingrese la columna de origen", VALID_OPTIONS);
            if (isProgramOption(inputOption, VALID_PROGRAM_OPTIONS)) {
                break;
            }
            source.col = ctoi(inputOption);

            printGameScreen(b);
            inputOption = readValidOption("Ingrese la fila de destino", VALID_OPTIONS);
            if (isProgramOption(inputOption, VALID_PROGRAM_OPTIONS)) {
                break;
            }
            dest.row = ctoi(inputOption);

            printGameScreen(b);
            inputOption = readValidOption("Ingrese la columna de destino", VALID_OPTIONS);
            if (isProgramOption(inputOption, VALID_PROGRAM_OPTIONS)) {
                break;
            }
            dest.col = ctoi(inputOption);
        } while (0);

        switch (inputOption) {
            case 'q':
            case 'Q':
                if (readConfirmOption("¿Esta usted seguro?")) {
                    printf("Adios\n");
                } else {
                    inputOption = OPTION_NOTHING;
                }
                break;
            case 'h':
            case 'H':
                clearScreen();
                printInstruction();
                pauseMessage(NULL);
                break;
            case 'r':
            case 'R':
                fillBoard(b);
                break;
            case 'w':
            case 'W':
                printf("Win game step\n");
                break;
        }
    } while ('q' != inputOption);
}