我正在用 cocos2dx 编写游戏,我正在尝试重构一个被调用几次的方法。我想从车辆类型的枚举中返回一个二维数组
我怎样才能得到类似以下的工作?
int Vehicle::getVehicle(VehicleTypes vehicletypes)
{
int vehicle[8][8] = {0};
switch (vehicleType) {
case Car:
// --- ARRAY 1 ------
vehicle = {
{ 0,0,0,0,0,0,0,0 },
{ 0,0,1,2,5,8,0,0 },
{ 0,0,5,3,4,5,0,0 },
{ 0,0,0,6,0,7,0,0 },
{ 0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0 },
};
break;
case Bus:
{
// --- ARRAY 2 ------
Vehicle = {
{ 0,0,0,0,0,0,0,0 },
{ 0,0,0,0,1,2,0,0 },
{ 0,0,3,4,5,0,0,0 },
{ 0,0,6,8,7,0,0,0 },
{ 0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0 },
};
break;
}
default:
break;
}
return vehicle;
}
谢谢