Alternatives to switches.
What would be more efficient than this? And by efficient I mean like how can i write a lot less code, and still have it do what I want.
Code:
void move()
{
while(condition == 0)
{
direction = getch();
switch(direction)
{
case 'w':
if(w.y == 10)
{
break;
}
else
{
w.y++;
break;
}
case 'a':
if(w.x == -10)
{
break;
}
else
{
w.x--;
break;
}
case 's':
if(w.y == -10)
{
break;
}
else
{
w.y--;
break;
}
case 'd':
if(w.x == 10)
{
break;
}
else
{
w.x++;
break;
}
}
cout << w.x << ", " << w.y << endl;
}
}