| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4580 人关注过本帖
标题:一个古堡救美的文字游戏
只看楼主 加入收藏
野人王
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2007-4-7
收藏
得分:0 
//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;
}
2008-04-03 21:35
野人王
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2007-4-7
收藏
得分:0 
//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;
        }
   }
}
2008-04-03 21:36
野人王
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2007-4-7
收藏
得分:0 
//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;
}

[[it] 本帖最后由 野人王 于 2008-4-3 21:38 编辑 [/it]]
2008-04-03 21:37
zjl138
Rank: 1
等 级:新手上路
威 望:1
帖 子:788
专家分:0
注 册:2007-11-12
收藏
得分:0 
根据错误提示应该是少了大括号,你仔细查一下吧!

i like linux...
2008-04-03 23:37
野人王
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2007-4-7
收藏
得分:0 
括号我都检查了好几遍了
2008-04-04 14:06
zjl138
Rank: 1
等 级:新手上路
威 望:1
帖 子:788
专家分:0
注 册:2007-11-12
收藏
得分:0 
//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

i like linux...
2008-04-04 14:42
zjl138
Rank: 1
等 级:新手上路
威 望:1
帖 子:788
专家分:0
注 册:2007-11-12
收藏
得分:0 
在//paly_game.cpp中
case 8:

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

i like linux...
2008-04-04 14:45
zjl138
Rank: 1
等 级:新手上路
威 望:1
帖 子:788
专家分:0
注 册:2007-11-12
收藏
得分:0 
你自已一下看符不符合你要求,我也要仔细研究一下这代码,写得很不错,呵呵!!!

i like linux...
2008-04-04 14:46
野比
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:24
帖 子:1627
专家分:516
注 册:2007-5-24
收藏
得分:0 
记得很早以前有个朋友在这里问了关于做R PG的问题,和这个差不多。当时我帮他想的是做任意房间怪物的,但是还很不完善,研究下你的代码。
P.S.可不可以打个包放在1楼呢?那样会方便很多的。3Q

女侠,约吗?
2008-04-05 04:21
hanpengqd
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2008-7-6
收藏
得分:0 
研究中
2008-07-08 15:16
快速回复:一个古堡救美的文字游戏
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022448 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved