Ejemplo n.º 1
0
Game::Game(CoordinateSystem2d* system): 
	m_system(system), 
	m_restart(false),
	frames_to_cheer(0),
	cheer_start(0),
	m_last_time(0), 
	m_dt(0) {
	ResetScore();
	srand((unsigned int)time(NULL));
};
void StartGame() {
  SCORE score;
  ResetScore(&score);
  while (1) {
    p_r_s player_choice;
    p_r_s machine_choice;
    // What the player picks?
    char c = GetUserInput();
    // Do we choose a control key rather than p r s?
    int controlKey = 0;
    switch (c) {
    case 'p':
      player_choice = paper;
      break;
    case 'r':
      player_choice = rock;
      break;
    case 's':
      player_choice = scissors;
      break;
    case 'g':
      PrintScore(&score);
      controlKey = 1;
      break;
    case 'h':
      PrintHelp();
      controlKey = 1;
      break;
    case 'e':
      PrintScore(&score);
      exit(0);
    default:
      PrintHelp();
      controlKey = 1;
      break;
    }
    if (controlKey)
      continue;
    // What the machine picks?
    machine_choice = MachineSelect();
    outcome re = Compare(player_choice, machine_choice); 
    PrintRoundResult(player_choice, machine_choice, re);
    SaveScore(re, &score);
  }
  return;
}
Ejemplo n.º 3
0
void CGameStats::OnGameplayEvent(IEntity *pEntity, const GameplayEvent &event)
{
/*	for(int i=0;i<gEventNamesNum;++i)
	{
		if(gEventNames[i].key == event.event)
		{
			CryLog("GameStats : Event %s",gEventNames[i].name);
		}
	}*/

	int e_id = pEntity ? (int) pEntity->GetId() : 0;
	switch(event.event)
	{
	case eGE_GameStarted:
		StartGame(event.value!=0);
		break;
	case eGE_GameEnd:
		EndGame(event.value!=0);
		break;
	case eGE_SuddenDeath:
		SuddenDeath(event.value!=0);
		break;
	case eGE_RoundEnd:
		EndRound(event.value!=0, atoi(event.description));
		break;
	case eGE_Renamed:
		SetName(e_id, event.description);
		break;
	case eGE_Scored:
		SetScore(e_id, event.description, (int)event.value);
		break;
	case eGE_Kill:
		OnKill(e_id, (EntityId*)event.extra);
		if(pEntity)
			ProcessPlayerStat(pEntity,event);
		break;
	case eGE_Death:
		OnDeath(e_id, (int)(TRUNCATE_PTR)event.extra);
		if(pEntity)
			ProcessPlayerStat(pEntity,event);
		break;
  case eGE_WeaponShot:
	case eGE_WeaponHit:
	case eGE_SuitModeChanged:
	case eGE_WeaponMelee:
	case eGE_LeftVehicle:
	case eGE_EnteredVehicle:
	case eGE_ItemSelected:
	case eGE_WeaponReload:
	case eGE_Damage:
	case eGE_Revive:
	case eGE_WeaponFireModeChanged:
	case eGE_ZoomedIn:
	case eGE_ZoomedOut:
		if(pEntity)
			ProcessPlayerStat(pEntity,event);
		break;
	case eGE_Connected:
		{
			bool restored = event.value!=0.0f;

			struct SExtraData
			{
					int status[2];
			};

			SExtraData* pExtra = static_cast<SExtraData*>(event.extra);
			NewPlayer(e_id, pExtra->status[0], pExtra->status[1]!=0, restored);
		}
		break;
  case eGE_ChangedTeam:
    SetTeam(e_id,(int)event.value);
    break;
  case eGE_Spectator:
    SetSpectator(e_id,(int)event.value);
		if(pEntity)
			ProcessPlayerStat(pEntity,event);
    break;
	case eGE_Disconnected:
		RemovePlayer(e_id, event.value!=0);
		break;
	case eGE_ScoreReset:
		ResetScore(e_id);
		break;
  case eGE_Rank:
    SetRank(e_id,(int)event.value);
    break;
	case eGE_GameReset:
		GameReset();
		break;
	default:
		break;
	}
}
Ejemplo n.º 4
0
/* Applies changes(transformations) to objects and 
 * the method is called every frame in main. Therefore
 * contributes to the effect of animation. */ 
void Game::Run(){
	Point2d next_position;
	float distance, nextx, nexty;
	bool reset = false;
	
	SpectatorsCheers();
	switch (state){
		case (HOLD):
			if (score1 == 3 || score2 == 3)
				// We use a bool and not a state because
				// we want the game to be restarted when 
				// the player hits the ball again.
				m_restart = true;
			break;
		case (GOAL):
		case (WALK): {
			// In case m_restart is true we must restart the game
			if (m_restart){
				state = RESTART; 
				m_restart = false;
				break;
			}

			// Move if in a lower section
			// We check if somebody scored a goal
			if (state == WALK){
				m_last_scored = CheckGoal(true);
				if (m_last_scored != -1){
					DrawScoreForTeam(m_last_scored);
					reset = CheckGoalLimit();
					if (reset == true) {
						// Might be that the ball need to be 
						// reseted immediately after it crossed the
						// line of the gate. That can happend if 
						// the speed is to high
						BeginSpectatorsCheers();
						PickNewRandomPlayer(!m_last_scored);
					}
					state = GOAL;
				}
				else {
					// If the ball hits the wall it will bounce off
					WallHitCheck();
				}
			}
			else if (state == GOAL){
				reset = CheckGoalLimit();
				// If the ball reached the limit withing the goal
				// then we give it to a player from the other team
				if (reset == true){
					BeginSpectatorsCheers();
					PickNewRandomPlayer(!m_last_scored);
					state = HOLD;
				}
			}

			// We check for collisions with other players
			nextx = SPEED * deltax * m_dt;
			nexty = SPEED * deltay * m_dt;
			next_position.set(ball->GetObject()->axiscenter.x + nextx, 
						  ball->GetObject()->axiscenter.y + nexty);
			
			std::vector<Point2d>::iterator it;

			// with players from team1
			for (it = player1_pos.begin(); it != player1_pos.end(); ++it){
				distance = CheckCollision(next_position, *it);
				if (distance > 0.0f){ 
					m_team = 0;
					m_player = it - player1_pos.begin();
					if (m_player != m_player_last || m_team != m_team_last){
						state = HOLD;
					}
				}
			}
			
			// with players from team2
			for (it = player2_pos.begin(); it != player2_pos.end(); ++it){
				distance = CheckCollision(next_position, *it);
				if (distance > 0.0f){
					m_team = 1;
					m_player = it - player2_pos.begin();
					if (m_player != m_player_last || m_team != m_team_last){
						state = HOLD;
					}
				}
			}

			// In the case the ball has been thrown then 
			// we translate it on the field
			m_system->objectTranslate(ball->GetObject(), nextx, nexty);

			break;
		}
		case (BLANK):{
			// We are going to wait
			Sleep(3000);
			// And then we are going to start the game again
			Init();
			state = HOLD;
			break;
		}
		case (RESTART):{
			field->RemoveScoreLines();
			PickNewRandomPlayer(rand() % 2);
			// We need to wait for the next frame to see the
			// changes on the screen. Therefore we use another
			// state.
			state = BLANK;
			m_restart = false;
			ResetScore();
			m_system->objectRemoveAll();
			player1_pos.clear();
			player2_pos.clear();
			player1.clear(); 
			player2.clear();
			break;
		}
		
	}

}