I am doing an assignment which involves creating a maze and a ball that needs to go through the maze to an end tile then stop the scenario. The maze is made up of 208 buttons in a Jbutton Grid layout. I am replacing certain buttons with a brown tile icon to make up the maze. The ball needs to run along those brown tiles as its path and not be able to move off the brown tile icon images.
I have built the maze and have got quite far with this but now I am stumped on the concept of keeping the ball within the boundary edges and on the brown tiles. I have been told to use if statements, but not had the process explained to me in a way I can understand.
a) I have a Ball Object which implements the Runnable interface and traces the various positions of a ball.
b) I then have a Ball_Bounce JPanel inside a JFrame which creates two instances of the Ball object and then paints them to the JPanel.
As per my understanding, when the main() program in Ball_Bounce.java is started, there a total of three threads running in this program, one for each ball and one for the main(). What I cannot understand is whenever the balls collide, I end up getting the "Collision" message twice even though the collision is checked only in the main() thread.
[#]public class Ball implements Runnable { private boolean xUp, yUp, xUp1, yUp1; private int x, y, xDx, yDy; private final int MAX_X = 500, MAX_Y = 500; private boolean flag = true; private static Thread ball;
For my project I have to write a piece of code where it returns true or false value depending whether the indicated cell is on edge of a rectangular grid (true) or not (false). Any algorithm for the following method: public static boolean onEdge (int n, int numRows, int numCols)?? To highlight, numRows and numCols and n start from 0.
I'm trying to get my animation for my java game to move along the edges of my device. Once it hits the edge I would like it to turn and keep moving along the edges. I'm sure this is easier than I'm making it but I can't find much on this. Right now my animation moves right and goes right off the screen until the app is closed and restarted.
I am doing a simple program, just to find multiples of 7 all the way to 125. But the loop its not stopping at 125 and is going to 126.
public class Assingment2B { public static void main(String[] args) { int number = 0; while (number <= 125) { number += 7; if (number % 7 == 0) { System.out.println(number);
So far i've built an array of char W= wall, O=open, R= rat, and P= path
I have another class "RAT" which will navigate through the maze. so im having trouble with the method to get the position of the rat when it is navigating through maze. this is what i have.
public class FinalMaze { static char[][] mazeArray = new char[][] { {'o','o','o','o','o','o'}, {'o','w','w','r','w','o'}, {'o','w','p','p','w','o'}, {'o','w','p','w','w','o'}, {'o','w','p','p','w','o'}, {'o','w','w','p','w','o'}, {'o','w','w','p','w','o'}, {'o','o','o','o','o','o'}, };
im having 2 simple problems that are for somereason going above my head right now.
1: i need to start the program at the first possible position (row 0 col 0) 2: i need to be able to read multiple mazes in one file.
Code:
import java.io.*; public class Driver { private File mapFile = new File("map.txt"); private char[][]maze; private char pathMarker = '2'; private int row,col,ndx=0; public static void main(String[] args) { Driver d = new Driver();
I am currently in the process of making a game in java. it's going fairly well, however, one problem that i am having is that i cant seem to get my enemy sprites not stack up onto one another. What i want to happen is if two enemy sprites come in contact with one another i want them to touch but not to overlap. However, i cant seem to get this to work.
This is the enemy class:
import java.awt.Graphics; import java.awt.Image; import java.awt.Rectangle; import java.util.ArrayList; import javax.swing.ImageIcon; public class Enemy extends Base { int x; int y;
So what I'm trying to do is write a code in java which finds a path through a maze. I want it to go through the maze and determine if there's a * symbol at that location or not. If there is a * symbol at the specified location then the program would search for another position until it finds one without the * symbol and if it can't then I'll have the program return null. I also want it to implement backtracking which I'm not sure how to do. Here's my code so far
private boolean findPath(int fromRow, int fromCol, int toRow, int toCol){ boolean solved = true; for(int i=fromRow; i<toRow; i++){ for(int j=fromCol; j<toCol; j++){ if (x[i][j] == ('*')){ //do something } } } return false; }
the code isn't finished yet however what I'm not sure is what do I do with the if statement and how do I implement backtracking?
I'm not getting any errors, just i can't seem to stop the music from playing after clicking the jbutton "Sound On" / "Sound Off" again. I've tried a few methods but it just isn't working for me.
I'm not getting any errors, just i can't seem to stop the music from playing after clicking the jbutton "Sound On" / "Sound Off" again. I've tried a few methods but it just isn't working for me.
I made a kind of maze game that includes the class keylistener and orients a object, i can't find where the program tracks this object (where its x and y coordinates are). So now my object can move freely through all walls and i want it to bounce back or at least something to happen when the object reaches a wall.
I want to find a way to limit my objects movement and because i cant find where the coordinates or variable for this object is i cannot limit its movement
import javax.swing.Timer; import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Ball extends JPanel { private int delay = 10; private Timer timer = new Timer(delay, new TimerListener()); private int x = 0; private int y = 0;
I am writing a three part program that essentially works like a magic 8 ball. I have the switch/case part which gives the answers from a random number generator, then I also have a graphics file to create the ball as a visual. Lastly I have the frame to display the ball. The problem I am having is that, I am trying to make the program so that when you type in a question and press return the ball will show the answer and then you can type another question and press return and the ball will show a different answer. To quit you would simply type "quit". Right now however the ball is not showing up in my frame until I type quit, then to ask another question I have to end the run and start over again. Here is my program so far:
Case/Switch: public class MagicEightBall { private int number; private String answer;
Actually, i want to create multiple ball using multithreading.I have created a class 'CreateBall' and this class is making ball and second class 'Balls' is a Panel where the ball is display.But only one ball is being displayed.
Here is my code.......
CreateBall.java import java.awt.*; public class CreateBall implements Runnable { int px,py; int w=20,h=20; Graphics g; public CreateBall(int px,int py)
I'm trying to do is get this ball to bounce around the screen and ive gotten so far but not sure how to proceed. The ball keeps disappearing.
//bouncing ball
float x; //ball x position float dx = 3; //ball x direction is right, step 5 float y; //ball y position float dy = 3; void setup () //runs once at start
I want to make a simply game,actualy not a game but I want to moving object curve just like angry bird. Where I can move an object with curve motion. But I don't know how. I just can make it move straight(left,right,down,up).
I've got to make a ball bounce around a screen.... From what I can gather they seem to hold back useful java code.
anyway, i've changed the code over and over, and think this is the most succinct way i can manage it. but i have a problem. where i've marked the code (*****) and the following line are conditional on each other. so one won't provide the correct answer without the other line executing first, and vice versa (ignore the code after, i haven't looked at where that should be yet ). Anyway I don't really want to rip the code apart, again, because i'm pretty sure it's close.
I was making a pong game, part copied code off the internet, part my own code, part my friends code. It works well enough, but the ball starts at one speed, and stays the same. I would like to know how to make the ball slowly increase.
It is a java applet, which shouldn't casue any harm right?
My code:
Pong Applet
import java.applet.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Pong extends Applet implements MouseMotionListener, KeyListener {
I have created this ping pong game but having problem with ball and paddle collusion. After first collusion it gives score 1 but later it never touch the paddle.
Code:
import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.util.Random.*; import javax.swing.ImageIcon; public class Ball extends JFrame implements ActionListener, KeyListener{ int xSpeed=0;
[Code] ....
I think something is wrong here:
public void actionPerformed(ActionEvent e){ y=y+xSpeed; repaint(); if(y> this.getWidth()){ y=25; score -=1; } if(blockRect.intersects(ballRect)){ y=40; score +=1; x =200; y = 300; }
I wrote a code from our text book for Pong. Im trying to figure out how to fill the ball with color. Im also wondering how to speed the ball up once there is contact with the paddle. The initial speed is ok but once contact is made with the paddle, it slows down. Makes it too easy to play. Here is my code so far. As far as the game goes, it works and is good. Just wanted to add a couple customizations.
I am working on a program that asks me to track the position of an imaginary ball as it bounces around an imaginary box. The user gives me input for the starting position of the ball (x,y), the bottom-left boundaries of the box (xl, yl), the top right boundaries (xr, yr) and the angle. The program then needs to find where the ball will hit the box, and then print that location and find the new angle for the next point. My program currently works in most cases if the angle is less than pi.
Here is my code
public class BouncyBall { public static void main(String args[]){ if (args.length != 8) { System.out.println("Error: usage is X, Y, Angle, Xl, Yl, Xr, Yr,N"); System.exit(1); } double x,y,xl,yl,xr,yr,angle; int n; x=Double.parseDouble(args[0]); y=Double.parseDouble(args[1]);