It`s a small game, if I could call it like that. A game I made pretty much time ago, but still, I can`t figure out what`s wrong...
Heres the code
import java.applet.Applet; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Font; import java.awt.Frame; import java.awt.Graphics; import java.awt.Window; import java.awt.event.InputEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JOptionPane; import javax.swing.UIManager; public class shooterTest extends Applet implements MouseListener { int pos1 ; int pos2 ; int pos3 ; int pos4 ; int score = 0; int bullets = 10; public void init(){ setBackground(Color.lightGray); setSize(700, 500); try{ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); }catch(Exception e){ JOptionPane.showMessageDialog(null, "Look and feel may have not been initialised !","System",JOptionPane.ERROR_MESSAGE); } addMouseListener(this); } public void paint(Graphics g){ pos1 = (int) (Math.random() * 300); pos2 = (int) (Math.random() * 300); pos3 = (int) (Math.random() * 290); pos4 = (int) (Math.random() * 290); g.drawRect(pos1, pos2, pos3, pos4); Font font = new Font("Font", Font.BOLD, 16); g.setFont(font); g.drawString("Score : "+score, 10, 20); g.drawString("Bullets : "+getBullets(), 10, 40); } public void mouseClicked(MouseEvent e) { if(e.getModifiers()==InputEvent.BUTTON1_MASK){ if(bullets > 0){ bullets--; repaint(); }else{ JOptionPane.showMessageDialog(null, "You can`t shoot ! You`re out of bullets !","You have to recharge !",JOptionPane.WARNING_MESSAGE); } if(e.getX() > pos1 && e.getY() > pos2 && e.getX() < pos3 && e.getY() < pos4){ score += 10; repaint(); } }else if(e.getModifiers()==InputEvent.BUTTON3_MASK){ setBullets(10); repaint(); } } public void mouseEntered(MouseEvent arg0) { } public void mouseExited(MouseEvent arg0) { } public void mousePressed(MouseEvent arg0) { } public void mouseReleased(MouseEvent arg0) { } static final shooterTest applet = new shooterTest(); public static void main(String args[]){ Frame fereastra = new Frame("Java Shooter I"); fereastra.add(applet, BorderLayout.CENTER); fereastra.setBounds(300, 300, 700, 500); fereastra.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e){ applet.destroy(); Window win = e.getWindow(); win.dispose(); } }); fereastra.setResizable(false); applet.init(); applet.start(); fereastra.setVisible(true); } public int getBullets() { return bullets; } public void setBullets(int bullets) { this.bullets = bullets; } }
It was meant to be a shooter, the player had to click inside a rectangle with random positions, if he did, to the score would have been added 10 points, and from the bullets substracted 1. When he ran out of bullets, he had to click the right button to recharge.
The problem is this :
You had to click in the upper left corner of the rectangle and not anywhere inside it.
What I found out is that, if the rectangle had these positions : x, y, 400, 300 ; you had to click : x, y, 300, 200... I don`t know if that helps, but anyway, I said everything I knew...
Thank you everyone in advance !
P.S. I`m not sure that "substracted" is the right word for it, with "substracted 1" I meant "bullets--;".I hope you understand what I meant...