Example #1
0
int main( void )
{
	char c;
	int moveDirection;				// 移動方向

	srand( time( NULL ) );			// Stinker戦闘のため乱数を初期化

	// 初期化
	initialiseDungeon();					// ダンジョンの初期化
	initialisePrince();						// プリンスの情報を初期化
	initialiseStinkers();					// Stinkerの情報を初期化
	initialiseGameEndingConditions();		// ゲームの終了条件を初期化
	printGameExplanation();					// ゲームのルールを表示

	// ゲームループ:勝利条件と敗北条件が満たしていないまで続く
	while( 1 )
	{
		showDungeon();							// ダンジョンの情報を表示
		showRoomInfo();							// 部屋の情報を表示

		checkStinkerFight();					// Stinkerがいるなら戦闘
		if( princeDead )						// Stinkerに負けた(敗北)
		{
			break;
		}
		if( rescuedPrincess )					// Super Stinkerを倒した(勝利)
		{
			break;
		}
		tryPickUpSword();						// 刀があるなら獲得
		tryDrinkHealthPotion();					// 健康ポーションがあるか、使うかのチェック

		moveDirection = getUserMove();			// ユーザーから移動方向を入力してもらう
		movePrince( moveDirection );			// ユーザが選んだ方向にプリンスを移動させる

	}

	// 勝利か敗北のメッセージでゲーム終了する
	printf( "\n" );
	printf( "*************\n" );
	printf( "* GAME OVER *\n" );
	printf( "*************\n" );
	if( rescuedPrincess )
	{
		printf( "You have defeated the Stinkers and saved your princess.\n" );
		printf( "Of course, you and your princess live happily ever after.\n" );
	}
	else
	{
		printf( "You died in battle and the Stinkers dance happily on your grave.\n" );
		printf( "Of course, they keep the princess in their dungeon forever.\n" );
	}
	printf( "\nPress any key to continue.\n" );
	c = getchar();

	return 0;
}
Example #2
0
//Just one possibility for mixing in AI and human
//Students can modify however they like.
action getMove(Game g){

  action move;
  if(getWhoseTurn(g) == UNI_A || getWhoseTurn(g) == UNI_B){
     move = decideAction(g); //AI
  } else {
      move = getUserMove(g);
  }
  return move;
}
Example #3
0
int main()
/* This is the main procedure of the tictactoe program
 * everything happens here.
 * Pre-condition: none
 * Post-condition: there was no problems
*/
{
	//program starts

	//create the intial game state structure
	infoPtr gameInfo = createInitialGameState();

	//find out if the user wishes to play and who must go first
	startAGame(gameInfo);

	//this is the main loop of the program
	//gameInfo->turn can only be EMPTY when the user doesn't want to play anymore
	while (gameInfo->turn != EMPTY)
	{
		//it's the user's turn to make a move
		if (gameInfo->turn == USER)
		{
			getUserMove(gameInfo);
		}else
		//it's the computer's turn to make a move
		{
			printf("Computing computer move...\n");
			getComputerMove(gameInfo);
		}

		//show how the game area now looks
		displayGameArea(gameInfo);

		//do we have a winner?, do we have a tie?, change turn?
		getMatchState(gameInfo);

		//if there was a tie or a win we need to ask if the user want's to play again
		if (gameInfo->turn == EMPTY)
		{
			//reset the play area
			resetPlayArea(gameInfo);
			//ask if we're playing
			startAGame(gameInfo);
		}
	}
	//shutdown everything
	shutDown(gameInfo);

	//program ends
}
Example #4
0
void PosController::ZMove()
{
	//TODO:Need to set value
	curAxis  = Z_Axis;
	axisMove(curAxis,curZStart,curZAcc,curZSpeed,getUserMove(m_zPercent));
}
Example #5
0
void PosController::YMove()
{
	//TODO:Need to set value
	curAxis  = Y_Axis;
	axisMove(curAxis,curStart,curAcc,curSpeed,getUserMove(m_yPercent));
}
Example #6
0
/// <summary>
/// 多轴运动函数
/// </summary>
/// <param name="UseAxis">轴号:0:X   1:Y   2:Z   3:T</param>
/// <param name="UseStart"></param>
/// <param name="UseAcc"></param>
/// <param name="UseSpeed"></param>
/// <param name="UseMove"></param>运动方向: 
void PosController::axisXYMove( double UseStart, double UseAcc, double UseSpeed)
{
	if (!check_Val(UseStart, MAX_START_SPEED/*,  HT_Public.AxisName[this.UseAxis] + " 轴起始速度必须正数,且只允许[ 0-" + MaxStartSpeed.ToString().Trim() + " ]之间数值!"*/))
	{
		return;
	}
	if (!check_Val(UseAcc, MAX_ACC_SPEED/*, HT_Public.AxisName[this.UseAxis] + " 轴加减速度必须正数,且只允许[ 0-" + MaxAccSpeed.ToString().Trim() + " ]之间数值!"*/))
	{
		return;
	}
	if (!check_Val(UseSpeed, MAX_RUN_SPEED/*, HT_Public.AxisName[this.UseAxis] + " 轴运行速度必须为正数,且只允许[ 0-" + MaxRunSpeed.ToString().Trim() + " ]之间数值!"*/))
	{
		return;
	}

	// 	if (!check_Val(UseMove, 0/*, HT_Public.AxisName[this.UseAxis] + " 轴运行位移必须为正数!"*/))
	// 	{
	// 		return;
	// 	}

	double UseEncConst = PulseUnit[X_Axis];  //获取脉冲当量


	float tempPercent = min(abs(m_xPercent), abs(m_yPercent));

	int start   = (int)(UseStart * UseEncConst * tempPercent);		    //启动速度
	double fAcc = (double)(UseAcc * UseEncConst * tempPercent);				//加速度
	int speed   = (int)(UseSpeed * UseEncConst * tempPercent);		    //运行速度
	
	if (!isConnected()) 
	{
		return;
	}
	//检测当量轴是否在运动
	if (!checkAxisDown(X_Axis) || !checkAxisDown(Y_Axis)) 
	{
		return;
	}

	long DistArray[2] = {0};
	DistArray[0] = getUserMove(m_xPercent) * UseEncConst; 
	DistArray[1]= getUserMove(m_yPercent) * UseEncConst;

	//检测轴是否到极限
	if (!check_Limit(X_Axis, getUserMove(m_xPercent),true))
	{
		YMove();
		return;
	}
	if (!check_Limit(Y_Axis, getUserMove(m_yPercent), true))
	{
		XMove();
		return;
	}

	//停止当前轴
	d1000_immediate_stop(X_Axis);
	d1000_immediate_stop(Y_Axis);


	short AxisArray[2] = {X_Axis, Y_Axis};
	d1000_start_t_line (2,AxisArray,DistArray, start, speed,fAcc);
}
Example #7
0
void getUserMove(infoPtr gameInfo)
/* This procedure get's the user's next move and applies it
 * Pre-condition: gameInfo exists
 * Post-condition: the user's move has been added to game info
*/
{
	if (gameInfo != NULL)
	{
		char input;
		int row,col;

		//ask in which row does the user want to play
		printf("\nMake your move!\nWhat row? (1-3):");

		//get the input
		input = getchar();

		if (input == 10)
		{
			//newline received after enter was hit
			input =  getchar();
		}

		//was the row a valid value (1-3)
		while ((input < 49) || (input > 51))
		{
			//it was not, tell the user
			printf("You must enter a value between 1 and 3\nWhat row? (1-3):");
			//get the input
			input = getchar();

			if (input == 10)
			{
				//newline received after enter was hit
				input =  getchar();
			}
		}
		//turn the ascii value into an int value
		row = input - 48;

		//ask which column the user want to play
		printf("What Column? (1-3):");

		//get the input
		input = getchar();

		if (input == 10)
		{
			//newline received after enter was hit
			input =  getchar();
		}

		//was the column a valid value (1-3)
		while ((input < 49) || (input > 51))
		{
			//it was not, tell the user
			printf("You must enter a value between 1 and 3\nWhat column? (1-3):");
			//get the input
			input = getchar();

			if (input == 10)
			{
				//newline received after enter was hit
				input =  getchar();
			}
		}
		//turn the ascii value into an int value
		col = input - 48;

		//now we check if the square the user wants to play on is available
		if (gameInfo->playArea[row-1][col-1] == EMPTY)
		{
			//it is available
			gameInfo->playArea[row-1][col-1] = USER;
		}else
		{
			printf("\nSorry this square has already been taken!\nTry again");
			//get the move again
			getUserMove(gameInfo);
		}
	}
}