Пример #1
0
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    actorsList = "";
    ui->movieGenerFrom->setEnabled(false);
    ui->movieDirectorFrom->setEnabled(false);
    ui->actorDateEdit->setMaximumDate(QDate::currentDate());
    ui->actorDateEditFrom->setMaximumDate(QDate::currentDate());
    ui->actorDateEditFrom->setDate(QDate::fromString("1900-01-01","yyyy-MM-dd"));
    ui->actorDateEditTo->setMaximumDate(QDate::currentDate());
    ui->actorDateEditTo->setDate(QDate::currentDate());
    ui->directorDateEdit->setMaximumDate(QDate::currentDate());
    ui->directorDateEditFrom->setMaximumDate(QDate::currentDate());
    ui->directorDateEditFrom->setDate(QDate::fromString("1900-01-01","yyyy-MM-dd"));
    ui->directorDateEditTo->setMaximumDate(QDate::currentDate());
    ui->directorDateEditTo->setDate(QDate::currentDate());
    ui->movieDateEdit->setMaximumDate(QDate::currentDate());
    ui->movieDateEditFrom->setMaximumDate(QDate::currentDate());
    ui->movieDateEditFrom->setDate(QDate::fromString("1900-01-01","yyyy-MM-dd"));
    ui->movieDateEditTo->setMaximumDate(QDate::currentDate());
    ui->movieDateEditTo->setDate(QDate::currentDate());
    //ui->movieActorsFrom->setSelectionBehavior();
    connect(ui->openFileAction,SIGNAL(triggered()),this,SLOT(openFileDialog()));
    connect(ui->addActorButton,SIGNAL(clicked()),this,SLOT(emitAddActor()));
    connect(ui->addMovieButton,SIGNAL(clicked()),this,SLOT(emitAddMovie()));
    connect(ui->addGenerButton,SIGNAL(clicked()),this,SLOT(emitAddGener()));
    connect(ui->addDirectorButton,SIGNAL(clicked()),this,SLOT(emitAddDirector()));
    connect(ui->selectActorButton,SIGNAL(clicked()),this,SLOT(emitSelectFromActors()));
    connect(ui->movieAddActorsList,SIGNAL(clicked(QModelIndex)),this,SLOT(addActorToList(QModelIndex)));
    connect(ui->movieActorsFrom,SIGNAL(clicked(QModelIndex)),this,SLOT(addActorToListFrom(QModelIndex)));
    connect(ui->selectDirectorButton,SIGNAL(clicked()),this,SLOT(emitSelectFromDirectors()));
    connect(ui->selectGenerButton,SIGNAL(clicked()),this,SLOT(emitSelectFromGeners()));
    connect(ui->execOwnPushButton,SIGNAL(clicked()),this,SLOT(showOwnQueryResult()));
    connect(ui->selectMoviesButton,SIGNAL(clicked()),this,SLOT(emitSelectFromMovies()));
    ui->tabWidget->setDisabled(true);
}
Пример #2
0
int main()
{
    cursorY = 0;
    cursorX = 0;

    int deltaY = 0;
    int deltaX = 0;

    srand(time(0));

    initscr();

	raw();
	keypad(stdscr, TRUE);
	noecho();
	curs_set(0);
	start_color();

	resize_term(30, 80);

    init_pair(1, COLOR_GREEN, COLOR_BLACK);
    init_pair(2, COLOR_YELLOW, COLOR_BLACK);
    init_pair(3, COLOR_RED, COLOR_BLACK);
    init_pair(4, COLOR_CYAN, COLOR_BLACK);
    init_pair(5, COLOR_WHITE, COLOR_RED);
    init_pair(6, COLOR_WHITE, COLOR_GREEN);
    init_pair(7, COLOR_WHITE, COLOR_YELLOW);
    init_pair(8, COLOR_RED, COLOR_RED);
    init_pair(9, COLOR_RED, COLOR_GREEN);
    init_pair(10, COLOR_RED, COLOR_YELLOW);
    init_pair(11, COLOR_WHITE, COLOR_BLACK);
    init_pair(12, COLOR_MAGENTA, COLOR_BLACK);

    while(retry){

        Shop shop;
        SkillTree skillTree;

        breakLoop = false;
        int timeStart = time(0);

        clear();

        cursorY = mapHeight/2;
        cursorX = mapWidth/2+5;

        playerMovementSpeed = 50;
        playerMovementSpeedHelper = 0;

        playerHealth = 100;
        playerMaxHealth = 100;
        playerStamina = 10;
        playerMaxStamina = 10;
        playerStaminaRegen = 250;
        playerStaminaRegenHelper = 0;
        playerAmmo = 100;
        playerBulletSpeed = 30;
        playerDamage = 1;
        playerBulletRange = 20;
        playerFiringSpeed = 500;
        playerFiringSpeedHelper = 0;
        playerClip = 10;
        playerClipLimit = 10;
        playerHiddenClip = 0;
        playerReloading = false;
        playerReloadingRate = 4000;
        playerReloadingHelper = 0;
        playerReloadingModifier = 0;
        playerSpecialWeaponTypes = {0,0,0,0,0,0,0,0,0,0};
        playerWeaponName = {'P','i','s','t','o','l'};
        playerCurrentWeapon = {0,0};
        playerBandages = 0;
        playerBandaging = false;
        playerBandagesHelper = 0;
        playerMeleeDamage = 0;
        playerMeleeDirecton = 0;
        playerMeleeHelper = 0;
        playerStaminaPills = 0;

        playerMoney = 0;
        killMoney = 1;
        playerXP = 0;
        playerXPNeeded = 10;
        playerXPGet = 1;
        playerSkillPoints = 0;
        playerLevel = 1;
        lastTiersUnlocked = false;

        round = 1;
        roundZombies = 5;
        roundZombiesFloat = 5;
        roundZombiesHelper = 0;
        zombieSpawnRate = 5000;
        zombieSpawnRateHelper = 0;
        betweenRoundPause = false;
        betweenRoundPauseHelper = 0;
        zombieForceSpawnHelper = 500;

        playerTimeSurvived = 0;
        playerZombiesKilled = 0;
        playerBulletsFired = 0;
        playerTotalMoneyEarned = 0;
        playerMoves = 0;
        playerTimesBandaged = 0;
        playerTimesReloaded = 0;
        playerAmountBought = 0;
        playerAmountEnteredShop = 0;
        playerAmountEnteredSkillTree = 0;
        playerPeakMoneyOwned = 0;
        playerTotalStaminaPillsUsed = 0;
        playerAmountMelee = 0;
        playerTotalAmountForce = 0;
        playerTimesHit = 0;
        playerTimesPaused = 0;

        timeout(0); //time before the getch passes with no input

        for(int i = 0; i < MAX_ACTORS; i++){
            actorList[i] = NULL;
        }

        for(int i = 0; i < MAX_BULLETS; i++){
            bulletList[i] = NULL;
        }

        for(int y = 0; y < mapHeight; y++){
            for(int x = 0; x < mapWidth; x++){
                if(mapArray[y][x] == 7){
                    mapArray[y][x] = 0;
                }
            }
        }

        int z = 25 + rand() % 125;

        for(int i = 0; i < z; i++){
            int y = rand() % mapHeight;
            int x = rand() % mapWidth;

            if(mapArray[y][x] == 0 && isPassable(y, x) && (cursorY != y || cursorX != x) && mapArray[y-1][x] != 2){
                mapArray[y][x] = 7;
            }
        }

        //put stuff before the game loop here

        while(!breakLoop){
            drawMap();
            drawStats();

            playerTimeSurvived = time(0) - timeStart;

            if(playerMoney > playerPeakMoneyOwned)
                playerPeakMoneyOwned = playerMoney;

            if(playerHealth <= 0){
                if(gameOver()){
                    breakLoop = true;
                    retry = true;
                }else{
                    breakLoop = true;
                    retry = false;
                }
            }

            if(playerStaminaRegenHelper >= playerStaminaRegen){
                if(playerStamina < playerMaxStamina){
                    playerStamina++;
                }
                playerStaminaRegenHelper = 0;
            }

            if(playerClip == 0 && !playerReloading && playerAmmo > 0){
                reloadGun();
            }

            if(playerXP >= playerXPNeeded){
                playerSkillPoints++;
                playerLevel++;
                playerXPNeeded *= 1.1;
                playerXP = 0;
            }

            for(int i = 0; i < MAX_ACTORS; i++){
                if(actorList[i] != NULL && actorList[i]->checkActive()){
                    actorList[i]->update();
                    actorList[i]->draw();
                }
            }

            for(int i = 0; i < MAX_BULLETS; i++){
                if(bulletList[i] != NULL && bulletList[i]->checkActive()){
                    bulletList[i]->update();
                    bulletList[i]->draw();
                }
            }

            for(int i = 0; i < MAX_BULLETS; i++){
                if(specialBulletList[i] != NULL && specialBulletList[i]->checkActive()){
                    specialBulletList[i]->update();
                    specialBulletList[i]->draw();
                }
            }

            if(roundZombiesHelper >= roundZombies){
                betweenRoundPause = true;
            }

            if(betweenRoundPause){
                betweenRoundPauseHelper++;
                if(betweenRoundPauseHelper >= 100000){
                    roundStart();
                }
            }

            if(zombieSpawnRateHelper >= zombieSpawnRate && !betweenRoundPause){
                int y, x;
                int side = rand() % 4;
                switch(side){
                    case 0:
                        y = 0;
                        x = rand() % mapWidth;
                        break;

                    case 1:
                        y = mapHeight - 1;
                        x = rand() % mapWidth;
                        break;

                    case 2:
                        y = rand() % mapHeight;
                        x = 0;
                        break;

                    case 3:
                        y = rand() % mapHeight;
                        x = mapWidth - 1;
                        break;

                }
                if(isPassable(y, x)){
                    Actor *newActor = new Actor();

                    newActor->setAppearance('@', 1);
                    newActor->setPos(y, x);
                    newActor->setSpeed(600-round*3);
                    newActor->setHealth(10);
                    newActor->setMaxRange(20);
                    addActorToList(newActor);
                    zombieSpawnRateHelper = 0;
                    roundZombiesHelper++;
                }
            }

            attron(COLOR_PAIR(0));
            move(cursorY, cursorX);
            addch('@');
            attroff(COLOR_PAIR(0));

            bool donePause = false;

            int input = getch();

            switch(input){
                case KEY_UP:
                    deltaY = -1;
                    playerMeleeDirecton = 0;
                    break;

                case KEY_DOWN:
                    deltaY = 1;
                    playerMeleeDirecton = 1;
                    break;

                case KEY_LEFT:
                    deltaX = -1;
                    playerMeleeDirecton = 2;
                    break;

                case KEY_RIGHT:
                    deltaX = 1;
                    playerMeleeDirecton = 3;
                    break;

                case 'w':
                    addBulletToList(0);
                    break;

                case 's':
                    addBulletToList(1);
                    break;

                case 'a':
                    addBulletToList(2);
                    break;

                case 'd':
                    addBulletToList(3);
                    break;

                case 'r':
                    reloadGun();
                    break;

                case 'n':
                    if(betweenRoundPause){
                        roundStart();
                        playerTotalAmountForce++;
                    }
                    break;

                case 'm':
                    if(!betweenRoundPause && zombieForceSpawnHelper >= 500){
                        int y, x;
                        int side = rand() % 4;
                        switch(side){
                            case 0:
                                y = 0;
                                x = rand() % mapWidth;
                                break;

                            case 1:
                                y = mapHeight - 1;
                                x = rand() % mapWidth;
                                break;

                            case 2:
                                y = rand() % mapHeight;
                                x = 0;
                                break;

                            case 3:
                                y = rand() % mapHeight;
                                x = mapWidth - 1;
                                break;

                        }
                        if(isPassable(y, x)){
                            Actor *newActor = new Actor();

                            newActor->setAppearance('@', 1);
                            newActor->setPos(y, x);
                            newActor->setSpeed(600-round*3);
                            newActor->setHealth(10);
                            newActor->setMaxRange(20);
                            addActorToList(newActor);
                            zombieSpawnRateHelper = 0;
                            roundZombiesHelper++;
                            zombieForceSpawnHelper = 0;
                        }
                        playerTotalAmountForce++;
                    }
                    break;

                case 't':
                    playerAmountEnteredSkillTree++;
                    skillTree.skillScreen();
                    break;

                case 'b':
                    if(playerHealth < playerMaxHealth && playerBandages > 0 && !playerReloading){
                        playerBandaging = true;
                    }
                    break;

                case 'v':
                    if(playerStaminaPills > 0 && playerStamina < playerMaxStamina){
                        if(playerStamina + playerStamina/2 <= playerMaxStamina){
                            playerStamina += playerStamina/2;
                        }else{
                            playerStamina = playerMaxStamina;
                        }
                        playerStaminaPills--;
                    }

                case 'e':
                    if(playerMeleeDamage > 0 && playerMeleeHelper >= 500){
                        for(int i = 0; i < MAX_BULLETS; i++){
                            if(bulletList[i] == NULL || !bulletList[i]->checkActive()){
                                int y, x;
                                Bullet *newBullet = new Bullet();
                                y = cursorY;
                                x = cursorX;
                                newBullet->setDirection(playerMeleeDirecton);
                                if(playerMeleeDamage < 4){
                                    if(playerMeleeDirecton == 0 || playerMeleeDirecton == 1){
                                        newBullet->setAppearance('|', 11);
                                    }else if(playerMeleeDirecton == 2 || playerMeleeDirecton == 3){
                                        newBullet->setAppearance('-', 11);
                                    }
                                }else if(playerMeleeDamage >= 4){
                                    if(playerMeleeDirecton == 0 || playerMeleeDirecton == 1){
                                        newBullet->setAppearance('|', 12);
                                    }else if(playerMeleeDirecton == 2 || playerMeleeDirecton == 3){
                                        newBullet->setAppearance('-', 12);
                                    }

                                }
                                newBullet->setPos(y, x);
                                newBullet->setSpeed(50);
                                if(playerMeleeDamage == 5){
                                    newBullet->setRange(3);
                                }else{
                                    newBullet->setRange(2);
                                }
                                newBullet->setDamage(playerMeleeDamage);
                                bulletList[i] = newBullet;
                                playerMeleeHelper = 0;
                                playerAmountMelee++;
                                break;
                            }
                        }
                    }
                    break;

                case 'p':
                    mvprintw(13, mapWidth+2, "GAME PAUSED - PRESS P TO UNPAUSE");
                    mvprintw(14, mapWidth+2, "PRESS R TO RESET THE GAME");
                    mvprintw(15, mapWidth+2, "WARNING: YOU WON'T SEE THE FINAL STATS");
                    playerTimesPaused++;
                    while(!donePause){
                        int input = getch();
                        if(input == 'p'){
                            donePause = true;
                        }else if(input == 'r'){
                            breakLoop = true;
                            donePause = true;
                        }
                    }
                    break;

                case ' ':
                    if(mapArray[cursorY][cursorX] == 5){
                        playerAmountEnteredShop++;
                        shop.shopScreen();
                    }
                    break;

                default:
                    break;

            }

            if(isPassable(cursorY + deltaY, cursorX + deltaX) && playerMovementSpeedHelper >= playerMovementSpeed && playerStamina > 0){
                cursorY += deltaY;
                cursorX += deltaX;
                if(input == KEY_UP || input == KEY_DOWN || input == KEY_LEFT || input == KEY_RIGHT){
                    playerMovementSpeedHelper = 0;
                    playerMoves++;
                    playerStamina--;
                    playerStaminaRegenHelper = 0;
                }
            }

            deltaX = 0;
            deltaY = 0;

            playerMovementSpeedHelper++;
            playerStaminaRegenHelper++;
            playerFiringSpeedHelper++;
            playerMeleeHelper++;
            zombieSpawnRateHelper++;
            zombieForceSpawnHelper++;

            if(playerReloading){
                playerReloadingHelper++;
                if(playerReloadingHelper >= playerReloadingRate){
                    playerReloading = false;
                    playerAmmo += playerHiddenClip;
                    if(playerAmmo - playerClipLimit > 0){
                        playerAmmo -= playerClipLimit;
                        playerClip = playerClipLimit;
                    }else{
                        playerAmmo -= playerClipLimit;
                        playerClip = playerClipLimit + playerAmmo;
                        playerAmmo = 0;
                    }
                    playerTimesReloaded++;
                    playerHiddenClip = 0;
                    playerReloadingHelper = 0;
                }
            }

            if(playerBandaging){
                playerBandagesHelper++;
                if(playerBandagesHelper >= 1500){
                    if(playerHealth + (playerMaxHealth/4) <= playerMaxHealth){
                        playerHealth += (playerMaxHealth/4);
                    }else{
                        playerHealth = playerMaxHealth;
                    }
                    playerBandaging = false;
                    playerBandages--;
                    playerTimesBandaged++;
                    playerBandagesHelper = 0;
                }
            }

            refresh();
        }
    }

	endwin();
}