引数を渡す方法を知りたいですか?
あなたはC++の初心者のようです。関数について少し読みたいと思うかもしれません。
機能 (I) 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);
}
あなたが何を求めているのか正確に伝えるのは難しいです。
アイデア。
たぶん、あなたはこのようなものが欲しいかもしれません(ここで大げさな推測をしています。ほとんどの場合、1つのシナリオを示しているだけです.):
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
}
}