Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include "newgame.h"
- #include "painttab.h"
- #include<QLineEdit>
- #include<QComboBox>
- #include <QMessageBox>
- #include<QPainter>
- namespace GAME
- {
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- setWindowTitle("one button clicker");
- setFixedSize(size());
- connect(this, SIGNAL(StartFormChanged()), this, SLOT(setStartForm()));
- connect(this, SIGNAL(reasonDisabledMoveBtn(const QString &)), this, SLOT(disableMoveBtn(const QString &)));
- connect(this, SIGNAL(FormChanged()), this, SLOT(setForm()));
- connect(this, SIGNAL(endgame()), this, SLOT(calcwinner()));
- // connect(this, SIGNAL(newgame()), this, SLOT(on_actionNew_game_triggered()));
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
- void MainWindow::on_actionQuit_triggered()
- {
- qApp->exit();
- }
- void MainWindow::on_actionNew_game_triggered()
- {
- srand(time(0));
- NewGame ng;
- if(ng.exec() == QDialog::Accepted)
- {
- ng.names[0] = ng.player1->text();
- ng.names[1] = ng.player2->text();
- switch(ng.choose1->currentIndex())
- {
- case WIZARD: ng.choises[0] = 'w';
- break;
- case WARRIOR: ng.choises[0] = 'b';
- break;
- case ASSASIN: ng.choises[0] = 'a';
- break;
- }
- switch(ng.choose2->currentIndex())
- {
- case WIZARD: ng.choises[1] = 'w';
- break;
- case WARRIOR: ng.choises[1] = 'b';
- break;
- case ASSASIN: ng.choises[1] = 'a';
- break;
- }
- }
- else
- return;
- Data = new field(ng.names, ng.choises);
- Data->a_pos = Data->tmpPosForReset = rand()%2;
- Data->d_pos = !Data->a_pos;
- emit StartFormChanged();
- }
- void MainWindow::setStartForm()
- {
- ui->battle_log->clear();
- for(int i=0; i<2; ++i)
- tabs.push_back(new PaintTab);
- for(int i=0; i<2; i++)
- {
- if(Data->p[i]->get_initchar() == WIZARD)
- {
- tabs[i]->colorForPoints = Qt::GlobalColor::blue;
- tabs[i]->colorForShield = Qt::GlobalColor::white;
- tabs[i]->points->setText("mana\npoints");
- }
- else
- {
- tabs[i]->colorForPoints = Qt::GlobalColor::white;
- tabs[i]->colorForShield = Qt::GlobalColor::white;
- if(Data->p[i]->get_initchar() == WARRIOR)
- {
- tabs[i]->colorForShield = Qt::GlobalColor::magenta;
- tabs[i]->points->setText("fury\npoints");
- }
- if(Data->p[i]->get_initchar() == ASSASIN)
- tabs[i]->points->setText("dark\npoints");
- }
- }
- ui->class1->addTab(tabs.at(0), "view");
- ui->class2->addTab(tabs.at(1), "view");
- clearSpellBox();
- // for(int i=0;i<2;++i)
- // tabs[i]->update();
- ui->lbl_round_2->setNum(Data->get_roundcount());
- if(ui->btn_make_attack->text() == "Skip!")
- ui->btn_make_attack->setText("Attack!");
- ui->lbl_move_info->setText("");
- ui->actionClear_form->setEnabled(true);
- ui->lbl_move->setText(Data->p[Data->a_pos]->get_name() + " makes a move:");
- ui->lbl_name1->setText(Data->p[0]->get_name());
- ui->lbl_name2->setText(Data->p[1]->get_name());
- ui->btn_make_attack->setEnabled(false);
- ui->spellBox->setEnabled(false);
- if(Data->p[Data->a_pos]->get_initchar() == WARRIOR || Data->p[Data->a_pos]->get_initchar() == ASSASIN)
- ui->btn_make_attack->setEnabled(true);
- if(Data->p[Data->a_pos]->get_initchar() == WIZARD)
- ui->spellBox->setEnabled(true);
- switch(Data->p[0]->get_initchar())
- {
- case WARRIOR: ui->lbl_class1_2->setText("Warrior"); break;
- case WIZARD: ui->lbl_class1_2->setText("Wizard"); break;
- case ASSASIN: ui->lbl_class1_2->setText("Assasin"); break;
- }
- switch(Data->p[1]->get_initchar())
- {
- case WARRIOR: ui->lbl_class2_2->setText("Warrior"); break;
- case WIZARD: ui->lbl_class2_2->setText("Wizard"); break;
- case ASSASIN: ui->lbl_class2_2->setText("Assasin"); break;
- }
- setPrimaryParam();
- ui->lbl_dmg1_2->setNum(Data->p[0]->get_damage());
- ui->lbl_dmg2_2->setNum(Data->p[1]->get_damage());
- if(Data->p[0]->get_initchar() == WIZARD)
- ui->lbl_md1_2->setNum(static_cast<Wizard*>(Data->p[0])->get_magic_damage());
- else
- ui->lbl_md1_2->setText("none");
- if(Data->p[1]->get_initchar() == WIZARD)
- ui->lbl_md2_2->setNum(static_cast<Wizard*>(Data->p[1])->get_magic_damage());
- else
- ui->lbl_md2_2->setText("none");
- if(Data->p[0]->get_initchar() == WIZARD)
- ui->lbl_other1_2->setText("It's hard to win!\n\nmagic damage: cost - 17 mp,\ncooldown - 2 rounds\n\nmagic shield: cost - 30mp,\ncooldown - 3 rounds\n\nrestore mana:\ncooldown - 3 rounds");
- else if(Data->p[0]->get_initchar() == ASSASIN)
- ui->lbl_other1_2->setText("ability: dark contract -\ncreates an antimagic shield\n\nability: critical hit -\nwith a 50% chance to deal\n150% damage");
- else
- ui->lbl_other1_2->setText("ability: Skin of ancestors -\nreduction of physical damage\ntaken by 15%,\nincrease in magic damage\ntaken by 20%\n\nability: rage of blood -\nthe player becomes enraged\nand stuns the enemy,\nrestoring his armor");
- if(Data->p[1]->get_initchar() == WIZARD)
- ui->lbl_other2_2->setText("It's hard to win!\n\nmagic damage: cost - 17 mp,\ncooldown - 2 rounds\n\nmagic shield: cost - 30mp,\ncooldown - 3 rounds\n\nrestore mana:\ncooldown - 3 rounds");
- else if(Data->p[1]->get_initchar() == ASSASIN)
- ui->lbl_other2_2->setText("ability: dark contract -\ncreates an antimagic shield\n\nability: critical hit -\nwith a 50% chance to deal\n150% damage");
- else
- ui->lbl_other2_2->setText("ability: Skin of ancestors -\nreduction of physical damage\ntaken by 15%,\nincrease in magic damage\ntaken by 20%\n\nability: rage of blood -\nthe player becomes enraged\nand stuns the enemy,\nrestoring his armor");
- }
- void MainWindow::on_actionReset_game_triggered()
- {
- Data->count = 1;
- ui->actionReset_game->setEnabled(false);
- ui->actionClear_form->setEnabled(false);
- ui->battle_log->clear();
- Data->a_pos = Data->tmpPosForReset;
- Data->d_pos = !Data->a_pos;
- Data->message = "";
- for(auto & x: Data->p)
- {
- x->health = x->get_max_health();
- x->set_shield_is_active(false);
- if(x->get_initchar() == WARRIOR)
- {
- x->set_shield(x->get_max_shield());
- x->set_points(0);
- static_cast<Warrior*>(x)->enemyStanCount = 0;
- }
- if(x->get_initchar() == WIZARD)
- {
- x->set_shield(0);
- x->set_points(x->get_max_points());
- std::fill(static_cast<Wizard*>(x)->Counts.begin(), static_cast<Wizard*>(x)->Counts.end(), 0);
- }
- if(x->get_initchar() == ASSASIN)
- {
- x->set_shield(0);
- x->set_points(0);
- static_cast<Assasin*>(x)->critical = static_cast<Assasin*>(x)->orignCritical;
- }
- }
- emit FormChanged();
- }
- void MainWindow::disableMoveBtn(const QString & reason)
- {
- ui->lbl_move_info->setText(reason);
- ui->btn_make_attack->setEnabled(false);
- }
- void MainWindow::on_btn_make_attack_clicked()
- {
- if(Data->p[Data->a_pos]->get_initchar() == WIZARD)
- {
- if(ui->btn_mag_attack->isChecked())
- static_cast<Wizard *>(Data->p[Data->a_pos])->set_count_magic_damage(5); // 2 раунда перезарядки
- if(ui->btn_shield->isChecked())
- static_cast<Wizard *>(Data->p[Data->a_pos])->set_count_shield(7); // 3 раунда перезарядки
- if(ui->btn_res_mana->isChecked())
- static_cast<Wizard *>(Data->p[Data->a_pos])->set_count_restore_mana(7); // 3 раунда перезарядки
- }
- bool result = Data->get_move();
- graphicTabHadler();
- Data->a_pos = !Data->a_pos;
- Data->d_pos = !Data->d_pos;
- Data->inc_count();
- emit FormChanged();
- if(result)
- emit endgame();
- }
- void MainWindow::setForm()
- {
- clearSpellBox();
- if(Data->count == 1)
- ui->actionClear_form->setEnabled(true);
- if(Data->count == 2)
- ui->actionReset_game->setEnabled(true);
- ui->lbl_round_2->setNum(Data->get_roundcount());
- ui->lbl_move->setText(Data->p[Data->a_pos]->get_name() + " makes a move:");
- setPrimaryParam();
- ui->spellBox->setEnabled(false);
- if(ui->btn_make_attack->text() == "Skip!")
- ui->btn_make_attack->setText("Attack!");
- if(Data->p[Data->a_pos]->get_initchar() == WIZARD)
- {
- ui->btn_make_attack->setEnabled(false);
- ui->spellBox->setEnabled(true);
- }
- if(Data->p[Data->d_pos]->get_initchar() == WARRIOR)
- {
- if(static_cast<Warrior *>(Data->p[Data->d_pos])->enemyStanCount > 0)
- {
- ui->btn_make_attack->setText("Skip!");
- if(Data->p[Data->a_pos]->get_initchar() == WIZARD)
- {
- ui->btn_make_attack->setEnabled(true);
- ui->spellBox->setEnabled(false);
- }
- }
- }
- // for(int i=0; i<2; ++i)
- // tabs[i]->update();
- QObject * obj = sender();
- if(obj != ui->actionReset_game)
- ui->battle_log->append(Data->message + "\n\n");
- }
- void MainWindow::calcwinner()
- {
- QMessageBox msgBox;
- msgBox.setWindowTitle("victory!");
- msgBox.setText(Data->calc_winner());
- msgBox.setInformativeText("Try again?");
- msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
- msgBox.setDefaultButton(QMessageBox::Ok);
- int ret = msgBox.exec();
- switch(ret)
- {
- case QMessageBox::Ok: on_actionNew_game_triggered(); break;
- case QMessageBox::Cancel: on_actionClear_form_triggered(); break;
- }
- }
- void MainWindow::on_btn_attack_clicked()
- {
- ui->lbl_move_info->clear();
- ui->btn_make_attack->setEnabled(true);
- static_cast<Wizard *>(Data->p[Data->a_pos])->CurrentSpell = DAMAGE;
- }
- void MainWindow::on_btn_mag_attack_clicked()
- {
- ui->btn_make_attack->setEnabled(false);
- if(static_cast<Wizard *>(Data->p[Data->a_pos])->get_count_magic_damage() == 0)
- {
- if(Data->p[Data->a_pos]->get_points() >= GAME::MDCOST)
- {
- ui->lbl_move_info->clear();
- static_cast<Wizard *>(Data->p[Data->a_pos])->CurrentSpell = MAGICDAMAGE;
- ui->btn_make_attack->setEnabled(true);
- }
- else
- emit reasonDisabledMoveBtn("Your manapoints hits too low,\nplease choise another spell!");
- }
- else
- emit reasonDisabledMoveBtn("Your spells is not ready,\nplease choise another spell!");
- }
- void MainWindow::on_btn_shield_clicked()
- {
- ui->btn_make_attack->setEnabled(false);
- if(static_cast<Wizard *>(Data->p[Data->a_pos])->get_count_shield() == 0)
- {
- if(Data->p[Data->a_pos]->get_points() >= SHIELDCOST)
- {
- ui->lbl_move_info->clear();
- static_cast<Wizard *>(Data->p[Data->a_pos])->CurrentSpell = SHIELD;
- ui->btn_make_attack->setEnabled(true);
- }
- else
- emit reasonDisabledMoveBtn("Your manapoints hits too low,\nplease choise another spell!");
- }
- else
- emit reasonDisabledMoveBtn("Your spells is not ready,\nplease choise another spell!");
- }
- void MainWindow::on_btn_res_mana_clicked()
- {
- ui->btn_make_attack->setEnabled(false);
- if(static_cast<GAME::Wizard *>(Data->p[Data->a_pos])->get_count_restore_mana() == 0)
- {
- ui->lbl_move_info->clear();
- static_cast<Wizard *>(Data->p[Data->a_pos])->CurrentSpell = RESTOREMANA;
- ui->btn_make_attack->setEnabled(true);
- }
- else
- emit reasonDisabledMoveBtn("Your spells is not ready,\nplease choise another spell!");
- }
- void MainWindow::on_actionAbout_game_triggered()
- {
- QMessageBox::information(this, "attention!", "зашел сюда - хуев тебе пачка", QMessageBox::Ok);
- }
- void MainWindow::on_actionClear_form_triggered()
- {
- delete Data;
- for(int i=0;i<2;++i)
- delete tabs.at(i);
- clearSpellBox();
- ui->lbl_name1->setText("---");
- ui->lbl_name2->setText("---");
- ui->lbl_class1_2->setText("---");
- ui->lbl_class2_2->setText("---");
- ui->lbl_dmg1_2->setText("---");
- ui->lbl_dmg2_2->setText("---");
- ui->lbl_health1_2->setText("---");
- ui->lbl_health2_2->setText("---");
- ui->lbl_md1_2->setText("---");
- ui->lbl_md2_2->setText("---");
- ui->lbl_move->setText("---");
- ui->lbl_round_2->setText("---");
- ui->lbl_shield1_2->setText("---");
- ui->lbl_shield2_2->setText("---");
- ui->lbl_points1_2->setText("---");
- ui->lbl_points2_2->setText("---");
- ui->lbl_other1_2->clear();
- ui->lbl_other2_2->clear();
- ui->battle_log->clear();
- ui->lbl_move_info->clear();
- ui->spellBox->setEnabled(false);
- ui->btn_make_attack->setEnabled(false);
- ui->actionClear_form->setEnabled(false);
- ui->actionReset_game->setEnabled(false);
- }
- void MainWindow::clearSpellBox()
- {
- if(ui->btn_attack->isChecked())
- {
- ui->btn_attack->setAutoExclusive(false);
- ui->btn_attack->setChecked(false);
- ui->btn_attack->setAutoExclusive(true);
- }
- if(ui->btn_mag_attack->isChecked())
- {
- ui->btn_mag_attack->setAutoExclusive(false);
- ui->btn_mag_attack->setChecked(false);
- ui->btn_mag_attack->setAutoExclusive(true);
- }
- if(ui->btn_shield->isChecked())
- {
- ui->btn_shield->setAutoExclusive(false);
- ui->btn_shield->setChecked(false);
- ui->btn_shield->setAutoExclusive(true);
- }
- if(ui->btn_res_mana->isChecked())
- {
- ui->btn_res_mana->setAutoExclusive(false);
- ui->btn_res_mana->setChecked(false);
- ui->btn_res_mana->setAutoExclusive(true);
- }
- }
- void MainWindow::setPrimaryParam()
- {
- ui->lbl_health1_2->setText(QString::number(Data->p[0]->get_health()) + "/" + QString::number(Data->p[0]->get_max_health()));
- ui->lbl_health2_2->setText(QString::number(Data->p[1]->get_health()) + "/" + QString::number(Data->p[1]->get_max_health()));
- ui->lbl_shield1_2->setText(QString::number(Data->p[0]->get_shield()) + "/" + QString::number(Data->p[0]->get_max_shield()));
- ui->lbl_shield2_2->setText(QString::number(Data->p[1]->get_shield()) + "/" + QString::number(Data->p[1]->get_max_shield()));
- ui->lbl_points1_2->setText(QString::number(Data->p[0]->get_points()) + "/" + QString::number(Data->p[0]->get_max_points()));
- ui->lbl_points2_2->setText(QString::number(Data->p[1]->get_points()) + "/" + QString::number(Data->p[1]->get_max_points()));
- }
- void MainWindow::graphicTabHadler()
- {
- for(int i=0;i<2;++i)
- {
- tabs[i]->current_y0_0_length = tabs[i]->y_length * (Data->p[i]->get_max_health() / Data->p[i]->get_health()) - 1;
- tabs[i]->current_y0_0 = tabs[i]->y0 + 1 + tabs[i]->y_length - (tabs[i]->current_y0_0_length + 1);
- tabs[i]->update();
- }
- }
- /*
- void MainWindow::graphicTabHadler()
- {
- if(Data->p[Data->a_pos]->get_initchar() == WIZARD)
- {
- if(static_cast<Wizard*>(Data->p[Data->a_pos])->CurrentSpell == SHIELD)
- {
- tabs[Data->a_pos]->colorForShield = Qt::GlobalColor::cyan;
- tabs[Data->a_pos]->current_y0_1 = tabs[Data->a_pos]->y0 + 1;
- tabs[Data->a_pos]->current_y0_1_length = tabs[Data->a_pos]->y_length - 1;
- tabs[Data->a_pos]->d_y3 = (tabs[Data->a_pos]->y_length / MAX_MANA_POINTS) * SHIELDCOST;
- tabs[Data->a_pos]->current_y0_2 += tabs[Data->a_pos]->d_y3;
- tabs[Data->a_pos]->current_y0_2_length -= tabs[Data->a_pos]->d_y3;
- }
- if(static_cast<Wizard*>(Data->p[Data->a_pos])->CurrentSpell == RESTOREMANA)
- {
- if(Data->p[Data->a_pos]->get_points() >= MAX_MANA_POINTS)
- {
- tabs[Data->a_pos]->current_y0_2 = tabs[Data->a_pos]->y0;
- tabs[Data->a_pos]->current_y0_2_length = tabs[Data->a_pos]->y_length;
- }
- else
- {
- tabs[Data->a_pos]->d_y3 = (tabs[Data->a_pos]->y_length / MAX_MANA_POINTS) * static_cast<Wizard*>(Data->p[Data->a_pos])->get_restored_mana();
- tabs[Data->a_pos]->current_y0_2 += tabs[Data->a_pos]->d_y3;
- tabs[Data->a_pos]->current_y0_2_length -= tabs[Data->a_pos]->d_y3;
- }
- }
- if(static_cast<Wizard*>(Data->p[Data->a_pos])->CurrentSpell == DAMAGE || static_cast<Wizard*>(Data->p[Data->a_pos])->CurrentSpell == MAGICDAMAGE)
- {
- if(static_cast<Wizard*>(Data->p[Data->a_pos])->CurrentSpell == MAGICDAMAGE)
- {
- tabs[Data->a_pos]->d_y3 = (tabs[Data->a_pos]->y_length / MAX_MANA_POINTS) * MDCOST;
- tabs[Data->a_pos]->current_y0_2 += tabs[Data->a_pos]->d_y3;
- tabs[Data->a_pos]->current_y0_2_length -= tabs[Data->a_pos]->d_y3;
- }
- if(Data->p[Data->a_pos]->tmp > 0)
- {
- tabs[Data->d_pos]->d_y2 = Data->p[Data->a_pos]->tmp * (tabs[Data->a_pos]->y_length / Data->p[Data->d_pos]->get_max_points());
- tabs[Data->d_pos]->current_y0_1 += tabs[Data->d_pos]->d_y2;
- tabs[Data->d_pos]->current_y0_1_length -= tabs[Data->d_pos]->d_y2;
- }
- else if(Data->p[Data->a_pos]->tmp < 0)
- {
- tabs[Data->d_pos]->colorForShield = Qt::GlobalColor::white;
- tabs[Data->d_pos]->current_y0_1 = tabs[Data->a_pos]->y0 + 1;
- tabs[Data->d_pos]->current_y0_1_length = tabs[Data->a_pos]->y_length - 1;
- tabs[Data->d_pos]->d_y1 = Data->p[Data->a_pos]->currentDamage * (tabs[Data->a_pos]->y_length / Data->p[Data->d_pos]->get_max_health());
- tabs[Data->d_pos]->current_y0_0 += tabs[Data->d_pos]->d_y1;
- tabs[Data->d_pos]->current_y0_0_length -= tabs[Data->d_pos]->d_y1;
- }
- else
- {
- tabs[Data->d_pos]->d_y1 = Data->p[Data->a_pos]->currentDamage * (tabs[Data->a_pos]->y_length / Data->p[Data->d_pos]->get_max_health());
- tabs[Data->d_pos]->current_y0_0 += tabs[Data->d_pos]->d_y1;
- tabs[Data->d_pos]->current_y0_0_length -= tabs[Data->d_pos]->d_y1;
- }
- }
- }
- for(int i=0;i<2;++i)
- tabs[i]->update();
- }
- */
- } //end of GAME
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement