mayoscuro

Members
  • Content count

    6
  • Joined

  • Last visited

Community Reputation

105 Neutral

About mayoscuro

  • Rank
    Newbie
  1. Map of console rpg

    Is developed in windows console ¿Is that what your asking me?
  2. Map of console rpg

    Thanks ^ ^ Now I have another question ... How I can detect the arrow keys without using the library <conio.h>? Is there any way to use std :: KeyChar without pressing the enter key?
  3. Map of console rpg

    hello, I'm doing a small console rpg in c + +. In this rpg just have to move a letter "p" by a matrix (two-dimensional) until you reach the letter "M". The problem appears to generate the array. I think it's easy, the problem is that the ion Assignment I copied below (void generarmapa (game & board)) the array always takes the same value ("H") and all others are ignored. Can someone explain why this happens? Is there another way to assign these values??? Thank you very much ^ ^ sorry for the possible bad writing of the text, I do not speak much English, I do what I can, I will gradually improve [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] [CODE] typedef std::vector< std::vector< int > > juego; void generarmapa(juego &tablero){ for(int y=0;y<19;y++ ){ tablero[0][y] ='H','H','H','H','H','H','H','H','H','H','H','H','H','H','H','H','H','H','H'; } for(int y=0;y<19;y++ ){ tablero[1][y] ='H','P','H','H','H','H','H',' ',' ',' ',' ',' ','O','H','H','H','H','H','H'; } for(int y=0;y<19;y++ ){ tablero[2][y] ='H',' ','H',' ',' ',' ',' ',' ','H','H','H','H','H','H','H','H','H','H','H'; } for(int y=0;y<19;y++ ){ tablero[3][y] ='H',' ','H',' ','H','H','H','E',' ','H','H','H',' ',' ',' ',' ','B',' ','M'; } for(int y=0;y<19;y++ ){ tablero[4][y] ='H',' ','E',' ','H','H','H',' ','H','H','H','H',' ','H','H','H','H','H','H'; } for(int y=0;y<19;y++ ){ tablero[5][y] ='H','H','H','H','H','H','H',' ','H','H','H','H',' ','H','H','H','H','H','H'; } for(int y=0;y<19;y++ ){ tablero[6][y] ='H','H','H','H','H','H','H',' ','H','H','H','H',' ','H','H','H','H','H','H'; } for(int y=0;y<19;y++ ){ tablero[7][y] ='H','H','H','H','H','H','H',' ',' ',' ','E',' ',' ','H','H','H','H','H','H'; } for(int y=0;y<19;y++ ){ tablero[8][y] ='H','H','H','H','H','H','H','H','H','H','H','H','H','H','H','H','H','H','H'; } } juego dimensionar_vector(juego &tablero) { int tamañovector=19; tablero; tablero.resize( tamañovector ); for(int i=0; i < 9; ++i) { tablero[i].resize(tamañovector); } return tablero; } [/CODE]
  4. tic tac toe c++

    Thank you everyone, at the end I solve one part of my problem with thant functions: [CODE]void recorrer(juego &tablero,int y,int x,int anteriorx,int anteriory){ int num_x=0; int num_o=0; int copiay=y; int copiax=x; //FILAS: for(y ;y<tablero.size();y--){ incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory); } num_x=0; num_o=0; y=copiay; for(y ;y>=0 && y<tablero.size();++y){ incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory); } //COLUMNAS: num_x=0; num_o=0; x=copiax; y=copiay; for(x ;x<tablero.size() && x>=0;x--){ incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory); } num_x=0; num_o=0; x=copiax; y=copiay; for(x ;x>=0 && x<tablero.size();++x){ incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory); } //DIAGONALES(Izquierda a derecha): num_x=0; num_o=0; x=copiax; y=copiay; for (x,y; x>=0 && y>=0 || x<tablero.size() && y<tablero.size();x--, y--){ incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory); } num_x=0; num_o=0; x=copiax; y=copiay; for (x,y; x<tablero.size() && y<tablero.size();x++, y++){ incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory); } //DIAGONALES(Derecha a izquierda): num_x=0; num_o=0; x=copiax; y=copiay; for (x,y; x<tablero.size() && y>=0;x--, y++){ incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory); } num_x=0; num_o=0; x=copiax; y=copiay; for (x,y; x<tablero.size() && y>=0;x++, y--){ incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory); } } int incrementarxo(juego &tablero,int &x, int &y,int &num_x, int &num_o,int anteriorx, int anteriory){ if (tablero[x][y]=='X'){ num_x++; ganarx(num_x); return num_x; }else if (num_x < 3 && tablero[x][y] != 'X' && x != anteriorx || num_x < 3 && tablero[x][y] != 'X' && y != anteriory) num_x=0; if (tablero[x][y]=='O'){ num_o++; ganaro(num_o); return num_o; }else if (tablero[x][y]=!'O' && num_o<3) num_o=0; ganarx(num_x); ganaro(num_o); } void ganaro(int num_o){ if(num_o>=3){ std::cout<<"Ha ganado el jugador 2"<<std::endl; FinPartida(); } } void ganarx(int num_x){ if (num_x>=3){ std::cout<<"Ha ganado el jugador 1"<<std::endl; FinPartida(); } } //FIN COMPROBACIONES[/CODE] But now I have other problem, I need who one variable save the value of the last move, I need that because in my code if you have | x | Nothing | x | and you put one X in the midle yo don't win. That is the only problem. So I need that variable to make my program who don't delete the X (or O) if x=oldx The real problem is that variables must be initialized and can not find how to save the previous move. Have I explained well? Anyone can help my with that problem? Thank you, one more time.
  5. tic tac toe c++

    Yes,your right is variable size. Sorry I will try to explain this to you , the rules are the same as in a original tic tac toe (3x3) with the only exeption that you can chose the size(3x3,4x4...8x8).
  6. tic tac toe c++

    Hello, I'm a beginner, and I want to develop a tic tac toe with variable proportions. the problem is i dont know how to check correctly who wins (X or O) If anyone knows the solution... Can you explain me how solve this problem? Thank you ^^ The complete code is this: [code] // Tres en raya.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <stdio.h> #include <vector> #include <conio.h> typedef std::vector< std::vector< int > > tablero; //-----------------Funciones---------------------- void jugadores(tablero &tablero); //char comprobar_ganador(tablero &tablero); void RecorrerVector(tablero &tablero); int comprobar(tablero &tablero, int i,int j); void mostrar_tablero(tablero &tablero); tablero dimensionar_vector(tablero &tablero); //int comprobar_ganador_pasodos(tablero &tablero, int &num_x, int &num_o,int &i,int &j); //int comprobar_ganador_pasotres(int &num_x, int &num_o); void FinPartida(); void ganaro(int num_o); void ganarx(int num_x); int incrementarxo(tablero &tablero,int &x,int &i, int y,int &num_x, int &num_o); void linea(tablero &tablero,int y); void mostrar_tablero(tablero &tablero) { int i; int j; for(i=0; i<tablero.size(); i++) { std::cout<<" "<<" " << static_cast < char >( tablero[ i ][ 0 ] ); std::cout<<" |"<<" " << static_cast < char >( tablero[ i ][ 1 ] ); std::cout<<" |"<<" "<< static_cast < char >( tablero[ i ][ 2 ] ); if (tablero.size() >= 4)std::cout<<" |"<<" "<< static_cast < char >( tablero[ i ][ 3 ] ); if (tablero.size() >= 5)std::cout<<" |"<<" "<< static_cast < char >( tablero[ i ][ 4 ] ); if (tablero.size() >= 6)std::cout<<" |"<<" "<< static_cast < char >( tablero[ i ][ 5 ] ); if (tablero.size() >= 7)std::cout<<" |"<<" "<< static_cast < char >( tablero[ i ][ 6 ] ); if (tablero.size() >= 8)std::cout<<" |"<<" "<< static_cast < char >( tablero[ i ][ 7 ] ); if(i==i) std::cout<<"\n-------------------------------------------------------------------------------"<<std::endl; } std::cout<<"\n"<<std::endl; } void jugadores(tablero &tablero) { int x; int y; int z=1; do{ std::cout<<"es el turno del jugador"<<z<<":"<<std::endl; std::cout<<"Introduce las cordenadas y, x del lugar en el que quieras colocar la ficha"<<std::endl; std::cin>> x >> y; x--; y--; if( x < 0 || x >= tablero.size() || y < 0 || y >= tablero.size() ){ std::cout<<"Las coordenadas que has indicado son erroneas.\n\nvuelbe a intentarlo:"<<std::endl; if (z==2){ z=z-1; } jugadores(tablero); } if(tablero[x] [y] == 'X' || tablero [x] [y] == 'O') { std::cout<<"Tienes que escribir las cordenadas y, x del lugar en el que quieras colocar la ficha.\n Vuelbe a intentarlo:"<<std::endl; if (z==2){ z=z-1; } jugadores(tablero); } else if(z==1) tablero[x][y] = 'X'; else if (z==2) tablero[x][y] = 'O'; //z=z+1; mostrar_tablero(tablero); linea(tablero,y); }while(z==1||z==2); } //COMPROBACIONES: void linea(tablero &tablero,int y){ int num_x=0; int num_o=0; int i=0; for(int x=0; x<tablero.size();x++){ incrementarxo(tablero,x,y,i,num_x,num_o); } } int incrementarxo(tablero &tablero,int &x,int &i, int y,int &num_x, int &num_o){ if (tablero[y][x]=='X'){ num_x++; return num_x; }else if (tablero[y][x]=!'X' && num_x<3) num_x=0; if (tablero[y][x]=='O'){ num_o++; return num_o; }else if (tablero[y][x]=!'O' && num_o<3) num_o=0; ganarx(num_x); ganaro(num_o); } void ganaro(int num_o){ if(num_o>=3){ std::cout<<"Ha ganado el jugador 2"<<std::endl; FinPartida(); } } void ganarx(int num_x){ if (num_x>=3){ std::cout<<"Ha ganado el jugador 1"<<std::endl; FinPartida(); } } //FIN COMPROBACIONES tablero dimensionar_vector(tablero &tablero) { int tamañovector=0; tablero; std::cout<<"Elige las dimensiones del tablero(Maximo 8) Ejemplo: 5 = 5x5"<<std::endl; std::cin>>tamañovector; if (tamañovector>=9){ std::cout<<"Las proporciones dadas son demasiado grandes, el maximo es de 8x8 (8)\nVuelbe a intentarlo:"<<std::endl; system("pause"); dimensionar_vector(tablero); } tablero.resize( tamañovector ); for(int i=0; i < tamañovector; ++i) { tablero[i].resize(tamañovector); } return tablero; } int main() { tablero tablero; char v=' '; std::cout<<"Tres en raya:\n"; std::cout<<"El jugador1 jugara con X y el jugador2 con O\n\n"; dimensionar_vector(tablero); std::cout<<"este es el tablero de juego:"<<std::endl; mostrar_tablero (tablero); do { jugadores(tablero); } while(v==' '); std::cin.get(); return 0; } void FinPartida(){ int jugarsalir; std::cout<<"La partida ha finalizado\n\n Pulsa 1 para jugar otra partida, de lo contrario pulsa cualquier otra tecla para salir del programa"<<std::endl; std::cin>>jugarsalir; if (jugarsalir == 1){ system("cls"); main(); }else exit(1); } [/code] [mod edit by rip-off -- please use code tags when pasting code]