I am creating the rush hour game. I am using the cars and trucks as Jlabel. I have created a 6x6 grid using GridLayout and I need to place the cars or trucks into the grid. I know how to place into a grid a Jlabel that takes only one cell. But how do you place a Jlabel that takes up more than one cell? For example, the cars occupy two cells on the grid, and the trucks 3 cells
When I add the first car only, it puts it in the correct spot and I can move it correctly. However when I attempt to add another car, the image of the second car repaint itself onto the first one, and the second car is not functioning at all (not moving)...
Opoly works this way: The board is a circular track of variable length (the user determines the length when the game app runs). There is only one player, who begins the game at position 0.
Thus, if the board length is 20, then the board locations start at position 0 and end at position 19. The player starts with a reward of 100, and the goal of the game is to reach or exceed reward value 1000. When this reward value is reached or exceeded, the game is over. When the game ends, your program should report the number of turns the player has taken, and the final reward amount attained.
In Opoly the game piece advances via a spinner - a device that takes on one of the values 1, 2, 3, 4, 5 at random, with each of the five spin values equally likely.
Although the board is circular, you should draw the state of the board as a single "line", using an 'o' to represent the current player position, and * represent all other positions. Thus if the board size is 10, then this board drawing:
**o******
means that the player is at location 2 on the board.
Here are the other Opoly game rules:
If your board piece lands on a board cell that is evenly divisible by 7, your reward doubles.
If you land on the final board cell, you must go back 3 spaces. Thus if the board size is 20, the last position is position 19, and if you land there, you should go back to position 16. (If the position of the last cell is evenly divisible by 7, no extra points are added, but if the new piece location, 3 places back, IS evenly divisible by 7, then extra points ARE added).
If you make it all the way around the board, you get 100 points. Note that if you land exactly on location 0, you first receive 100 extra points (for making it all the around), and then your score is doubled, since 0 is evenly divisible by 7,
Every tenth move (that is, every tenth spin of the spinner, move numbers 10,20,30,... etc.), reduces the reward by 50 points. This penalty is applied up front, as soon as the 10th or 20th or 30th move is made, even if other actions at that instant also apply. Notice that with this rule it's possible for the reward amount to become negative.
Here is the driver class for the game:
import java.util.*; public class OpolyDriver{ public static void main(String[] args){ System.out.println("Enter an int > 3 - the size of the board"); Scanner s = new Scanner(System.in); int boardSize = s.nextInt();
[Code] ....
heres the methods:
REQUIRED CODE STRUCTURE: Your Opoly class must include the following methods (in addition to the Opoly constructor) and must implement the method calls as specified:
playGame - The top-level method that controls the game. No return value, no parameters. Must call drawBoard, displayReport, spinAndMove, isGameOver.
spinAndMove - spins the spinner and then advances the piece according to the rules of the game. No return value, no parameters. Must call spin and move.
spin - generates an integer value from 1 to 5 at random- all equally likely. Returns an integer, no parameters.
move - advances the piece according to the rules of the game. No return value, takes an integer parameter that is a value from 1 to 5.
isGameOver - checks if game termination condition has been met. Returns true if game is over, false otherwise. No parameters.
drawBoard - draws the board using *'s and an o to mark the current board position. Following each board display you should also report the current reward. No return value, no parameters.
displayReport - reports the end of the game, and gives the number of rounds of play, and the final reward. No return value, no parameters.
Im trying to make a tic tac toe game that you play against the computer using a random number generator and two dimensional arrays for the game board. Im not trying to make a GUI, the assignment is to have the board in the console, which I have done. I have run into a few problems with trying to get the computer player to correctly generate 2 integers and have those two integers be a place on the game board. Here is my code so far.
import java.util.Random; import java.util.Scanner; public class TicTacToe { private static Scanner keyboard = new Scanner(System.in); private static char[][] board = new char[3][3]; public static int row, col;
I tried this program, its guessing game. Where program decide 1 number and user will guess number. I am getting 1 problem. When user want to play game again.the random number remain same. So where i can put reset random in code..? And 1 more question if I want to write driver code for this. What should i transfer to driver code.
import java.util.Random; import java.util.Scanner; public class GuessGame { public static void main(String args[]) { String choice="y";
I've been at this for a while and I would like to make the Camera in my game follow the player and I know the way to do this would be to move the map and not the player. How would I do this if my map is rendered from a text file using for loops. Here is my code for the map.
package Game; import java.awt.Graphics; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class Map {
I am creating a simple AirHockey game in Eclipse Java Jframe. I was just wondering how it is i add a score keeper to my game. for example if player 1 scores a goal 1 is added onto there score at the top.
import java.util.Scanner; public class TicTacToe { public static void main(String[] args) { //Create scanner Scanner in = new Scanner(System.in); //Declare variables to hold the board
[Code] ....
I need to create a while statement for random computer moves.
I'm making a game which lets the player move around with arrow keys, but my KeyListeners are working less-than-satisfactorily. I googled this and I found that I should use KeyBindings.
1) Right now I have booleans for each key used in the game. When a key is pressed, the boolean is set to true, and set to false when it is released. In the ActionListener for the Timer I have, I then check if each is pressed or not, and do the corresponding action. I do this so that movement is smooth.If I was to use KeyBindings, would I use the same technique, or would I just do the action in their Action?
2) How do I do it? From the example I thought was most useful, this is my guess: (this code would be in a JPanel)
Java Code:
this.getInputMap().put( KeyStroke.getKeyStroke( "ENTER" ) , "doEnterAction" ); this.getActionMap().put( "doEnterAction" , EnterAction ); static class EnterAction extends AbstractAction { public void actionPerformed( ActionEvent tf ) { enterKeyIsPressed=true; //If using this method, I would also have a separate InputMapping, ActionMapping,
I know a lot of people taking beginning java courses have posted questions about creating a tic tac toe game, but here is another one. Below is my code. I can't seem to get the X's and O's to show up on the board or to determine a winner.
import java.util.*; public class Trial3 { public static char turn; public static int count; public static void main(String[]args) { Scanner input=new Scanner(System.in); char[][]b=new char[3][3]; boolean flag=false; count=0;
Create another class called Race with a main method. Make some Car objects, and use them in a race.The first race will have 2 cars. The main method only needs 2 local variables, i.e. the 2 Car objects.
-The length of the race is 1000.
-Both cars will start out with a speed of 30.
The race will be implemented as a loop. Each time through the loop:
-Your cars will move to a next location by adding their current speed to their location. (If the speed is 50, and they are at location 200, then change the location to 250.)
-Call out the race (SOPLs) like a NASCAR announcer: Andretti is in the lead at position 365. He is flying at 30 mph!
-Or It's neck and neck with both cars at position 45 or something more creative that you can come up with.
-Each car will increase or decrease their speed randomly each time through the main loop.
-The car that is behind will increase its speed by 2 mph, and the car that is in the lead will decrease its speed by 2 mph. (Tighten the race to make it more exciting.)
-The loop will continue until one of the cars is declared to be the winner.
This is my code so far.
public class RaceCarsMain { public static void main(String[] args) {
int length = 0;
Cars c = new Cars("Andretti", 30); Cars c2 = new Cars("Fiviotini", 30); while (c.getLocation() < 1000){ length++; c.randomSpeedChange(); c.accelerate(2); c.deaccelerate(2); c.locationchange();
[code]....
I have been able to print out the first car "Andretti" until its location reaches 1000, but the 2nd car I have not being able to print out the change of speed and change of location.how to proceed and making the 2nd car do the same, do I have to create another class? or how can i use the Cars class to do it for both.
When the tile loads it loads at the side where i wanted it to be and when my character falls down the image/tile stretches to the collision and stops. looks like this stretches.jpg
Our assignment is to make a version of the classic 'Connect Four' game, where we need to construct a GUI that shows the current state of the game and instead of having a winner once a player has four chips in a row, the game needs to continue until no chips can be placed anymore.We currently get stuck in the GUI part. Running it right now results in a board with empty spaces only. Also after choosing a column to place, the board remains empty.
Our question: How do we get the board filled with the right color of chips at the right place?We know the 'ArcsPanel'-class (almost at the bottom of the code) is wrong, but we don't know what to do to make it right.
how to make a simple game. I am having trouble when it comes to adding sound though. It tells me to do this:
package net.game.Game;
import java.applet.Applet; import java.applet.AudioClip; public class Sound { public static final AudioClip BALL = Applet.newAudioClip(Sound.class.getResource("ball.wav")); public static final AudioClip GAMEOVER = Applet.newAudioClip(Sound.class.getResource("gameover.wav")); public static final AudioClip BACK = Applet.newAudioClip(Sound.class.getResource("back.wav")); }
What this does is it gets the sound file then gives it a name(BALL=ball.wav GAMEOVER=gameover.wav ect..) and then there is other code in other classes that call the sound so it will run but it keeps giving me an error and I don't know what to do. How can I get it to import the sound? Here is the error.
PHP Code:
Exception in thread "main" java.lang.ExceptionInInitializerError at net.game.Game.stuff.<init>(stuff.java:35) at net.game.Game.stuff.main(stuff.java:62) Caused by: java.lang.NullPointerException at sun.applet.AppletAudioClip.<init>(Unknown Source) at java.applet.Applet.newAudioClip(Unknown Source) at net.game.Game.Sound.<clinit>(Sound.java:7) ... 2 more
I am new to java, i can develop basic java programs but am not really good at it. How should i pursue and how should i start. I know the game rules.Do i need to learn swings for the same?
This code is for a tic tac toe game. I have a action listener set up and if the user entered a move that would win the game of tic tac toe it would call on a restart() method to clear the board, but every time some one wins the GUI freezes.
class ListenerCA implements ActionListener { public void actionPerformed(ActionEvent event) { Board.clear(); if (turn == 0) { start.answer = "CA";
[Code] .....
The code below this is the normal execution flow.
static void start_game(String board[][]){ final int one = 1; final int two = 2; int x = 0; play game = new play();
[Code] .....
In the above code gui == true always, I just kept an option if i ever wanted to run the program in console. The code below is the restart method.
I am trying to create a Hangman game with a gui. i already have buttons for the letters, each with its own action listener. I'm having difficulties creating the gallows and man.
I have a class called guiTest, which contains all of the letters. This is essentially what i have. Can I add the image to this class, or do I need to create a new class that extends JFrame?
i can develop basic java programs but am not really good at it.I have been given this assignment of developing UNO game in java and have been given 10 days. How should i pursue and how should i start.I know the game rules.Do i need to learn swings for the same?
Here is my Code for the Game Of Life that I am programming to teach my self java. I am trying to create a GUI and I have done so and a window displays however i don't understand how i can get the Game of Life to display within that GUI?
import java.io.*; import javax.swing.JFrame; import java.awt.Color; import java.awt.FlowLayout; //Provides default layout managing import javax.swing.JLabel; public class LifeMain extends JFrame
How do I track player (piece) movement?Building on the movement, to capture the piece you don't jump over it as in checkers, you move your piece onto the other color, so...How do I count pieces captured?
I'm really struggling on the physical code part. Conceptually I get that I need to store the information of each button clicked, but I don't understand HOW to store it, HOW to move a piece, and HOW to implement a system of turns.