Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- Implementação controlada pelo GIt
- Alunos:
- Fagner de oliveira Bernardo 14.2.4155
- Natália Monferari Sol 14.2.4335
- */
- #ifdef __APPLE__
- #include <GLUT/glut.h>
- #else
- #include <GL/glut.h>
- #endif
- //#include <stdlib.h>
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- #include<unistd.h>
- //#include <windows.h>
- using namespace std;
- typedef struct ponto{
- GLfloat x;
- GLfloat y;
- }TPonto;
- #define INDICE 25
- #define QUAD2X2 4
- #define QUAD3X3 9
- #define NIVEL_INICIAL 1
- #define NUM_EMB_BOMB 10
- #define EMBARCACOES 5
- #define TAMANHO 40
- /*======================DECLARAÇÃO DE VARIÁVEIS GLOBAIS======================*/
- /*Especifica aposicao da janela*/
- GLfloat posX = 700.0, posY = 150.0, rate = 0.05;
- /*Especifica as dimensoes da janela*/
- GLfloat windowWidth = 520, windowHeight = 440;
- //turn: guarda as posicoes dos quadrados que vao mudar de cor
- //rodada guarda a quantidade de quadrado a memorizar
- //onGame é deve ser falsa quando o player perder
- //guess: guarda os cliques do jogador na posicao dos objetos na tela
- //verificacao: usada para chamar a funcao que avalia o resultado do jogo
- //jogoAtual: guarda qual jogo está sendo jogado no momento
- //indice: guarda a quantidade de cliques de mouse dados nas posicoes dos quadrados
- //tempo: determina o tempo base da duração do quadrado preto
- TPonto a, b, c, d;
- int turn[INDICE], guess[INDICE], nivel = NIVEL_INICIAL, jogoAtual = 0, indice = 0,
- verificacao = 0, tempo = 700, flagBlackColor = 0, posicoesEmb[NUM_EMB_BOMB], lin[NUM_EMB_BOMB], col[NUM_EMB_BOMB],
- tabuleiro[TAMANHO][TAMANHO] = {}, linha = 0, coluna = 0;
- /*===========================INICIO DAS DEFINIÇÕES===========================*/
- void init(void);
- /*Gerador dos numeros aleatórios*/
- void geraNum2x2();
- /*Gerador dos numeros aleatórios*/
- void geraNum3x3();
- bool confereBomba(int, int);
- /*Gerador dos numeros aleatórios*/
- void geraNumBatalha();
- void quad2x2();
- void jogoMemoriaFacil();
- void jogoMemoriaDificil();
- void jogoBatalhaNaval();
- void quad3x3();
- void desenhaCubos();
- void display(void);
- /*Função calback chamada para gerenciar eventos do mouse*/
- void GerenciaMouse(int button, int state, int x, int y);
- void verificaAcerto();
- void posicionaEmbarcacoes();
- void GoMenu(int value);
- /*===========================FIM DAS DEFINIÇÕES===========================*/
- int main (int argc, char** argv) {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
- glutInitWindowSize(windowWidth, windowHeight);
- glutInitWindowPosition(posX, posY);
- glutCreateWindow("Menu");
- int sub1 = glutCreateMenu(GoMenu);
- glutAddMenuEntry("Fácil",1);
- glutAddMenuEntry("Difícil",2);
- glutCreateMenu(GoMenu);
- glutAddSubMenu("Memória", sub1);
- glutAddMenuEntry("Batalha Naval",3);
- glutAddMenuEntry("Sair",4);
- glutAttachMenu(GLUT_RIGHT_BUTTON);
- glutMouseFunc(GerenciaMouse);
- init();
- glutDisplayFunc(display);
- glutMainLoop();
- return 0;
- }
- /*===========================INICIO DAS ESPECIFICAÇÕES===========================*/
- void GoMenu(int value) {
- switch(value){
- case 1:
- jogoAtual = 1;
- nivel = NIVEL_INICIAL;
- indice = 0;
- geraNum2x2();
- //Zera o vetor de chutes
- for (int i = 0; i < INDICE; i++){
- guess[i] = -1;
- }
- jogoMemoriaFacil();
- break;
- case 2:
- jogoAtual = 2;
- nivel = NIVEL_INICIAL;
- indice = 0;
- geraNum3x3();
- //Zera o vetor de chutes
- for (int i = 0; i < INDICE; i++){
- guess[i] = -1;
- }
- jogoMemoriaDificil();
- break;
- case 3:
- jogoAtual = 3;
- nivel = NIVEL_INICIAL;
- geraNumBatalha();
- jogoBatalhaNaval();
- break;
- case 4:
- exit(0);
- break;
- }
- glutPostRedisplay();
- }
- void init(void) {
- glClearColor(1.0, 1.0,1.0,0.0);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- a.x = -1.0;
- a.y = 0.8;
- b.x = -0.8;
- b.y = 0.8;
- c.x = -0.8;
- c.y = 1.0;
- d.x = -1.0;
- d.y = 1.0;
- cout << "init" << endl;
- /*Determina as configurações do plano cartesiano de projeção*/
- glOrtho(0.0, 1.0, 0.0, 1.0, 0.0 ,0.0);
- }
- void geraNum2x2(){
- cout << "Entrou geraNum()" << endl;
- //Gera uma semente para o tempo
- srand((unsigned) time (NULL));
- //Gera um vetor com 25 numeros aleatorios
- for(int i = 0 ; i < INDICE ; i++){
- turn[i] = rand()%QUAD2X2 +1;
- cout << turn[i] << " ";
- }
- cout << endl;
- }
- void geraNum3x3(){
- cout << "Entrou geraNum()" << endl;
- //Gera uma semente para o tempo
- srand((unsigned) time (NULL));
- //Gera um vetor com 25 numeros aleatorios
- for(int i = 0 ; i < INDICE ; i++){
- turn[i] = rand()%QUAD3X3 +1;
- cout << turn[i] << " ";
- }
- cout << endl;
- }
- bool confereBomba(int linha, int coluna){
- //Confere se não tem nada na posicao
- if(tabuleiro[linha][coluna] == 0){
- tabuleiro[linha][coluna] = 2;
- return true;
- }
- else{
- //Se houver, anda uma linha até achar um lugar vazio
- if(linha < TAMANHO-1){
- linha++;
- confereBomba(linha, coluna);
- }
- //Anda uma coluna para a direita até achar um lugar vazio
- else if(coluna < TAMANHO-1){
- linha = 0;
- coluna++;
- confereBomba(linha, coluna);
- }
- //Caso não ache lugar vazio, retorna falso. Dentro do while será gerado outra posicao aleatoria
- else{
- return false;
- }
- }
- }
- void geraNumBatalha(){
- cout << "Entrou geraNum()" << endl;
- //Gera uma semente para o tempo
- srand((unsigned) time (NULL));
- //Gera um vetor com 10 embarcaccoes aleatorias
- for(int i = 0 ; i < NUM_EMB_BOMB ; i++){
- posicoesEmb[i] = rand()%EMBARCACOES +1;
- cout << posicoesEmb[i] << " ";
- }
- //Gera 10 posicoes aleatorias para as bombas
- for(int j =0; j < NUM_EMB_BOMB; j++){
- linha = rand()%TAMANHO;
- coluna = rand()%TAMANHO;
- //Confere a posicao da bomba está vazia
- while(!confereBomba(linha, coluna)){
- linha = rand()%TAMANHO;
- coluna = rand()%TAMANHO;
- }
- cout << "Linha: "<<linha<<" Coluna: "<< coluna << endl;
- }
- cout << endl;
- }
- void quad2x2(){
- if(flagBlackColor == 1){
- glColor3f(0.0, 0.0, 0.0);
- cout << "Black color: " << flagBlackColor << " direito superior" << endl;
- }
- else{
- glColor3f(1.0, 1.0, 0.0);
- }
- /*Gera um poligono direita superior*/
- glBegin(GL_POLYGON);
- glVertex3f(0.0,0.0,0.0);
- glVertex3f(0.5,0.0,0.0);
- glVertex3f(0.5,0.5,0.0);
- glVertex3f(0.0,0.5,0.0);
- glEnd();
- if(flagBlackColor == 2){
- glColor3f(0.0, 0.0, 0.0);
- cout << "Black color: " << flagBlackColor << " esquerdo superior" << endl;
- }
- else{
- glColor3f(1.0, 0.0, 0.0);
- }
- /*Gera um poligono esquerda superior*/
- glBegin(GL_POLYGON);
- glVertex3f(0.0,0.0,0.0);
- glVertex3f(0.0,0.5,0.0);
- glVertex3f(-0.5,0.5,0.0);
- glVertex3f(-0.5,0.0,0.0);
- glEnd();
- if(flagBlackColor == 3){
- glColor3f(0.0, 0.0, 0.0);
- cout << "Black color: " << flagBlackColor << " esquerdo inferior" << endl;
- }
- else{
- glColor3f(0.0, 0.0, 1.0);
- }
- /*Gera um poligono esquerda inferior*/
- glBegin(GL_POLYGON);
- glVertex3f(0.0,0.0,0.0);
- glVertex3f(-0.5,0.0,0.0);
- glVertex3f(-0.5,-0.5,0.0);
- glVertex3f(0.0,-0.5,0.0);
- glEnd();
- if(flagBlackColor == 4){
- glColor3f(0.0, 0.0, 0.0);
- cout << "Black color: " << flagBlackColor << " direito inferior" << endl;
- }
- else{
- glColor3f(0.0, 1.0, 0.0);
- }
- /*Gera um poligono direita inferior*/
- glBegin(GL_POLYGON);
- glVertex3f(0.0,0.0,0.0);
- glVertex3f(0.0,-0.5,0.0);
- glVertex3f(0.5,-0.5,0.0);
- glVertex3f(0.5,0.0,0.0);
- glEnd();
- glFlush();
- }
- void quad3x3(){
- if(flagBlackColor == 1){
- cout << "Black color: " << flagBlackColor << " direito direita L1" << endl;
- glColor3f(0.0, 0.0, 0.0);
- }
- else{
- glColor3f(1.0, 1.0, 0.0);
- }
- /*Gera um poligono direita L1*/
- glBegin(GL_POLYGON);
- glVertex3f(0.6,0.6,0.0);
- glVertex3f(0.2,0.6,0.0);
- glVertex3f(0.2,0.2,0.0);
- glVertex3f(0.6,0.2,0.0);
- glEnd();
- if(flagBlackColor == 2){
- cout << "Black color: " << flagBlackColor << " central L1" << endl;
- glColor3f(0.0, 0.0, 0.0);
- }
- else{
- glColor3f(1.0, 0.0, 0.0);
- }
- /*Gera um poligono central L1*/
- glBegin(GL_POLYGON);
- glVertex3f(0.2,0.6,0.0);
- glVertex3f(-0.2,0.6,0.0);
- glVertex3f(-0.2,0.2,0.0);
- glVertex3f(0.2,0.2,0.0);
- glEnd();
- if(flagBlackColor == 3){
- cout << "Black color: " << flagBlackColor << " esquerda L1" << endl;
- glColor3f(0.0, 0.0, 0.0);
- }
- else{
- glColor3f(0.0, 0.0, 1.0);
- }
- /*Gera um poligono esquerda L1*/
- glBegin(GL_POLYGON);
- glVertex3f(-0.2,0.6,0.0);
- glVertex3f(-0.6,0.6,0.0);
- glVertex3f(-0.6,0.2,0.0);
- glVertex3f(-0.2,0.2,0.0);
- glEnd();
- if(flagBlackColor == 4){
- cout << "Black color: " << flagBlackColor << " direita L2" << endl;
- glColor3f(0.0, 0.0, 0.0);
- }
- else{
- glColor3f(0.5, 0.5, 0.0);
- }
- /*Gera um poligono direita L2*/
- glBegin(GL_POLYGON);
- glVertex3f(0.6,-0.2,0.0);
- glVertex3f(0.2,-0.2,0.0);
- glVertex3f(0.2,0.2,0.0);
- glVertex3f(0.6,0.2,0.0);
- glEnd();
- if(flagBlackColor == 5){
- cout << "Black color: " << flagBlackColor << " central L2" << endl;
- glColor3f(0.0, 0.0, 0.0);
- }
- else{
- glColor3f(0.0, 0.5, 0.5);
- }
- /*Gera um poligono central L2*/
- glBegin(GL_POLYGON);
- glVertex3f(0.2,-0.2,0.0);
- glVertex3f(-0.2,-0.2,0.0);
- glVertex3f(-0.2,0.2,0.0);
- glVertex3f(0.2,0.2,0.0);
- glEnd();
- if(flagBlackColor == 6){
- cout << "Black color: " << flagBlackColor << " esquerda L2" << endl;
- glColor3f(0.0, 0.0, 0.0);
- }
- else{
- glColor3f(0.5, 0.0, 0.5);
- }
- /*Gera um poligono esquerda L2*/
- glBegin(GL_POLYGON);
- glVertex3f(-0.2,-0.2,0.0);
- glVertex3f(-0.6,-0.2,0.0);
- glVertex3f(-0.6,0.2,0.0);
- glVertex3f(-0.2,0.2,0.0);
- glEnd();
- if(flagBlackColor == 7){
- cout << "Black color: " << flagBlackColor << " direita L3" << endl;
- glColor3f(0.0, 0.0, 0.0);
- }
- else{
- glColor3f(1.0, 0.5, 5.0);
- }
- /*Gera um poligono direita L3*/
- glBegin(GL_POLYGON);
- glVertex3f(0.6,-0.6,0.0);
- glVertex3f(0.2,-0.6,0.0);
- glVertex3f(0.2,-0.2,0.0);
- glVertex3f(0.6,-0.2,0.0);
- glEnd();
- if(flagBlackColor == 8){
- cout << "Black color: " << flagBlackColor << " central L3" << endl;
- glColor3f(0.0, 0.0, 0.0);
- }
- else{
- glColor3f(0.5, 0.5, 1.0);
- }
- /*Gera um poligono central L3*/
- glBegin(GL_POLYGON);
- glVertex3f(0.2,-0.6,0.0);
- glVertex3f(-0.2,-0.6,0.0);
- glVertex3f(-0.2,-0.2,0.0);
- glVertex3f(0.2,-0.2,0.0);
- glEnd();
- if(flagBlackColor == 9){
- cout << "Black color: " << flagBlackColor << " esquerda L3" << endl;
- glColor3f(0.0, 0.0, 0.0);
- }
- else{
- glColor3f(0.5, 1.0, 0.5);
- }
- /*Gera um poligono esquerda L3*/
- glBegin(GL_POLYGON);
- glVertex3f(-0.2,-0.6,0.0);
- glVertex3f(-0.6,-0.6,0.0);
- glVertex3f(-0.6,-0.2,0.0);
- glVertex3f(-0.2,-0.2,0.0);
- glEnd();
- glFlush();
- }
- void desenhaCubos(){
- float passo = 0.0;
- cout << "desenha" << endl;
- for(int i = 0; i <= 40; i++){
- cout << "Ponto A: ("<< a.x << "," << a.y << ")" << endl;
- cout << "Ponto B: ("<< b.x << "," << b.y << ")" << endl;
- cout << "Ponto C: ("<< c.x << "," << c.y << ")" << endl;
- cout << "Ponto D: ("<< d.x << "," << d.y << ")" << endl;
- for(int j = 0; j <= 40; j++){
- /*Gera um poligono*/
- glBegin(GL_POLYGON);
- //Troca a cor dos quadrados
- if(j%2 == 0){
- if (i%2 == 0){
- glColor3f(1.0, 1.0, 0.0);
- }
- else{
- glColor3f(0.0, 1.0, 1.0);
- }
- }
- else{
- if (i%2 == 0){
- glColor3f(0.0, 1.0, 1.0);
- }
- else{
- glColor3f(1.0, 1.0, 0.0);
- }
- }
- //Desenha um quadrado
- glVertex3f(a.x + passo, a.y, 0.0);
- glVertex3f(b.x + passo, b.y, 0.0);
- glVertex3f(c.x + passo, c.y, 0.0);
- glVertex3f(d.x + passo, d.y, 0.0);
- //muda as coordenadas base para desenhar outro quadrado na prox iteracao
- glEnd();
- passo += rate;
- }
- //Retorna ao inicio da linha
- passo = 0.0;
- // Desce p a proxima linha de renderização
- a.y -= rate;
- b.y -= rate;
- c.y -= rate;
- d.y -= rate;
- }
- glFlush();
- a.x = 0.0;
- a.y = 0.0;
- b.x = 0.2;
- b.y = 0.0;
- c.x = 0.2;
- c.y = 0.2;
- d.x = 0.0;
- d.y = 0.2;
- }
- bool confereDestroyer(int lin, int col){
- cout << "Confere: lin"<< lin << " col"<< col <<endl;
- //Confere se não tem nada na posicao
- if(tabuleiro[lin][col] == 0 && tabuleiro[lin][(col+1)] == 0 && tabuleiro[(lin+1)][(col+1)] == 0 && tabuleiro[(lin+1)][(col+2)]== 0 && tabuleiro[(lin+1)][(col+3)] == 0){
- tabuleiro[lin][col] = 1;
- tabuleiro[lin][(col+1)] = 1;
- tabuleiro[(lin+1)][(col+1)] = 1;
- tabuleiro[(lin+1)][(col+2)] = 1;
- tabuleiro[(lin+1)][(col+3)] = 1;
- return true;
- }
- else{
- //Se houver, anda uma linha até achar um lugar vazio
- if(lin < TAMANHO-2){
- lin++;
- confereDestroyer(lin, col);
- }
- //Anda uma coluna para a direita até achar um lugar vazio
- else if (col < TAMANHO-4) {
- lin = 0;
- col++;
- confereDestroyer(lin, col);
- }
- //Caso não ache lugar vazio, retorna falso. Dentro do while será gerado outra posicao aleatoria
- else{
- return false;
- }
- }
- }
- bool confereSubmarino(int lin, int col){
- cout << "Confere: lin"<< lin << " col"<< col <<endl;
- //Confere se não tem nada na posicao
- if(tabuleiro[lin][col] == 0 && tabuleiro[lin][(col+1)] == 0 && tabuleiro[lin][(col+2)] == 0 && tabuleiro[lin][(col+3)] == 0 && tabuleiro[lin][(col+4)] == 0 && tabuleiro[(lin-1)][(col+2)] == 0){
- tabuleiro[lin][col] = 1;
- tabuleiro[lin][(col+1)] = 1;
- tabuleiro[lin][(col+2)] = 1;
- tabuleiro[lin][(col+3)] = 1;
- tabuleiro[lin][(col+4)] = 1;
- tabuleiro[(lin-1)][(col+2)] = 1;
- return true;
- }
- else{
- //Se houver, anda uma linha até achar um lugar vazio
- if(lin < TAMANHO-1){
- lin++;
- confereSubmarino(lin, col);
- }
- //Anda uma coluna para a direita até achar um lugar vazio
- else if (col < TAMANHO-5) {
- lin = 0;
- col++;
- confereSubmarino(lin, col);
- }
- //Caso não ache lugar vazio, retorna falso. Dentro do while será gerado outra posicao aleatoria
- else{
- return false;
- }
- }
- }
- bool conferePortaAvioes(int lin, int col){
- cout << "Confere: lin"<< lin << " col"<< col <<endl;
- //Confere se não tem nada na posicao
- if(tabuleiro[lin][col] == 0 && tabuleiro[lin][(col+1)] == 0 && tabuleiro[lin][(col+2)] == 0 && tabuleiro[lin][(col+3)] == 0 && tabuleiro[(lin+1)][(col+2)] == 0 && tabuleiro[(lin+1)][(col+3)] == 0 && tabuleiro[(lin+1)][(col+4)] == 0 && tabuleiro[(lin+1)][(col+5)] == 0){
- tabuleiro[lin][col] = 1;
- tabuleiro[lin][(col+1)] = 1;
- tabuleiro[lin][(col+2)] = 1;
- tabuleiro[lin][(col+3)] = 1;
- tabuleiro[(lin+1)][(col+2)] = 1;
- tabuleiro[(lin+1)][(col+3)] = 1;
- tabuleiro[(lin+1)][(col+4)] =1;
- tabuleiro[(lin+1)][(col+5)] = 1;
- return true;
- }
- else{
- //Se houver, anda uma linha até achar um lugar vazio
- if(lin < TAMANHO-2){
- lin++;
- conferePortaAvioes(lin, col);
- }
- //Anda uma coluna para a direita até achar um lugar vazio
- else if (col < TAMANHO-6) {
- lin = 0;
- col++;
- conferePortaAvioes(lin, col);
- }
- //Caso não ache lugar vazio, retorna falso. Dentro do while será gerado outra posicao aleatoria
- else{
- return false;
- }
- }
- }
- bool confereCorveta(int lin, int col){
- cout << "Confere: lin"<< lin << " col"<< col <<endl;
- //Confere se não tem nada na posicao
- if(tabuleiro[lin][col] == 0 && tabuleiro[lin][(col+1)] == 0 && tabuleiro[(lin+1)][(col+1)] == 0 ){
- tabuleiro[lin][col] = 1;
- tabuleiro[lin][(col+1)] = 1;
- tabuleiro[(lin+1)][(col+1)] = 1;
- return true;
- }
- else{
- //Se houver, anda uma linha até achar um lugar vazio
- if(lin < TAMANHO-2){
- lin++;
- confereCorveta(lin, col);
- }
- //Anda uma coluna para a direita até achar um lugar vazio
- else if (col < TAMANHO-2) {
- lin = 0;
- col++;
- confereCorveta(lin, col);
- }
- //Caso não ache lugar vazio, retorna falso. Dentro do while será gerado outra posicao aleatoria
- else{
- return false;
- }
- }
- }
- bool confereLancaAtaque(int lin, int col){
- cout << "Confere: lin"<< lin << " col"<< col <<endl;
- //Confere se não tem nada na posicao
- if(tabuleiro[lin][col] == 0 && tabuleiro[lin][(col+1)] == 0 && tabuleiro[(lin+1)][(col+2)] == 0){
- tabuleiro[lin][col] = 1;
- tabuleiro[lin][(col+1)] = 1;
- tabuleiro[(lin+1)][(col+2)] = 1;
- return true;
- }
- else{
- //Se houver, anda uma linha até achar um lugar vazio
- if(lin < TAMANHO-2){
- lin++;
- confereLancaAtaque(lin, col);
- }
- //Anda uma coluna para a direita até achar um lugar vazio
- else if (col < TAMANHO-3) {
- lin = 0;
- col++;
- confereLancaAtaque(lin, col);
- }
- //Caso não ache lugar vazio, retorna falso. Dentro do while será gerado outra posicao aleatoria
- else{
- return false;
- }
- }
- }
- void posicionaEmbarcacoes(){
- for(int i = 0 ; i < NUM_EMB_BOMB ; i++){
- //Destroyer
- if(posicoesEmb[i] == 1){
- //gera posicao aleatoria para o destroyer
- lin[i] = rand()%(TAMANHO-1) ;
- col[i] = rand()%(TAMANHO-3);
- cout << "Lin["<<i <<"]: " << lin[i] << "Col: " << col[i] << endl;
- //Confere a posicao do destroyer está vazia
- while (!confereDestroyer(lin[i],col[i])){
- lin[i] = rand()%(TAMANHO-1);
- col[i] = rand()%(TAMANHO-3);
- }
- }
- //Submarino
- else if(posicoesEmb[i] == 2){
- //gera posicao aleatoria para o submarino
- lin[i] = rand()%(TAMANHO-1)+1;
- col[i] = rand()%(TAMANHO-4);
- cout << "Lin["<<i <<"]: " << lin[i] << "Col: " << col[i] << endl;
- //Confere a posicao do submarino está vazia
- while (!confereSubmarino(lin[i],col[i])){
- lin[i] = rand()%(TAMANHO-1)+1 ;
- col[i] = rand()%(TAMANHO-4);
- }
- }
- else if(posicoesEmb[i] == 3){
- //gera posicao aleatoria para o porta avioes
- lin[i] = rand()%(TAMANHO-1);
- col[i] = rand()%(TAMANHO-5);
- cout << "Lin["<<i <<"]: " << lin[i] << "Col: " << col[i] << endl;
- //Confere a posicao do porta avioes está vazia
- while (!conferePortaAvioes(lin[i],col[i])){
- lin[i] = rand()%(TAMANHO-1) ;
- col[i] = rand()%(TAMANHO-5);
- }
- }
- else if(posicoesEmb[i] == 4){
- //gera posicao aleatoria para a corveta
- lin[i] = rand()%(TAMANHO-1);
- col[i] = rand()%(TAMANHO-1);
- cout << "Lin["<<i <<"]: " << lin[i] << "Col: " << col[i] << endl;
- //Confere a posicao da corveta está vazia
- while (!confereCorveta(lin[i],col[i])){
- lin[i] = rand()%(TAMANHO-1) ;
- col[i] = rand()%(TAMANHO-1);
- }
- }
- else{
- //gera posicao aleatoria para a lanca de ataque
- lin[i] = rand()%(TAMANHO-1);
- col[i] = rand()%(TAMANHO-2);
- cout << "Lin["<<i <<"]: " << lin[i] << "Col: " << col[i] << endl;
- //Confere a posicao da lanca de ataque está vazia
- while (!confereLancaAtaque(lin[i],col[i])){
- lin[i] = rand()%(TAMANHO-1) ;
- col[i] = rand()%(TAMANHO-2);
- }
- }
- }
- }
- void imprime(){
- for(int i = 0; i < TAMANHO; i++){
- cout << i << " " ;
- for(int j = 0; j < TAMANHO; j++){
- cout << tabuleiro[i][j] << " " ;
- }
- cout << endl;
- }
- }
- void display(void){
- cout << "Entrou display()" << endl;
- glClear(GL_COLOR_BUFFER_BIT);
- // Limpa a janela
- glMatrixMode(GL_PROJECTION);
- //Evita erro de projeção da imagem
- glLoadIdentity();
- //cout << "jogoAtual: " << jogoAtual << endl;
- if(jogoAtual == 1){
- quad2x2();
- }
- else{
- if (jogoAtual == 2){
- quad3x3();
- }
- else{
- if (jogoAtual == 3){
- cout << "batalha navalis" << endl;
- }
- }
- }
- cout << "Saiu display()" << endl;
- }
- void GerenciaMouse(int button, int state, int x, int y){
- if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){
- cout << "Pixel x: " << x << endl;
- cout << "Pixel y: " << y << endl;
- }
- /*if (button == GLUT_RIGHT_BUTTON){
- cout << "Botao direito apertado" << endl;
- }*/
- //Usa estas regras para o mouse se o jogo for o nivel fácil
- if(jogoAtual == 1){
- //Região do quadrado superior direito
- if (x > 260 && x < 389 && y > 110 && y < 218 && button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){
- guess[indice] = 1;
- indice++;
- cout << "Quadrado superior direito, ";
- cout << "indice: " << indice << endl;
- if(indice == nivel){
- verificacao = 1;
- verificaAcerto();
- }
- }
- //Região do quadrado superior esquerdo
- if (x > 130 && x < 260 && y > 110 && y < 218 && button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){
- guess[indice] = 2;
- indice++;
- cout << "Quadrado superior esquerdo, ";
- cout << "indice: " << indice << endl;
- if(indice == nivel){
- verificacao = 1;
- verificaAcerto();
- }
- }
- //Região do quadrado inferior esquerdo
- if (x > 130 && x < 260 && y > 218 && y < 329 && button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){
- guess[indice] = 3;
- indice++;
- cout << "Quadrado inferior esquerdo, ";
- cout << "indice: " << indice << endl;
- if(indice == nivel){
- verificacao = 1;
- verificaAcerto();
- }
- }
- //Região do quadrado inferior direito
- if (x > 260 && x < 389 && y > 218 && y < 329 && button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){
- guess[indice] = 4;
- indice++;
- cout << "Quadrado inferior direito, " ;
- cout << "indice: " << indice << endl;
- if(indice == nivel){
- verificacao = 1;
- verificaAcerto();
- }
- }
- }
- if(jogoAtual == 2){
- //Região do quadrado direito L1
- if (x > 313 && x < 415 && y > 88 && y < 174 && button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){
- guess[indice] = 1;
- indice++;
- cout << "Quadrado superior direito, ";
- cout << "indice: " << indice << endl;
- if(indice == nivel){
- verificacao = 1;
- verificaAcerto();
- }
- }
- //Região do meio L1
- if (x > 209 && x < 311 && y > 88 && y < 174 && button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){
- guess[indice] = 2;
- indice++;
- cout << "Quadrado superior esquerdo, ";
- cout << "indice: " << indice << endl;
- if(indice == nivel){
- verificacao = 1;
- verificaAcerto();
- }
- }
- //Região do esquerdo L1
- if (x > 104 && x < 207 && y > 88 && y < 174 && button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){
- guess[indice] = 3;
- indice++;
- cout << "Quadrado inferior esquerdo, ";
- cout << "indice: " << indice << endl;
- if(indice == nivel){
- verificacao = 1;
- verificaAcerto();
- }
- }
- //Região do quadrado direito L2
- if (x > 313 && x < 415 && y > 176 && y < 263 && button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){
- guess[indice] = 4;
- indice++;
- cout << "Quadrado inferior direito, " ;
- cout << "indice: " << indice << endl;
- if(indice == nivel){
- verificacao = 1;
- verificaAcerto();
- }
- }
- //Região do quadrado meio L2
- if (x > 209 && x < 311 && y > 176 && y < 263 && button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){
- guess[indice] = 5;
- indice++;
- cout << "Quadrado inferior direito, " ;
- cout << "indice: " << indice << endl;
- if(indice == nivel){
- verificacao = 1;
- verificaAcerto();
- }
- }
- //Região do quadrado esquerdo L2
- if (x > 104 && x < 207 && y > 176 && y < 263 && button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){
- guess[indice] = 6;
- indice++;
- cout << "Quadrado inferior direito, " ;
- cout << "indice: " << indice << endl;
- if(indice == nivel){
- verificacao = 1;
- verificaAcerto();
- }
- }
- //Região do quadrado direito L3
- if (x > 260 && x < 389 && y > 265 && y < 351 && button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){
- guess[indice] = 7;
- indice++;
- cout << "Quadrado inferior direito, " ;
- cout << "indice: " << indice << endl;
- if(indice == nivel){
- verificacao = 1;
- verificaAcerto();
- }
- }
- //Região do quadrado meio L3
- if (x > 209 && x < 311 && y > 265 && y < 351 && button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){
- guess[indice] = 8;
- indice++;
- cout << "Quadrado inferior direito, " ;
- cout << "indice: " << indice << endl;
- if(indice == nivel){
- verificacao = 1;
- verificaAcerto();
- }
- }
- //Região do quadrado esquerdo L3
- if (x > 104 && x < 207 && y > 265 && y < 351 && button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){
- guess[indice] = 9;
- indice++;
- cout << "Quadrado inferior direito, " ;
- cout << "indice: " << indice << endl;
- if(indice == nivel){
- verificacao = 1;
- verificaAcerto();
- }
- }
- }
- glutPostRedisplay();
- }
- void jogoMemoriaFacil(){
- cout << "Entrou jogoMemoriaFacil()" << endl;
- int i;
- // Controla cada jogada até o player errar
- for(i = 0; i < nivel ; i++){
- cout << "tempo" << tempo << endl;
- Sleep(tempo - (10*nivel));
- //Pinta um quadrado de preto
- flagBlackColor = turn[i];
- display();
- cout << "Piscou " << i << endl;
- Sleep(tempo - (10*nivel));
- //Pinta o quadrado com a cor original
- flagBlackColor = 0;
- display();
- }
- }
- void jogoMemoriaDificil(){
- cout << "Entrou jogo da memoria Dificil" << endl;
- int i;
- // Controla cada jogada até o player errar
- for(i = 0; i < nivel ; i++){
- cout << "tempo" << tempo << endl;
- Sleep(tempo - (10*nivel));
- //Pinta um quadrado de preto
- flagBlackColor = turn[i];
- display();
- cout << "Piscou " << i << endl;
- Sleep(tempo - (10*nivel));
- //Pinta o quadrado com a cor original
- flagBlackColor = 0;
- display();
- }
- }
- void jogoBatalhaNaval(){
- desenhaCubos();
- posicionaEmbarcacoes();
- imprime();
- }
- void verificaAcerto(){
- int cont = 0;
- cout << "Entrou verifica acerto" << endl;
- cout << "valor do indice: " << indice << endl;
- if(verificacao == 1){
- for(int j = 0 ; j < indice ; j++){
- if (turn[j] == guess[j]){
- cont++;
- }
- }
- cout << "valor do indice: " << indice << endl;
- cout << "valor do cont: " << cont << endl;
- if(cont == indice){
- cout << "Voce acertou!" << endl;
- indice = 0;
- if(nivel <= 25){
- nivel++;
- cout << "Nivel: " << nivel << endl;
- Sleep(500);
- //Inicia o próximo nivel do jogo conforme o jogo que esta sendo jogado
- switch(jogoAtual){
- case 1:{
- jogoMemoriaFacil();
- break;
- }
- case 2:{
- jogoMemoriaDificil();
- break;
- }
- }
- }
- else{
- exit(0);
- }
- }
- else{
- cout << "Voce errou!" << endl;
- exit(0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement