学习型 ASP/PHP/ASP.NET 主机 30元/年全能 ASP/PHP/ASP.NET 主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付
轻松建立自己的群组,招兵买马   
发新话题
打印

一个古堡救美的文字游戏

//rand.cpp

//get the stochastic number
#include <iostream>
#include <ctime>
using namespace std;
int Rand()
{
    int a;
    srand( (unsigned)time(NULL) );
    a = rand() % 9 + 1;
    return a;
}

TOP

//paly_game.cpp

#include <iostream>
#include "room1.h"
#include "room2.h"
#include "room3.h"
#include "room4.h"
#include "room5.h"
#include "room6.h"
#include "room7.h"
#include "room8.h"
#include "room9.h"

void play_game()
{
    int princess,bugbear;
    int m = 1;                  //remark the room number
    string direct;
    room *pt;
    int Rand();
    princess = Rand();    //get the room number which the princess in
    do
    {
        bugbear = Rand();       //get the room number which the bugbear in
    }while(bugbear == princess); //and the bugbear is not in the same room with princess
    while (1)
    {
        if ( m == princess)   //you get the princess and you win
        {
            cout << "Here is the princess and you extricate her!" << endl;
            cout << "*******************************************" << endl;
            cout << "* win && The princeess falls love in you..." << endl;
            cout << "*******************************************" << endl;
            exit(1);
        }
        if (m == bugbear)  // the bugbear kills you and you lost
        {
            cout << "Here is the bugbear and you are killed!" << endl;
            cout << "*************GAME***OVER***************" << endl;
            exit(0);
        }
        switch(m)
        {
        case 1:    // you are in the
            pt = new room1;
            pt->show();
            do
            {
                cin >> direct;
                if ( direct == "east")
                    m = 4;
                else if (direct == "south")
                          m = 2;
                     else
                     {
                          m = 0;
                          cout << "The direction is wrong!" << endl;
                          cout << "Please enter your direction to go:" << endl;
                     }
            }while(m == 0);
            delete pt;
            break;
        case 2:
            pt = new room2;
            pt->show();
            do
            {
                cin >> direct;
                if ( direct == "north")
                    m = 1;
                else if (direct == "up")
                          m = 6;
                     else
                         {
                          m = 0;
                          cout << "The direction is wrong!" << endl;
                          cout << "Please enter your direction to go:" << endl;
                     }
            }while(m == 0);
            break;
        case 3:
            pt = new room3;
            pt->show();
            do
            {
                cin >> direct;
                if ( direct == "north")
                    m = 4;
                else
                    {
                          m = 0;
                          cout << "The direction is wrong!" << endl;
                          cout << "Please enter your direction to go:" << endl;
                     }
            }while(m == 0);
            delete pt;
            break;
        case 4:
            pt = new room4;
            pt->show();
            do
            {
                cin >> direct;
                if ( direct == "south")
                    m = 3;
                else if (direct == "west")
                         m = 1;
                    else if (direct == "up")
                             m = 9;
                         else
                             {
                          m = 0;
                          cout << "The direction is wrong!" << endl;
                          cout << "Please enter your direction to go:" << endl;
                     }
            }while(m == 0);
            delete pt;
            break;
        case 5:
            pt = new room5;
            pt->show();
            do
            {
                cin >> direct;
                if ( direct == "east")
                    m = 9;
                else if (direct == "south")
                          m = 6;
                     else
                          {
                          m = 0;
                          cout << "The direction is wrong!" << endl;
                          cout << "Please enter your direction to go:" << endl;
                     }
            }while(m == 0);
            delete pt;
            break;
        case 6:
            pt = new room6;
            pt->show();
            do
            {
                cin >> direct;
                if ( direct == "east")
                    m = 7;
                else if (direct == "north")
                          m = 5;
                    else if (direct == "down")
                            m = 2;
                        else
                            {
                          m = 0;
                          cout << "The direction is wrong!" << endl;
                          cout << "Please enter your direction to go:" << endl;
                     }
            }while(m == 0);
            delete pt;
            break;
        case 7:
            pt = new room7;
            pt->show();
            do
            {
                cin >> direct;
                if ( direct == "west")
                    m = 6;
                else if (direct == "north")
                          m = 8;
                     else
                     {
                         m = 0;
                          cout << "The direction is wrong!" << endl;
                          cout << "Please enter your direction to go:" << endl;
                     }
            }while(m == 0);
            delete pt;
            break;
        case 8:
            pt = new room8;
            pt->show();
            room8.show();
            do
            {
                cin >> direct;
                if ( direct == "south")
                    m = 7;
                else if (direct == "north")
                          m = 9;
                     else
                     {
                          m = 0;
                          cout << "The direction is wrong!" << endl;
                          cout << "Please enter your direction to go:" << endl;
                     }
            }while(m == 0);
            delete pt;
            break;
        case 9:
            pt = new room9;
            pt->show();
            do
            {
                cin >> direct;
                if ( direct == "south")
                    m = 8;
                else if (direct == "west")
                          m = 5;
                    else if (direct == "down")
                            m = 4;
                        else
                        {
                          m = 0;
                          cout << "The direction is wrong!" << endl;
                          cout << "Please enter your direction to go:" << endl;
                        }
            }while(m == 0);
            delete pt;
            break;
        }
   }
}

TOP

//main.cpp

#include <iostream>
#include "room1.h"
#include "room2.h"
#include "room3.h"
#include "room4.h"
#include "room5.h"
#include "room6.h"
#include "room7.h"
#include "room8.h"
#include "room9.h"

int main()
{
    void play_game();
    play_game();
    system("PAUSE");
    return 0;
}

[ 本帖最后由 野人王 于 2008-4-3 21:38 编辑 ]

TOP

根据错误提示应该是少了大括号,你仔细查一下吧!
Say goodbye to Windows.

TOP

括号我都检查了好几遍了

TOP

//room6.h

#ifndef ROOM6_H
#define ROOM6_H
#include "room.h"
class room6:public room
{
public:
    room6()
    {
        getname("funroom");
        set_exits();
    }
    void set_exits()
    {
        exits_num = 3;
        exits[0] = "east";
        exits[1] = "west";
        exits[2] = "down";
    }
    friend void play_game();
};/////////////////////////////////////////////////这里少!!!!!
#endif
Say goodbye to Windows.

TOP

在//paly_game.cpp中
case 8:

            pt = new room8;
            pt->show();
            room8.show();//////////////////////明显多了这句///////////
Say goodbye to Windows.

TOP

你自已一下看符不符合你要求,我也要仔细研究一下这代码,写得很不错,呵呵!!!
Say goodbye to Windows.

TOP

记得很早以前有个朋友在这里问了关于做R PG的问题,和这个差不多。当时我帮他想的是做任意房间怪物的,但是还很不完善,研究下你的代码。
P.S.可不可以打个包放在1楼呢?那样会方便很多的。3Q

TOP

研究中

TOP

发新话题