Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public enum Direction {
- NORTH(0,-1),
- NORTHEAST(1,-1),
- EAST(1,0),
- SOUTHEAST(1,1),
- SOUTH(0,1),
- SOUTHWEST(-1,1),
- WEST(-1,0),
- NORTHWEST(-1,-1);
- int x;
- int y;
- Direction(int x, int y)
- {
- this.x = x;
- this.y = y;
- }
- public Direction getOpposite()
- {
- return Direction.values()[(this.ordinal()+4)%8]
- }
- }
- ...
- public bool hasCharInDirection(char[][] minefield, char target, int x, int y, Direction dir)
- {
- int newx = x + dir.x;
- int newy = y + dir.y;
- if (0 <= newy && newy < minefield.length
- && 0 <= newx && newx < minefield[0].length)
- {
- return minefield[newy][newx] == target;
- }
- return false;
- }
- ...
- int mineCount = 0;
- for (Direction dir : Direction.values())
- {
- mineCount += hasCharInDirection(minefield, '*', x, y, dir) ? 1 : 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement