• Create Account

Banner advertising on our site currently available from just \$5!

# mayoscuro

Member Since 18 Apr 2012
Offline Last Active Dec 02 2012 05:38 AM

### Map of console rpg

24 October 2012 - 11:00 AM

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
```
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;
}
```

### tic tac toe c++

18 April 2012 - 02:30 PM

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:

```
// 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 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;
}
}

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;
}
}
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){
FinPartida();
}
}
void ganarx(int num_x){
if (num_x>=3){
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 {

} 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);
}
```

[mod edit by rip-off -- please use code tags when pasting code]

PARTNERS