Exemplo n.º 1
0
int main()
{
  int select;
  int err=1;
  /* array of grid members */
  GridMember** memberList;
  memberList = createGridList();
  /* setting random generator */
  srand(time(NULL));
  /* create game grid members */
  while(err) {
    /* clear screen and always show title */
    displayTitle();
    /* config game options */
    configGame(&select);
    err = createGridMembers(memberList, select);
  }
  /* enter game loop */
  while(1) {
    /* clear screen and always show title */
    displayTitle();
    /* show game grid */
    showGrid(memberList);
    /* count neighbours */
    countNeighbours(memberList);
    /* update status */
    updateGrid(memberList);
    /* time tick */
    timeTick();
  }
  displayEnd();
  freeGridList(memberList);
  return 0;
}
Exemplo n.º 2
0
int main()
{
  char choice;
  char name[80];
  int number;
  int found;
  SymbolTable book;
  int i;
  /* initialize phone book */
  book = createSymbolTable(&makePhoneBook, &comparePhone);

  do{
    choice = getMenu();
    switch(choice){

    case '1':
      printf("Enter the name: ");
      scanf("%[^\n]", name);
      myfflush();
      printf("Enter the number: ");
      scanf("%d", &number);
      myfflush();
      addEntry(&number, &name, &book);
      printf("%d\n", book.total);
      break;

    case '2':
      printf("Enter the number you want to find: ");
      scanf("%d", &number);
      myfflush();
      found = getEntryValue(&number, &book);
      if(found == -1) printf("Not found\n");
      else{
	displayTitle();
	displayEntry(book.entries[found]);
      }      
      break;

    case '3':
      displayTitle();
      for(i = 0; i < book.current; i++){
	displayEntry(book.entries[i]);
      }
      break;

    case '4':
      dropSymbolTable(&book);
      break;
      
    default: printf("Invalid choice\n");
    }
  }while(choice != EXIT);
}
Exemplo n.º 3
0
/** Builds the screen.
*/
void
CASignUpScreen::buildScreen() 
{
    // Counter for cursor animation:
    static float cursorAnim = 0.0;

    // Backgroud:
    //
    CA_RES->menu_bg.draw ( *CA_APP->graphicContext, CL_Rect(0, 0, CA_APP->width, CA_APP->height) );

    // Title / help:
    //
    displayTitle();
    displayHelp();

    // Cursor:
    //
    CL_Draw::fill( *CA_APP->graphicContext, CL_Rectf(racePreview[cursor]->getLeft()-12, racePreview[cursor]->getTop()-12,
                           racePreview[cursor]->getRight()+12, racePreview[cursor]->getBottom()+12),
                           CL_Colorf (255, 216, 84, (int)((cursorAnim/2)*255) ));

    CA_RES->advanceAnimation( &cursorAnim, 1, 2.0, CAResources::Revolving );

    // Race previews:
    //
    for( int race=0; race<3; ++race )
    {
        if( racePreview[race] )
        {
            racePreview[race]->display();
            CA_RES->font_normal_14_white.draw_text( *CA_APP->graphicContext, racePreview[race]->getHCenter(),
                                                racePreview[race]->getTop()-22,
                                                (race==0 ? "Easy" : (race==1 ? "Medium" : "Hard")) );
        }
        if (m_selected == true)
        {
            for (unsigned int pl=0; pl<m_RacePlayer[race].size(); pl++)
            {
                CA_RES->font_normal_14_white.draw_text ( *CA_APP->graphicContext,racePreview[race]->getHCenter(),
                                                    racePreview[race]->getBottom()+22*(pl+1), m_StringRacePlayer[race][pl] );
            }
        }
    }

  
    //
    // UpgradesPanel
    UpgradesPanel uPanel(CA_APP->player[0], CA_RES->font_normal_14_white, CA_RES->font_lcd_13_green, racePreview[2]->getRight() + 32, racePreview[0]->getTop()-22);
    uPanel.display();
    
}
Exemplo n.º 4
0
void uw_htmloutput(FILE *outP, GAME_AREA *ga, char ** inv, int inc, int is_interactive, int has_table, int init)
{
	if((trxFp = fopen(TRAXSKELFILE, "r")) == NULL)
		exit(4);

	if (is_interactive)
		fprintf(outP, "Content-Type: text/html\n\n");

	writeSkeleton(outP);
	displayTitle(outP, init);
	writeSkeleton(outP);
	displayHeader(outP, init);
	writeSkeleton(outP);
	displayMoves(outP, inv, inc, has_table, init);
	writeSkeleton(outP);
	displayBoard(outP, ga, has_table);
	writeSkeleton(outP);
	displayForm(outP, inv, inc, has_table, init);
	writeSkeleton(outP);

	fclose(trxFp);
	trxFp = NULL;
}
Exemplo n.º 5
0
void run() {
	displayTitle();
	displayIntroMessage();

	outputFlagContainer *outputFlags = malloc(sizeof(outputFlagContainer));

	while(true) {
		displayPreGameMenu();

		outputFlags = getUserInput(outputFlags);
		if (outputFlags->HELP) {
			displayHelpMessage();
		} else if (outputFlags->YES || outputFlags->PLAY) {
			gameloop(outputFlags);
		} else if (outputFlags->QUIT || outputFlags->NO) {
			displayQuitMessage();
			break;
		} else {
			displayBadInputMessage();
		}
	}

	free(outputFlags);
}
/** Builds the screen.
*/
void
CAChampionshipScreen::buildScreen() 
{
    // Background:
    //
    m_background.draw ( *CA_APP->graphicContext, CL_Rect(0, 0, CA_APP->width, CA_APP->height) );
    displayTitle();

    CL_Draw::fill( *CA_APP->graphicContext, CL_Rectf(left, top, right, bottom), CL_Colorf(0, 0, 0, 64) );
    
    const int rankWidth = 30;
    const int rankLeft = 0;

    const int nameWidth = 200;
    const int nameLeft = 50;

    const int addPtWidth = 30;
    const int addPtLeft = 260;

    const int totalPtWidth = 50;
    const int totalPtLeft = 300;

    const int caWidth = (totalPtLeft + totalPtWidth)*2;
    const int middleMargin = 30;
   

    const int caHeight = (barHeight * m_player.size())/2;
    const int marginTop = (top+bottom)/2 - caHeight/2;

    for (unsigned int rank=0; rank < m_player.size(); rank++)
    {
        std::ostringstream ossRankStr, ossTotalPoints, ossRacePoints;
        ossRankStr << rank + 1 << ".";
        ossTotalPoints << m_player[rank]->getTotalPoints();
        int marginLeft = (right+left)/2 + middleMargin/2;
        int upPos = rank - m_player.size()/2; 
        if (rank < m_player.size()/2 )
        {
            marginLeft -= caWidth/2 + middleMargin;
            upPos = rank;
        }
        // Buttons:
        //
        m_button.draw ( *CA_APP->graphicContext, CL_Rect(marginLeft+rankLeft, marginTop+barHeight*upPos, marginLeft+rankLeft+rankWidth, marginTop+(barHeight*(upPos+1))) );
        m_button.draw ( *CA_APP->graphicContext, CL_Rect(marginLeft+nameLeft, marginTop+barHeight*upPos, marginLeft+nameLeft+nameWidth, marginTop+(barHeight*(upPos+1))) );
        if (m_displayMode != DISPLAY_CHAMPIONSHIP)
        {
            for (int i=0; i<= int(m_displayMode); i++)
            {
                std::vector<Player*>::const_iterator it = std::find(m_runningPlayers[i].begin(), m_runningPlayers[i].end(), m_player[rank]);
                if (it != m_runningPlayers[i].end() && m_player[rank]->getRacePoints() != 0)
                {
                    CL_Image buttonToUse = (i==0 ? m_buttonEasy : (i==1)? m_buttonMedium : m_buttonHard); // Choose the button color
                    buttonToUse.draw ( *CA_APP->graphicContext, CL_Rect(marginLeft+addPtLeft, marginTop+barHeight*upPos, marginLeft+addPtLeft+addPtWidth, marginTop+(barHeight*(upPos+1))) );
                    ossRacePoints << "+" << m_player[rank]->getRacePoints();
                }
            }
        }
        m_button.draw ( *CA_APP->graphicContext, CL_Rect(marginLeft+totalPtLeft, marginTop+barHeight*upPos, marginLeft+totalPtLeft+totalPtWidth,  marginTop+(barHeight*(upPos+1))) );

        // Texts:
        //
        const int textPosX = marginLeft;
        const int textPosY = marginTop + 4 + barHeight*upPos;
        m_font.draw_text( *CA_APP->graphicContext, textPosX+rankLeft+rankWidth/2, textPosY,  ossRankStr.str());
        m_font.draw_text( *CA_APP->graphicContext, textPosX+nameLeft+nameWidth/2, textPosY, m_player[rank]->getName() );
        m_font.draw_text( *CA_APP->graphicContext, textPosX+addPtLeft+addPtWidth/2, textPosY, ossRacePoints.str() );
        m_font.draw_text( *CA_APP->graphicContext, textPosX+totalPtLeft+totalPtWidth/2, textPosY, ossTotalPoints.str() );
    }
}
Exemplo n.º 7
0
void _entryPoint()
{
	struct Services services;
	
	/****************************>           Get Handles           <****************************/
	//Get a handle to coreinit.rpl
	OSDynLoad_Acquire("coreinit.rpl", &services.coreinit_handle);
	//Get a handle to vpad.rpl */
	unsigned int vpad_handle;
	OSDynLoad_Acquire("vpad.rpl", &vpad_handle);
	/****************************>       External Prototypes       <****************************/
	//VPAD functions
	int(*VPADRead)(int controller, VPADData *buffer, unsigned int num, int *error);

	//OS functions
	void(*_Exit)();
	
	/****************************>             Exports             <****************************/
	//VPAD functions
	OSDynLoad_FindExport(vpad_handle, 0, "VPADRead", &VPADRead);

	// Draw functions
	OSDynLoad_FindExport(services.coreinit_handle, 0, "OSScreenPutPixelEx", &services.OSScreenPutPixelEx);
	OSDynLoad_FindExport(services.coreinit_handle, 0, "DCFlushRange", &services.DCFlushRange);
	OSDynLoad_FindExport(services.coreinit_handle, 0, "OSScreenFlipBuffersEx", &services.OSScreenFlipBuffersEx);
	OSDynLoad_FindExport(services.coreinit_handle, 0, "OSScreenGetBufferSizeEx", &services.OSScreenGetBufferSizeEx);
	OSDynLoad_FindExport(services.coreinit_handle, 0, "OSScreenPutFontEx", &services.OSScreenPutFontEx);
	OSDynLoad_FindExport(services.coreinit_handle, 0, "OSScreenClearBufferEx", &services.OSScreenClearBufferEx);
	//OS functions
	OSDynLoad_FindExport(services.coreinit_handle, 0, "_Exit", &_Exit);
	cleanSlate(&services);
	
	/****************************>             Globals             <****************************/
	struct SpaceGlobals mySpaceGlobals;
	//Flag for restarting the entire game.
	mySpaceGlobals.restart = 1;
	mySpaceGlobals.services = &services;

	// initial state is title screen
	mySpaceGlobals.state = 1;
	mySpaceGlobals.titleScreenRefresh = 1;

	//Flags for render states
	mySpaceGlobals.renderResetFlag = 0;
	mySpaceGlobals.menuChoice = 0; // 0 is play, 1 is password
	
	// setup the password list
	unsigned int pwSeed = 27;
	int x;
	for (x=0; x<100; x++)
		mySpaceGlobals.passwordList[x] = (int)(prand(&pwSeed)*100000);
	
	// set the starting time
	int64_t (*OSGetTime)();
    OSDynLoad_FindExport(services.coreinit_handle, 0, "OSGetTime", &OSGetTime);
	mySpaceGlobals.seed = OSGetTime();
	
	/****************************>            VPAD Loop            <****************************/
	int error;
	VPADData vpad_data;
	
	// decompress compressed things into their arrays, final argument is the transparent color in their palette
	decompress_sprite(3061, 200, 100, compressed_title, mySpaceGlobals.title, 39);
	decompress_sprite(511, 36, 36, compressed_ship, mySpaceGlobals.orig_ship, 14);
	decompress_sprite(206, 23, 23, compressed_enemy, mySpaceGlobals.enemy, 9);
	
	// setup palette and transparent index
	mySpaceGlobals.curPalette = ship_palette;
	mySpaceGlobals.transIndex = 14;
	
	// initialize starfield for this game
	initStars(&mySpaceGlobals);
	
	mySpaceGlobals.invalid = 1;
		
	while (1)
	{
		VPADRead(0, &vpad_data, 1, &error);
		
		//Get the status of the gamepad
		mySpaceGlobals.button = vpad_data.btn_hold;
		
		mySpaceGlobals.rstick = vpad_data.rstick;
		mySpaceGlobals.lstick = vpad_data.lstick;
		
		mySpaceGlobals.touched = vpad_data.tpdata.touched;
		if (mySpaceGlobals.touched == 1)
		{
			mySpaceGlobals.touchX = ((vpad_data.tpdata.x / 9) - 11);
			mySpaceGlobals.touchY = ((3930 - vpad_data.tpdata.y) / 16);
		}
		
		if (mySpaceGlobals.restart == 1)
		{
			reset(&mySpaceGlobals);
			mySpaceGlobals.restart = 0;
		}
		
		if (mySpaceGlobals.state == 1) // title screen
		{
			displayTitle(&mySpaceGlobals);
			doMenuAction(&mySpaceGlobals);
		}
		else if (mySpaceGlobals.state == 2) // password screen
		{
			displayPasswordScreen(&mySpaceGlobals);
			doPasswordMenuAction(&mySpaceGlobals);
		}
		else if (mySpaceGlobals.state == 3) // pause screen
		{
			displayPause(&mySpaceGlobals);
			doMenuAction(&mySpaceGlobals);
		}
		else if  (mySpaceGlobals.state == 4) // game over screen
		{
			displayGameOver(&mySpaceGlobals);
			doMenuAction(&mySpaceGlobals);
		}
		else 	// game play
		{
			//Update location of player1 and 2 paddles
			p1Move(&mySpaceGlobals);

			// perform any shooting
			p1Shoot(&mySpaceGlobals);
			
			// handle any collisions
			handleCollisions(&mySpaceGlobals);
			
			// do explosions
			handleExplosions(&mySpaceGlobals);
			
			// if we're out of lives, break
			if (mySpaceGlobals.lives <= 0 && mySpaceGlobals.state == 4)
				continue;
			
			// add any new enemies
			addNewEnemies(&mySpaceGlobals);
			
			//Render the scene
			render(&mySpaceGlobals);
			
			// check for pausing
			checkPause(&mySpaceGlobals);
		}
		//To exit the game
		if (mySpaceGlobals.button&BUTTON_HOME)
		{
			break;
		}

	}
	cleanSlate(mySpaceGlobals.services);
	_Exit();
}