关于UML的问题!急。
第一次听说UML,就是两天前,要给一段程序画个UML出来
不会啊 急
哪位大哥帮忙画一下啊 会的人应该不难的 因为程序不复杂
我的email:zhougz2000@hotmail.com 加我QQ也行:365640642 谢谢啦 本人比较穷 分不多 多包涵
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
# define LocationEmpty_Code 1
# define LocationTreasure_Code 2
# define LocationTried_Code 3
# define LocationReset_Code 4
class Treasure
{
protected:
int grid;
int **Map;
int Dig_X_Coord;
int Dig_Y_Coord;
int Difficulty;
int TotalMoves;
int MovesSoFar;
int Treasure_X_Coord;
int Treasure_Y_Coord;
bool PlayerWon;
bool PlayerDead ;
public:
Treasure(void);
int getGrid();
int printMap();
int readCoord();
void setGrid(int grid);
void winMessage();
void Dig();
void noTreasureMessage();
void showmenu();
void initMap(int gridSize);
};
Treasure::Treasure(void)
{
srand(time(0));
grid = 7;
PlayerWon = false;
PlayerDead = false;
Difficulty = 10;
TotalMoves = Difficulty;
MovesSoFar = 0;
initMap(grid);
}
void Treasure::initMap(int gridSize)
{
// sets the size of the map
grid = gridSize;
Map = new int*[grid];
//cout << "setting size of grid to be : \n" << grid;
for(int x = 0; x < grid; x++)
{
Map[x] = new int[grid];
}
for(int y = 0; y < grid; y++)
{
for(int x = 0; x < grid; x++)
{
Map[x][y] = LocationEmpty_Code;
}
}
Treasure_X_Coord = (int)(rand()%grid);
Treasure_Y_Coord = (int)(rand()%grid);
Map[Treasure_X_Coord][Treasure_Y_Coord] = LocationTreasure_Code;
Dig_X_Coord = LocationReset_Code;
Dig_Y_Coord = LocationReset_Code;
}
int Treasure::readCoord()
{
return 1;
}
int Treasure::getGrid()
{
return grid;
}
void Treasure::winMessage()
{
// thw win message if the treasure is found
cout <<"\n\nWell done! You win a 2-day holiday into The Other Matrix."<< endl;
}
void Treasure::Dig()
{ while(!PlayerWon && !PlayerDead)
{
// displays the map
printMap();
cout<<"\nEnter X co-ordinate to Dig:"<<endl;
cin >> Dig_X_Coord;
cout<<"\nEnter Y co-ordinate to Dig:"<<endl;
cin>>Dig_Y_Coord;
if(Dig_X_Coord==Treasure_X_Coord && Dig_Y_Coord==Treasure_Y_Coord)
{
Map[Treasure_X_Coord][Treasure_Y_Coord] = LocationTreasure_Code;
printMap();
cout << "\n\nYou found the treasure in "
<< (MovesSoFar+1) <<" move(s)." << endl;
PlayerWon = true;
winMessage();
}
else
{
MovesSoFar++;
Map[Dig_X_Coord][Dig_Y_Coord] = LocationTried_Code;
noTreasureMessage();
if(MovesSoFar == TotalMoves)
{
PlayerDead=true;
cout<<"\n\nBad luck. Pirates made you walk the plank."<<endl;
}
else
{
cout<<"\nYou have " << (TotalMoves-MovesSoFar) << " move(s) until the pirates arrive."<<endl;
}
}
}
}
int Treasure::printMap()
{
cout <<"\n\t";
for(int x=0; x<grid; x++)
cout <<"\t" << x;
for(int y=0; y<grid; y++)
{
cout <<"\n\t" << y;
for(int x=0; x<grid; x++)
{
if(Map[x][y] == LocationEmpty_Code)
cout <<"\t?";
else if(Map[x][y] == LocationTreasure_Code)
cout <<"\t?";
else if(Map[x][y] == LocationTried_Code)
cout <<"\t#";
}
}
return 1;
}
void Treasure::noTreasureMessage()
{
int messageflag = (int)(rand()%2 + 0.5);
switch(messageflag)
{
case 0: cout <<"\nOh look, a hole with nothing in it."<< endl;break;
case 1: cout <<"\nNo treasure here."<< endl;break;
case 2: cout <<"\nThis is boring."<< endl;break;
}
}
void Treasure::showmenu()
{
cout<<" _____________________________________________________________________________\n"
<<"| TREASURE HUNT |\n"
<<"|___________________________________________________________________________|\n"<<endl;
cout<<"Somewhere buried in a field is a treasure chest.\n"
<<"Find the treasure before the pirates arrives.\n"
<<"Symbols: '?'=Dig Site, '#'=tried, '*'=treasure"<<endl;
}
class GameLevel : public Treasure
{
private:
public:
GameLevel();
void setGameLevel(int level);
void showGameLevel();
int selectGameLevel(int level);
};
GameLevel::GameLevel()
{
}
void GameLevel::showGameLevel()
{
cout <<"\n";
cout <<" _____________________________________________________________________________\n";
cout <<"| PLEASE SELECT |\n";
cout <<"|___________________________________________________________________________|\n";
cout <<"| 1 VERY HARD |\n";
cout <<"| |\n";
cout <<"| 2 HARD |\n";
cout <<"| |\n";
cout <<"| 3 NORMAL |\n";
cout <<"| |\n";
cout <<"| 4 EASY |\n";
cout <<"| |\n";
cout <<"| 5 VERY EASY |\n";
cout <<"|___________________________________________________________________________|\n"<<endl;
}
int GameLevel::selectGameLevel(int level)
{
int choice;
do{ showGameLevel();
cin>>choice;
switch (choice)
{
case 1 : setGameLevel(1);
cout << "setting size of grid to be : " << grid;break;
case 2 : setGameLevel(2);
cout << "setting size of grid to be : " << grid;break;
case 3 : setGameLevel(3);
cout << "setting size of grid to be : " << grid;break;
case 4 : setGameLevel(4);
cout << "setting size of grid to be : " << grid;break;
case 5 : setGameLevel(5);
cout << "setting size of grid to be : " << grid;break;
default: cout<<"\n\tInvalid entry\n"<<endl;
}
} while (choice > 5);
return 0 ;
}
void GameLevel::setGameLevel(int level)
{
int grid;
if (level == 1)
{ grid = 8;
initMap(grid);
}
else if (level == 2)
{ grid = 6;
initMap(grid);
}
else if (level == 3)
{ grid = 5;
initMap(grid);
}
else if (level == 4)
{ grid = 3;
initMap(grid);
}
else if (level == 5)
{ grid = 2;
initMap(grid);
}
TotalMoves = grid;
}
void main(void)
{
GameLevel gamelevel;
int level=0;
int grid;
//cout << "PLEASE ENTER GRID SIZE: ";
//cin >> grid;
//game.initMap(grid);
gamelevel.showmenu();
gamelevel.selectGameLevel(level);
gamelevel.Dig();
system("pause");
}