IMPLEMENT_RMI(CGameRules, ClPlayerLeft) { my->CallHook("PlayerLeft", params.entityId, params.name); NOTIFY_UI_MP( PlayerLeft(params.entityId, params.name) ); return true; }
void MainWindow::chance(int *i) { int rdm = rand() % 7; switch (rdm) { case 0: QMessageBox::warning(this,"Warning","You're very naughty, pay 50$",QMessageBox::Ok,QMessageBox::NoButton); players[*i]->setMoney(players[*i]->getMoney() - 50); break; case 1: QMessageBox::information(this,"Congratulations","You win a big prize, take 350$",QMessageBox::Ok,QMessageBox::NoButton); players[*i]->setMoney(players[*i]->getMoney() + 350); break; case 2: QMessageBox::information(this,"Congratulations","You've got a new baby take 100$ as a gift",QMessageBox::Ok,QMessageBox::NoButton); players[*i]->setMoney(players[*i]->getMoney() + 100); break; case 3: QMessageBox::warning(this,"Warning","You're very kind, you payed 150 for father-less children",QMessageBox::Ok,QMessageBox::NoButton); players[*i]->setMoney(players[*i]->getMoney() - 150); break; case 4: QMessageBox::information(this,"Congratulations","It is your birthday take 50 as a gift",QMessageBox::Ok,QMessageBox::NoButton); players[*i]->setMoney(players[*i]->getMoney() + 50); break; case 5: QMessageBox::warning(this,"Warning","You pay 25$ each for your four children in school in fees",QMessageBox::Ok,QMessageBox::NoButton); players[*i]->setMoney(players[*i]->getMoney() - 100); break; case 6: QMessageBox::warning(this,"Warning","You win a very big prize, but you have to pay 30$ to take it",QMessageBox::Ok,QMessageBox::NoButton); players[*i]->setMoney(players[*i]->getMoney() - 30); break; } if (players[*i]->getMoney() < 0) { return PlayerLeft(); } }
void MainWindow::chest(int *i) { int rdm = rand() % 7; switch (rdm) { case 0: QMessageBox::information(this,"Congratulations","Congratulations, you win a case against the bank, take 150$"); players[*i]->setMoney(players[*i]->getMoney() + 150); break; case 1: QMessageBox::warning(this,"Warning","You throw rubbish in the street, pay 50$ as a penalty$"); players[*i]->setMoney(players[*i]->getMoney() - 50); break; case 2: QMessageBox::warning(this,"Warning","You have an accident with your car, pay 40$ as a penalty$",QMessageBox::Ok,QMessageBox::NoButton); players[*i]->setMoney(players[*i]->getMoney() - 40); break; case 3: QMessageBox::warning(this,"Warning","You try to escape from prison, go to prison now",QMessageBox::Ok,QMessageBox::NoButton); players[*i]->setPos(30); players[*i]->setLostTurn(players[*i]->getLostTurn() + 1); break; case 4: QMessageBox::warning(this,"Warning","You lost a case, pay 20$ lawyer fees",QMessageBox::Ok,QMessageBox::NoButton); players[*i]->setMoney(players[*i]->getMoney() - 20); break; case 5: QMessageBox::information(this,"Congratulations","You win a prize, take 100$",QMessageBox::Ok,QMessageBox::NoButton); players[*i]->setMoney(players[*i]->getMoney() + 100); break; case 6: QMessageBox::information(this,"Congratulations","You had been accused, but your innocence appeared, take 200$ as amends",QMessageBox::Ok,QMessageBox::NoButton); players[*i]->setMoney(players[*i]->getMoney() + 200); break; } if (players[*i]->getMoney() < 0) return PlayerLeft(); }
IMPLEMENT_RMI(CGameRules, ClPlayerLeft) { NOTIFY_UI_MP( PlayerLeft(params.entityId, params.name) ); return true; }
//main int main() { int letra; OpcaoBackground(letra); //primitive variables int NUM_ENEMYRED = 10; //quantidade de inimigos vermelhos int NUM_ENEMYBLUE = 10; //quantidade de inimigos azuis int NUM_BOSS = 5; int text_color = 255; //variavel para cor (animacao inicial de jogo - efeito relampago) int text_boss = 255; //variavel para cor de texto boss int FPS = 60; //frames per second bool done = false; bool redraw = true; enum KEYS {UP, DOWN, LEFT, RIGHT, Q, W, E, R}; bool keys[8] = {false, false, false, false, false, false, false, false}; //object variables struct Player player; struct Enemy_red enemyred[NUM_ENEMYRED]; struct Enemy_blue enemyblue[NUM_ENEMYBLUE]; struct Boss boss[NUM_BOSS]; struct Shoot shootQ; struct Shoot shootW; struct Shoot shootE; struct Obstacle obstacle; struct SpriteScientist scientist; struct Sprite background; struct Sprite background1; struct Sprite background2; struct Sprite background3; struct Sprite background4; struct Sprite background5; struct Sprite background6; struct Sprite enemyred_sprite; //allegro variables ALLEGRO_DISPLAY *display; ALLEGRO_EVENT_QUEUE *event_queue = NULL; ALLEGRO_TIMER *timer = NULL; ALLEGRO_FONT *title_font = NULL; ALLEGRO_FONT *medium_font = NULL; //////////////////////////////////////////////////////////////////////// //verificacoes de erro if(!al_init()) return -1; //caso de erro ao inicializar allegro display = al_create_display(WIDTH,HEIGHT); //criar display if(!display) return -1; //se der merda //Allegro Module Init al_init_primitives_addon(); al_init_font_addon(); if (!al_init_ttf_addon()) { printf("Falha ao inicializar addon allegro_ttf.\n"); return -1; } al_install_keyboard(); if(!al_init_image_addon()) { printf("Falha ao inicializar image addon"); return -1; } event_queue = al_create_event_queue(); timer = al_create_timer(1.0 / FPS); medium_font = al_load_font("fonts/EHSMB.TTF", 50, 0); if (!medium_font) { al_destroy_display(display); printf("Falha ao carregar fonte.\n"); return -1; } title_font = al_load_font("fonts/French Electric Techno.ttf", 200, 0); if (!title_font) { al_destroy_display(display); printf("Falha ao carregar fonte.\n"); return -1; } int b; //Inicializacao de objetos InitPlayer(player, &text_color); //funcao que "inicia" player InitScientist(scientist); if (!scientist.bitmap) { al_destroy_display(display); printf("Falha ao carregar sprite scientist.\n"); return -1; } InitEnemyRed(enemyred, &NUM_ENEMYRED); //funcao que inicia enemyred InitEnemyBlue(enemyblue, &NUM_ENEMYBLUE); //funcao que inicia enemyblue InitShootQ(shootQ); //funcao que inicializa disparo 1 (capacitor) if(!shootQ.bitmap) { al_destroy_display(display); printf("Falha ao carregar sprite shootQ.\n"); return -1; } InitShootW(shootW); //funcao que inicializa disparo 2 (indutor) if(!shootW.bitmap) { al_destroy_display(display); printf("Falha ao carregar sprite shootW.\n"); return -1; } InitShootE(shootE); //funcao que inicializa habilidade de escudo (shield / resistor) if(!shootE.bitmap) { al_destroy_display(display); printf("Falha ao carregar sprite shield.\n"); return -1; } InitObstacle(obstacle); //funcao que inicializa obstaculos InitBoss(boss, &NUM_BOSS); //funcao que inicializa chefes (bosses) InitBackground(background, letra); //funcao que inicializa sprite de background InitBackground1(background1, letra); //funcao que inicializa sprite de background1 alternativo InitBackground2(background2, letra); //funcao que inicializa sprite de background2 alternativo InitBackground3(background3, letra); //funcao que inicializa sprite de background3 alternativo InitBackground4(background4, letra); //funcao que inicializa sprite de background4 alternativo InitBackground5(background5, letra); //funcao que inicializa sprite de background4 alternativo InitBackground6(background6, letra); //funcao que inicializa sprite de background4 alternativo InitEnemyredSprite(enemyred_sprite); // funcao que inicializa sprite de inimigo vermelho al_register_event_source(event_queue, al_get_keyboard_event_source()); al_register_event_source(event_queue, al_get_display_event_source(display)); al_register_event_source(event_queue, al_get_timer_event_source(timer)); al_start_timer(timer); while (!done) { ALLEGRO_EVENT ev; al_wait_for_event(event_queue, &ev); //se clicar para fechar a janela if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { done = true; } //evento do timer (vai entrar nesse else if sempre, a nao ser que feche a janela) else if(ev.type == ALLEGRO_EVENT_TIMER) { redraw = true; if(keys[RIGHT] && !player.moving) { player.velx = player.speed; player.moving = true; } if(keys[LEFT] && !player.moving) { player.velx = player.speed; player.moving = true; } ChangeColor(&text_color, player, boss, &NUM_BOSS, &text_boss); PlayerJump(player, &keys[UP]); PlayerRight(player, &keys[RIGHT], scientist); PlayerLeft(player, &keys[LEFT]); //updates UpdateShootQ(shootQ, player); UpdateShootW(shootW, player); UpdateShootE(shootE, player); UpdateEnemyRed(enemyred, &NUM_ENEMYRED, player, shootQ); UpdateEnemyBlue(enemyblue, &NUM_ENEMYBLUE, player, shootW); UpdateObstacle(obstacle, medium_font, player); UpdateBoss(boss, &NUM_BOSS, &text_boss, player, enemyred, &NUM_ENEMYRED, enemyblue, &NUM_ENEMYBLUE); //colisoes ShootQColisionEnemyRed(shootQ,enemyred, &NUM_ENEMYRED, player); ShootWColisionEnemyBlue(shootW, enemyblue, &NUM_ENEMYBLUE, player); ShootColisionBoss(shootW, shootQ, boss, &NUM_BOSS, player); PlayerColisionEnemyBlue(player, enemyblue, &NUM_ENEMYBLUE); PlayerColisionEnemyRed(player, enemyred, &NUM_ENEMYRED); PlayerColisionObstacle(player,obstacle); PlayerColisionBoss(player, boss, &NUM_BOSS); ResetPlayer(player, enemyred, &NUM_ENEMYRED, enemyblue, &NUM_ENEMYBLUE, obstacle, boss, &NUM_BOSS, &text_color); } else if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { switch(ev.keyboard.keycode) { case ALLEGRO_KEY_ESCAPE: done = true; break; case ALLEGRO_KEY_UP: keys[UP] = true; break; case ALLEGRO_KEY_RIGHT: keys[RIGHT] = true; break; case ALLEGRO_KEY_LEFT: keys[LEFT] = true; break; case ALLEGRO_KEY_Q: keys[Q] = true; FireShootQ(shootQ, player); break; case ALLEGRO_KEY_W: keys[W] = true; FireShootW(shootW, player); break; case ALLEGRO_KEY_E: keys[E] = true; FireShootE(shootE, player); break; case ALLEGRO_KEY_R: keys[R] = true; break; } } else if(ev.type == ALLEGRO_EVENT_KEY_UP) { switch(ev.keyboard.keycode) { case ALLEGRO_KEY_UP: keys[UP] = false; break; case ALLEGRO_KEY_RIGHT: keys[RIGHT] = false; player.moving = false; break; case ALLEGRO_KEY_LEFT: keys[LEFT] = false; player.moving = false; break; case ALLEGRO_KEY_Q: keys[Q] = false; break; case ALLEGRO_KEY_W: keys[W] = false; break; case ALLEGRO_KEY_E: keys[E] = false; break; case ALLEGRO_KEY_R: keys[R] = false; break; } } if(redraw && al_is_event_queue_empty(event_queue)) { redraw = false; //desenhar objetos DrawBackground(background, letra); DrawBackground1(background1, letra); DrawBackground2(background2, letra); DrawBackground3(background3, letra); DrawBackground4(background4, letra); DrawBackground5(background5, letra); DrawBackground6(background6, letra); DrawText(title_font, medium_font, player, boss, &NUM_BOSS, &text_color, &text_boss); DrawShootQ(shootQ); DrawShootW(shootW); DrawShootE(shootE, player); DrawEnemyRed(enemyred, &NUM_ENEMYRED, player, enemyred_sprite); DrawEnemyBlue(enemyblue, &NUM_ENEMYBLUE, player); DrawBoss(boss, &NUM_BOSS, player); DrawObstacle(obstacle); DrawScientist(player, scientist, &keys[LEFT], &keys[RIGHT]); al_flip_display(); } } al_destroy_event_queue(event_queue); al_destroy_timer(timer); al_destroy_font(title_font); al_destroy_font(medium_font); al_destroy_display(display); al_destroy_bitmap(scientist.bitmap); al_destroy_bitmap(shootE.bitmap); for(b=0; b<background.frame_max; b++) { al_destroy_bitmap(background.image[b]); } for(b=0; b<background1.frame_max; b++) { al_destroy_bitmap(background1.image[b]); } for(b=0; b<background2.frame_max; b++) { al_destroy_bitmap(background2.image[b]); } for(b=0; b<background3.frame_max; b++) { al_destroy_bitmap(background3.image[b]); } for(b=0; b<background4.frame_max; b++) { al_destroy_bitmap(background4.image[b]); } for(b=0; b<background5.frame_max; b++) { al_destroy_bitmap(background5.image[b]); } for(b=0; b<background6.frame_max; b++) { al_destroy_bitmap(background6.image[b]); } return 0; }//final da MAIN!!
void MainWindow::on_btn_Roll_clicked() { if(ui->btn_Roll->text() == "Next player") { NextPlayer(); ui->btn_Roll->setText("Roll"); return; } int oldPos = players[cPlayer]->getPos(); if(spaces[oldPos]->is2XSpeed()) ui->txt_Log->appendPlainText("2XSpeed, hurry up!!!!\nYour roll dive result is: " + QString::number(players[cPlayer]->rollDice(spaces[oldPos]->is2XSpeed()))); else ui->txt_Log->appendPlainText("Your roll dive result is: " + QString::number(players[cPlayer]->rollDice(spaces[oldPos]->is2XSpeed()))); int newPos = players[cPlayer]->getPos(); if (newPos < oldPos) { ui->txt_Log->appendPlainText(players[cPlayer]->getPiece() + " complete new round, take new 350$"); players[cPlayer]->setMoney(players[cPlayer]->getMoney() + 350); } if (spaces[newPos]->isChance()) { chance(&cPlayer); } else if (spaces[newPos]->isChest()) { chest(&cPlayer); } else if (spaces[newPos]->isPrison()) { if (players[cPlayer]->getMoney() >= 50) { ui->txt_Log->appendPlainText(players[cPlayer]->getPiece() + " fall in prison, you have to pay 50$"); players[cPlayer]->setMoney(players[cPlayer]->getMoney() - 50); } else { ui->txt_Log->appendPlainText(players[cPlayer]->getPiece() + " fall in prison, you lost the next turn"); players[cPlayer]->setLostTurn(players[cPlayer]->getLostTurn() + 1); } } else if (!spaces[newPos]->isPark()) { if (spaces[newPos]->isFree() && players[cPlayer]->getMoney() >= spaces[newPos]->getPrice()) { if (QMessageBox::question(this,"Buy a park", "Would you like to buy " + spaces[newPos]->getName(), QMessageBox::Yes,QMessageBox::No) == QMessageBox::Yes) { spaces[newPos]->setOwner(players[cPlayer]->getPiece()); players[cPlayer]->setMoney( players[cPlayer]->getMoney() - spaces[newPos]->getPrice()); if (!spaces[newPos]->isUp() && players[cPlayer]->getMoney() >= spaces[newPos]->getPrice()) { if (QMessageBox::question(this,"Upgrade", "Would you like to upgrade " + spaces[newPos]->getName() + ", it'll double price and fees too", QMessageBox::Yes,QMessageBox::No) == QMessageBox::Yes) { players[cPlayer]->setMoney( players[cPlayer]->getMoney() - spaces[newPos]->getPrice()); spaces[newPos]->upgrade(); } } } } else { if (spaces[newPos]->getOwner().compare( players[cPlayer]->getPiece()) == 0) { if (!spaces[newPos]->isUp() && players[cPlayer]->getMoney() >= spaces[newPos]->getPrice()) { if (QMessageBox::question(this,"Upgrade", "Would you like to upgrade " + spaces[newPos]->getName() + ", it'll double price and fees too", QMessageBox::Yes,QMessageBox::No) == QMessageBox::Yes) { players[cPlayer]->setMoney( players[cPlayer]->getMoney() - spaces[newPos]->getPrice()); spaces[newPos]->upgrade(); } } if (QMessageBox::question(this,"Sell", "Would you like to sell " + spaces[newPos]->getName() + ", to bank", QMessageBox::Yes,QMessageBox::No) == QMessageBox::Yes) { players[cPlayer]->setMoney( players[cPlayer]->getMoney() + spaces[newPos]->getPrice()); spaces[newPos]->setOwner("No One"); } } else { for (int l = 0; l < players.size(); ++l) { if (l != cPlayer) { if (players[l]->getPiece().compare( spaces[newPos]->getOwner()) == 0) { QMessageBox::information(this,"Notice", "You have to pay " + (QString::number(spaces[newPos]->getPrice()/ 10)) + "$ to " + players[l]->getPiece() + "player\n",QMessageBox::Ok); if (players[cPlayer]->getMoney() >= spaces[newPos]->getPrice() / 10) { players[cPlayer]->setMoney( players[cPlayer]->getMoney() - (spaces[newPos]->getPrice() / 10)); players[l]->setMoney( players[l]->getMoney() + (spaces[newPos]->getPrice() / 10)); } else { return PlayerLeft(); } } } } } } } NextPlayer(); }