你想知道如何传递参数吗?
你似乎是 C++ 的新手。您可能想阅读一些有关函数的信息。
功能(一)关于Cplusplus
Cplusplus上的功能(二)
struct box{
//code
}; //forgot semicolon
void checker(box A, box B, box C, box D, box E, box Q){
//code
}
void display() //forgot parenthesis
{
box A, B, C, D, E, Q;
//initialize and use variables.
//call function...
checker(A, B, C, D, E, Q);
}
很难说出你到底在问什么。
一个主意。
也许你想要这样的东西(在这里大胆猜测。主要只是向你展示一个场景。):
class Box
{
//code
};
class GameState
{
public:
GameState(map<std::string, Box> _boxes);
void display();
void moveBox(std::string boxID, int x, int y);
private:
bool checkMove(std::string boxID, int x, int y);
std::map<std::string, Box> boxes;
};
void mainLoop()
{
map<string, Box> boxes;
boxes["A"] = Box();
boxes["B"] = Box();
boxes["C"] = Box();
boxes["D"] = Box();
boxes["E"] = Box();
boxes["Q"] = Box();
bool quit = false;
GameState game(boxes);
while(true)
{
int action = game.getAction();
switch(action)
{
case DISPLAY_ACTION:
game.display();
break;
case MOVE_ACTION:
string boxId;
int x, y;
//get those somehow...
game.moveBox(boxId, x, y);
break;
case QUIT;
quit = true;
break;
}
if (quit)
break;
}
}
int GameState::getAction(box& aBox)
{
//return some action code
}
bool GameState::checkMove(string boxId, int x, y)
{
//check box
}
void GameState::display()
{
}
void GameState::moveBox(string boxId, int x, int y)
{
if (checkMove(boxId, x, y))
{
//more code
}
}