示例#1
0
文件: Guess.c 项目: TC01/gcc4ti
void _main(void)
{
  const char *text;
  const char *ptr;
  char buffer[10];
  int number,guessed,dialogkey;
  HANDLE dialog;
  rand_seed=137*peek(0x600017);  // pick the seed from the timer
  while(TRUE)
    {
      text="Guess the number between 1 and 1000";
      number=0; guessed=1+randomnum(1000);
      while(TRUE)
        {
          *buffer=0;
          if(!(dialog=DialogNewSimple(140,50))) return;
          DialogAddTitle(dialog,"~GUESS THE NUMBER~ GAME",BT_OK,BT_CANCEL);
          if(number!=guessed)
            DialogAddRequest(dialog,4,24,"Enter the number",0,5,5);
          else
            {
              text="YOU GUESSED THE NUMBER!!!";
              DialogAddText(dialog,4,24,"Press ENTER for a new game...");
            }
          DialogAddText(dialog,4,15,text);
          dialogkey=DialogDo(dialog,CENTER,CENTER,buffer,NULL);
          HeapFree(dialog);
          if(dialogkey!=13) return;
          if(number==guessed) break;
          number=0; ptr=buffer;
          while(isdigit(*ptr)) number=10*number+(*ptr++)-'0';
          if(*ptr) text="Non-digit character entered!";
          else if(guessed>number) text="Sorry, my number is greater!";
          else if(guessed<number) text="Sorry, my number is smaller!";
        }
    }
}
示例#2
0
文件: gfx.c 项目: bcherry/bcherry
// drawHiScoreBoard - draws the hiscore board, and updates it with the hiscore from the latest game
void drawHiScoreBoard(unsigned long int newscore) {
	SCORE scores[MAX_HISCORES];
	short int loop, pos = -1;
	char name[10], str[50], *error = "File I/O Error";
	HANDLE dlg;

	// restore interrupt handlers
	OSSetSR(0x0000);

	if (!loadHiScores(scores)) {
		// cannot open hiscore file -- display error
		DlgMessage(error,"Unable to Load HiScore Data",BT_OK,BT_NONE);
		return;
	}

	// check if latest score is a highscore
	for (loop = (MAX_HISCORES - 1); loop >= 0; loop--) {
		if (newscore > scores[loop].score) {
			// new HiScore!!
			pos = loop;
		}
	}

	if (pos != -1) {
		// if we found a new hiscore
		if ((dlg = DialogNewSimple(DLGWIDTH,DLGHEIGHT)) == H_NULL) {
			DlgMessage("Memory Allocation Error","Not Enough Free Memory!",BT_OK,BT_NONE);
		} else {
			DialogAddTitle(dlg,"New Hiscore!",BT_OK,BT_NONE);
			DialogAddRequest(dlg,5,25,"Your Name:",0,9,11);

			sprintf(str,"You earned the #%hd hiscore position!",pos+1);
			DialogAddText(dlg,5,15,str);

			do {
				// truncate name variable
				name[0] = 0;
			} while (DialogDo(dlg,CENTER,CENTER,name,NULL) != KEY_ENTER);

			// free the dialog box memory
			HeapFree(dlg);

			// move the hiscore list down
			if (pos < (MAX_HISCORES - 1)) {
				for (loop = (MAX_HISCORES - 1); loop > pos; loop--) {
					scores[loop].score = scores[loop - 1].score;
					scores[loop].name[0] = 0;
					strcpy(scores[loop].name,scores[loop - 1].name);
				}
			}

			// fill in the new hiscore
			scores[pos].score = newscore;
			scores[pos].name[0] = 0;
			strcpy(scores[pos].name,name);

			if (!saveHiScores(scores)) {
				DlgMessage(error,"Unable to save HiScore Board",BT_OK,BT_NONE);
			}
		}
	}

	// display the hiscore board

	// clear the screen
	ClrScr();

	// draw the screen borders
	drawBorder();

	// draw the game logo
	drawLogo();

	FontSetSys(F_8x10);
	DrawStr(25,35,"Hiscore Board",A_NORMAL);
	FontSetSys(F_6x8);

	for (loop = 0; loop < 5; loop++) {
		printf_xy(20,50+loop*10,"#%hd %-9s %lu",loop+1,scores[loop].name,scores[loop].score);
	}

	ngetchx();

	// disable interrupts
	OSSetSR(0x0700);

	// wait for keypresses to dissipate
	delay(KEYDELAY);
}
示例#3
0
文件: t2048.c 项目: 1cook/t2048
// Main Function
void _main( void ){
	//Create or load savefile
	SAVE gameState;
	if(readSave(&gameState))
		makeSave(&gameState);
	writeSave(&gameState); /*just to test whether writing is possible here
	so the player doesn't spend a long time and lose their progress*/
	//Buffer for the text at the bottom of the
	scoreString = (char*)malloc(60*sizeof(char));
	if(scoreString == NULL)
		exit(ER_MEMORY);
	
	//Pause menu
	pauseMenu = PopupNew(strConv[11], 50);
	if(pauseMenu == H_NULL)
		memkill(4, ER_MEMORY);
		PopupAddText(pauseMenu, -1, "New Game", 1);
		PopupAddText(pauseMenu, 0, "Options", 2);
			PopupAddText(pauseMenu,2,"Toggle Animations",5);
			PopupAddText(pauseMenu,2,"Reset Save Data",6);
			PopupAddText(pauseMenu, -1, "Exit", 3);
			PopupAddText(pauseMenu, -1, "About", 4);
	
	//Hiscore Name Entry
	nameBox = DialogNewSimple(140,35);
	if(nameBox == H_NULL)
		memkill(3, ER_MEMORY);
		DialogAddTitle(nameBox,"NEW HISCORE!",BT_OK,BT_NONE);
		DialogAddRequest(nameBox,3,14,"Name:", 0, 10, 14);
	
	//Game Over Entry
	gameOver = PopupNew("GAME OVER!", 40);
	if(gameOver == H_NULL)
		memkill(2, ER_MEMORY);
		PopupAddText(gameOver,-1,"Try Again",1);
		PopupAddText(gameOver,-1,"Exit",2);
	
	
	//About Dialouge
	aboutBox = DialogNewSimple(140,80);
	if(aboutBox == H_NULL)
		memkill(1, ER_MEMORY);	
		DialogAddTitle(aboutBox,"ABOUT",BT_OK,BT_NONE);

			DialogAddText(aboutBox, 3, 13, "2048: A sliding tile puzzle");
			DialogAddText(aboutBox, 3, 21, "Ti68k port by Harrison Cook");
			DialogAddText(aboutBox, 3, 29, "Original game by Gabriele Cirulli");
			DialogAddText(aboutBox, 3, 37, "\"Based on\" 1024 by Veewo Studio");
			DialogAddText(aboutBox, 3, 45, "\"Conceptually Similar to\":");
			DialogAddText(aboutBox, 3, 52, "Threes by Asher Vollmer");
			DialogAddText(aboutBox, 3, 59, "Built using TIGCC");
	
	ClrScr();
	FontSetSys(F_8x10);
	randomize();
	short int key;
	for(;;){
		ClrScr();
		drawGrid(gameState.grid);
		sprintf(scoreString, "Score: %lu Hiscore: %lu by %s", gameState.score, gameState.bscore, gameState.name);
		if(!isGridAvailable(gameState.grid)){
			
			if(gameState.score > gameState.bscore){
					DialogDo(nameBox,CENTER,CENTER,	gameState.name,NULL);
					gameState.bscore = gameState.score;
					FontSetSys(F_8x10);
			}
			gameState.score = 0;
			initGrid(gameState.grid);
			switch(PopupDo(gameOver,CENTER,CENTER,0)){
			case 1:
				continue;
				break;
			default:
				goto endGame;
				
			}
		}
		ST_helpMsg(scoreString);
		nodraw:
		ST_busy(ST_IDLE);
		key = ngetchx();
		ST_busy(ST_BUSY);
		ST_helpMsg(scoreString);
		char move = 4;
		if(key == KEY_UP)
			move = UP;
		else if(key == KEY_RIGHT)
			move = RIGHT;
		else if(key == KEY_DOWN)
			move = DOWN;
		else if(key == KEY_LEFT)
			move = LEFT;
		else if(key == KEY_OFF || key==KEY_ON)
			//Turn the calculator off during a game. Resume it later
			off();
		else if(key == KEY_ESC){ //Brings up the pause menu
			switch (PopupDo(pauseMenu,CENTER,CENTER,0)){
				case 1: //1. New Game
					gameState.score = 0;
					initGrid(gameState.grid);
					break;
				//case 2: //2. Options
					//this is a submenu
				case 3: //3: Exit
					endGame:
					writeSave(&gameState);
					memkill(0,0);
					break;
				case 4: //4: About
					DialogDo(aboutBox,CENTER,CENTER,NULL,NULL);
					//Dialog sets the font weirdly, set it back
					FontSetSys(F_8x10);
					break;
				case 5: //1. Toggle Animations
					gameState.animations = !gameState.animations;
					break;
				case 6: //2. Reset Saved Data
					makeSave(&gameState);
					break;
			}
		}
		else goto nodraw;
		if(move < 4){
			if(isDirectionAvailable(gameState.grid, move)){
				shiftGrid(gameState.grid,move,&gameState.score, gameState.animations);
				pushNewTile(gameState.grid);
			}
			else goto nodraw;
		}
	}
}