Esempio n. 1
0
static void fight(char_t *c)
{
	// Always hit the enemy first
	int damage = getDamage(getPlayer(), c);

	char buf[50];
	if(!doDamage(c, damage)){
		getPlayer()->stats.xp += c->stats.xp;
		removeCharMap(&map, c);

		sprintf(buf, "You killed \"%s\"", getNameFromChar(c));
		popupText(buf);

		checkLevelUp();
		return;
	}else{
		sprintf(buf, "You deal %d damage", damage);
		popupText(buf);
	}

	damage = getDamage(c, getPlayer());
	sprintf(buf, "You take %d damage", damage);
	popupText(buf);
	if(!doDamage(getPlayer(), damage)){
		getPlayer()->stats.health = 0;
		die();
	}
}
	int ICharacter::checkLevelUp(int exp) 		//Checks to see if a character's exp passed the level up threshold
	{			
		int currentExp = this -> exp,
			level = this -> level, 
			nextLevelEXP;

		if(currentExp >= (nextLevelEXP = (level * (level + 1) * 500)))
		{				
			levelUp();

			return checkLevelUp(currentExp - nextLevelEXP);
		}

		return currentExp;
	}
Esempio n. 3
0
int gameScreen(int lv0, int sc0){
	int i, inp;
	
	if( lv0 >= MAX_LEVEL || lv0 < 0 ){
		fprintf(stderr, "レベル指定が不正です\n");
		exit(1);
	}
	initGame(lv0, sc0);
	gdscr_initscr();
	
	gdscr_refresh();
	drawString(6, 40, "Press space key to start", FORMAT_CENTER);
	while( 1 ){
		inp = getch();
		if( inp == ' ' )break;
		if( inp == 'q' )break;
	}
	
	timeout(0);
	setLevel(LEVEL);
	while( !gbump_check() && inp != 'q' ){
	
		/*sleep処理*/
		usleep(DELAY);
	
		/*入力受付処理*/
		inp = getch();
		if( inp == ' ' ) gjump_flagSet();
		
		/*レベルアップ処理*/
		if( checkLevelUp() ){
			LEVEL++;
			setLevel(LEVEL);
		}
		
		/*画面更新処理*/
		gfield_shiftl();
		gobstacle_put(&FIELD[FIELD_WIDTH - 1]);
		gjump_jumpPlayer();
		SCORE++;
		gdscr_refresh();
	}
	
	/*終了処理*/
	setHighScore(SCORE);
	SCORE_HIGH = getHighScore();
	timeout(-1);
	freeMatrix(PLAYER_MATRIX);
	PLAYER_MATRIX = PLAYER_MATRIX_LOSE;
	
	/*終了画面描画*/
	gdscr_draw();
	drawString(5, 5, "GAME OVER.", FORMAT_LEFT);
	printCommand(22, 76, FORMAT_RIGHT, COMMAND_LIST, COMMAND_NUM);
	refresh();
	
	/*コマンド取得*/
	inp = getCommand(COMMAND_LIST, COMMAND_NUM);
	
	/*開放*/
	freeMatrix(PLAYER_MATRIX_LOSE);
	gobstacle_memFree();
	gdscr_endwin();
	
	/*メッセージ返却*/
	switch( inp ){
		case 'r':
			return COMMAND_RETRY;
		case 'm':
			return COMMAND_MENU;
		case 'q':
			return COMMAND_QUIT;
		default:
			return 9999;
	}
}
	void ICharacter::gainExperience(int exp)					//After spending exp to level up (if level up is possible with amount of exp), 
		{														//the remaining amount of exp becomes the new value
			this -> exp = checkLevelUp(exp);			
		}