mardi 24 septembre 2019

Which method is better and why?

I am coding up a new Micro Mouse Simulator and i want to ask which method i write down there is more correct ( memory, errors, etc. ) and why?

I looked up some others posts but didnt find out an answer.

So the switch code is:

switch (direction){
                case NORTH:
                    cell.setWall(direction, x != 0);
                    break;
                case EAST:
                    cell.setWall(direction, y != size - 1);
                    break;
                case WEST:
                    cell.setWall(direction, y != 0);
                    break;
                case SOUTH:
                    cell.setWall(direction, x != size - 1);
                    break;
            }

And the if statment:

            if ( direction == Direction.NORTH && x != 0 ||
                    direction == Direction.SOUTH && x != size - 1 ||
                    direction == Direction.WEST && y != 0 ||
                    direction == Direction.EAST && y != size - 1 ) {
                cell.setWall(direction, false);
            }

Perhaps you have any other more advanced ideas? I am open.

Aucun commentaire:

Enregistrer un commentaire