Exemplo n.º 1
0
//Functions related to find/replace : Start
void executeFindAndReplace(){
	FILE * file;
	char nameOfFile[256];
	char textToFind[256];
	char textToReplace[256];
	char buffer[256];
	printf("File Name\n");
	writeToLog("File Name");
	scanf("%s", nameOfFile);
	printFileContents(nameOfFile);
	file = fopen(nameOfFile, "r");
	if(!file){
		printf("The file you entered does not exist or is empty!\n");
		writeToLog("The file you entered does not exist or is empty!");
		fclose(file);
		displayMainMenu();
		return;
	}
	printf("Enter text to find.\n");
	writeToLog("Enter text to find.");
	scanf("%s", textToFind);
	writeToLog(textToFind);
	printf("Enter text to replace.\n");
	writeToLog("Enter text to replace.");
	scanf("%s", textToReplace);
	writeToLog(textToReplace);
	while(fgets(buffer, 256, (FILE*) file)){
		replace(buffer, textToFind, textToReplace);
	}
	fclose(file);
	displayMainMenu();	
}
Exemplo n.º 2
0
int main() {
    hideCursor();
    char title[] = "Simple Game Demo";
    setTitle(title);

    int opt = displayMainMenu();
    while (opt != 3) {
        clrscr();
        if (opt == 0) {
            char msg[] = "Let's play a game\nEat the # to win the game";
            displayMsg(0, 0, msg);
            Sleep(1000);
            clrscr();
            playGame();
        } else if (opt == 1) {
            printf("This is load");
        } else if (opt == 2) {
            printf("This is setting");
        }
        clrscr();
        opt = displayMainMenu();
    }

    return 0;
}
Exemplo n.º 3
0
/**@brief creates a new display to indicate that the player has lost and needs to restart */
void Game::display_game_over() {
    qDebug() << "game over.";

    level->input->releaseKeyboard();
    level->clear();
    delete level;
    level = nullptr;

    //clear the screen from the level
    scene = new QGraphicsScene();
    setScene(scene);

    //next create the Game Over text
    QGraphicsTextItem* gameOverText = new QGraphicsTextItem(QString("You Perished. Game Over."));
    //set font and size
    QFont game_over_font ("28 Days Later", 25);
    gameOverText->setFont(game_over_font);
    //position the text
    int gameOverXPos = this->width()/2 - gameOverText->boundingRect().width()/2;
    int gameOverYPos = 150;
    gameOverText->setPos(gameOverXPos, gameOverYPos);
    //add it to the scene
    scene->addItem(gameOverText);


    //create back to main menu button
    Button* returnToMenu = new Button(QString("Return to Menu"));
    //position button
    int returnXPos = this->width()/2 - returnToMenu->boundingRect().width()/2;
    int returnYPos = 425;
    returnToMenu->setPos(returnXPos, returnYPos);
    //connect this button to quit the game
    QObject::connect(returnToMenu, SIGNAL(clicked()), this, SLOT(displayMainMenu()));
    scene->addItem(returnToMenu);
}
Exemplo n.º 4
0
Arquivo: main.c Projeto: chamboard/Ju
void pauseResumeSteps(sequencer* seqA, sequencer* seqB, uint32_t* errors) { 				// pauseResumeSteps() pauses/resumes the two sequencers passed in parameters.
	static uint8_t stepA=0,stepB=0;											 
	if (!stepA) {																			// If Seq increases or decreases. 
		printf("%s paused\n",seqA->name);													//  
		stepA=seqA->presetStep;																// 	Saves value of seqA.presetStep in stepA.
		seqA->presetStep=0;																	//  Sets seqA.presetStep to 0.
																							
	}
	else {																					// Else 
		printf("%s running\n",seqA->name);               									//
		seqA->presetStep=stepA;																//	Sets seqA.presetStep to saved value	of stepA.
		stepA=0;																			//  Resets stepA.
																							
	}
	if (!stepB) {																			// If Seq1 increases or decreases. 
		printf("%s paused\n",seqB->name);													//  
		stepB=seqB->presetStep;																//  Saves value of seqB.presetStep in stepB.
		seqB->presetStep=0;																	//  Sets seqB.presetStep to 0.
	}
	else {																					// Else
		printf("%s running\n",seqB->name);
		seqB->presetStep=stepB;																//	Sets seqB.presetStep to saved value of stepB.
		stepB=0;																			//  Resets stepB.
	}
	*errors+=CHAN_addr(IO24_NUM,seqA->presetStepAddr);										// Sets current address at address of SEQ_PRESET_STEP.
	*errors+=CHAN_setByte(IO24_NUM,seqA->presetStep);										// Writes value of seqA.presetStep at current address.
	*errors+=CHAN_addr(IO24_NUM,seqB->presetStepAddr);										// Sets current address at address of SEQ1_PRESET_STEP.
	*errors+=CHAN_setByte(IO24_NUM,seqB->presetStep);										// Writes value of seqB.presetStep at current address.
	errors+=CHAN_command(IO24_NUM,7);														// Executes IO24 command 0x07 named STEPCOUNT_SEQUENCER_RUN because SEQ_PRESET_STEP or SEQ1_PRESET_STEP have been edited.
	displayMainMenu();																		// Displays main menu.
}
Exemplo n.º 5
0
//Starting story after new game
void startNewGame()
{
    system("cls");

    printf("Here start a great adventure.\n\n");
    Sleep(2000);
    printf("...Hello young Hero\n\n");
    Sleep(1000);
    printf("you have been sent by gods to help us\n\n");
    Sleep(1000);
    printf("all our caves are now full of evil creatures\n\n");
    Sleep(1000);
    printf("they infested our cities and take all our needs\n\n");
    Sleep(1000);
    printf("we don't have anything left and our sons and wifes\n\n");
    Sleep(1000);
    printf("need food and drugs to survive\n\n");
    Sleep(1000);
    printf("you are our only hope\n\n");
    Sleep(1000);
    printf("so tell me more about you...\n\n");
    Sleep(3000);

    Player *Hero = NewPlayer();

    displayMainMenu(Hero);
}
Exemplo n.º 6
0
/**@brief shows a set of instructions for the user to understand gameplay */
void Game::display_instructions() {
    //start by clearing the scene from the Main Menu
    scene->clear();

    //next we create the instructions portion
    QGraphicsTextItem* instructionsText =
            new QGraphicsTextItem (QString("You are about to embark on an epic quest champion! In order to protect the\n"
                                           "Emerald Dream, you must cleanse the land of demons. Use WASD or the arrow\n"
                                           "keys to move around and Spacebar to fire your wrath attack. At any time you\n"
                                           "can hit escape if the battle becomes too intense. Beware of the demons, if they\n"
                                           "cross the threshold this will lower your health. If your health reaches 0, you\n"
                                           "lose the game. If you kill 10 of the demons, you win! You have all you need\n"
                                           "now fulfill your druidic duties! May Elune be with you!"));
    //set the font and size
    QFont instructFont ("Lithos Pro", 17);
    instructionsText->setFont(instructFont);
    //position the text
    int instructXPos = this->width()/2 - instructionsText->boundingRect().width()/2;
    int instructYPos = 150;
    instructionsText->setPos(instructXPos, instructYPos);
    //add it to the scene
    scene->addItem(instructionsText);

    //create the Back to Main Menu Button
    Button* returnToMenu = new Button(QString("Return to Menu"));
    //position button
    int returnXPos = this->width()/2 - returnToMenu->boundingRect().width()/2;
    int returnYPos = 425;
    returnToMenu->setPos(returnXPos, returnYPos);
    //connect this button to quit the game
    QObject::connect(returnToMenu, SIGNAL(clicked()), this, SLOT(displayMainMenu()));
    scene->addItem(returnToMenu);

}
Exemplo n.º 7
0
main(int argc, char *argv[]){
    int menuchoice;
    Students st;
    char filename[100];
 
    if (argc > 1)
    {
        printf("You have imported a file.\n");
        strcpy(filename, argv[1]);
    }
    else
    {
        printf("The program is going to use the default file.\n");
        strcpy(filename, FILENAME);
    }
    printf("Filename: %s\n", filename);
    initStudents (&st);
    do
    {
        menuchoice=displayMainMenu();
        switch (menuchoice)
        {
            case 0: exit(0);
            case 1: loadData(filename, &st); break;
            case 2: saveData(filename, &st); break;
            case 3: addStudent(&st); break;
            case 4: deleteStudent(&st); break;
            case 5: sortID(&st); break;
            case 6: sortSurName(&st); break;
            case 7: displayStudents(st);break;
        }
    } while(1);
}
Exemplo n.º 8
0
/**@brief displays a new screen to indicate that the player has won the game */
void Game::display_end_screen() {
    level->input->releaseKeyboard();
    level->clear();
    delete level;
    level = nullptr;

    //clear the screen from the level
    scene = new QGraphicsScene();
    setScene(scene);

    //next create the end screen text
    QGraphicsTextItem* endText = new QGraphicsTextItem(QString("You defeated all the demons! Congratulations Champion!"));
    //set font and size
    QFont endFont ("Adventure", 25);
    endText->setFont(endFont);
    //position the text
    int endXPos = this->width()/2 - endText->boundingRect().width()/2;
    int endYPos = 150;
    endText->setPos(endXPos, endYPos);
    //add it to the scene
    scene->addItem(endText);


    //create back to main menu button
    Button* returnToMenu = new Button(QString("Return to Menu"));
    //position button
    int returnXPos = this->width()/2 - returnToMenu->boundingRect().width()/2;
    int returnYPos = 425;
    returnToMenu->setPos(returnXPos, returnYPos);
    //connect this button to quit the game
    QObject::connect(returnToMenu, SIGNAL(clicked()), this, SLOT(displayMainMenu()));
    scene->addItem(returnToMenu);
}
Exemplo n.º 9
0
int main(){
	setArraySize();
	displayMainMenu();
    system("clear");
	printf("Bye Bye Bye! \n");
    freeToIndex();
    return 0;
}
Exemplo n.º 10
0
Arquivo: main.c Projeto: chamboard/Ju
void invertWrap(sequencers* seqs, uint32_t* errors) { 										// invertWrap() sets SEQ_WRAP to 0 or 1 switch previous value. SEQ_WRAP is common setting to the three sequencers.
	if (seqs->wrap==0) {																	// 
		seqs->wrap=1;																		//
	}																						//
	else seqs->wrap=0;																		// Sets variable seqs.wrap to 0 or 1 switch its previous value.
	*errors+=CHAN_addr(IO24_NUM,seqs->wrapAddr);											// Sets current address at address of SEQ_WRAP.
	*errors+=CHAN_setByte(IO24_NUM,seqs->wrap);												// Writes value of seqs.wrap at current address.
	printf("wrap set to %d\n",seqs->wrap);													// Displays new value of SEQ_WRAP.
	if (seqs->wrap==1) *errors+=CHAN_command(IO24_NUM,7);									// Executes IO24 command 0x07 named STEPCOUNT_SEQUENCER_RUN : restarts stepcount sequenced outputs mode because SEQ_WRAP has been set to 1.
	displayMainMenu();																		// Displays main menu.
}
Exemplo n.º 11
0
/*
 * This function is fully implemented
 *
 */
void run(Dragon * dragons, int & currentDragonNumbers)
{
	int choice = -1;
	PernThread * pernPtr = nullptr;
	while (choice != QUIT)
	{
		displayMainMenu();
		cout << "Enter choice >> ";
		cin >> choice;
		cin.ignore(10000, '\n');
		process(dragons, currentDragonNumbers, choice, pernPtr);
	}
}
Exemplo n.º 12
0
//Display the game over menu
void displayGameOverMenu(Player *player)
{
    int userChoice;
    int flag = 0;
    int i = 0;

    system("cls");

    while(flag < 10){
        for(i = 0; i < 15; i++){
            Sleep(10);
            system("cls");
            color(i, 0);

            printf("#####################################\n");
            printf("############# GAME OVER #############\n");
            printf("#####################################\n");

            printf("\nYour score is -> %d\n", player->score);
            printf("Dungeon(s) done : %d\n", player->nbrDungeons);
            printf("You killed %d monster(s)...\n", player->nbrKills);
        }
        flag++;
    }

    if(player->life > 0){
        printf("\nYou still have %d life(s)\n", player->life);
        printf("Would you like to continue ?\n");
        printf("1 : yes\n2 : No\n");
        userChoice = userInputInt();

        switch(userChoice){
            case 1:
                player->life--;
                player->health = player->maxHP;
                player->gold = 0;
                setPotionAtStart(player);
                displayMainMenu(player);
                break;
            default:
                break;
        }
    }
    printf("You are dead, you finished the game with :\n");
    printf("Score -> %d\n", player->score);
    printf("Kills -> %d\n", player->nbrKills);
    printf("Dungeon(s) -> %d\n", player->nbrDungeons);
    printf("Try to do better next time...\n");
    Sleep(5000);
    startMenu();
}
Exemplo n.º 13
0
// Functions related to the File Explorer Option : Start
void executeFileExplorerOption(int option){
	switch (option){
		case 1:
		  fileListSortByName();
		  break;
  		case 2:
		  fileListSortBySize();
		  break;
  		case 3:
		  changeDirectory();
		  break;
  		case 4:
		  displayMainMenu();
		  break;
	}
}
Exemplo n.º 14
0
//Main menu in town
void displayMainMenu(Player *player)
{
    int userChoice = 0;

    system("cls");
    color(10, 0);

    printf("<< IN TOWN >>\n\n");
    printf("----------------------------------\n");
    printf("Here are all the things you can do :\n");
    printf("--------------------------------------\n\n");
    color(11, 0);
    printf("1 - Empty an infested Dungeon\n");
    color(14, 0);
    printf("2 - Go to the tavern if you want to buy new stuff or potions\n");
    color(15, 0);
    printf("3 - Display player menu\n");
    color(12, 0);
    printf("4 - Save and quit\n");
    color(15, 0);

    while(1){
        userChoice = userInputInt();

        switch(userChoice){
            case 1:
                goThroughDungeon(player);
                break;
            case 2:
                goToTavern(player);
                break;
            case 3:
                menu_player(player, 0);
                break;
            case 4:
                saveYourGame(player);
                startMenu();
                break;
            default:
                printf("Please enter a correct entry !\n");
                Sleep(1500);
                displayMainMenu(player);
                break;
        }
    }
}
Exemplo n.º 15
0
//First menu where you can start or load
int startMenu()
{
    Player* newPlayer;
    int userChoice = 0;

    system("cls");
    color(12, 0);

    printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
    printf("~~~                                                   ~~~\n");
    printf("~~~        ***       LOST IN A DUNGEON      ***       ~~~\n");
    printf("~~~                         BY                        ~~~\n");
    printf("~~~                    --- EX@W ---                   ~~~\n");
    printf("~~~                                                   ~~~\n");
    printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");

    color(15, 0);

    printf("\n\n");
    printf("Would you like to continue a story or start a new one? \n");
    printf("-------------------------------------------------------\n");
    printf("1 : New Game\n");
    printf("2 : Load Game\n\n");
    printf("Press enter to exit the game...\n");

    userChoice = userInputInt();

    switch(userChoice){
        case 1:
            startNewGame();
            break;
        case 2:
            newPlayer = loadYourGame();
            displayMainMenu(newPlayer);
            break;
        case 0:
            exit (0);
        default:
            printf("Please enter a correct entry...\n");
            Sleep(2000);
            startMenu();
            break;
    }
    return (0);
}
Exemplo n.º 16
0
Arquivo: main.c Projeto: chamboard/Ju
void displayStatus(sequencer* seqA, sequencer* seqB, uint32_t* errors) { 					// displayStatus() displays sense and number of remaining steps for each sequencer. 
	uint8_t countA=0,countB=0;																
	uint8_t stepA=0, stepB=0;
	*errors+=CHAN_addr(IO24_NUM,seqA->presetCountAddr);										// Sets current address at address of SEQ_PRESET_COUNT.			
	CHAN_getBytes(IO24_NUM,1,&countA);														// Stores value of SEQ_PRESET_COUNT in variable countA.
	*errors+=CHAN_addr(IO24_NUM,seqB->presetCountAddr);										// Sets current address at address of SEQ1_PRESET_COUNT.
	CHAN_getBytes(IO24_NUM,1,&countB);														// Stores value of SEQ1_PRESET_COUNT in variable countB.
	printf("Remaining step(s) for sequencer %s : %d\n",seqA->name,countA);					//
	printf("Remaining step(s) for sequencer %s : %d\n",seqB->name,countB);					// Displays remaining steps for the two sequencers.
	*errors+=CHAN_addr(IO24_NUM,seqA->presetStepAddr);										// Sets current address at address of SEQ_PRESET_STEP.
	CHAN_getBytes(IO24_NUM,1,&stepA);														// Stores value of SEQ_PRESET_STEP in variable stepA.
	*errors+=CHAN_addr(IO24_NUM,seqB->presetStepAddr);										// Sets current address at address of SEQ1_PRESET_STEP.
	CHAN_getBytes(IO24_NUM,1,&stepB);														// Stores value of SEQ1_PRESET_STEP in variable stepB.
	if (stepA==0) printf("sequencer %s does nothing\n",seqA->name);							//
	else if (stepA==1) printf("sequencer %s increases\n",seqA->name);						//
	else if (stepA==2) printf("sequencer %s decreases\n",seqA->name);						// Displays if Seq does nothing, increases or decreases.
	if (stepB==0) printf("sequencer %s does nothing\n",seqB->name);							//
	else if (stepB==1) printf("sequencer %s increases\n",seqB->name);						//
	else if (stepB==2) printf("sequencer %s decreases\n",seqB->name);						// Displays if Seq1 does nothing, increases or decreases.
	displayMainMenu();																		// Displays main menu.		
}
Exemplo n.º 17
0
Arquivo: main.c Projeto: chamboard/Ju
void add10Steps(sequencer* seqA, sequencer* seqB, uint32_t* errors) {     					// add10Steps() adds 10 steps to the two sequencers passed in parameters. 
	uint8_t countA=0,countB=0;												 
	*errors+=CHAN_addr(IO24_NUM,seqA->presetCountAddr);										// Sets current address at address of SEQ_PRESET_COUNT.
	CHAN_getBytes(IO24_NUM,1,&countA);														// Stores value of SEQ_PRESET_COUNT in variable countA.
	*errors+=CHAN_addr(IO24_NUM,seqB->presetCountAddr);										// Sets current address at address of SEQ1_PRESET_COUNT.
	CHAN_getBytes(IO24_NUM,1,&countB);														// Stores value of SEQ1_PRESET_COUNT in variable countB.
	*errors+=CHAN_addr(IO24_NUM,seqA->presetCountAddr);										// Sets current address at address of SEQ_PRESET_COUNT.
	*errors+=CHAN_setByte(IO24_NUM,seqA->presetCount+countA);								// Writes 10+countA at current address.	
	*errors+=CHAN_addr(IO24_NUM,seqB->presetCountAddr);										// Sets current address at address of SEQ1_PRESET_COUNT.
	*errors+=CHAN_setByte(IO24_NUM,seqB->presetCount+countB);								// Writes 10+countB at current address.
	if (countA==0||countB==0) {																// If one of the two sequencers has finished its sequence.
		printf("Restarting sequencers for 10 steps.\n");									//
		errors+=CHAN_command(IO24_NUM,7);													// 	Executes IO24 command 0x07 named STEPCOUNT_SEQUENCER_RUN to restart stepcount sequenced outputs mode. 
	}
	else {																					// Else 
		printf("Remaining steps for sequencer %s : %d\n",
			seqA->name,seqA->presetCount+countA);											//  Displays remaining steps for the two sequencers.
		printf("Remaining steps for sequencer %s : %d\n",
			seqB->name,seqB->presetCount+countB);
	}	
	displayMainMenu();																		// Displays main menu.
}
Exemplo n.º 18
0
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
  APP_LOG(APP_LOG_LEVEL_DEBUG, "Message recieved!");
  
  // Get the first pair
  Tuple *t = dict_read_first(iterator);

  // Process all pairs present
  while (t != NULL) {
    char s_buffer[64];

    // Process this pair's key
    switch (t->key) {
      case GET_LATEST:
        snprintf(s_buffer, sizeof(s_buffer), "GET_LATEST Received '%s'", t->value->cstring);
        APP_LOG(APP_LOG_LEVEL_DEBUG, s_buffer);
        _latest = t->value->cstring;
        displayMainMenu(_latest);
        break;
      case HELLO:
        snprintf(s_buffer, sizeof(s_buffer), "HELLO Received '%s'", t->value->cstring);
        APP_LOG(APP_LOG_LEVEL_DEBUG, s_buffer);
        sendDoGetMessageIfBluetoothConnected();
        break;
      case ERROR:
        snprintf(s_buffer, sizeof(s_buffer), "ERROR Received '%s'", t->value->cstring);
        APP_LOG(APP_LOG_LEVEL_ERROR, s_buffer);
        show_no_con_error();
        break;
      default:
        snprintf(s_buffer, sizeof(s_buffer), "Unidentified Received '%s'", t->value->cstring);
        APP_LOG(APP_LOG_LEVEL_DEBUG, s_buffer);
        break;
    }

    // Get next pair, if any
    t = dict_read_next(iterator);
  }
}
Exemplo n.º 19
0
//Beginning of main(void)
int main(void)
{
	
	


	
				//Initializes variables
				struct holeStruct holeData[MAX_HOLES];
	
				struct dimenssionStruct dimenssion;
	
				struct dimenssionStruct*dimenPtr=&dimenssion;
	
				char label1[50];
	
				char label2[50];
	
				float inputDepth=0;
	
				//Holds input indicating if user wants to run or quit the program	 
				int mainChoice=0;
	
				//This hold the value (as returned by scanf()) indicating number of assignments made
				int validDepth=0;
	
				int soilChoice=0;
	
	
	

				int readResult=0; 
	
				//result from readData function is stored in readResult var.
				readResult=readData(holeData,label1,label2);
	
				
				switch(readResult)
				{
	
					case 0:
					{
		
								
									//If readResult=0, below code is executed
										   
									calcDimen(holeData,dimenPtr);
	
									calcHoleCoord(holeData,dimenPtr);
	
									initGraphics(dimenPtr);
	
									showAllData(holeData,label1,label2,dimenPtr);

									setcolor(WHITE);
									outtextxy(2,2,"Enter a depth in the console to see the soil information at that depth here.");	  
				 
									/*This do..while loop calls the routines inside it 
									as long as user does not decide to quit the program*/
									do{
		
		
		
													mainChoice=displayMainMenu();
		
		
													if(mainChoice==1)
													{
				
																do
																{
																			printf("\nEnter a depth (in meters):");
							
																			fflush(stdin);
							
																			validDepth=scanf("%f",&inputDepth);
							
						
																}while(validDepth==0);
						
							
																inputDepth=fabs(inputDepth);
					
																soilChoice=displaySoilMenu();
					
																processPrint(holeData,inputDepth,label1,label2,dimenPtr,soilChoice,1);
					
						
													}
		
		
			
	
	
	
										}while(mainChoice!=2);
	
	
				
										break;
					}


	
					case 1:
					{
			
										printf("You have chosen to exit the program because data from the file could not be read.\n Press Enter to exit.");
		
										break;
			
					}
					
					default:
					{
							printf("\nUnexpected error occoured in main(void)\n");
							break;
					}
		
	
	
				}

				return readResult;

	
	
}
Exemplo n.º 20
0
int main ( int argc, char** argv )
{
      if(Load_Wordlist()==-1)
    {
     printf( "Unable to load wordlist\n");
    return 1;
    }
    // initialize SDL video
    if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
    {
        printf( "Unable to init SDL: %s\n", SDL_GetError() );
        return 1;
    }
    if (TTF_Init()==-1)
    {
        printf( "Unable to init SDL: %s\n", SDL_GetError() );
        return 1;
    }


    // make sure SDL cleans up before exit
    atexit(SDL_Quit);

    // create a new window
   screen = SDL_SetVideoMode(480, 640, 16,SDL_HWSURFACE|SDL_DOUBLEBUF);
    if ( !screen )
    {
        printf("Unable to set 640x480 video: %s\n", SDL_GetError());
        return 1;
    }

    // *******************************************Load Resources********************************************/
    //******************************************************************************************************/
    //****************************************That's right, resources***************************************/
    //******************************************************************************************************/
    option=IMG_Load("option.png");
    if (!option)
    {
        printf("Unable to load bitmap: %s\n", SDL_GetError());
        return 1;
    }
      option2=IMG_Load("option2.png");
    if (!option)
    {
        printf("Unable to load bitmap: %s\n", SDL_GetError());
        return 1;
    }
    background=IMG_Load("background.png");
    if (!background)
    {
        printf("Unable to load bitmap: %s\n", SDL_GetError());
        return 1;
    }
   gamefont=TTF_OpenFont("Courier_New.ttf",25);
   gamefontsmall=TTF_OpenFont("Courier_New.ttf",16);
    if (gamefont==NULL||gamefontsmall==NULL)
    {
        printf("Unable to load font: %s\n", SDL_GetError());
        return 1;
    }
    // *************************************Initialising some vars********************************************/
    //********************************************************************************************************/
    cur_rect.w=200;
    cur_rect.h=80;
    cur_rect.x=(480-200)/2;
    cur_text_rect.h=20;
    screen_rect.w=480;
    screen_rect.h=640;
    screen_rect.x=0;
    screen_rect.y=0;
    int i;
    for(i=0;i<6;i++){options[i].text=NULL;}
    textColor.r=0;
    textColor.g=0;
    textColor.b=0;
    milliseconds=SDL_GetTicks();
    srand(time(NULL));
    //**************************************************Main loop LOL*******************************************/
    //**********************************************************************************************************/
    //****************************************************Here we go...*****************************************/
    //**********************************************************************************************************/
    displayMainMenu();

    //***********************************************************************************************************
    //********************************************Event processing***********************************************
    //***********************************************************************************************************

    while (!done)
    {
        // message processing loop
        SDL_Event event;
        while (SDL_PollEvent(&event))
        {
            // check for messages
            switch (event.type)
            {
                // exit if the window is closed
            case SDL_QUIT:
                done = true;
                break;

                // check for keypresses
            case SDL_KEYDOWN:
                {
                    // exit if ESCAPE is pressed
                    if (event.key.keysym.sym == SDLK_ESCAPE)
                        done = true;
                    break;
                }
            case SDL_MOUSEBUTTONDOWN:
            {
            handleClick(GetClickedOption(event.button.x,event.button.y));
            }
            } // end switch
        } // end of message processing
        //***************************************************************************************
        //*****************************Rendering*************************************************
        //***************************************************************************************
  // clear screengetline
        SDL_BlitSurface(background, 0, screen, &screen_rect);
        if(gamestate>=1&&gamestate<=3)
        {
        SDL_BlitSurface(questiontext,0,screen,&screen_rect);
        }
        int i;
        for(i=0;i<optnum;i++)
        {
        displayOption(options[i]);
        }

        //Run the physics
        runPhysics();
        // finally, update the screen :)
        SDL_Flip(screen);
    } // end main loop

    // free loaded bitmap
    SDL_FreeSurface(questiontext);
    SDL_FreeSurface(option2);
    SDL_FreeSurface(option);
    SDL_FreeSurface(background);
    TTF_CloseFont(gamefont);
    TTF_Quit();
    for(i=0;i<numwords;i++)
    {
    Free_Word(Words[i]);
    }
    free(Words);
    // all is well ;)
    printf("Exited cleanly\n");
    return 0;
    }
Exemplo n.º 21
0
 void handleClick(int opt)
 {
 if(gamestate==0)//Main menu
 {
 switch(opt)
 {
 case 0://quit
 done=true;
 break;
 case 2://Hard
 gamestate=3;
 generateHardQuestion();
 break;
 case 3:
 gamestate=2;
 generateMediumQuestion();//Medium
 break;
 case 4://Easy
 gamestate=1;
 generateEasyQuestion();
 break;
 }
 }
 else if(gamestate==1||gamestate==2||gamestate==3)//Easy,Medium,Hard
 {
 if(opt==-1)return;//If no option was clicked, do nothing
 if(options[opt].state==true)return;//TODO-fix problems //If the question was clicked, do nothing
 if(strcmp(answer,options[opt].string)!=0)//If the wrong answer was clicked, remove it and deduct score
 {
 removeOption(opt);
 score--;
 }
 else
 {
 score++; //Increase score and generate next question
 if(gamestate==1)
 {
 generateEasyQuestion();
 }
 else if(gamestate==2)
 {
 generateMediumQuestion();
 }
 else if(gamestate==3)
 {
 generateHardQuestion();
 }
 if(questions==26)
 {
 questions=0;
 gamestate=4;
 showScore();
 }
 }
 }
 else if(gamestate==4)
 {
 if(opt==0)
 {
 score=0;
 gamestate=0;
 displayMainMenu();
 }
 }
 }
//Beginning of main(void)
int main(void)
{

	
	//Initializes variables
			  struct hole holeData[MAX_HOLES];
	
				struct graphicWindow gfxWin;
				
				struct soil_palette soilPalette;
	
				char label1[LABEL_LENGTH];
	
				char label2[LABEL_LENGTH];
	
				float inputDepth=0;
	
				//Holds input indicating if user wants to run or quit the program	 
				int mainChoice=0;
	
				//This hold the value (as returned by scanf()) indicating number of assignments made
				int validDepth=0;
	
			
	
	
	

				int readResult=0; 
	
				//result from readData function is stored in readResult var.
				readResult=readData(holeData,label1,label2);
	
				
				switch(readResult)
				{
	
					case 0:
					{
		
								
									//If readResult=0, below code is executed
										   
									calcDimen(holeData,&gfxWin);
	
									initGraphics(&gfxWin,&soilPalette);
									
									calcHoleCoord(holeData,&gfxWin);
	
									
									
								
	
									showAllData(holeData,label1,label2,&gfxWin);	
								   
				 
									/*This do..while loop calls the routines inside it 
									as long as user does not decide to quit the program*/
								  do{
		
		
		
													mainChoice=displayMainMenu();
		
		
													if(mainChoice==1)
													{
				
																do
																{
																			printf("\nEnter a depth (in meters):");
							
																			fflush(stdin);
							
																			validDepth=scanf("%f",&inputDepth);
							
						
																}while(validDepth==0);
						
							
																inputDepth=fabs(inputDepth);
					
															
																processInput(holeData,soilPalette,inputDepth,label1,label2,&gfxWin,displaySoilMenu(),1);
					
						
													}
		
		
			
	
	
	
										}while(mainChoice!=2);
	
	
				
										break;
					}


	
					case 1:
					{
			
										printf("You have chosen to exit the program because data from the file could not be read.\n Press Enter to exit.");
		
										break;
			
					}
					
					default:
					{
							printf("\nUnexpected error occoured in main(void)\n");
							break;
					}
		
	
	
				}
			return readResult;

	
			

	
	
}
Exemplo n.º 23
0
Arquivo: main.c Projeto: chamboard/Ju
uint8_t displaySeqMenu(char c,sequencer* seqN,uint32_t* errors) {							// showMenu() lets the user edit specific settings of the sequencer passed in sequencer.
	uint8_t c2='\0';																		// 
	uint8_t exit_loop=0;																	// 
	uint8_t count=0;
	uint8_t step=0;
	printf("\n\tSequencer %s menu\n",seqN->name);
	printf("\tType :\t'?' to display status : sense and number of remaining steps.");
	printf("\n\t\t'a' to add 10 steps.\n\t\t's' to change sense.\n");
	printf("\t\t'd' to change steps delay.\n\t\t'r' to return.\n\t\t'q' to exit.\n");
	fflush(stdout);
	while (c2!='q'&&c2!='m'&&c2!='d'&&c2!='r'&&c2!='s'&&c2!='a'&&c2!='?') {
		getch_start();																		//
		c2=getch_try();																		//
		getch_stop();																		// Gets the last character typed without stopping program (see FUNCTIONS above).
	}
	if (c2) {
		//printf("c2 : %c\n",c2);
		if (c2=='q') {
			printf("\n");
			exit_loop=1;																	// If character typed is 'q' : Exits loop.
		}
		else {
			if (c2=='a') {																	// If 'a' is typed : adds 10 step to the sequencer passed to the function.  
				*errors+=CHAN_addr(IO24_NUM,seqN->presetCountAddr);							//  Switch seqN parameter passed to the function, sets current address at address of SEQ_PRESET_COUNT or SEQ2_PRESET_COUNT.
				CHAN_getBytes(IO24_NUM,1,&count);											//  Reads value of current address and store it in the variable count.
				*errors+=CHAN_addr(IO24_NUM,seqN->presetCountAddr);							//  Sets current address at address of SEQ_PRESET_COUNT or SEQ2_PRESET_COUNT.
				*errors+=CHAN_setByte(IO24_NUM,seqN->presetCount+count);					//  Writes count+10 at current address.
				if (!count) {																// If count=0. 
					printf("Restarting sequencer %s for 10 steps.\n",seqN->name);			//  Sequencer is stopped and must be restarted.
					errors+=CHAN_command(IO24_NUM,7);										//
				}
				else printf("Remaining steps for sequencer %s : %d\n",						// Else display number of remaining steps of the sequencer passed to the function.
									seqN->name,seqN->presetCount+count); 
			}
			else if (c2=='?') {																// If '?' is typed : displays status of the sequencer passed to the function.
				*errors+=CHAN_addr(IO24_NUM,seqN->presetCountAddr);							//  Sets current address at address of SEQ_PRESET_COUNT or SEQ2_PRESET_COUNT.
				CHAN_getBytes(IO24_NUM,1,&count);											//  Reads value of current address and store it in the variable count.
				printf("Remaining step(s) for sequencer %s : %d\n",seqN->name,count);		//  Display number of remainings steps of the sequencer passed to the function.
				*errors+=CHAN_addr(IO24_NUM,seqN->presetStepAddr);							//  Switch seqN parameter passed to the function, sets current address at address of SEQ_PRESET_STEP or SEQ2_PRESET_STEP.
				CHAN_getBytes(IO24_NUM,1,&step);											//  Reads value of current address and store it in the variable step.
				if (step==0) printf("sequencer %s does nothing\n",seqN->name);				//
				else if (step==1) printf("sequencer %s increases\n",seqN->name);			//
				else if (step==2) printf("sequencer %s decreases\n",seqN->name);			//  Switch value of step displays sense of the sequencer passed to the function. 
			}
			else if (c2=='s') {																// If character typed is 's' : Edits the sense of the sequencer passed to the fuction.
				if (seqN->presetStep==1) seqN->presetStep=2;
				else if (seqN->presetStep==2) seqN->presetStep=0;
				else seqN->presetStep=1;
				*errors+=CHAN_addr(IO24_NUM,seqN->presetStepAddr);							//  Switch seqN parameter passed to the function, sets current address at address of SEQ_PRESET_STEP or SEQ2_PRESET_STEP into IO24.
				*errors+=CHAN_setByte(IO24_NUM,seqN->presetStep);							//  Writes seqN->presetStep at current address.
				*errors+=CHAN_command(IO24_NUM,7);											//  Executes IO24 command 0x07 named STEPCOUNT_SEQUENCER_RUN because SEQ_PRESET_STEP or SEQ2_PRESET_STEP have been edited.
				if (seqN->presetStep==0) printf("sequencer %s does nothing\n",seqN->name);	//
				else if (seqN->presetStep==1) printf("sequencer %s increases\n",seqN->name);//
				else if (seqN->presetStep==2) printf("sequencer %s decreases\n",seqN->name);//  Switch value of step displays the new sense of the sequencer passed to the function.
			}
			else if (c2=='d') {																// If character typed is 'd' : Edits delay between sequence steps . 
				if (c!='0') {																//  If the sequencer passed to the function is not Seq.
					printf("Seq%c steps delay Ts%c is such as",c,c);						//   Displays SEQ2_ASTEP_INC_TIME and current steps delay of the sequencer Seq2.
					printf(" Ts%c=Tseq*(SEQ%c_ASTEP_INC_TIME+1)",c,c);						//
					printf(" with Tseq=5ms and ");											//
					printf("SEQ%c_ASTEP_INC_TIME=%d\n",c,seqN->astepIncTime);				//
					printf("Enter new value for SEQ%c_ASTEP_INC_TIME=",c);					//   Asks a new vale for SEQ2_ASTEP_INC_TIME.
				}                                   
				else {								                                        //  Else 										
					printf("Seq steps delay Ts is such as Ts=Tseq*(SEQ_ASTEP_INC_TIME+1)");	//   Displays SEQ_ASTEP_INC_TIME and current steps delay of the sequencer Seq. 
					printf(" with Tseq=5ms and SEQ_ASTEP_INC_TIME=%d\n",seqN->astepIncTime);//   
					printf("Enter new value for SEQ_ASTEP_INC_TIME=");						//   
				}																			//   Asks a new vale for SEQ_ASTEP_INC_TIME.
				scanf("%3d",(unsigned int*)&seqN->astepIncTime);							// Stores the new value of SEQ_ASTEP_INC_TIME or SEQ2_ASTEP_INC_TIME into variable seqN.astepIncTime.
					
				*errors+=CHAN_addr(IO24_NUM,seqN->astepIncTimeAddr);						// Switch seqN parameter passed to the function, sets current address at address of SEQ_ASTEP_INC_TIME or SEQ2_ASTEP_INC_TIME.
				*errors+=CHAN_setByte(IO24_NUM,seqN->astepIncTime);							// Writes seqN->astepIncTime at current address.
				if (c!='0') {																//  If the sequencer passed to the function is not Seq.
					printf("Seq%c steps delay Ts%c ",c,c);									//
					printf("is now set such as Ts%c=Tseq*",c);								//
					printf("(SEQ%c_ASTEP_INC_TIME+1)=%dms\n",c,(seqN->astepIncTime+1)*5);	//   Displays new steps delay of Seq2.
				}
				else {																		//  Else
					printf("Seq steps delay Ts is now set such as Ts=Tseq*");				//
					printf("(SEQ_ASTEP_INC_TIME+1)=%dms\n",(seqN->astepIncTime+1)*5);		//   Displays new steps delay of Seq.
				}
			}																				
			if (c2!='r') return displaySeqMenu(c,seqN,errors);								// If charactere typed is not 'r' displays recursively menu of the sequencer passed to the function.
			else printf("return\n");														// Else 
			displayMainMenu();																//  Displays main menu.
		}
	}
	return exit_loop;
}
Exemplo n.º 24
0
Arquivo: main.c Projeto: chamboard/Ju
int main (int argc,char *argv[ ]) {
	
	bus_struct chantilly_stack;
	uint8_t myTXBuffer[1024]={0}; 					 
	uint8_t exit_loop=0;
	uint8_t c=0;
	uint32_t errors=0;
									
	sequencer seq={"Seq\0",0x0F,0x150,0x04,0x141,30,0x144,10,0x1CC,1,0x1CF};	// The sructure storing specific settings to sequencer Seq.
	//  seq.mask=0x0F;									
	//  seq.maskAddr=0x150;															
	//  seq.cursor=0x04;									
	//  seq.cursorAddr=0x141;							
	//  seq.astepIncTime=30;							
	//  seq.astepIncTimeAddr=0x144;					
	//  seq.presetCount=10;							
	//  seq.presetCountAddr=0x1CC;					
	//  seq.presetStep=1;																	
	//  seq.presetStepAddr=0x1CF;	
						
	sequencer seq1={"Seq1\0",0xF0,0x151,0x07,0x1C1,30,0x1C2,10,0x1CD,1,0x1D0};	// The sructure storing specific settings to sequencer Seq1.
	//  seq1.mask=0xF0;									
	//  seq1.maskAddr=0x151;							
	//  seq1.cursor=0x07;								
	//  seq1.cursorAddr=0x1C1;						
	//  seq1.astepIncTime=30;							
	//  seq1.astepIncTimeAddr=0x1C2;				
	//  seq1.presetCount=10;							
	//  seq1.presetCountAddr=0x1CD;					
	//  seq1.presetStep=1;								 									
	//  seq1.presetStepAddr=0x1D0;						
	
	sequencers seqs={0,0x1D2,1,0x146};				                          	// The structure storing common settings to the three sequencers.
	//	seqs.stepcountRestart=0;						  
	//	seqs.stepcountRestartAddr=0x1D2;				 
	//  seqs.wrap=1;									
	//	seqs.wrapAddr=0x146;											

	
	/************************************************************************************************************************************************************************************************************************************************
	*											SETS UP CHANTILLY																										                                                                            *
	************************************************************************************************************************************************************************************************************************************************/
	
	
	if(CHAN_setup("APP100",1)!=0) { printf("Error opening chantilly , error or processID { }\n"); CHAN_close();return 0;}	// stops here if can't open immediate core access mode.
	
	
	/************************************************************************************************************************************************************************************************************************************************
	*											CHECKS CHANTILLY STACK 				                                                                                                                                                                *
	************************************************************************************************************************************************************************************************************************************************/
	
	
	CHAN_checkBUS(&chantilly_stack,1,1);			// Checks what's on the addr1 of the chantilly stack bus.
	CHAN_checkBUS(&chantilly_stack,2,1);			// Checks what's on the addr2 of the chantilly stack bus.
	
	
	/************************************************************************************************************************************************************************************************************************************************
	*											SETS UP UPDATE PERIOD OF SEQUENCED OUTPUTS MODE 				                                                                                                                                    *
	************************************************************************************************************************************************************************************************************************************************/
	
	
	errors+=CHAN_addr4(IO24_NUM,0x52);             	// Sets current address to 0x52*4=0x148 into IO24 (CHAN_addr4() can only access multiple of 4 offsets,
													// 													must do empty reading or writing to increase current address). 
	errors+=CHAN_setByte(IO24_NUM,0x08);           	// Writes 0x08 at current address 0x148 into the IO24 (current address increases automatically).
	errors+=CHAN_setByte(IO24_NUM,0xCF);			// Writes 0xCF at current address 0x149 into the IO24.  
													// Two previous values at addresses 0x148 and 0x149 are used to set  SEQ_USER_VAL=0xCF08 => 0xFFFF-SEQ_USER_VAL=0x30F7=12535. 
	errors+=CHAN_setByte(IO24_NUM,0x01);			// Writes 0x01 at current address 0x14A into IO24.
													// Previous value is used to set SEQ_USER_PRESCA=1 => PRESCAseq=1/4 (0,1,2,..,7 respectively corresponding to 1/2,1/4,1/8,..,1/256). 
	// Sequencer mode is now set with update period, Tseq, such as Tseq=(0xFFFF-SEQ_USER_VAL)*100ns/PRESCAseq=12535*100ns*4=5.014ms.
	// That means, inputs are read every Tseq=5.014ms and sequenced outputs are updated every (SEQ_ASTEP_INC_TIME+1)*Tseq=(SEQ_ASTEP_INC_TIME+1)*5.014ms. 

	
	/************************************************************************************************************************************************************************************************************************************************
	*											SETS UP SEQUENCED OUTPUTS MODE				                                                                                                                                                        *
	************************************************************************************************************************************************************************************************************************************************/
	
	
	/** SETS UP SEQUENCED OUTPUTS */			
	
	errors+=CHAN_addr4(IO24_NUM,0x40);				// Sets current address at 0x40*4=0x100 into IO24.
	errors+=CHAN_setByte(IO24_NUM,0x00);			// Writes 0 at current address 0x100 into IO24. Used to set OUTPUT_A=0. 
	errors+=CHAN_setByte(IO24_NUM,0);				// Writes 0 at current address 0x101 into IO24. Used to set OUTPUT_B=0. 
	errors+=CHAN_addr4(IO24_NUM,0x54);				// Sets current address at 0x54*4=0x150 into IO24.
	errors+=CHAN_setByte(IO24_NUM,seq.mask);		// Writes seq.mask(=0x0F) at current address 0x150 into IO24. Used to set SEQ_MASK=0x0F
	errors+=CHAN_setByte(IO24_NUM,seq1.mask);		// Writes seq1.mask(=0xF0) at current address 0x151 into IO24. used to set SEQ1_MASK=0xF0
	// Since mode of sequencer is 1, Seq and Seq1 play on OutputA such as OutputA=data[SEQ_CURSOR]&SEQ_MASK|data[SEQ1_CURSOR]&SEQ1_MASK|OUTPUT_A with data[X]:value stored at address X and 0x04≤X≤0xFF.
	//								 Seq plays on OutputB such as OutputB=data[SEQ_CURSOR+128]|OUTPUT_B.
	// With above settings Seq1 plays on OutputA bit7, bit6, bit5 and bit4 Seq plays on OutputA bit3, bit2, bit1 and bit0, and on all bits of OutputB. 
	
	
	/** WRITES SEQUENCES VALUES */
	
	myTXBuffer[00]=0x11;							// Seq and Seq1 sequence on OutputA			
	myTXBuffer[01]=0x22;							// (1st sequence of the couple)	
	myTXBuffer[02]=0x44;							//  							
	myTXBuffer[03]=0x88;							//						
	errors+=CHAN_addr(IO24_NUM,0x04);				// Sets current address at 0x04 into IO24.
	errors+=CHAN_setBytes(IO24_NUM,4,myTXBuffer);	// Writes sequence (via myTXBuffer) at current address 0x04 into IO24.
	// Using mode 1 implies that first sequence of the couple is the sequence of Seq and Seq1 on OutputA. This sequence must be stored between included addresses 0x04 and 0x7F in RAM.
	
	myTXBuffer[00]=0x10;							// Seq sequence on OutputB			
	myTXBuffer[01]=0x20;							// (2nd sequence of the couple)	
	myTXBuffer[02]=0x40;							//  							
	myTXBuffer[03]=0x80;							//								
	errors+=CHAN_addr(IO24_NUM,0x84);				// Sets current address at 0x84 into IO24.
	errors+=CHAN_setBytes(IO24_NUM,4,myTXBuffer);	// Writes sequence (via myTXBuffer) at current address 0x04 into IO24.
	// Using mode 1 implies that second sequence of the couple is the sequence of Seq on OutputB. This sequence must be stored between included addresses 0x84 and 0xFF in RAM.
	
	
	/** SETS UP SEQUENCER Seq SETTINGS */
													// Presets via myTXBuffer :
	myTXBuffer[0]=0; 		  						// SEQ_STEP is useless in stepcount mode and replaced by SEQ_PRESET_STEP.
	myTXBuffer[1]=seq.cursor;						// SEQ_CURSOR=0x04 : 	 current RAM address of Seq sequence (permanently overwritten but as Seq increase must be initialized such as SEQ_CURSOR≤SEQ_END).
	myTXBuffer[2]=0x04;								// SEQ_START=0x04 : 	 RAM address where (common) Seq sequence begins.
	myTXBuffer[3]=0x07;   							// SEQ_END=0x08 : 		 RAM address where (common) Seq sequence ends. In mode 0, 0x04≤SEQ_START≤SEQ_END≤0x7F.
	myTXBuffer[4]=seq.astepIncTime;					// SEQ_ASTEP_INC_TIME :  used to change delay Ts between steps of Seq sequence such as Ts=(SEQ_ASTEP_INC_TIME+1)*Tseq=31*0.005014=155.434 ms. => fs=6.43Hz. 
	myTXBuffer[5]=0;								/*********************************************non implementé ??????******************************/
	myTXBuffer[6]=1;								// SEQ_WRAP=1 : 		 plays sequences infinitely by setting SEQ_CURSOR=SEQ_START if SEQ_STEP=1 or SEQ_CURSOR=SEQ_END if SEQ_STEP=2 when Seq sequence ends.
	myTXBuffer[7]=1;								// SEQ_MODE=1 : 		 the two sequencers Seq and Seq1 are independent and play a common sequence asynchronously. Seq and Seq1 settings are required.
	errors+=CHAN_addr4(IO24_NUM,0x50);				// Sets current address at 0x50*4=0x140 into IO24.
	errors+=CHAN_setBytes(IO24_NUM,8,myTXBuffer);	// Writes sequencer Seq settings (stored in myTXBuffer) at current address.
	errors+=CHAN_addr(IO24_NUM,seq.presetCountAddr);// Sets current address at 0x1CC into IO24.
	errors+=CHAN_setByte(IO24_NUM,seq.presetCount);	// Sets SEQ_PRESET_COUNT=10 : sequencer Seq executes 10 steps.
	errors+=CHAN_addr(IO24_NUM,seq.presetStepAddr);	// Sets current address at 0x1CF into IO24.
	errors+=CHAN_setByte(IO24_NUM,seq.presetStep);	// SEQ_PRESET_STEP=seq.presetStep=1 : sequencer Seq increases.
	errors+=CHAN_addr(IO24_NUM,seqs.stepcountRestartAddr);	// Sets current address at 0x1D2 into IO24.
	errors+=CHAN_setByte(IO24_NUM,seqs.stepcountRestart);	// SEQS_STEPCOUNT_RESTART=1 : sets SEQ_CURSOR=SEQ1_CURSOR=SEQ_START when executing the IO24 command named STEPCOUNT_SEQUENCER_RUN.
	// To edit SEQ_MODE and SEQ_WRAP, sequencer mode must be restarted by executing IO24 command 0x07 named STEPCOUNT_SEQUENCER_RUN. 
	// All others sequencer settings can be edited when stepcount sequenced outputs mode is running but it is not advisable.
	
	
	/** SETS UP SEQUENCER Seq1 SETTINGS */
	
	myTXBuffer[0]=0;
	myTXBuffer[1]=seq1.cursor;
	myTXBuffer[2]=seq1.astepIncTime;
	errors+=CHAN_addr4(IO24_NUM,0x70);						// Sets current address at 0x70*4=0x1C0 into IO24.
	errors+=CHAN_setBytes(IO24_NUM,3,myTXBuffer);			// Writes sequencer Seq1 settings (stored in myTXBuffer) at current address.
	errors+=CHAN_addr(IO24_NUM,seq1.presetCountAddr);		// Sets current address at 0x1CD into IO24.
	errors+=CHAN_setByte(IO24_NUM,seq1.presetCount);		// Sets SEQ1_PRESET_COUNT=10 : sequencer Seq1 executes 10 steps.
	errors+=CHAN_addr(IO24_NUM,seq1.presetStepAddr);		// Sets current address at 0x1D0 into IO24.
	errors+=CHAN_setByte(IO24_NUM,seq1.presetStep);			// Sets SEQ1_PRESET_STEP=1 : sequencer Seq1 increases.
	// To edit SEQ1_PRESET_STEP sequencer mode must be restarted by executing IO24 command 0x07 named STEPCOUNT_SEQUENCER_RUN.
	// All others sequencer Seq1 settings can be edited when stepcount sequenced outputs mode is running but it is not advisable.
			
	
	/************************************************************************************************************************************************************************************************************************************************
	*											STARTS SEQUENCED OUTPUTS MODE																																										*
	************************************************************************************************************************************************************************************************************************************************/											
	
	
	errors+=CHAN_command(IO24_NUM,0x07);			// Executes IO24 command 0x07 named STEPCOUNT_SEQUENCER_RUN : Starts (immediate inputs and) stepcount sequenced outputs mode.
	
	
	/************************************************************************************************************************************************************************************************************************************************
	*											LOOPS :			             	                                                                                                                                                                    *
	************************************************************************************************************************************************************************************************************************************************/


	printf("\nIO24 stepcount sequenced outputs mode 1 is started : \n");
	printf("Sequencers Seq and Seq1 are running with respective steps delays Ts and Ts1 set such as ");
	printf("Ts=Tseq*(SEQ_ASTEP_INC_TIME+1) and Ts1=Tseq*(SEQ1_ASTEP_INC_TIME+1) ");
	printf("with SEQ_ASTEP_INC_TIME=SEQ1_ASTEP_INC_TIME=30 and Tseq=5ms ");
	printf("then Ts=Ts1=31*5ms=155ms\n\n");
	displayMainMenu();
	
	
	while (!exit_loop) {														// Entering loop
		getch_start();															//
		c=getch_try();															//
		getch_stop();															//  Gets the last character typed without stopping program (see FUNCTIONS above).
		if (c) {                                                    			//  
			if (c=='q') {														//
				printf("\n");													//
				exit_loop=1;													//   If 'q' is typed exits loop.
			}																	//
			else if (c=='w') invertWrap(&seqs,&errors);							//	 Else if 'w' is typed inverts wrap of the three sequencers (even if Seq2 is unused). . 
			else if (c=='p') pauseResumeSteps(&seq,&seq1,&errors);				//	 Else if 'p' is typed pauses/resumes the two sequencers Seq and Seq1. 
			else if (c=='a') add10Steps(&seq,&seq1,&errors);					//	 Else if 'a' is typed adds 10 steps to the two sequencers Seq and Seq1. 
			else if (c=='?') displayStatus(&seq,&seq1,&errors);					//   Else if '?' is typed displays status.
			else if (c=='0') exit_loop=displaySeqMenu(c,&seq,&errors); 			// 	 Else if '0' is typed displays Seq menu.														
			else if (c=='2') exit_loop=displaySeqMenu(c,&seq1,&errors);			//   Else if '1' is typed displays Seq1 menu.	
		}
	}
	
	
	/************************************************************************************************************************************************************************************************************************************************
	*											EXITS PROGRAM				                                                                                                                                                                        *
	************************************************************************************************************************************************************************************************************************************************/
	
	
	/** STOPS IO24 */
	
	errors+=CHAN_command(IO24_NUM,6);           	// Executes IO24 command 0x06 named STOP : Stops IO24 running mode (optionnal, if not executed IO24 will go on maintening mode
													//																				actually running after having closed chantilly and program).  
	
	/** CLOSES CHANTILLY	*/
	
	errors+=CHAN_close();							// Closes immediate core access mode.
	
	
	/** DEBUG */
	
	printf("\naccess errors : %d\n\n",errors);		// Displays access errors (optionnal for debug).
	fflush(stdout);
	
	return 0;
	
}
Exemplo n.º 25
0
int main() {
	DBMSAPI dbms;	//Declare the dbms api

	initRelations(&dbms);
	cout << displayMainMenu() << endl;

	int searchResults = 0;
	
	while (1) {		//input loop
		string in;
		getline(cin, in);

		vector<string> tokens = splitAtSpace(in);	//split the command given by spaces

		if (tokens[0] == "HELP") {				//process HELP
			cout << displayMainMenu() << endl;
		}
		else if (tokens[0] == "EXIT") {			//process EXIT
			saveRelations(&dbms);
			exit(0);
		}
		else if (tokens[0] == "ADD") {			
			if (tokens[1] == "CAR") {			//process ADD CAR
				vector<string> values;
				for (int i = 2; i < tokens.size(); i++) {
					values.push_back(tokens[i]);
				}
				insertValue("cars", values, &dbms);
				cout << "Addition approved!" << endl << endl;
			}
			else if (tokens[1] == "DEALERSHIP") {//process ADD DEALERSHIP
				vector<string> values;
				for (int i = 2; i < tokens.size(); i++) {
					values.push_back(tokens[i]);
				}
				insertValue("dealerships", values, &dbms);
				cout << "Addition approved!" << endl << endl;
			}
		}
		else if (tokens[0] == "LIST") {			//process LIST
			if (tokens.size() != 5) {
				cout << "Invalid number of arguments!" << endl << endl;
			}
			else {
				//Price INTEGER, Date_Listed VARCHAR(20), VIN VARCHAR(17), Dealership_Name VARCHAR(30)
				string listing = "INSERT INTO listings VALUES FROM (" + tokens[1] + ", " + tokens[2] + ", " + tokens[3] + ", " + tokens[4] + ");";
				dbms.execute(listing);
				cout << "Listing approved!" << endl << endl;
			}
		}
		else if (tokens[0] == "UNLIST") {		//process UNLIST
			if (tokens.size() != 2) {
				cout << "Invalid number of arguments!" << endl << endl;
			}
			else {
				string removeListing = "DELETE FROM listings WHERE (VIN == \"" + tokens[1] + "\");";
				dbms.execute(removeListing);
			}
		}
		else if (tokens[0] == "SELL") {			//process SELL
			if (tokens.size() != 6) {
				cout << "Invalid number of arguments!" << endl << endl;
			}
			else {
				//Price INTEGER, Date_Sold VARCHAR(20), VIN VARCHAR(17), Dealership_Name VARCHAR(30), Buyer_Name VARCHAR(50)
				string sale = "INSERT INTO sales VALUES FROM (" + tokens[1] + ", " + tokens[2] + ", " + tokens[3] + ", " + tokens[4] + ", " + tokens[5] + ");";
				dbms.execute(sale);
				string removeListing = "DELETE FROM listings WHERE (VIN == \"" + tokens[3] + "\");";
				dbms.execute(removeListing);
				string removeInventory = "DELETE FROM cars WHERE (VIN == \"" + tokens[3] + "\");";
				dbms.execute(removeInventory);
				cout << "Sale approved!" << endl << endl;
			}			
		}
		else if (tokens[0] == "INVENTORY") {	//process INVENTORY
			showRelation("cars", &dbms);
		}
		else if (tokens[0] == "DEALERSHIPS") {	//process DEALERSHIPS
			showRelation("dealerships", &dbms);
		}
		else if (tokens[0] == "LISTINGS") {		//process LISTINGS
			showRelation("listings", &dbms);
		}
		else if (tokens[0] == "SALES") {		//process SALES
			showRelation("sales", &dbms);
		}
		else if (tokens[0] == "SEARCH") {		//process SEARCH
			searchResults++;
			stringstream ss;
			ss << searchResults;
			string query = "searchresult" + ss.str() + " <- select (";
			for (int i = 2; i < tokens.size(); i++) {
				query += tokens[i];
				if (i + 1 < tokens.size()) { query += " "; }
			}
			query += ") " + tokens[1] + ";";
			dbms.execute(query);			
			string showResult = "SHOW searchresult" + ss.str() + ";";
			dbms.execute(showResult);
			cout << endl;
		}
		else if (tokens[0] == "UPDATE") {
			if (tokens[1] == "LISTING") {		//process UPDATE LISTING
				if (tokens.size() != 4) {
					cout << "Invalid number of arguments!" << endl;
				}
				else {
					string updateListings = "UPDATE listings SET Price = " + tokens[3] + " WHERE VIN == " + tokens[2] + ";";
					dbms.execute(updateListings);
				}				
			}
		}
		else if (tokens[0] == "CROSS") {		//process CROSS
			string cross = "crossResult <- dealerships * cars;";
			dbms.execute(cross);
			string showCross = "SHOW crossResult;";
			dbms.execute(showCross);
			string closeCross = "CLOSE crossResult;";
			dbms.execute(closeCross);
		}
		else if (tokens[0] == "PROJECT") {		//process PROJECT
			string project = "projectResult <- project (";
			for (int i = 2; i < tokens.size(); i++) {
				project += tokens[i];
				if (i + 1 < tokens.size()) { project += ", "; }
			}
			project += ") " + tokens[1] + ";";
			dbms.execute(project);
			string showProject = "SHOW projectResult;";
			dbms.execute(showProject);
			string closeProject = "CLOSE projectResult;";
			dbms.execute(closeProject);
		}
		else if (tokens[0] == "UNION") {		
			if (tokens[1] == "SEARCHES") {		//process UNION SEARCHES
				string unionQuery = "unionResult <- " + tokens[2] + " + " + tokens[3] + ";";
				dbms.execute(unionQuery);
				string showUnion = "SHOW unionResult;";
				dbms.execute(showUnion);
				string closeUnion = "CLOSE unionResult;";
				dbms.execute(closeUnion);
			}
		}
		else if (tokens[0] == "DIFFERENCE") {	
			if (tokens[1] == "SEARCHES") {		//process DIFFERENCE SEARCHES
				string diffQuery = "diffResult <- " + tokens[2] + " - " + tokens[3] + ";";
				dbms.execute(diffQuery);
				string showDiff = "SHOW diffResult;";
				dbms.execute(showDiff);
				string closeDiff = "CLOSE diffResult;";
				dbms.execute(closeDiff);
			}
		}
		else {									//process unknown command
			cout << "Unknown command!" << endl << endl;
		}

	}
}
Exemplo n.º 26
0
void executeOptionThree(){
	printToIndex();
	displayMainMenu();

}