Test Foro de elhacker.net SMF 2.1

Programación => Programación C/C++ => Mensaje iniciado por: prometheus48 en 22 Diciembre 2011, 18:37 PM

Título: Problema AVENTURA DE TEXTO C++
Publicado por: prometheus48 en 22 Diciembre 2011, 18:37 PM
Hola,

Estba haciendo una aventura de texto, ya sabeis tpo ZORK:THE UNDERGORUND EMPIRE.
Entonces lo que quiero es esto.

#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char *argv[])
{
    string elec;
   
    system("title Lost!-PandoraX");
    cout<<"Welcome to Lost!!";
    cout<<"\n";
    cout<<"This is a text game adventure!"<<endl;
    cout<<"Created by Samuel Dominguez(PandoraX)";
    cout<<"\nPandoraX!";
    cout<<"\n\n";
    cout<<"You are on the first floor of a white house\nand you are sitting on a chair,\nthere is a key in front of you"<<endl;
    cout<<">";
    cin>>elec;
    if (elec=="take key")
    {
                    cout<<"Now, the key is on your pocket."<<endl;
                    cout<<"What now?"<<endl;
                    cout<<">";
                    cin>>elec;
                   
                    }
                    else
                    {
                        cout<<"I don't know what does '"<<elec;
                        cout<<"' mean"<<endl;
                        cout<<">";
                        cin>>elec;
                        }
        return EXIT_SUCCESS;
}

Lo que quiero es que cuando el jugador escriba algo que no sea 'take key' (coger llave", que le mande un mensaje diciendo que no sabe lo que a metido (eso ya esta hecho), y que vuelva a el if del principio. Se puede hacer con goto? Si, pero ya sabeis lo malo que es goto, es un mal habito programar con el a si que como lo hago?¿
Salu2!
Ah, y Feliz Navidad a todos!
Título: Re: Problema AVENTURA DE TEXTO C++
Publicado por: Eternal Idol en 22 Diciembre 2011, 19:09 PM
Podes meterlo en un bucle facilmente (for, while, etc.) y con un comando hacerlo termianr (quit, exit, etc.).