Beispiel #1
0
void MainWidget::rightClicked()
{
    qDebug() << "rightClicked";

    TGbutton *button = (TGbutton*)sender();

    int a,b;
    button->GetAB(a,b);
    emit sendClient("RIGHT", a, b);

    presses << "RIGHT";
    QPair <int,int> pair;
    pair.first = a;
    pair.second = b;
    pressBut << pair;

    if(button->curState == TGbutton::First)
    {
        button->setIcon(QIcon(":/flag.png"));
        button->curState = TGbutton::Flag;
        emit updateMines(--mines);
    }
    else if(button->curState == TGbutton::Flag)
    {
        button->setIcon(QIcon());
        button->curState = TGbutton::First;
        emit updateMines(++mines);
    }
}
Beispiel #2
0
void MainWidget::rightClicked(int i, int j)
{
    qDebug() << "rightClicked" << i << j;

    TGbutton *button = &fields[i][j];
    if(button->curState == TGbutton::First)
    {
        button->setIcon(QIcon(":/flag.png"));
        button->curState = TGbutton::Flag;
        emit updateMines(--mines);
    }
    else if(button->curState == TGbutton::Flag)
    {
        button->setIcon(QIcon());
        button->curState = TGbutton::First;
        emit updateMines(++mines);
    }
}
static void gameScreen_PhysicsTick( float dt )
{
	ourSpawnDelay -= dt;
	if( ourSpawnDelay <= 0.0f ) {
		spawnTroops( 0, MIN_ATTACKER_SPAWN, MAX_ATTACKER_SPAWN );
		ourSpawnDelay = randFloat( MIN_SPAWN_DELAY, MAX_SPAWN_DELAY );
	}

	theirSpawnDelay -= dt;
	if( theirSpawnDelay <=0.0f ) {
		spawnTroops( 1, MIN_DEFENDER_SPAWN, MAX_DEFENDER_SPAWN );
		theirSpawnDelay = randFloat( MIN_SPAWN_DELAY, MAX_SPAWN_DELAY );
	}

	updatePanjandrumsReady( dt );

	updatePanjandrums( dt );
	updateTroops( dt );
	updateExplosions( );
	updateMines( dt );
	particlesPhysicsTick( dt );

	updateSprite( launchToSprite, launchToPosition, VEC2_ONE, 0.0f );
}
Beispiel #4
0
int game(WINDOW *left, WINDOW *bottom, WINDOW *textBox, WINDOW *middle,
    int sock, unsigned char id, unsigned char players,
    unsigned char bombs, unsigned char mines, struct data *pData,
    unsigned char field[16][16]){
    
    unsigned char i, toReceive, toDiscard, chatLen, y, x;
    unsigned char msgLen, len, isChatting, turn, bombing;
    //255-64
    char buffer[191];
    //65 to fit a 0 at the end before printing
    char chatBuffer[65];

    fd_set set;

    //Initialize what we have to
    isChatting = 0;
    toReceive = 0;
    toDiscard = 0;
    chatLen = 2;
    bombing = 0;
    msgLen = 0;
    turn = players + 1;
    chatBuffer[1] = 't';
    y = 7;
    x = 7;

    //Windows' timeval
#ifdef WIN32
    struct timeval timeVal;
    timeVal.tv_sec = 0;
    timeVal.tv_usec = 250;
#endif

    //Main loop
    while(mines){
        //Build the set
        FD_ZERO(&set);
#ifndef WIN32
        FD_SET(fileno(stdin), &set);
#endif
        FD_SET(sock, &set);

        //Wait for something to happen
#ifdef WIN32
        if(select(FD_SETSIZE, &set, NULL, NULL, &timeVal) < 0){
#else
        if(select(FD_SETSIZE, &set, NULL, NULL, NULL) < 0){
#endif
            return 1;
        }

        //Read the keyboard first
#ifndef WIN32
        if(FD_ISSET(fileno(stdin), &set)){
#endif
            //Send the message if the handler says it's OK
            switch(keyboardHandler(middle, textBox, &chatLen, &isChatting,
                bombs, &bombing, &y, &x, id, turn, field, chatBuffer)){

                //Chat
                case 1:
                    //Set the size of the message and send it
                    chatBuffer[0] = chatLen - 1;
                    send(sock, chatBuffer, chatLen, 0);
                    //Cleanup
                    isChatting = 0;
                    mvwhline(textBox, 0, 0, ' ', COLS-18);
                    chatLen = 2;
                    wrefresh(textBox);
                    break;

                //Sweep
                case 2:
                    buffer[0] = 2;
                    buffer[1] = 's';
                    buffer[2] = (y << 4) | (x & 15);
                    send(sock, buffer, 3, 0);
                    break;

                //Bomb
                case 3:
                    buffer[0] = 2;
                    buffer[1] = 'b';
                    buffer[2] = (y << 4) | (x & 15);
                    send(sock, buffer, 3, 0);
                    bombs--;
                    updateBombs(left, id, bombs);
                    break;
            }
#ifndef WIN32
        }
#endif

        //Receive data
        //Read the keyboard first
        if(FD_ISSET(sock, &set)){
            //Receive if we can
            if(toReceive){
                len = recv(sock, buffer + (msgLen - toReceive) * sizeof(char),
                    toReceive, 0);

                if(len > 0){
                    toReceive -= len;
                    if(toReceive){
                        continue;
                    }
                }
            }
            //Discard if we have to
            else if(toDiscard){
                len = recv(sock, buffer, toDiscard, 0);
                if(len > 0){
                    toDiscard -= len;
                    continue;
                }
            }
            //Get the length of the new message
            else {
                len = recv(sock, buffer, 1, 0);
                //Get the length if we didn't lose connection
                if(len > 0){
                    //Adjust the values
                    if((unsigned char) buffer[0] > 64){
                        msgLen = 64;
                        toReceive = 64;
                        toDiscard = (unsigned char) buffer[0] - 64;
                    }
                    else {
                        msgLen = (unsigned char) buffer[0];
                        toReceive = (unsigned char) buffer[0];
                    }
                    continue;
                }
            }
            //Lost connection
            if(len <= 0){
                return 1;
            }

            //If we got down here, we're ready to parse

            //Chat
            if(buffer[0] == 't'){
                addLine(bottom, msgLen, buffer, pData);
            }
            //New player
            else if(buffer[0] == 'c'){
                //Copy name
                for(i = 2; i < msgLen; i++){
                    //Make it 7-bit
                    if(buffer[i] < 32){
                        buffer[i] = '?';
                    }
                    pData[(unsigned char) buffer[1]].name[i - 2] = buffer[i];
                }

                //Null terminate
                pData[(unsigned char) buffer[1]].name[i-2] = 0;

                //Update the stats
                pData[(unsigned char) buffer[1]].stats = 1;

                //Add player to the left panel
                addPlayer(left, bottom, (unsigned char) buffer[1], pData);
            }
            //Player left
            else if(buffer[0] == 'l'){
                //Update the stats
                pData[(unsigned char) buffer[1]].stats = 0;

                //Remove from the window
                removePlayer(left, bottom, (unsigned char) buffer[1], pData);
            }
            //New turn
            else if(buffer[0] == 'v'){
                //Update the stats
                turn = buffer[1];

                //Remove from the window
                tellTurn(bottom, turn, pData);

                //Draw the cursor if we're playing now
                if(turn == id){
                    bombing = 0;
                    startCursor(middle, &y, &x, bombing, field);
                }
                //Hide cursor
                else {
                    setValue(middle, y, x, field[y][x] & 15,
                        (field[y][x] & 240) >> 4);
                }
            }
            //Player won
            else if(buffer[0] == 'w'){
                return 0;
            }
            //Reveal
            else if(buffer[0] == 'r'){
                for(i = 1; i < msgLen; i += 2){
                    //Update the matrix
                    field[(buffer[i] & 240) >> 4][buffer[i] & 15] =
                        buffer[i+1];

                    //Update the screen
                    setValue(middle, (buffer[i] & 240) >> 4, buffer[i] & 15,
                        buffer[i+1], turn);

                    //Set the player and update the score
                    if(buffer[i+1] > 8){
                        field[(buffer[i] & 240) >> 4][buffer[i] & 15] |=
                            turn << 4;

                        pData[turn].score++;

                        updateMines(left, --mines);
                    }
                }
                //Update the score on the screen
                updateScore(left, turn, pData);
            }
        }