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