Beispiel #1
0
// This procedure has issues in some place, need re-check
void Server::restartGame()
{
    QString code;
    QString message;
    code == "02";
    message = code + "nothing";
    for (int i = 0; i < numberOfPlayers; i++){
        players[i]->sendMessage(message);
    }
    int add;
    playerTurn = 0;
    round = 0;
    hand++;
    if (hand > numberOfPlayers-1)
        hand = 0;
    deck->suffleDeck();
    add = 0;
    for (int card = 0; card < 3; card++) {
        for(int i = 0; i < numberOfPlayers; i++) {
            if (hand == 0) {
                players[i]->setCards(card, deck->newCard());
            }
            if (hand == 1) {
                add = i + hand;
                if (add > 3) {
                    players[add-4]->setCards(card, deck->newCard());
                } else {
                    players[add]->setCards(card, deck->newCard());
                }
            }
            if (hand == 2) {
                add = i + hand;
                if (add > 3) {
                    players[add-4]->setCards(card, deck->newCard());
                } else {
                    players[add]->setCards(card, deck->newCard());
                }
            }
            if (hand == 3) {
                add = i + hand;
                if (add > 3) {
                    players[add-4]->setCards(card, deck->newCard());
                } else {
                    players[add]->setCards(card, deck->newCard());
                }
            }
        }
    }
    setPlayerTurn(hand);
    players[getPlayerTurn()]->yourTurn();
}
Beispiel #2
0
void Server::checkGame()
{
    qDebug() << "Server::checkGame()";
    int highValueRoundOne;
    int highValueRoundTwo;
    int highValueRoundThree;
    int playerWinnerRoundOne;
    int playerWinnerRoundTwo;
    int playerWinnerRoundThree;
    bool team0Winner;
    bool team1Winner;
    highValueRoundOne = 0;
    highValueRoundTwo = 0;
    highValueRoundThree = 0;
    playerWinnerRoundOne = -1;
    playerWinnerRoundTwo = -1;
    playerWinnerRoundThree = -1;
    team0Winner = false;
    team1Winner = false;

    // round = [0,1,2]
    //qDebug() << "Card of player0:" << cardsOfRoundOne[0];
    //qDebug() << "Card of player1:" << cardsOfRoundOne[1];
    for (int i = 0; i < numberOfPlayers; i++) {
        if (cardsOfRoundOne[i] > highValueRoundOne) {//when round 0
            qDebug() << "Cards round one: " << cardsOfRoundOne[i];
            highValueRoundOne = cardsOfRoundOne[i];
            playerWinnerRoundOne = i;
        }
        if (getRound() != 0) //when round 1
            if (cardsOfRoundTwo[i] > highValueRoundTwo) {
                qDebug() << "Cards round two: " << cardsOfRoundTwo[i];
                highValueRoundTwo = cardsOfRoundTwo[i];
                playerWinnerRoundTwo = i;
            }
        if (getRound() == 2) { //when round 2
            if (cardsOfRoundThree[i] > highValueRoundThree) {
                qDebug() << "Cards round three: " << cardsOfRoundThree[i];
                highValueRoundThree = cardsOfRoundThree[i];
                playerWinnerRoundThree = i;
            }
        }
        qDebug() << "High Value Card of Round[0]" <<highValueRoundOne;
        qDebug() << "High Value Card of Round[1]" <<highValueRoundTwo;
        qDebug() << "High Value Card of Round[2]" <<highValueRoundThree;
    }

    qDebug() << "Winner first round" << playerWinnerRoundOne;
    qDebug() << "Winner second round" << playerWinnerRoundTwo;
    qDebug() << "Winner third round" << playerWinnerRoundThree;

    if (round > 0) {
        qDebug() << "Round 2 tests";
        if (playerWinnerRoundOne % 2 == 0) {
            if (playerWinnerRoundTwo % 2 == 0) {
                team0Winner = true; //ganhou 1 e 2
                qDebug() << "Team0 Win round 1 and 2";
            } else {//perdeu 2
                if (round == 2) {
                    if (playerWinnerRoundThree % 2 == 0) {
                        team0Winner = true; // ganhou 1 e 3
                        qDebug() << "Team0 Win round 1 and 3";
                    } else {
                        team1Winner = true; // perdeu 2 e 3
                        qDebug() << "Lost round 2 and 3";
                    }
                }
            }
        } else {//perdeu 1
            if (playerWinnerRoundTwo %2 == 0) {
                if (round == 2) {
                    if (playerWinnerRoundThree % 2 == 0) {
                        team0Winner = true; // ganhou 2 e 3
                        qDebug() << "Team0 Win round 2 and 3";
                    } else {
                        team1Winner = true; // perdeu 1 e 3
                        qDebug() << "Team0 Lost round 1 and 3";
                    }
                }
            } else {
                team1Winner = true; // perdeu 1 e 2
                qDebug() << "Lost round 1 and 2";
            }
        }
    }

    if (!team0Winner && !team1Winner) {
        // The player who win this round play again
        if (round == 0) {
            qDebug() << "No game's winner | round[0]";
            setPlayerTurn(playerWinnerRoundOne);
        }
        if (round == 1) {
            qDebug() << "No game's winner | round[1]";
            setPlayerTurn(playerWinnerRoundTwo);
        }
    } else { // faz algo pq alguem ganhou
        if (team0Winner) {
            qDebug() << "Team0 win this match!";
            //restartGame();
        }
        if (team1Winner) {
            qDebug() << "Team1 win this match!";
            //restartGame();
        }
    }
    nextRound();
}
Beispiel #3
0
void Combat::changePlayerTurnSlot(QAbstractButton* temp)
{
    //refresh the dice value
    dice->refreshLabel();

    if(getPlayerTurn() == playerCount.at(playerCount.size()-1))
    {
        //all the player finish rolling dice, begin to apply hits.vice versa
        if(rollDice)
        {
            if(getCombatTurn() <= 3)
            {
                rollDice = false;
                //start to apply hit
                dice->hide();
            } else {
                //start next combat turn
                setCombatTurn(1);
                dice->show();
                button->hide();
                button2->hide();
            }
        } else {
            rollDice = true;
            if(getCombatTurn() == 3)
            {
                setCombatTurn(getCombatTurn()+1);
                button->show();
                button2->show();
            } else {
                //start to roll dice
                dice->show();
                //start next combat turn
                setCombatTurn(getCombatTurn()+1);
            }
        }
        //change to next player
        setPlayerTurn(playerCount.at(0));
        if(getThingsFromPlayerID(getPlayerTurn()).size() == 0)
        {
            if(ownPlayer == getPlayerTurn())
            {
                if(getBuildingValue() == 0)
                {
                    //change to next player
                    changePlayerTurnSlot(temp);
                }
            } else {
                //change to next player
                changePlayerTurnSlot(temp);
            }
        }
    } else {
        //change to next player
        for(int i = 0; i < playerCount.size(); i++)
        {
            if(playerCount.at(i) == getPlayerTurn())
            {
                setPlayerTurn(playerCount.at(i+1));
                if(getThingsFromPlayerID(getPlayerTurn()).size() == 0)
                {
                    if(ownPlayer == getPlayerTurn())
                    {
                        if(getBuildingValue() == 0)
                        {
                            //change to next player
                            changePlayerTurnSlot(temp);
                        }
                    } else {
                        //change to next player
                        changePlayerTurnSlot(temp);
                    }
                }
                break;
            }
        }
    }

}
Beispiel #4
0
void Combat::initialLayout()
{
    vertical_layout = new QGridLayout;
    playerCount = detectWhichPlayer();
    for(int i = 0; i < playerCount.size(); i++)
    {
        switch (playerCount.at(i)) {
        case 1:
            vertical_layout->addWidget(createPlayerBox(PlayerOneThing,1),i,0);
            break;
        case 2:
            vertical_layout->addWidget(createPlayerBox(PlayerTwoThing,2),i,0);
            break;
        case 3:
            vertical_layout->addWidget(createPlayerBox(PlayerThreeThing,3),i,0);
            break;
        case 4:
            vertical_layout->addWidget(createPlayerBox(PlayerFourThing,4),i,0);
            break;
        default:
            break;
        }
        //initial the hitpoint for each player
        QLabel *hitPoint = new QLabel;
        hitPoint->setObjectName("0");
        QString temp ="Player " + QString::number(playerCount.at(i)) + " HitPoint : " + hitPoint->objectName();
        hitPoint->setText(temp);
        playerHitPoint.push_back(hitPoint);
        vertical_layout->addWidget(hitPoint,i,1);
        //initial the building if owerner have one
        if(ownPlayer == playerCount.at(i))
        {
            if(HexBuilding)
            {

                buildingButton = new QPushButton;
                buildingButton->setObjectName(QString::number(getHexBuilding()->getID()));
                QString temp = "border-image: url(" + getHexBuilding()->getUrl();
                buildingButton->setStyleSheet(temp + ")");
                buildingButton->setFixedSize(80,80);
                connect(buildingButton,SIGNAL(clicked()),this,SLOT(buildingButtonClickSlot()));
                vertical_layout->addWidget(buildingButton,i,2);
                //initial the building value
                buildingValue = getHexBuilding()->getIncome();
            }
        }
    }
    //roll the dice first
    rollDice = true;
    //initial the dice widget
    dice = new DiceWidget(this);
    vertical_layout->addWidget(dice,0,3);
    dice->setFixedSize(100,100);
    connect(dice, SIGNAL(updateDiceValueSignal(int)), this, SLOT(updateDiceValueSlot(int)));
    dice->show();
    //set the player turn label
    playerTurnLabel = new QLabel;
    playerTurnLabel->setStyleSheet("background-color: white;");
    setPlayerTurn(playerCount.at(0));
    vertical_layout->addWidget(playerTurnLabel,0,4);
    //initial the button
    button = new QPushButton;
    button2 = new QPushButton;
    button->setText("Continue");
    button2->setText("Retreats");
    vertical_layout->addWidget(button,1,3);
    vertical_layout->addWidget(button2,1,4);
    connect(button,SIGNAL(clicked()),this,SLOT(continueButtonSlot()));
    connect(button2,SIGNAL(clicked()),this,SLOT(retreatButtonSlot()));
    button->hide();
    button2->hide();
    //add the globalwidget
    globalWidget = new QWidget(this);
    globalWidget->setLayout(vertical_layout);
}
Beispiel #5
0
//Update players structs based on keyboard
void updateActions() {
	if (IORD(keys,0) == 8) {
		moveLeft(turn);
		p[turn].moved = TRUE;
	}
	//moves right
	if (IORD(keys,0) == 4) {
		moveRight(turn);
		p[turn].moved = TRUE;
	}
	//turret fire
	if (IORD(keys,0) == 2) {
		//fire power should be 0<power<100
		turretFire(turn, 100, windPower, 0); //need to get power from keyboard
		setPlayerTurn();

	}
	//turret CW
	if (IORD(switches,0) == 1) {
		turretCW(turn);
	}
	//turret CCW
	if (IORD(switches,0) == 2) {
		turretCCW(turn);
	}
	if (IORD(switches,0) == 4) {
		p[pOne].hp = 0;
	}

	if (fLeft == 1) {
		p[turn].moved = TRUE;
		moveLeft(turn);
	}
	if (fRight == 1) {
		p[turn].moved = TRUE;
		moveRight(turn);
	}
	if (fUp == 1) {
		turretCCW(turn);
	}
	if (fDown == 1) {
		turretCW(turn);
	}
	if (fpDown == 1) {
		if (p[turn].power - 1 >= 0)
			p[turn].power--;
	}
	if (fpUp == 1) {
		if (p[turn].power + 1 <= 100)
			p[turn].power++;
	}
	if (fBullet == 1) {
		fBullet = 0;
		p[turn].bulletType = (p[turn].bulletType + 1)%2;
	}
	if (fFire == 1) {
		if (!p[turn].isFalling) {
			alt_up_ps2_disable_read_interrupt(ps2);
			turretFire(turn, p[turn].power, windPower, p[turn].bulletType);
			setPlayerTurn();
			alt_up_ps2_enable_read_interrupt(ps2);
			printf("Before enabled interupt\n");
			alt_up_ps2_clear_fifo(ps2);
			printf("Fifo cleared\n");
			fFire = 0;
			drawHealth(p[pOne].hp, p[pTwo].hp, p[pThree].hp, p[pFour].hp);
			drawBullet(p[turn].bulletType);
			updateScreen();
			drawHealth(p[pOne].hp, p[pTwo].hp, p[pThree].hp, p[pFour].hp);
		}
	}
}
Beispiel #6
0
int main(void) {
	while (1) {
		state = 0;
		int setTime = 15;
		numPlayers = 2;
		initScreen();
		clearScreen();
		initCharBuffer();
		clean_up();
		initKeyboard();
		initState0();
		initAI();


		//Bypass the menu system for testing
		if (IORD(keys,0) == 8) {
			initPlayer(pOne, MARIO, "pOne", 50, 100, HUMAN);
			initPlayer(pTwo, LUIGI, "pTwo", 50, 100, COMPUTER);
			state = 2;
		} else {
			while (state == 0) {
				decode_scancode(ps2, &decode_mode, buf, &ascii);
				state_0(decode_mode, buf[0]);
			};
			initState1(pOne);
			if(aOn)file_handle = initAudio(fname);
			if(aOn)alt_irq_register(AUDIO_0_IRQ, &ab, (alt_isr_func) write_fifo);
			if(aOn)		alt_up_audio_enable_write_interrupt(ab->audio);
			while (state == 1) {
				decode_scancode(ps2, &decode_mode, buf, &ascii);
				state_1(decode_mode, buf[0], ascii);
				if(aOn)loop_audio(file_handle, fname, ab);
			};
		}

		//clean_up();
		clearCharBuffer();
		clearScreen();

		//enable keyboard IRQ
		void* keyboard_control_register_ptr = (void*) (KEYBOARD_BASE + 4);
		alt_irq_register(KEYBOARD_IRQ, keyboard_control_register_ptr,
				keyboard_ISR);
		alt_up_ps2_enable_read_interrupt(ps2);

		//Draw field and UI to both buffers
		initField();

		updateField();
		drawName(p[pOne].name, p[pTwo].name, p[pThree].name, p[pFour].name);
		drawGas(p[pOne].gas);
		drawHealth(p[pOne].hp, p[pTwo].hp, p[pThree].hp, p[pFour].hp);
		drawBullet(p[pOne].bulletType);
		//drawWindIndicator(1);
		updateScreen();

		updateField();
		drawName(p[pOne].name, p[pTwo].name, p[pThree].name, p[pFour].name);
		drawGas(p[pOne].gas);
		drawHealth(p[pOne].hp, p[pTwo].hp, p[pThree].hp, p[pFour].hp);
		drawBullet(p[pOne].bulletType);
		//drawWindIndicator(1);

		float time;
		alt_timestamp_start();


		int start_timer_flag = 1;
		//printf("NUM PLAYERA %i\n", numPlayers);
		int i;
		while (state == 2) {
			int fallFlag = 1;

			//Checks to see if any players are falling
			while (fallFlag == 1) {
				fallFlag = 0;
				for (i = 0; i < numPlayers; i++) {
					if (p[i].alive) {
						if (p[i].y + TANK_HEIGHT >= SCREEN_HEIGHT-1) {
							p[i].hp = 0;
							p[i].alive = DEAD;
						}
						checkPlayerFalling(i);
						if (p[i].isFalling) {
							undrawPlayer(i);
							updatePlayer(i);
							fallFlag = 1;
						}
					}
				}
				if (fallFlag == 1) {
					updateScreen();
				}
			}

			if(start_timer_flag){
				start_time = (float) alt_timestamp() / (float) alt_timestamp_freq();
				start_timer_flag = 0;
			}
			time = (float) alt_timestamp() / (float) alt_timestamp_freq()-start_time;
			if (time >= setTime) {
				setPlayerTurn();
			}
			if (p[turn].type == HUMAN) {
				runGame();

			} else {
				p[turn].deg = 0;
				aiMain(turn);
				setPlayerTurn();
			}
			printTimer(setTime - time);
			int deadCount = 0;
			for (i = 0; i < numPlayers; i++) {
				if (p[i].alive == DEAD)
					deadCount++;
			}
			if (deadCount == numPlayers - 1) {
				usleep(500000);
				state = 3;
			}
		}

		alt_up_ps2_disable_read_interrupt(ps2);
		if(aOn)alt_up_audio_disable_write_interrupt(ab->audio);

		GameOverScreen();
	}
}