I took out some of the code, just some insignificant functions... this should be all you need to look it through. It compiles OK, there's just something wrong with running a java application...Code:import java.io.*; import java.awt.*; import java.util.*; import java.awt.event.*; public class Game extends Frame implements KeyListener, WindowListener { // Init stuff int [] [] Level = new int [100] [100]; int topCorrection = 35; // Set the TOP and LEFT values of the place where the LEVEL will begin to be drawn int leftCorrection = 16; int xPos = 0; int yPos = 0; int tileSize = 20; int oldX = 0; int oldY = 0; private BufferedReader inFile; int movesTaken = 0; int movesMax = 0; boolean won = false; public static void main (String [] args) { Game thisGame = new Game(); thisGame.setSize (530,500); thisGame.setVisible(true); } public Game () { createMap1(); repaint(); setTitle("d a g a m e (c) j a r e w a r e"); this.addWindowListener(this); this.addKeyListener (this); } public void update (Graphics g) { setBackground(Color.white); // Draw the level // Draw the position of the player drawPlayer(); if (movesTaken <= movesMax) { g.setColor(Color.green); } else { g.setColor(Color.red); } g.fillRect(16,345,500,40); g.setColor(Color.white); g.fillRect(21,350,490,30); g.setColor(Color.black); g.drawRect(16,345,500,40); g.drawRect(21,350,490,30); g.drawString("Moves left: " + movesTaken + " / " + movesMax + ")",26,365); //g.drawString("Player position, x = " + xPos + ", y = " + yPos + "",26,360); if (won) { g.setColor(Color.white); g.fillRect(0,0,1000,1000); g.setColor(Color.black); g.drawString("YOU WON!", 100, 100); } } public void keyTyped (KeyEvent e) { } public void keyPressed (KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_RIGHT) { if (Level[xPos+1][yPos] == 0 || Level[xPos+1][yPos] == 2 || Level[xPos+1][yPos] == 9) { oldX = xPos; oldY = yPos; xPos++; movesTaken++; } } else if (e.getKeyCode() == KeyEvent.VK_LEFT) { if (Level[xPos-1][yPos] == 0 || Level[xPos-1][yPos] == 2 || Level[xPos+1][yPos] == 9) { oldX = xPos; oldY = yPos; xPos--; movesTaken++; } } else if (e.getKeyCode() == KeyEvent.VK_UP) { if (Level[xPos][yPos-1] == 0 || Level[xPos][yPos-1] == 2 || Level[xPos+1][yPos] == 9) { oldX = xPos; oldY = yPos; yPos--; movesTaken++; } } else if (e.getKeyCode() == KeyEvent.VK_DOWN) { if (Level[xPos][yPos+1] == 0 || Level[xPos][yPos+1] == 2 || Level[xPos+1][yPos] == 9) { oldX = xPos; oldY = yPos; yPos++; movesTaken++; } } if (Level[xPos][yPos] == 9) { // The player has reached the goal! won = true; } repaint(); } public void keyReleased (KeyEvent e) { } public void windowClosing(WindowEvent e) { System.exit(0); } public void windowIconified(WindowEvent e) { } public void windowOpened(WindowEvent e) { } public void windowClosed(WindowEvent e) { } public void windowDeiconified(WindowEvent e) { } public void windowActivated(WindowEvent e) { repaint(); } public void windowDeactivated(WindowEvent e) { } }
-JR-




Reply With Quote