Ejemplo n.º 1
0
int checkWinner2() {
    for (x = 0; x < 3; x++) {
        count11 = 0;
        count12 = 0;
        count21 = 0;
        count22 = 0;
        count31 = 0;
        count32 = 0;
        for (j = 0; j < 3; j++) {
            if (posicions[x][j] == 'X')
                count11++;
            else if (posicions[x][j] == '0')
                count12++;

            if (posicions[j][x] == 'X')
                count21++;
            else if (posicions[j][x] == '0')
                count22++;

            if (posicions[j][j] == 'X')
                count31++;
            else if (posicions[j][j] == '0')
                count32++;
        }

        if (count11 == 3 || count21 == 3 || count31 == 3) {
            drawTable();
            printf("We have a winner!: cruz\n");
            return 0;
        }
        if (count12 == 3 || count22 == 3 || count32 == 3) {
            drawTable();
            printf("We have a winner!: cara\n");
            return 1;
        }
        if (posicions[0][2] == 'X' && posicions[1][1] == 'X' && posicions[2][0] == 'X') {
            drawTable();
            printf("We have a winner!: cruz\n");
            return 0;
        }
        if (posicions[0][2] == '0' && posicions[1][1] == '0' && posicions[2][0] == '0') {
            drawTable();
            printf("We have a winner!: cara\n");
            return 0;
        }
    }
    return 3;
}
Ejemplo n.º 2
0
void Game::handleGameEvents()
{
	SDL_ShowCursor( SDL_DISABLE);
	switch(switchScreen)
	{
	case GAMETABLE:
		reduceFPS();
		drawTable();
		handleEvents();
		break;
	case HELPFIRST:
		helpWindowScreen();
		reduceFPS();
		handleHelpFirst();
		break;
	case HELPSECOND:
		helpSecondScreen();
		reduceFPS();
		handleHelpFirst();
		break;
	case HELPTHIRD:
		helpThirdScreen();
		reduceFPS();
		handleHelpFirst();
		break;
	case STATSMENU:
		statsWindowScreen();
		reduceFPS();
		handleHelpEvent();
		break;
	default:
		break;
	}
}
Ejemplo n.º 3
0
void jugar2(int p) {
    do {
        system("cls");
        drawTable();
        if (p % 2 == 0) {
            system("Color f0");
            printf("Juega cruz\n");
        } else {
            system("Color 07");
            printf("Juega cara\n");
        }

        printf("\tIngresar fila: ");
        scanf("%d", &fila);

        printf("\tIngresar columna: ");
        scanf("%d", &columna);

    } while (posicions[fila][columna] == 'X' || posicions[fila][columna] == '0');

    if (p % 2 == 0)
        posicions[fila][columna] = 'X';
    else
        posicions[fila][columna] = 'O';
    system("cls");
}
Ejemplo n.º 4
0
void Render::paintGL() {
    glClear(GL_COLOR_BUFFER_BIT);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glDisable(GL_DEPTH_TEST);
    glDepthMask(GL_FALSE);
    move();
    drawGrid();
    drawCar();
    drawSparks();
    drawBody(world->getTrack()->getBody());
    drawText();
    drawParents();
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0, width(), height(), 0, 1.0, -1.0);
    drawTable();
    drawGraph();
    glPopMatrix(); //GL_MODELVIEW
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
}
Ejemplo n.º 5
0
void drawAlignedTable(double dbHorizontalAlign,double dbVerticalAlign,u8 chMinRow,u8 chMinColumn,u8 chMaxRow,u8 chMaxColumn,u8 chColumnsCount,u8 chRowsCount,u8 chCellWidth,u8 chCellHeight,enum BORDER_STYLES BORDER_STYLE,enum CONSOLE_FONT_COLORS BORDER_COLOR,enum CONSOLE_FONT_COLORS BGCOLOR,struct stTable *stTableSettings) {
double dbTextContainerX[2]={0,chCellWidth*chColumnsCount},dbTextContainerY[2]={0,chRowsCount*chCellHeight};
    if (chMinColumn>chMaxColumn) {
        permutePointers((void *) &chMinColumn,(void *) &chMaxColumn);
    }
    if (chMinRow>chMaxRow) {
        permutePointers((void *) &chMinRow,(void *) &chMaxRow);
    }
    drawTable(getRoundNumber(getPolyContainerPosition(&dbTextContainerY[0],2,chMinRow,chMaxRow,dbVerticalAlign)),getRoundNumber(getPolyContainerPosition(&dbTextContainerX[0],2,chMinColumn,chMaxColumn,dbHorizontalAlign)),chColumnsCount,chRowsCount,chCellWidth,chCellHeight,BORDER_STYLE,BORDER_COLOR,BGCOLOR,stTableSettings);
}
Ejemplo n.º 6
0
/*
** This function will draw our mandala.
*/
void drawMandala(Sdl *sdl, Color *color, Mandala *mandala, Window *window) {
  if (color->rainbow == 1) {
    rainbowMode(color);
    SDL_SetRenderDrawColor(sdl->renderer, color->r, color->g, color->b, 255);
  }
  else
    SDL_SetRenderDrawColor(sdl->renderer, 90, 90, 90, 255);

  drawCircle(sdl, window, mandala);
  drawTable(sdl, mandala);
}
Ejemplo n.º 7
0
int showTable(const vector<vector<char>>& record, const vector<int>& type, const vector<string>& attr_show){
	vector<vector<string>> table;
	vector<string> column;
	vector<int> maxSize;
	int size;
	//record确定行数,type&attr_show确定列数
	int n = 0;
	for (int i = 0; i < attr_show.size(); i++){
		column.clear();
		column.push_back(attr_show[i]);
		size = attr_show[i].size();

		for (int j = 0; j < record.size(); j++){
			string t = "";
			if (type[i] == 1){//int
				int x = char4ToInt(subVector(record[j], n, n + 4));
				stringstream ss;
				ss << x;
				t = ss.str();
			}
			else if (type[i] == 2){//float
				float x = char4ToFloat(subVector(record[j], n, n + 4));
				stringstream ss;
				ss << x;
				t = ss.str();
			}
			else{
				vector<char> vt = subVector(record[j], n, n + type[i] - 3);
				for (int k = 0; k < vt.size(); k++){
					if (vt[k])
						t += vt[k];
				}
			}

			if (t.size()>size){
				size = t.size();
			}
			column.push_back(t);
		}
		table.push_back(column);
		maxSize.push_back(size);
		if (type[i] == 1 || type[i] == 2)
			n += 4;
		else
			n += (type[i] - 3);
	}

	drawTable(table, maxSize);

	return record.size();
}
Ejemplo n.º 8
0
void HostTerminal::onDealDone(const Info& info)
{
  dealCount++;
  if(human_detected)
  {
    drawTable(info);
    
    if(pressAnyKeyOrQuit()) quit = true;
  }
  else
  {
    /*if(dealCount % 10 == 0)*/ std::cout << std::endl << "Deal " << dealCount << " done." << std::endl << std::endl;
  }
}
Ejemplo n.º 9
0
/**
 * Generate a table chart with a given parent and measure
 * @param parent the parent of the widget
 * @param meas the active measure
 */
WidgetTableChart::WidgetTableChart(QWidget *parent, Measure &meas):QWidget(parent),ui(new Ui::WidgetTableChart),_meas(new Measure(meas))
{
    ui->setupUi(this);

    this->setStyleSheet(
                "QPushButton#pushButtonSaveTableData {"
                "background-color: rgb(125,125,175);"
                "border-style: outset;"
                "border-width: 2px;"
                "border-color: rgb(50,50,75);"
                "border-radius: 5px;"
                "font: bold 22px;"
                "min-width: 7em;}"

                "QPushButton#pushButtonSaveTableData:hover:pressed {"
                "background-color: rgb(100,100,145);"
                "border-style:inset;}"

                "QPushButton#pushButtonSaveTableData:hover {"
                "background-color: rgb(130,130,180);}"

                "QPushButton#pushButtonLoadTable {"
                "background-color: rgb(125,125,175);"
                "border-style: outset;"
                "border-width: 2px;"
                "border-color: rgb(50,50,75);"
                "border-radius: 5px;"
                "font: bold 22px;"
                "min-width: 7em;}"

                "QPushButton#pushButtonLoadTable:hover:pressed {"
                "background-color: rgb(100,100,145);"
                "border-style:inset;}"

                "QPushButton#pushButtonLoadTable:hover {"
                "background-color: rgb(130,130,180);}"
                );
    ui->listBarChartMunicipality->setSelectionMode(QAbstractItemView::MultiSelection);
    ui->listBarChartYears->setSelectionMode(QAbstractItemView::MultiSelection);
    //List Stuff
    QStringList mlist = meas.stringMuniList();
    ui->listBarChartMunicipality->addItems(mlist);
    //ui->listBarChartYears->addItem("2008"); ui->listBarChartYears->addItem("2009"); ui->listBarChartYears->addItem("2010"); ui->listBarChartYears->addItem("2011"); ui->listBarChartYears->addItem("2012");
    ui->listBarChartYears->addItems(_meas->yearRange());
    ui->measurename->setText(_meas->name());
    drawTable();

    _dirname = "";
}
Ejemplo n.º 10
0
int drawTable2(int table[TABLESIZE][TABLESIZE], int * x, int * y, int flag)
{
    char key;
    char buf[MAXLINE];
    int xCross = *x;
    int yCross = *y;
    drawTable(table, xCross, yCross);
    do
    {
        printf("Den Luot Ban (w:up, s:down, a:left, d:right): ");
        key = getch();
        switch(key)
        {
        case 'w'://up
            if(xCross > 0) xCross--;
            clear();
            drawTable(table, xCross, yCross);
            break;
        case 's'://down
            if(xCross < TABLESIZE-1) xCross++;
            clear();
            drawTable(table, xCross, yCross);
            break;
        case 'a'://left
            if(yCross > 0) yCross--;
            clear();
            drawTable(table, xCross, yCross);
            break;
        case 'd'://right
            if(yCross < TABLESIZE -1) yCross++;
            clear();
            drawTable(table, xCross, yCross);
            break;
        default:
            break;
        }
        if(key == '\n'){
            if(table[xCross][yCross] == 0) break;
        }
    }
    while(key != 'q' && key != 'Q');
    if(key == '\n')
    {
        (*x) = xCross;
        (*y) = yCross;
        sprintf(buf,"%d %d", xCross, yCross);
        signInTable(table, buf, flag);
        clear();
        drawTable(table, xCross, yCross);
        return 0;
    }
    else if(key == 'q' || key == 'Q') return 1;;

}
Ejemplo n.º 11
0
int hexeditorRedraw(HexEditor* prHex) {
    AppletConfig* prApCfg = NULL;
    ColorConfig* prColor = NULL;

    if (prHex == NULL) {
        return HEXEDITOR_MEMORY;
    }
    if (prHex->dirty == 0) {
        return;
    }
    prApCfg = prHex->prApCfg;
    prColor = &prApCfg->rPanel.rColor;
    pspDebugScreenSetBackColor(prColor->background);
    pspDebugScreenSetTextColor(prColor->text);
    pspDebugScreenSetXY(prHex->config.position.x, prHex->config.position.y);
    pspDebugScreenKprintf("%-67s", "Hex Editor");
    drawTable(prHex);
    drawCursor(prHex);
    prHex->dirty = 0;
    return HEXEDITOR_SUCCESS;
}
Ejemplo n.º 12
0
void initializeWorld(){
	hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
	FlushConsoleInputBuffer(hConsole);	
	
	drawTable();
	
	rotatingBar(WIDTH/2, HEIGHT/2, 0);
	
	gotoxy(0,0);
	SetConsoleTextAttribute(hConsole, colors[0]);
	printf("O");
	SetConsoleTextAttribute(hConsole, colors[1]);
	gotoxy(WIDTH,0);
	printf("O");
	SetConsoleTextAttribute(hConsole, colors[2]);
	gotoxy(WIDTH,HEIGHT);
	printf("O");
	SetConsoleTextAttribute(hConsole, colors[3]);
	gotoxy(0,HEIGHT);
	printf("O");
	
}
Ejemplo n.º 13
0
void jugar(int p) {
    do {
        system("cls");
        drawTable();
        if (p % 2 == 0) {
            system("Color f0");
            printf("Juega cruz\n");
        } else {
            system("Color 07");
            printf("Juega cara\n");
        }
        printf("\tIngresar posicion: ");
        scanf("%d", &ubicacion);
        ubicacion--;
    } while (posicion[ubicacion] == 'X' || posicion[ubicacion] == '0');

    if (p % 2 == 0)
        posicion[ubicacion] = 'X';
    else
        posicion[ubicacion] = 'O';
    system("cls");
}
Ejemplo n.º 14
0
void startMethod() {

//        Старт с заданным начальным распределением (см далее) и количеством
//        потоков K
//        Начальное распределение может быть задано в двух вариантах (нужно
//        реализовать оба):
//        а)файл в формате CSV (https://ru.wikipedia.org/wiki/CSV)
//        б)задаются лишь размеры NxM, поле генерируется случайным образом
    int choice = getInitType();
    
    if (choice == 1) {
        
        if (getCSVTable() == 1) {
            getTable();
        }
        
        cout << "Here's your initial table:" << endl;
        drawTable(init_table);        
        
    } else if (choice == 2) {
        
        getTable();
        cerr << "Here's your initial table:" << endl;
        drawTable(init_table);        
    } else {
        cerr << "Wrong choice while starting..." << endl;
    }
        
    int count = world_size - 1;
    int integral = N / count;
    int last = N / count + N % count;
//    cout << "integral: " << integral << endl;
//    cout << "last: " << last << endl;
    
    if (N < count) { 
        cerr << "Too many processes:)" << endl;
        exit(0);
    }
    
    
    MPI_Bcast(&M, 1, MPI_INT, MPI_ROOT, intercomm);
    
    //processes 1 .. count - 2
    int work_N;
    for (int i = 1; i < count - 1; ++i) {
        work_N = integral + 2;
        MPI_Send(&work_N, 1, MPI_INT, i, data_tag, intercomm);
        MPI_Send(init_table[(i - 1) * integral], work_N * M, MPI_INT, i, data_tag, intercomm);
    }

    //process 0
    work_N = integral + 1;
    MPI_Send(&work_N, 1, MPI_INT, 0, data_tag, intercomm);
    MPI_Send(init_table[0], work_N * M, MPI_INT, 0, data_tag, intercomm);
    
    //process count - 1
    work_N = last + 1;
    MPI_Send(&work_N, 1, MPI_INT, count - 1, data_tag, intercomm);
    MPI_Send(init_table[N - last - 1], work_N * M, MPI_INT, count - 1, data_tag, intercomm);
    
}
Ejemplo n.º 15
0
/**
 * Redraw the table
 */
void WidgetTableChart::on_pushButtonLoadTable_clicked()
{
    drawTable();
}
Ejemplo n.º 16
0
int main()
{
	// not recommended to do something with sizes :(
	COORD size = {9, 8};
	drawTable(size);

	// task - aim, request - user input
	i4 task(generateTask());
	i4 request;

	// index to watch which digit user is entered
	// line - offset for the log output
	int index = 0, line = 4;
	
	bool bQuit = false;
	while (!bQuit)
	{
		char ch[] = {readKey(), '\0'};
		int code = (int)(ch[0]);

		// if input is digit
		if (code > 47 && code < 58 && index < 4)
		{
			int num = code - 48;
			bool bDublicate = false;
			for (int i = 0; i < index; ++i)
			{
				if (request[i] == num)
				{
					bDublicate = true;
					break;
				}
			}

			if (bDublicate)
				continue;

			request[index] = num;
			++index;
			print({2 + index, 1}, ch);
		}

		// if input is erase
		if (code == KEY_BACK && index > 0)
			print({2 + index--, 1}, "_");

		// if input is confirm
		if (code == KEY_ENTER && index == 4)
		{
			print({3, 1}, "____");
			i2 fb = getFeedback(request, task);

			// hard way to do simple thing
			char c[] = {
				request[0] + 48,
				request[1] + 48,
				request[2] + 48,
				request[3] + 48,
				' ',
				fb[0] + 48,
				':',
				fb[1] + 48,
				'\0'
			};
			print({1, line}, c);
			++line;
			index = 0;

			// make the table longer if needed
			if (line > size.Y-1)
			{
				print({0, size.Y}, "|");
				print({size.X, size.Y}, "|");
				++size.Y;
			}

			// win event
			if (fb[0] == 4)
			{
				for (int i = 0; i < size.X-1; ++i)
					print({1 + i, line}, "!");

				readKey();
				break;
			}
		}

		// if input is exit
		if (code == KEY_ESC)
			return 0;
		//printf("%d", code);
	}
	clearScreen();
	system("pause");
	return 0;
}
Ejemplo n.º 17
0
void describeTable(const vector<string> &attr, const vector<int> &type, const vector<int> &isKey){
	vector<vector<string>> table;
	vector<int> maxSize;
	vector<string> temp;
	int size = 0;

	temp.push_back("Field");
	size = temp[0].size();
	for (int i = 0; i < attr.size(); i++){
		temp.push_back(attr[i]);
		if (attr[i].size()>size)
			size = attr[i].size();
	}
	table.push_back(temp);
	maxSize.push_back(size);

	temp.clear();
	temp.push_back("Type");
	size = temp[0].size();
	for (int i = 0; i < type.size(); i++){
		if (type[i] == 1)
			temp.push_back("int");
		else if (type[i] == 2)
			temp.push_back("float");
		else{
			string s = "char(";
			int n = type[i] - 3;
			stringstream ss;
			string str;
			ss << n;
			ss >> str;
			s += str;
			s += ")";
			temp.push_back(s);
		}
		if (temp[1 + i].size() > size)
			size = temp[1 + i].size();
	}
	table.push_back(temp);
	maxSize.push_back(size);

	temp.clear();
	temp.push_back("Null");
	size = temp[0].size();
	for (int i = 0; i <isKey.size(); i++){
		if (isKey[i] == 2)
			temp.push_back("NO");
		else
			temp.push_back("YES");

		if (temp[1 + i].size() > size)
			size = temp[1 + i].size();
	}
	table.push_back(temp);
	maxSize.push_back(size);

	temp.clear();
	temp.push_back("Key");
	size = temp[0].size();
	for (int i = 0; i <isKey.size(); i++){
		if (isKey[i] == 2)
			temp.push_back("PRI");
		else if (isKey[i] == 1)
			temp.push_back("UNI");
		else
			temp.push_back("");
		if (temp[1 + i].size() > size)
			size = temp[1 + i].size();
	}
	table.push_back(temp);
	maxSize.push_back(size);

	temp.clear();
	temp.push_back("Default");
	size = temp[0].size();
	for (int i = 0; i < type.size(); i++){
		if (type[i] == 1)
			temp.push_back("0");
		else if (type[i] == 2)
			temp.push_back("NULL");
		else{
			temp.push_back("NULL");
		}
		if (temp[1 + i].size() > size)
			size = temp[1 + i].size();
	}
	table.push_back(temp);
	maxSize.push_back(size);

	drawTable(table, maxSize);
	cout << attr.size() << " rows in set." << endl;
}
Ejemplo n.º 18
0
//////////////////////////////////////////////////////////////////
// game
//
//
//
// Returns:
//    void
//
void game(void) {
    u8 moved;
    u8 *pvmem;
    u8 dir = 0;


    initGame();

    // Clear Screen
    clearScreen();

    pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 61, 72);
    cpct_drawSprite(logo_small, pvmem, 15, 55);

    //drawFrame(2, 1, 49, 182);
    drawTable();
    drawText("NEXT", 62, 2, 0);
    printCells();
    highestCardGame = getHighestCard();
    drawText("HIGHEST", 59, 138, 0);
    pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 63, 154);
    cpct_drawSprite(cards[highestCardGame], pvmem, CARD_W, CARD_H);

    moved = 0;
    // Loop forever
    while (1) {
        delay(24);

        rotatedCells = 0;

        if ((cpct_isKeyPressed(Joy0_Right)) || (cpct_isKeyPressed(keys.right))) {
            if (rotateCellsRight() > 0) {
                dir = RIGHT;
                addRandomCellTurn(RIGHT);
                moved = 1;
            }
        } else if ((cpct_isKeyPressed(Joy0_Left)) || (cpct_isKeyPressed(keys.left))) {
            if (rotateCellsLeft() > 0) {
                dir = LEFT;
                addRandomCellTurn(LEFT);
                moved = 1;
            }
        } else if ((cpct_isKeyPressed(Joy0_Down)) || (cpct_isKeyPressed(keys.down))) {
            if (rotateCellsDown() > 0) {
                dir = DOWN;
                addRandomCellTurn(DOWN);
                moved = 1;
            }
        } else if ((cpct_isKeyPressed(Joy0_Up)) || (cpct_isKeyPressed(keys.up))) {
            if (rotateCellsUp() > 0) {
                dir = UP;
                addRandomCellTurn(UP);
                moved = 1;
            }

        } else if ( cpct_isKeyPressed(keys.music)) {
            if (!playing) {
                activateMusic();
            } else {
                deActivateMusic();
            }
        } else if (cpct_isKeyPressed(keys.abort))
            break;

        if (moved) {
            //Empty the rotated cells buffer after ending the animation
            //cpct_waitVSYNC();

            if (changedCards.number > 0) {
                animate(dir);
                resetChangedCards();

                highestCardGame = getHighestCard();
                pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 63, 154);
                cpct_drawSprite(cards[highestCardGame], pvmem, CARD_W, CARD_H);

                // Play sound Effect
                cpct_akp_SFXPlay(3, 14, 50 + (highestCardGame * 2), 1, 0, AY_CHANNEL_A);

            }

            moved = 0;
            if (anyMovesLeft() == 0) {
                cpct_akp_stop();
                cpct_akp_musicInit(song05);
                cpct_akp_musicPlay();
                drawScore();
                wait4UserKeypress();
                drawFrame(14, 60, 68, 130);
                drawText("NO MORE MOVES", 20, 70, 1);
                drawText("GAME OVER", 22, 90, 1);
                sprintf(aux_txt, "SCORE  %d", score);
                drawText(aux_txt, 22, 110, 1);
                delay(200);
                wait4UserKeypress();
                setHighScore(score);
                drawScoreBoard();
                cpct_akp_stop();
                cpct_akp_musicInit(song02);
                cpct_akp_musicPlay();
                break;
            }
        }

    }
}
Ejemplo n.º 19
0
int main(int argc, char** argv)
{
	int i = 0, params_valid = 1;
	char c, *udp_addr;
	gametable* game = NULL;
	
	int udp_sockfd,n, udp_port;
	struct sockaddr_in udp_servaddr,cliaddr;
	char sendline[1000];
	char recvline[1000];
	
	for(i = 0; i < argc; i++) {
		if(strcmp(argv[i], "-h") == 0) {
			if(i + 1 <= argc) {
				udp_addr = argv[++i];
			}
		} else if(strcmp(argv[i], "-u") == 0) {
			if(i + 1 <= argc) {
				udp_port = atoi(argv[++i]);
			}
		} /*else if(strcmp(argv[i], "-t") == 0) {
			if(i + 1 <= argc) {
				param_tcpport = argv[++i];
			}
		} */
	}
    
    if(udp_addr == NULL) {
        printf("hostname's not set, use -h <hostname> to set one\n");
        params_valid = 0;
    }
    
    if(udp_port == NULL) {
        printf("udp port's not set, use -u <port> to set one\n");
        params_valid = 0;
    }
    /*
    if(param_tcpport == NULL) {
        printf("tcp port's not set, use -t <port> to set one\n");
        params_valid = 0;
    }*/
    
    if(!params_valid) {
        printf("Couldn't run server due to mis-configuration. Quitting.\n");
        return 1;
    }
	
	initscr();
	intrflush(stdscr, FALSE); // Prevent interrupt flush
	keypad(stdscr,TRUE);
	timeout(0);
	
	start_color();
	init_pair(1, COLOR_RED, COLOR_BLACK);
	init_pair(2, COLOR_YELLOW, COLOR_BLACK);
	init_pair(3, COLOR_GREEN, COLOR_BLACK);
	init_pair(4, COLOR_BLUE, COLOR_BLACK);
	
	// client
	udp_sockfd=socket(AF_INET,SOCK_DGRAM,0);

	int flags = fcntl(udp_sockfd, F_GETFL);
	flags |= O_NONBLOCK;
	fcntl(udp_sockfd, F_SETFL, flags);
	
	bzero(&udp_servaddr,sizeof(udp_servaddr));
	udp_servaddr.sin_family = AF_INET;
	udp_servaddr.sin_addr.s_addr=inet_addr(udp_addr);
	udp_servaddr.sin_port=htons(udp_port);

	//printw("%s %d", udp_addr, udp_port);
	printw("Commands: /join, /ready, /area, /place <column>, /chat <message>, /quit\n");
	
	char c_input[100], c_input_copy[100];
	
	while (1) {
		sleep(0.01);
		
		// try receiving packet from server
		struct connect_four_packet_common * packet_recv = recvline;
    
        n=recvfrom(udp_sockfd,packet_recv,10000,0,NULL,NULL);
        recvline[n]=0;

        if (n > 2)
		{
			//printw("Got packet code %lu\n", packet_recv->msg_code);
			// parse packet
			switch(packet_recv->msg_code)
			{
				case 1000:
					printw(" %s\n", ((struct connect_four_packet_error *)packet_recv)->message);
					break;
				case 1:
					printw("Game joined. Type /ready when you're ready.\n");
					break;
				case 3:
					{
						struct connect_four_packet_start * packet_start = packet_recv;
						game = newGame(packet_start->column_count, packet_start->row_count);
						printw("Game started. %d players, game size %dx%d.\n", packet_start->player_count, game->width, game->height);
					}
					break;
				case 4:
					printw("Your turn. Select column with /place <number>\n");
					break;
				case 6:
				{
					struct connect_four_packet_area * packet_area = packet_recv;
					printw("%s", packet_area->area);
					strcpy(game->array, packet_area->area);
					drawTable(game);
					break;
				}
				case 7:
					printw("Player %d won!\n", ((struct connect_four_packet_winner *)packet_recv)->winner_id);
					printw("Type /join for a new game.\n");
					break;
				case 11:
					printw("%d: %s\n",((struct connect_four_packet_chat_server *)packet_recv)->player_id, ((struct connect_four_packet_chat_server *)packet_recv)->msg);
					break;
				case 20:
				{
					struct connect_four_packet_pong *packet_pong = malloc(sizeof(struct connect_four_packet_pong));
					packet_pong->msg_code = 21;
					sendto(udp_sockfd, packet_pong, sizeof(*packet_pong), 0,  (struct sockaddr *)&udp_servaddr, sizeof(udp_servaddr));
					free(packet_pong);
				}
			}
		}
		// if there's input, deactivate non-blocking input and read a line
		c = getch();
		if (c == ERR)
			continue;
		else 
			timeout(-1);
		getstr(c_input);
		//printw("%s\n", c_input);
		timeout(0);
		strcpy(c_input_copy, c_input);
		
		char *command = strtok(c_input_copy, " ");
		
		// parse commands, assign message codes based on them and send a packet
		if (strcmp(command, "quit") == 0)
		{
			struct connect_four_packet_quit *packet_quit = malloc(sizeof(struct connect_four_packet_quit));
			packet_quit->msg_code = 8;
			sendto(udp_sockfd, packet_quit, sizeof(*packet_quit), 0,  (struct sockaddr *)&udp_servaddr, sizeof(udp_servaddr));
			free(packet_quit);
			break;
		}
		else if (strcmp(command, "join") == 0)
		{
			struct connect_four_packet_join *packet_join = malloc(sizeof(struct connect_four_packet_join));
			packet_join->msg_code = 0;
			sendto(udp_sockfd, packet_join, sizeof(*packet_join), 0,  (struct sockaddr *)&udp_servaddr, sizeof(udp_servaddr));
			free(packet_join);
		}
		else if (strcmp(command, "ready") == 0)
		{
			struct connect_four_packet_ready *packet_ready = malloc(sizeof(struct connect_four_packet_ready));
			packet_ready->msg_code = 2;
			sendto(udp_sockfd, packet_ready, sizeof(*packet_ready), 0,  (struct sockaddr *)&udp_servaddr, sizeof(udp_servaddr));
			free(packet_ready);
		}
		else if (strcmp(command, "place") == 0)
		{
			struct connect_four_packet_column *packet_column = malloc(sizeof(struct connect_four_packet_column));
			packet_column->msg_code = 5;
			packet_column->selected_column = atoi(strtok(NULL, " "));
			sendto(udp_sockfd, packet_column, sizeof(*packet_column), 0,  (struct sockaddr *)&udp_servaddr, sizeof(udp_servaddr));
			free(packet_column);
		}
		else if (strcmp(command, "chat") == 0)
		{
			char* text = c_input;
			text = text + 5;
			
			struct connect_four_packet_chat_client *packet_chat_client = malloc(sizeof(struct connect_four_packet_chat_client));
			packet_chat_client->msg_code = 10;
			strcpy(packet_chat_client->msg, text);
			packet_chat_client->length = strlen(text);
			sendto(udp_sockfd, packet_chat_client, sizeof(*packet_chat_client), 0,  (struct sockaddr *)&udp_servaddr, sizeof(udp_servaddr));
			free(packet_chat_client);
		}
	}
	endwin();
}
Ejemplo n.º 20
0
//Exibe tudo na tela
void Display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glTranslatef (-80, 80, zoom);

    board();
    drawTeapot();
    drawSphere();
    drawCat();
    drawTable();

    if(gameOver && scoreRecorde > 0)
    {
        char tmp_str[40];

        glColor3f(1, 1, 0);
        glRasterPos2f(30, 10);

        sprintf(tmp_str, "Recorde: Level %d - Score %d", lvlRecorde, scoreRecorde);
        write(tmp_str);
    }

    char tmp_menu1[40];
    char tmp_menu2[40];
    char tmp_menu3[40];
    char tmp_menu4[40];
    char tmp_menu5[40];
    char tmp_menu6[40];
    char tmp_menu7[40];
    char tmp_menu8[40];
    char tmp_menu9[40];
    char tmp_menu10[40];
    char tmp_menu11[40];


    glColor3f(1.0, 0.0, 0.0);
    glRasterPos2f(0, 300);
    sprintf(tmp_menu1, "Creepy Cat");
    write(tmp_menu1);

    glColor3f(1, 1, 0);
    glRasterPos2f(-230, 270);
    sprintf(tmp_menu2, "- Objetivo: empurrar o teapot para fora dos limites da mesa");
    write(tmp_menu2);

    glColor3f(1, 1, 0);
    glRasterPos2f(-230, 240);
    sprintf(tmp_menu3, "- Cada teapot derrubado incrementa 100 pontos no score");
    write(tmp_menu3);

    glColor3f(1, 1, 0);
    glRasterPos2f(-230, 210);
    sprintf(tmp_menu4, "- A cada 500 pontos acumulados, o jogador sobe um level");
    write(tmp_menu4);

    glColor3f(1, 1, 0);
    glRasterPos2f(-230, 180);
    sprintf(tmp_menu5, "- A cada level, aumenta a velocidade do gato e podem surgir obstaculos");
    write(tmp_menu5);

    glColor3f(1, 1, 0);
    glRasterPos2f(-230, 150);
    sprintf(tmp_menu6, "- O jogador perde a partida se o gato ultrapassar os limites da mesa");
    write(tmp_menu6);

    glColor3f(1, 1, 0);
    glRasterPos2f(-230, 120);
    sprintf(tmp_menu7, "- Controle do gato pelas teclas direcionais (UP, DOWN, LEFT, RIGHT)");
    write(tmp_menu7);

    glColor3f(1, 1, 0);
    glRasterPos2f(-230, 90);
    sprintf(tmp_menu8, "- Controle da camera pelas teclas numericas (1, 2, 3, 4, 5, 6)");
    write(tmp_menu8);

    glColor3f(1, 1, 0);
    glRasterPos2f(-230, 60);
    sprintf(tmp_menu9, "- Para redefinir a camera pressione < E N T E R >");
    write(tmp_menu9);

    glColor3f(1, 1, 0);
    glRasterPos2f(-230, 30);
    sprintf(tmp_menu10, "- Para sair do jogo pressione < E S C > a qualquer momento");
    write(tmp_menu10);

    glColor3f(1, 1, 1);
    glRasterPos2f(-130, -200);
    sprintf(tmp_menu11, "Pressione < E N T E R >  para iniciar a partida" );
    write(tmp_menu11);

    char tmp_nomes[40];

    glColor3f(1.0, 0.0, 0.0);
    glRasterPos2f(-130, -400);
    sprintf(tmp_nomes, "Criado por: Luan De Nale e Raffaela Monteiro" );
    write(tmp_nomes);

    glutPostRedisplay();
    glutSwapBuffers();
}
Ejemplo n.º 21
0
void HostTerminal::onGameBegin(const Info& info)
{
  std::cout << std::endl;
  drawTable(info);
}
Ejemplo n.º 22
0
int Gaming(){
	int i, j, k, flag;
	stopcheck = 0;
	bla = whi = 2;
	printScore();
	while(CheckWin()){
		if(leftPress() != 1){
			getMousePosition(&mx,&my);
			if(mousex != mx||mousey != my){
				putimage(mousex,mousey,imagep,XOR_PUT);
				mousex = mx; mousey = my;
				putimage(mousex,mousey,imagep,XOR_PUT);
			}
		}
		else if(mouseLeftFlag == 1)			/*得到点击的位置*/
		{
			mouseLeftFlag = 0;
			getMousePosition(&mx,&my);
			for(i = 1; i < 9; i++){
				for(j = 1; j < 9; j++){
					if((mx > STARTX + SIDELENGTH * j && mx < STARTX + SIDELENGTH * (j+1)) && (my > STARTY + SIDELENGTH * i && my < STARTY + SIDELENGTH * (i+1))){
						break;
					}
				}
				if((mx > STARTX + SIDELENGTH * j && mx < STARTX + SIDELENGTH * (j+1)) && (my > STARTY + SIDELENGTH * i && my < STARTY + SIDELENGTH * (i+1))){
						break;
				}
			}
			if(color[i][j] == EMPTY){
				color[i][j] = colornow;
				inow = i; jnow = j; 
				if(change(i,j) == 1){
					if(BLA == colornow){
						ChessBlaSound();
						colornow = WHI;
					}
					else{
						ChessWhiSound();
						colornow = BLA;
					}
				}
				else{
					WarningSound();
					color[i][j] = EMPTY;
				}
			}
			cleardevice();
			drawTable();
			flag = bla = whi = count = 0;
			for(i = 1; i < 9; i++){
				for(j = 1; j < 9; j++){
					if(color[i][j] == BLA){
						bla++;
						count++;
					}else if(color[i][j] == WHI){
						whi++;
						count++;
					}else if(color[i][j] == EMPTY){
						color[i][j] = colornow;
						if(determine(i,j) == 1)
							flag = 1;
						color[i][j] = EMPTY;
					}
					drawChessman(i,j,color[i][j]);
				}
			}
			if(color[inow][jnow] != EMPTY)
				drawChessnow();
			if(flag == 0){
				if(BLA == colornow)
					colornow = WHI;
				else
					colornow = BLA;
				for(i = 1; i < 9; i++){
					for(j = 1; j < 9; j++){
						if(color[i][j] == EMPTY){
							color[i][j] = colornow;
							if(determine(i,j) == 1)
								flag = 1;
							color[i][j] = EMPTY;
						}
					}
				}
				if(flag == 0)
					stopcheck = 1;
			}
			printScore();
		}
	}
	return 1;
}
Ejemplo n.º 23
0
void myDisplay(void){
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(60.0, 1.0 * screenWidth / screenHeight, 0.1, 100.0);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  gluLookAt(cameraX, cameraY, cameraZ, coiX, coiY, coiZ, 0.0, 1.0, 0.0);

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

  //set the light source properties
  glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient0);
  glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse0);
  glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular0);
  glLightfv(GL_LIGHT0, GL_POSITION, light_position0);

  glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient1);
  glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse1);
  glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular1);
  glLightfv(GL_LIGHT1, GL_POSITION, light_position1);


  //set the remaining light sources	- write your code here
  glLightfv(GL_LIGHT2, GL_AMBIENT, light_ambient2);
  glLightfv(GL_LIGHT2, GL_DIFFUSE, light_diffuse2);
  glLightfv(GL_LIGHT2, GL_SPECULAR, light_specular2);
  glLightfv(GL_LIGHT2, GL_POSITION, light_position2);

  glLightfv(GL_LIGHT3, GL_AMBIENT, light_ambient3);
  glLightfv(GL_LIGHT3, GL_DIFFUSE, light_diffuse3);
  glLightfv(GL_LIGHT3, GL_SPECULAR, light_specular3);
  glLightfv(GL_LIGHT3, GL_POSITION, light_position3);

  glLightfv(GL_LIGHT4, GL_AMBIENT, light_ambient4);
  glLightfv(GL_LIGHT4, GL_DIFFUSE, light_diffuse4);
  glLightfv(GL_LIGHT4, GL_SPECULAR, light_specular4);
  glLightfv(GL_LIGHT4, GL_POSITION, light_position4);
  //turn on or off the fog - write your code here
if(fogSetting){
    glEnable(GL_FOG);
}
else {
    glDisable(GL_FOG);

}





  glColor3d(0.0, 0.0, 0.0);

/////////////////////////////////////////floor////////////////////////////////////////
  glMaterialfv(GL_FRONT, GL_AMBIENT, floor_ambient);
  glMaterialfv(GL_FRONT, GL_DIFFUSE, floor_diffuse);
  glMaterialfv(GL_FRONT, GL_SPECULAR, floor_specular);
  glMaterialfv(GL_FRONT, GL_SHININESS, floor_shininess);

glRotatef(theta,0,1,0);
  //draw the bottom floor
  glPushMatrix();
  glTranslatef(0,floorHeight/2.0,0);
  glScaled(floorWidth, floorHeight, floorWidth);

  glutSolidCube(1.0);
  glPopMatrix();

  //draw the left wall
  glPushMatrix();
  glTranslated(-floorWidth / 2.0, floorWidth / 2.0, 0.0);
  glRotated(90.0, 0.0, 0.0, 1.0);
  glScaled(floorWidth, floorHeight, floorWidth);
  glutSolidCube(1.0);
  glPopMatrix();

  //draw the right wall
  glPushMatrix();
  glTranslated(0.0, floorWidth / 2.0, -floorWidth / 2.0);
  glRotated(90.0, 1.0, 0.0, 0.0);
  glScaled(floorWidth, floorHeight, floorWidth);
  glutSolidCube(1.0);
  glPopMatrix();

  if (textureSetting == ON) glEnable(GL_TEXTURE_2D);

  //map an image texture on the left wall
  glBindTexture(GL_TEXTURE_2D, texImage1Name);
  glBegin(GL_QUADS);
    glNormal3f(1.0, 0.0, 0.0);
    glTexCoord2f(0.0, 0.0); glVertex3d(-floorWidth / 2.0 + floorHeight, 1.5, floorWidth / 2.0 - 1.25);
    glTexCoord2f(1.0, 0.0); glVertex3d(-floorWidth / 2.0 + floorHeight, 1.5, -floorWidth / 2.0 + 1.25);
    glTexCoord2f(1.0, 1.0); glVertex3d(-floorWidth / 2.0 + floorHeight, floorWidth - 0.5, -floorWidth / 2.0 + 1.25);
    glTexCoord2f(0.0, 1.0); glVertex3d(-floorWidth / 2.0 + floorHeight, floorWidth - 0.5, floorWidth / 2.0 - 1.25);
  glEnd();

  //map another image texture on the right wall - write your code here
  glBindTexture(GL_TEXTURE_2D, texImage2Name);
  glBegin(GL_QUADS);
    glNormal3f(0.0, 0.0, 1.0);
    glTexCoord2f(0.0, 0.0); glVertex3d(-floorWidth / 2.0 + 0.5, 1.5, -floorWidth / 2.0 + floorHeight);
    glTexCoord2f(1.0, 0.0); glVertex3d( floorWidth / 2.0 - 0.5, 1.5, -floorWidth / 2.0 + floorHeight);
    glTexCoord2f(1.0, 1.0); glVertex3d( floorWidth / 2.0 - 0.5, floorWidth - 0.5,-floorWidth / 2.0 + floorHeight);
    glTexCoord2f(0.0, 1.0); glVertex3d(-floorWidth / 2.0 + 0.5, floorWidth - 0.5,-floorWidth / 2.0 + floorHeight);
  glEnd();
  //map the checkerboard texture on the bottom floor - write your code here






  glBindTexture(GL_TEXTURE_2D, texCheckerBoardName);
  glBegin(GL_QUADS);
    glNormal3f(0.0, 1.0, 0.0);
    glTexCoord2f(0.0, 0.0); glVertex3d(-floorWidth / 2.0 , floorHeight+0.001, floorWidth / 2.0 );
    glTexCoord2f(1.0, 0.0); glVertex3d( floorWidth / 2.0 , floorHeight+0.001, floorWidth / 2.0 );
    glTexCoord2f(1.0, 1.0); glVertex3d( floorWidth / 2.0 , floorHeight+0.001, -floorWidth / 2.0 );
    glTexCoord2f(0.0, 1.0); glVertex3d(-floorWidth / 2.0 , floorHeight+0.001, -floorWidth / 2.0 );
  glEnd();






  if (textureSetting == ON) glDisable(GL_TEXTURE_2D);
//////////////////////////////////////////floor////////////////////////////////////////

  glTranslated(0.0, floorHeight, 0.0);


	//set up furniture (table, chairs) material properties
	glMaterialfv(GL_FRONT, GL_AMBIENT, furniture_ambient);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, furniture_diffuse);
	glMaterialfv(GL_FRONT, GL_SPECULAR, furniture_specular);
	glMaterialfv(GL_FRONT, GL_SHININESS, furniture_shininess);

	//draw the two chairs - write your code here
    glPushMatrix();
    glTranslatef(-floorWidth / 4.0, 0, floorWidth / 4.0);
    glRotatef(-90,0,1,0);
    chair();
    glPopMatrix();

    glPushMatrix();
    glTranslatef(floorWidth / 4.0, 0, -floorWidth / 4.0);
    chair();
    glPopMatrix();

	//shift to the quad on the floor which the table will be placed
	glPushMatrix();
	glTranslated(-1.0, 0.0, -1.0);

	//draw the table
	drawTable();

	//raise to the table top: all the remaining objects are above the table
	glTranslated(0.0, tableTopHeight, 0.0);

	//set up teapot/teacup material properties - write your code here
	glMaterialfv(GL_FRONT, GL_AMBIENT, teapot_ambient);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, teapot_diffuse);
	glMaterialfv(GL_FRONT, GL_SPECULAR, teapot_specular);
	glMaterialfv(GL_FRONT, GL_SHININESS, teapot_shininess);
	//draw the teapot - write your code here
	glPushMatrix();
	glTranslatef(0,0.15,0);
	glRotatef(45,0,1,0);
    tpot();
    glPopMatrix();
	//draw the teacup - write your code here
    glPushMatrix();
    glTranslatef(0, 0, tableTopWidth / 4.0);
    tcup();
    glPopMatrix();
    glPushMatrix();
    glTranslatef(tableTopWidth / 4.0, 0, 0);
    tcup();
    glPopMatrix();
	//set up lamp material properties - write your code here
	glMaterialfv(GL_FRONT, GL_AMBIENT, lamp_ambient);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, lamp_diffuse);
	glMaterialfv(GL_FRONT, GL_SPECULAR, lamp_specular);
	glMaterialfv(GL_FRONT, GL_SHININESS, lamp_shininess);
	//draw the lamp - write your code here
    glPushMatrix();
    glTranslatef(-tableTopWidth / 4.0, 0, -tableTopWidth / 4.0);
    lamp();
    glPopMatrix();

	glPopMatrix();
	//set up dustbin material properties - write your code here
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glMaterialfv(GL_FRONT, GL_AMBIENT, dustbin_ambient);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, dustbin_diffuse);
	glMaterialfv(GL_FRONT, GL_SPECULAR, dustbin_specular);
	glMaterialfv(GL_FRONT, GL_SHININESS, dustbin_shininess);
	//draw the dustbin - write your code here
  glPushMatrix();
  glTranslated(floorWidth / 4.0, dustbinHeight/2.0, floorWidth / 4.0);
  glScaled(dustbinWidth, dustbinHeight, dustbinWidth);
  glutSolidCube(1.0);
  glPopMatrix();
glDisable(GL_BLEND);
  glutSwapBuffers();
}