你想知道如何傳遞參數嗎?
你似乎是C++的新手。您可能想閱讀一些關於功能的內容。
Functions (I) On Cplusplus
Functions (II) On 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
}
}
什麼是你的問題? –
如何在顯示功能中調用該檢查器功能 –