示例#1
0
void Game::initializeSocket(int type){
	if(firstGame)
		socketConnect();
	char connectMsg[256];
	if(type == 1)
		sprintf(connectMsg, "initialize(%i, 1).\n", this->gameboard->size);
	else if (type == 2) //Man vs CPU
		sprintf(connectMsg, "initialize(%i, 2, %s).\n", this->gameboard->size, this->player2->cpudiff);
	else if(type == 3) //CPU vs Man
		sprintf(connectMsg, "initialize(%i, 3, %s).\n", this->gameboard->size, this->player1->cpudiff);
	else if(type == 4)
		sprintf(connectMsg, "initialize(%i, 4, %s, %s).\n", this->gameboard->size, this->player1->cpudiff, this->player2->cpudiff);
	printf("%s\n", connectMsg);
	envia(connectMsg, strlen(connectMsg));
	char ans[256];

	recebe(ans);

	//Guardar o tabuleiro PROLOG
	int i=3;
	while(true){
		if(ans[i] == ')')
			break;
		this->tabProlog[i-3] = ans[i];
		i++;
	}
	this->tabProlog[i-3] = '\0';

	char* buf = (char*)malloc(256*sizeof(char));
	strcpy(buf, this->tabProlog);
	gameboardsProlog.push(buf);
}
示例#2
0
void quit() {
	cout << "Asking prolog to quit" << endl;
	char buff[] = "quit.\n";
	envia(buff, 6);
	char ans[128];
	recebe(ans);
}
示例#3
0
void TwixtSocket::quit() {
	//cout << "Asking prolog to quit" << endl;
	char buff[] = "quit.\n";
	envia(buff, 6);
	char ans[128];
	recebe(ans);
}
示例#4
0
void Game::updateScores(){
	//Actualizar o resultado do jogo apos uma jogada efectuada
	char buffer[256];
	sprintf(buffer, "getScore(%s).\n", this->tabProlog);
	envia(buffer, strlen(buffer));
	//Recebe resposta
	char ans[256];
	recebe(ans);
	int i = 3; //Ler a partir daqui
	if(strncmp(ans, "ok", 2) == 0){
		char score1[5];
		while(ans[i] != ','){
			score1[i-3] = ans[i];
			i++;
		}
		score1[i-3] = '\0';
		this->player1->score = atoi(score1);
		i++;
		char score2[5];
		int j=0;
		while(ans[i] != ')'){
			score2[j] = ans[i];
			j++;
			i++;
		}
		score2[j] = '\0';
		this->player2->score = atoi(score2);
	}
}
示例#5
0
void far procEmissor() {
	char msg[25];
	int result;
	while (1) {
		strcpy(msg, "msg teste");
		result = envia(msg, "procReceptor");
		if (result == 0) {
			printf("Terminando processo...Destino nao encontrado\n");
			terminaProcesso1();
		}
		else if (result == 1) {
			while (result == 1) {
				result = envia(msg, "procReceptor");
			}
		}
	}
}
示例#6
0
/**
 * [senderThread Thread function to call envia()]
 * @param param [A value to be send]
 */
void* senderThread(void* param) {
   	int value;
   	value = *((int*) param);

   	envia(value);

    return NULL;
}
示例#7
0
void Game::makeCpuPlay(){
	char buffer[256];
	char ans[256];

	sprintf(buffer, "cpuPlay(%i, %s).\n", this->currentPlayer, this->tabProlog);
	envia(buffer, strlen(buffer));
	recebe(ans);
	processAnswer(ans);
}
示例#8
0
void lan_block_put(const block_morse b , uint8_t nd){
  // [no,nd,missatje,crc]
  // Fiquem l'estat a pendent d'enviar
  estat=pendent_enviar;
  // Fiquem la trama be
  fix(b,nd);
  print("\n\rTrama: ");
  print(tx); 
  // Enviem la trama
  envia();   
  intens=0;
  print("Done");
  // Un cop hem acabat d'enviar tornem al principi
  estat=esperant;
}
示例#9
0
void Game::makePlay(GLuint selected){
	char buffer[256];
	char ans[256];
	int i=3;
	//De 1 a size do tabuleiro - BACK-NUMBER
	if(selected >=1 && selected <= this->gameboard->size){
		printf("Back %d\n", selected);
		//comunicação - é pedida a avaliação da jogada
		// caso positivo - desenha a animaçao
		//desenha novo tabuleiro
		sprintf(buffer, "executePlay(%d, %s, %d, %s).\n", this->currentPlayer, "'B'", selected, this->tabProlog);
	}

	//De size+1 até size*2 - 1
	else if(selected >= this->gameboard->size+1 && selected <= (this->gameboard->size*2)){
		int position = selected - this->gameboard->size;
		printf("Front %d", position);
		sprintf(buffer, "executePlay(%d, %s, %d, %s).\n", this->currentPlayer, "'F'", position, this->tabProlog);
	}

	//De size*2 até size*3 - 1
	else if(selected >= (this->gameboard->size)*2+1 && selected <= (this->gameboard->size*3)){
		int position = selected - this->gameboard->size*2;
		printf("Left: %d", position);
		sprintf(buffer, "executePlay(%d, %s, %d, %s).\n", this->currentPlayer, "'L'", position, this->tabProlog);
		//Partir a resposta em tabuleiro - x - y
	}

	//De size*3 até ao fim
	else if(selected >= (this->gameboard->size)*3+1){
		int position = selected - this->gameboard->size*3;
		printf("Right: %d", position);
		sprintf(buffer, "executePlay(%d, %s, %d, %s).\n", this->currentPlayer, "'R'", position, this->tabProlog);
	}
	envia(buffer, strlen(buffer));
	recebe(ans);

	processAnswer(ans);
}
void PortaSerial::buscaDispositivo(const char *comando, char respEsperada, bool loop)
{
  	char msg[255];
	char resp[255];
  	bool conexao = false;
	char porta[100];
	int ret;
	int pos = 0;
	
	string dir = string("/dev");
	vector<string> files = vector<string>();
	while(!conexao)
	{
		files.clear();
		if(conectado)
		fecha();
		while(files.size() <= 0)
		{
			gettty(dir,files);
		}
		if(pos == files.size())
		{
			pos = 0;
		}
		sprintf(porta, "/dev/%s", files[pos++].c_str());
		setPort(porta);
		abre(baud, canonical, databits, parity, startbit, stopbit);
		sprintf(msg, "%s\0", comando);
		ret = envia(msg, resp);
		if(resp[0] == respEsperada || !loop)
			conexao = true;
	}
	if(resp[0] != respEsperada)
	{
		conectado = false;
	}
}