Beispiel #1
0
//inicializa o mapa e o desenha na tela, além de inicializar as hordas e seus inimigos
void Fase::init() throw (FileNotFoundException, InitException, GameOverException)
{
	int inimigos_horda;
cout << "\nFASE " << this->num_fase << endl;
	//inicializa o mapa
	try{
		Mapa::loadMap(nome_mapa);
		Mapa::desenhaMapa();
	}catch(bad_alloc ba){
		throw InitException("falha ao alocar memoria para o mapa da fase!" );
	}
	
	//inicializa as hordas
	try{
		//cria um vetor de hordas vazios
		this->hordas = new vector<Horda*>();
		
		int i;
		for(i=0; i<this->num_hordas; i++)
		{
			//determina o numero exato de inimigos em cada horda
			inimigos_horda = rand()%5 + 1;
			inimigos_horda *= rand()%2 ? 1 : -1;		
			inimigos_horda += this->num_medio_inimigos_por_horda;
			inimigos_horda < 5 ? inimigos_horda=5 : inimigos_horda=inimigos_horda;
cout << "horda "<< i+1 << endl;
			
			this->hordas->push_back(new Horda(inimigos_horda, this->num_fase));
			this->hordas->at(i)->init();
			this->execHorda(i);
		}
	}catch(bad_alloc ba){
		throw InitException("falha ao alocar memoria para as hordas da fase!");
	}
}
SOCKET ScreenshotServer::listen()
{
	WSADATA wsaData;
	int goodStart = WSAStartup(MAKEWORD(2, 2), &wsaData);
	if (goodStart != 0)
	{
		std::string message = "Could not start WSA: " + std::to_string(goodStart) + "\n";
		log_ << message;
		throw InitException(message);
	}

	addrinfo* result = nullptr, *ptr = nullptr, hints;
	ZeroMemory(&hints, sizeof(hints));

	hints.ai_family = AF_INET;
	hints.ai_socktype = SOCK_STREAM;
	hints.ai_protocol = IPPROTO_TCP;
	hints.ai_flags = AI_PASSIVE;

	int goodResolve = getaddrinfo(NULL, std::to_string(port_).c_str(), &hints, &result);
	if (goodResolve != 0)
	{
		WSACleanup();
		throw InitException("Could not resolve addrinfo: " + std::to_string(goodResolve));
	}

	SOCKET serverSocket = INVALID_SOCKET;
	serverSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol);

	if (serverSocket == INVALID_SOCKET)
	{
		freeaddrinfo(result);
		WSACleanup();
		throw new InitException("Could not create server socket: " + std::to_string(WSAGetLastError()));
	}

	int goodBind = bind(serverSocket, result->ai_addr, static_cast<int>(result->ai_addrlen));
	if (goodBind != 0)
	{
		freeaddrinfo(result);
		closesocket(serverSocket);
		WSACleanup();
		throw InitException("Could not bind socket: " + std::to_string(WSAGetLastError()));
	}

	freeaddrinfo(result);

	if ( ::listen(serverSocket, SOMAXCONN) == SOCKET_ERROR)
	{
		closesocket(serverSocket);
		WSACleanup();
		throw InitException("Could not listen on socket: " + std::to_string(WSAGetLastError()));
	}

	return serverSocket;
}
Beispiel #3
0
const QJsonArray WorldInfo::load(QString filename) {
  QFile file(filename);
  if (!file.open(QIODevice::ReadOnly))
    throw InitException(tr("%1 is missing!").arg(filename));
  QJsonDocument doc = QJsonDocument::fromJson(file.readAll());
  file.close();

  if (doc.isNull())
    throw InitException(tr("%1 is corrupt").arg(filename));

  if (!doc.isArray())
    throw InitException(tr("%1 isn't an array").arg(filename));

  return doc.array();
}
void Inicializador::initGrafico()throw(InitException)
{
	if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
		throw InitException( string("Erro ao inicializar SDL: ") + string(SDL_GetError()) );
	
	atexit(SDL_Quit);
	atexit(SDL_CloseAudio);
	
	if (TTF_Init() != 0)
		throw InitException(string("Erro ao inicializar o ttf: ") + string(TTF_GetError()));

	atexit(TTF_Quit);
	
	SDL_WM_SetCaption(NOME_BARRA_SUPERIOR.c_str(), NOME_BARRA_SUPERIOR.c_str());
	SDL_WM_SetIcon( IMG_Load( (PATH + IMAGEM_LOGO).c_str() ), NULL);
}
Beispiel #5
0
	OODL::OODL(Uint32 flags, bool defaultCleanup) throw(InitException) {
		if(SDL_Init(flags) != 0) {
			throw InitException();
		}
		
		if(defaultCleanup) {
			atexit(SDL_Quit);
		}
	}
void Inicializador::initSom()throw(InitException)
{
	SDL_AudioSpec desired, obtained;
	desired.freq = FREQUENCIA;
	desired.format = AUDIO_S16SYS;
	desired.channels = NUM_CANAIS;
	desired.samples = SIZE_SAMPLE;
	desired.callback = Audio::callback;
	
	if(SDL_OpenAudio(&desired, &obtained) < 0)
		throw InitException( string("Erro ao inicializar o som: ") + string(SDL_GetError()) );
		
	Audio::setAudioSpec(&obtained);
}
Beispiel #7
0
//inicializa os valores do inimigo
void Chipanze1::init() throw (InitException, FileNotFoundException)
{
	this->HP = INIMIGO_HP_PADRAO;
	this->dano = INIMIGO_DANO_PADRAO;
	this->vel = INIMIGO_VEL_PADRAO;
	this->hp_restante  = this->HP;
	
	try{
		this->img = new SDL_Sprite(ARQUIVO_CHIPANZE1,28, 45);//nome do arquivo e as dimensões de cada desenho da sprite
		Direcao dir=BAIXO;
		this->img->init(dir);
	}catch(bad_alloc ba){
		throw InitException("falha ao alocar o sprite do orangotango! não houve memoria suficiente!");
	}
	
}
Beispiel #8
0
void Tanque::init() throw(InitException, FileNotFoundException)
{
	this->HP = TORRE_HP_PADRAO*10;
	this->dano = 5*TORRE_DANO_PADRAO;
	this->tempoRecarga = 0;
	this->alcance = 1;
	custo = 10*TORRE_CUSTO_PADRAO;
	
	this->hp_restante  = this->HP;
	
	try{
		this->img = new SDL_Sprite(ARQUIVO_TORRE_BOMBERMAN,30, 30);//nome do arquivo e as dimensões de cada desenho da sprite
		Direcao dir=BAIXO;
		this->img->init(dir);
	}catch(bad_alloc ba){
		throw InitException("falha ao alocar o sprite do atiradorSimples! não houve memoria suficiente!");
	}
}
void AgentesProtetores::init() throw(InitException, FileNotFoundException)
{
	this->HP = TORRE_HP_PADRAO;
	this->dano = 0;
	this->tempoRecarga = 2*TORRE_TEMPO_RECARGUE_PADRAO;
	this->alcance = 0;
	custo = 2*TORRE_CUSTO_PADRAO;
	
	this->hp_restante  = this->HP;
	
	try{
		this->img = new SDL_Sprite(ARQUIVO_TORRE_AGENTES_PROTETORES,30, 30);//nome do arquivo e as dimensões de cada desenho da sprite
		Direcao dir=BAIXO;
		this->img->init(dir);
	}catch(bad_alloc ba){
		throw InitException("falha ao alocar o sprite do AgentesProtetores! não houve memoria suficiente!");
	}
}
Beispiel #10
0
/// Daten einlesen
void Position::init ()
{
    Daten& src = Daten::getInstance();

    /// Anzahl einlesen
    src.mSrcFilestream >> mAnzahl;

    if (mAnzahl < 0)
        throw InitException("Konnte Anzahl nicht einlesen");
    if (mAnzahl == 0)
        throw 0;

    /// Artikel erstellen und Daten einlesen
    Artikel* a = new Artikel();
    a->init();                      /// Artikel initialisieren...
    mArtikel = a->factory();        /// und konkrete Klasse erzeugen
    mArtikel->init();
}
Beispiel #11
0
void Muro::init() throw(InitException, FileNotFoundException)
{
	this->HP = TORRE_HP_PADRAO;
	this->dano = 0*TORRE_DANO_PADRAO;
	this->tempoRecarga = 0*TORRE_TEMPO_RECARGUE_PADRAO;
	this->alcance = 0*TORRE_ALCANCE_PADRAO;
	custo = 0.7*TORRE_CUSTO_PADRAO;
	
	this->hp_restante  = this->HP;
	
	try{
		this->img = new SDL_Sprite(ARQUIVO_TORRE_MURO,30, 30);//nome do arquivo e as dimensões de cada desenho da sprite
		Direcao dir=BAIXO;
		this->img->init(dir);
	}catch(bad_alloc ba){
		throw InitException("falha ao alocar o sprite do Muro! não houve memoria suficiente!");
	}
}
Beispiel #12
0
void Bombardeiro::init(int posX, int posY) throw(InitException, FileNotFoundException)
{
	this->HP = 2*TORRE_HP_PADRAO;
	this->dano = TORRE_DANO_PADRAO*2;
	this->tempoRecarga = TORRE_TEMPO_RECARGUE_PADRAO;
	this->alcance = TORRE_ALCANCE_PADRAO/2;
	custo = 3*TORRE_CUSTO_PADRAO;
	
	this->hp_restante  = this->HP;
	
	try{
		this->img = new SDL_Sprite(ARQUIVO_TORRE_BOMBARDEIRO,posX, posY);//nome do arquivo e as dimensões de cada desenho da sprite
		Direcao dir=BAIXO;
		this->img->init(dir);
	}catch(bad_alloc ba){
		throw InitException("falha ao alocar o sprite do atiradorSimples! não houve memoria suficiente!");
	}
}
Beispiel #13
0
Driver::Driver(EventQueue& logic_queue, bool use_simulator)
  : logic_queue(logic_queue),
    fsm(logic_queue)
{
  std::string driver_string = use_simulator ? "simulated" : "hardware";
  elev_init(use_simulator ? ET_Simulation : ET_Comedi);

  LOG_INFO("Driver started (" << driver_string << ")");

  int current_floor = initialize_position();
  if (current_floor >= 0) {
    LOG_INFO("Elevator is now at floor " << current_floor);
  }
  else {
    throw InitException("Failed to position the elevator at a known floor!");
  }

  fsm.set_floor(current_floor);
}
Beispiel #14
0
//inicializa os inimigos
void Horda::init() throw (InitException, FileNotFoundException)
{
	try{
		//this->vetorInimigos = new Chipanze1[this->numInimigos];	
		
		this->vetorInimigos = new vector<Inimigo*>();
		int i;
		for(i=0; i<this->numChipanzes1; i++)
		{
			vetorInimigos->push_back(new Chipanze1());
			vetorInimigos->back()->init();
		}
		for(i=0; i<this->numChipanzes2; i++)
		{
			vetorInimigos->push_back(new Chipanze2());
			vetorInimigos->back()->init();
		}
		for(i=0; i<this->numOragotangos; i++)
		{
			vetorInimigos->push_back(new Orangotango());
			vetorInimigos->back()->init();
		}
		for(i=0; i<this->numGorilas1; i++)
		{
			vetorInimigos->push_back(new Gorila1());
			vetorInimigos->back()->init();
		}
		for(i=0; i<this->numGorilas2; i++)
		{
			vetorInimigos->push_back(new Gorila2());
			vetorInimigos->back()->init();
		}
		
		random_shuffle(vetorInimigos->begin(), vetorInimigos->end());
	}catch(bad_alloc ba){
		throw InitException("erro ao alocar os inimigos!");
	}
	
cout << "criei " << numChipanzes1+numChipanzes2+numOragotangos+numGorilas1+numGorilas2 << " macacos" << endl;
}
Beispiel #15
0
Socket::ConnectionStatus Socket::connectSocket(void) {
    sockaddr_un clientAddr;

    memset(&clientAddr, 0, sizeof(clientAddr));

    clientAddr.sun_family = AF_UNIX;

    if (m_socketPath.length() >= sizeof(clientAddr.sun_path)) {
        close();
        LOGE("Error: socket path <%s> is too long [%zu]. Max len is [%zu]", m_socketPath.c_str(),
             m_socketPath.length(), sizeof(clientAddr.sun_path));
        throw InitException();
    }

    strcpy(clientAddr.sun_path, m_socketPath.c_str());

    LOGD("ClientAddr.sun_path <%s>", clientAddr.sun_path);

    int retval = TEMP_FAILURE_RETRY(::connect(m_sock, (struct sockaddr*)&clientAddr,
                                            SUN_LEN(&clientAddr)));
    if (retval == -1) {
        int err = errno;
        switch (err) {
            case EINPROGRESS:
                m_connectionInProgress = true;
                return ConnectionStatus::CONNECTION_IN_PROGRESS;
            case ECONNREFUSED:
                //no one is listening
                return ConnectionStatus::CONNECTION_FAILED;
            default:
                close();
                LOGE("'connect' function error [%d] : <%s>", err, strerror(err));
                throw UnexpectedErrorException(err, strerror(err));
        }
    }
    return ConnectionStatus::CONNECTION_SUCCEEDED;
}