Results 1 to 1 of 1
- 03-08-2012, 04:57 AM #1
Member
- Join Date
- Jan 2012
- Posts
- 21
- Rep Power
- 0
problems with StdDraw and Standard Drawing
hi my problem is that i was working with netbeans and my StdDraw was working perfectly now i formatted my computer and i trying to execute the same code but it is not working... the only way it works is if i debug it i will show you my code
so at the end of the code the if (StdDraw.hasNextKeyTyped()) does not work unless i debug it... any help please.. any software i need to download or something thank youJava Code:package project1; import java.util.*; import javax.swing.*; /** * * @author Elvis De Abreu */ public class TargetGallery { /**ArrayList of Targets initialize as a private*/ private ArrayList<Target> mytargets = new ArrayList<>(); /**Static object for the Target class*/ static Target tg = new Target(); /**Static object for the RifleSite class*/ static RifleSite rs = new RifleSite(); /**Static object for the TargetGallery class*/ static TargetGallery tgy = new TargetGallery(); /**the number of targets input by the user as private*/ private int number = 0; /**array that store the distance between 2 point for each target*/ private double[] total; /** * Method that build the background of the canvas * with a picture as a environment */ private void buildWorld() { StdDraw.setXscale(0, 250); StdDraw.setYscale(0, 250); StdDraw.picture(75, 130, "bath.jpeg", 450, 285); } /** * Method that draw a weapon in the middle of the * canvas as a shooter weapon */ private void drawShooter() { StdDraw.setXscale(0, 250); StdDraw.setYscale(0, 250); StdDraw.picture(125, 0, "weapon.png", 80, 45); } /** * randomly generates X locations for the targets * add them into the array list */ private void createTargets() { double x = 125; double y = 175; double radius = 7; String input = JOptionPane.showInputDialog("Type a number" + "between 2 and 5"); number = Integer.parseInt(input); for(int i = 0; i < number; i++) { Target targ = new Target(x, y, radius); mytargets.add(targ); Random rand = new Random(); x = rand.nextInt(400) + 10; /** for (Target e: mytargets) { if ((e.getX() <= (x+10)) && (e.getX() >= (x-10))) { mytargets.clear(); i--; continue; } }*/ } } /** * Method that run different methods which start the program */ public void run() { tgy.buildWorld(); //call the buildWorld method tgy.drawShooter(); //call the drawShooter method tgy.createTargets(); //call the createTarget method tgy.simulate(); //call the simulate method } /** * calculates the distance between the RifleSite and the Targets */ public void calcDistance() { //variable declaration/initialization double distance; double distance1; int i = 0; total = new double[number]; //for each loop to calculate x and y location of RifleSite and Targets for (Target e: mytargets) { distance = Math.pow(e.getX()-rs.getX(), 2.0); distance1 = Math.pow(e.getY()-rs.getY(), 2.0); total[i++] = Math.sqrt(distance + distance1); } } /** * Method that simulates the game */ public void simulate() { //Variable declaration/initialization boolean alive = true; int i = 0; for(Target e: mytargets) { e.drawAlive(); } rs.drawRifleSite(); //loop that will run while there is still targets alive or user press q while(true) { //if user press a key this if (StdDraw.hasNextKeyTyped()) { char ch = StdDraw.nextKeyTyped(); //store the key pressed //if person press Q will quit the program if (ch == 'q') { int done = JOptionPane.showConfirmDialog(null, "The Program will close now bye :)"); System.exit(0); } else if (ch == 'f') { tgy.calcDistance(); //calculates the distance //if statement to check if the distance if less than radius for(Target e: mytargets) { if (total[i] <= 7) { e.drawDead(); i++; } } } } } } /** * Method for the main of the Program * @param args the command line arguments */ public static void main(String[] args) { tgy.run(); } }
Similar Threads
-
problem with StdDraw and Eclipse
By elvis0288 in forum New To JavaReplies: 1Last Post: 03-06-2012, 10:17 PM -
StdDraw.setXscale i have problems with this
By elvis0288 in forum New To JavaReplies: 3Last Post: 03-04-2012, 01:09 PM -
Problems drawing lines on a Graph
By rhexis in forum New To JavaReplies: 0Last Post: 02-17-2012, 05:24 PM -
Standard input
By Jey in forum New To JavaReplies: 2Last Post: 08-18-2011, 10:31 AM -
Problems drawing a section of an image onto another image.
By Cain in forum Java 2DReplies: 1Last Post: 04-17-2009, 12:44 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks