コード例 #1
0
ファイル: spqr.c プロジェクト: ChrisCooper/SPQR
int SPQR_Game()
{
	//initializeAllObjects();

	int randomizer = 0;                    //Used for random timing of events

   inGame = 1;
	//The main game loop
	while (inGame)
    {

/*
	All timers use the format:

	if (timerVar less than 'X' and not the same as last time)
	{
		do_something;
	}
	else if (more than 'X')
	{
		do_something_else;
		reset timerVar;
	}

*/

			//Timer for updating money
			if (time(0) % 3 == 0 && moneyNotDone)//excecute every 3 seconds
			{
				updateMoney();
				moneyNotDone = 0;
			}
			else if (time(0) % 3 != 0)
			{
            moneyNotDone = 1;
			}

         /*Counter for playing ambient sounds, and updating resources     60 BPM*/
         if (economyCounter != economyCounterCheck)
			{
            checkThresholds();
            updateResources();
				calculatePopulation();
				if (!(economyCounter % 5)) // every 5 cycles
				{
					updateHousing();
				}
            economyCounterCheck = economyCounter;
				//playAmbientSound();
				if (!(randomizer = rand() % 2))
				{
					play_sample(ambientSound[rand() % NUMABIENTSOUNDS], 255, 127, 1000, 0);
				}
			}

			/*Counter for updating atributes of people        4 BPS*/
          if (updateCounter < 100000 && updateCounterCheck != updateCounter)
          {
              updatePeople();
					sortPeople();
              updateCounterCheck = updateCounter;
          }
          else
          {
              updateCounter = 0;
          }

			/*Counter for animation of people                 8 BPS*/
          if (animateCounter < 100000 && animateCounterCheck != animateCounter)
          {
              animatePeople();
					movePeople();
					sortPeople();
					calculatePercentages();
              animateCounterCheck = animateCounter;
          }
          else
          {
              animateCounter = 0;
          }

			/*Main logic vs. visuals loop                      60 BPS*/
			if (speedCounterCheck == speedCounter)
			{
			}
			else if (speedCounter > 1)
			{
              speedCounter = 0;
              gameVisuals();
			}
         else if (speedCounterCheck != speedCounter)
         {
              getInput();
              speedCounterCheck = speedCounter;
         }
    }
	return 0;
}
コード例 #2
0
void ydxh_ScrollArea::showNewMoney()
{
    emit updateMoney();
}
コード例 #3
0
void print_total_money (void)
{
    updateMoney();
}
コード例 #4
0
void selectUnitsInterface(Path* thePath, UnitListHeader * unitList, int * moneyAmount, TowerArray* theTowerList, int * theScore) {
    int currentOption = 1;
    int unitSelection = 0;
    Unit * toAdd;
    
    int levelCap = 1;
    while(levelCap < 6) {
        switch(getch()) {
            case KEY_UP:

                //move selection up one
                currentOption -= 1;
                if (currentOption < 1) {
                    currentOption = 1;
                }

                //draw box around option (and remove old)
                attron(COLOR_PAIR(3));
                removeChoiceBoxes();
                addBoxChoiceOption(currentOption);
                attroff(COLOR_PAIR(3));
                break;
            case KEY_DOWN:

                //move selection down one
                currentOption += 1;
                if (currentOption > 4) {
                    currentOption = 4;
                }

                //draw box around option (and remove old)
                attron(COLOR_PAIR(3));
                removeChoiceBoxes();
                addBoxChoiceOption(currentOption);
                attroff(COLOR_PAIR(3));
                break;
            case KEY_RIGHT:

                //if on unit selection, change
                if (currentOption == 1) {
                    //switch unit selection
                    if (unitSelection < 4) {
                        unitSelection++;
                        //mvaddstr(15,113," >  ");
                        updateUnitChoice(unitSelection);
                    }
                }
                break;
            case KEY_LEFT:

                //if on unit selection, change
                if (currentOption == 1) {
                    //switch unit selection
                    if (unitSelection > 0) {
                        unitSelection--;
                        //mvaddstr(15,64,"  < ");
                        updateUnitChoice(unitSelection);
                    }
                }
                break;
            case '\n':

                //select whatever is being hovered on
                switch(currentOption) {
                    case 4:
                        return;
                    case 3:

                        if (unitList->size > 0) {
                            //hide buttons
                            mvaddstr(25,85,"                  ");
                            mvaddstr(28,80,"                    ");
                            mvaddstr(29,80,"                    ");
                            mvaddstr(30,80,"                    ");
                            mvaddstr(33,83,"                    ");

                            if (mainRunningLoop(theTowerList,thePath,unitList,theScore,moneyAmount) == 1) {
                                *moneyAmount += 150;
                                levelCap++;

                                if (levelCap < 6) {
                                    //after done
                                    attron(COLOR_PAIR(0));
                                    drawPurchaseArea();
                                    basicSetupScreen(levelCap);
                                    updateMoney(*moneyAmount);
                                    attroff(COLOR_PAIR(0));
                                    //change
                                    attron(COLOR_PAIR(3));
                                    removeChoiceBoxes();
                                    addBoxChoiceOption(3);
                                    attroff(COLOR_PAIR(3));

                                    destroyTowerArray(theTowerList);

                                    //load level file
                                    switch(levelCap) {
                                        case 2:
                                            theTowerList = getTowerArray("assets/towersLevel2.txt");
                                            break;
                                        case 3:
                                            theTowerList = getTowerArray("assets/towersLevel3.txt");
                                            break;
                                        case 4:
                                            theTowerList = getTowerArray("assets/towersLevel4.txt");
                                            break;
                                        case 5:
                                            theTowerList = getTowerArray("assets/towersLevel5.txt");
                                            break;
                                        case 6:
                                            theTowerList = getTowerArray("assets/towersLevel5.txt");
                                            break;

                                    }
                                    drawTowers(theTowerList);
                                    updateUnitChoice(unitSelection);
                                }
                            }
                        }

                        break;
                    case 1:
                        break;
                    case 2:
                        toAdd = malloc(sizeof(Unit));

                        //purchase units
                        switch(unitSelection) {
                            case 0:
                                if (*moneyAmount >= unit1Cost) {
                                    *moneyAmount -= unit1Cost;
                                    NewUnit(toAdd,unit1,unitList);
                                }
                                break;
                            case 1:
                                if (*moneyAmount >= unit2Cost) {
                                    *moneyAmount -= unit2Cost;
                                    NewUnit(toAdd,unit2,unitList);
                                }
                                break;
                            case 2:
                                if (*moneyAmount >= unit3Cost) {
                                    *moneyAmount -= unit3Cost;
                                    NewUnit(toAdd,unit3,unitList);
                                }
                                break;
                            case 3:
                                if (*moneyAmount >= unit4Cost) {
                                    *moneyAmount -= unit4Cost;
                                    NewUnit(toAdd,unit4,unitList);
                                }
                                break;
                            case 4:
                                if (*moneyAmount >= unit5Cost) {
                                    *moneyAmount -= unit5Cost;
                                    NewUnit(toAdd,unit5,unitList);
                                }
                                break;
                        }

                        //display new amount of money
                        updateMoney(*moneyAmount);
                        drawUnitTypes(unitList);
                        break;
                    default:
                        break;
                }
                break;
            default:
                //some other irrelevant key was pressed (ignore it)
                break;
        }
    }
}
コード例 #5
0
ファイル: Menu.c プロジェクト: JuliePO/opengl1NanniPo
int clickMenuTour(LTower* p_ltower, LFileTower* p_lfileTower, Interface* interface, float x, float y) {

	//Vérifie si les elements ont été alloué
	if(p_ltower != NULL && p_lfileTower != NULL && interface != NULL) {

		char* type = "None";

		//Vérifie qu'on clique sur le bon bouton : tour hybride
		if(x <= 190 && x >= 10 && y <= 120 && y >= 70)
			type = "H";

		// Tour rocket
		else if(x <= 190 && x >= 10 && y <= 175 && y >= 125)
			type = "M";

		//Si le niveau est suppérieur à 3
		if(interface->lvl >= 3) {
			if(x <= 190 && x >= 10 && y <= 230 && y >= 180)
				type = "R";
		}

		//Si le niveau est suppérieur à 5
		if(interface->lvl >= 5) {
			if(x <= 190 && x >= 10 && y <= 285 && y >= 235)
				type = "L";
		}


		//Vérifie qu'il y a un type, sinon pas de clique sur l'un des boutons
		if(strcmp("None", type) != 0) {

			//Pointeur temporaire pour parcourir la liste
			FileTower* tmp = p_lfileTower->p_head;
	
			//Parcours la liste
			while(tmp != NULL) {
				//Si c'est l'hybride 
				if(strcmp(type, tmp->type_tower) == 0)
					break;

				tmp = tmp->p_next;
			}

			//S'il le joueur a assez d'argent
			if((interface->money) >= tmp->cost) {
				//Ajoute une tour
				addTower(p_ltower, tmp->power, tmp->rate, tmp->type_tower, tmp->range, tmp->cost, x, y);
				//Met a jour l'agent
				updateMoney(interface, tmp->cost);
				return 1;
			}
		}
		
	}
	else {
		fprintf(stderr, "Erreur : liste de tour, liste de fileTour ou interface non alloué\n");
		return 0;
	}

	return 0;

}