I'm trying to write a program that allows a user controlled character to move around a maze. That problem i'm having is having it determine when it runs into a wall. I have a code done up to handle it. I'm just running into some errors i need help cleaning up
public int CheckPixel(int x, int y) {
File file = new File("Zombie_Map.jpg");
BufferedImage image = ImageIO.read(file);
clr = image.getRGB(x,y);
red = (clr & 0x00ff0000) >> 16;
green = (clr & 0x0000ff00) >> 8;
blue = clr & 0x000000ff;
}
This is the code i'm using currently to test if a pixel is a certain colour, in this case the walls are black also (Zombie_Map) is just a mat version of the maze i made, nothing moves it just makes it easier to run the program.
This is the program i'm using for the user controlled character
public void keyPressed(KeyEvent e) {
switch( e.getKeyChar() ) {
case 'a':
int xValue = (int)human.x;
int yValue = (int)human.y;
CheckPixel(xValue-10,yValue);
System.out.println(xValue + " " + yValue);
if ((red == 0.0)&&(blue == 0.0)&&(green == 0.0)){
break;
}
else {
human.x -= 20.0;
}
}
repaint();
So that when i press the 'a' key, the character should move 20 pixels to the left unless there's a wall in it's way, represented by 0,0,0 on a RGB scale. So in this case i test 10 pixels to the left of the cursor's current position
However when i run the program like this i get these errors
javac ZombieEscape.java
ZombieEscape.java:170: missing return statement
}
^
ZombieEscape.java:165: unreported exception java.io.IOException; must be caught or declared to be thrown
BufferedImage image = ImageIO.read(file);
^
2 errors
I will admit, exceptions, and throwing and catching are not my strong suit when it comes to coding, I was just wondering if someone would be able to help me out here.