I finished a game. It works perfectly fine on my computer. Sent it to a friend. On his computer, for some reason, one of the keys that are used to play doesn't work inside the game. (It works in any other context, like a web browser).
He tried pushing this key with no other keys held. Still didn't work. So it's not a 'key combination' issue. We both use Windows and the most updated JRE version.
The key that doesn't work on his computer, is: ; (semicolon)
I am writing a program where i am trying to control a rectangle and determine where it moves, everything is working fine it is moving but i am trying to figure out how to change direction using the "WASD" keys. This is what I have and I am not sure why its not working.
Java Code:
addKeyListener( new KeyAdapter() { public void keyReleased(KeyEvent event) { for (MoveableShape creature : creatures) { if (((Creature)creature).isPlayer()) { if (event.getKeyCode() == KeyEvent.VK_W) //up
I had a game written in a 500x400 window using JFrame and a threaded JPanel. It used KeyListener to detect user input and worked just fine, problem was it was very click dependent and therefore I wanted to put it into fullscreen mode so I would no longer come across the problem of clicking outside the window and being taken out of the game. But when I ported the game to Full Screen Exclusive Mode the KeyListener no longer seems to be working and I have no clue why. I tried using KeyBindings as well, that code didn't work and is left commented out in the FSEM code.Here is my code for the windowed application:
import java.awt.Container; import javax.swing.*; public class Main extends JFrame{ private GamePanel panel; public Main(){ panel = new GamePanel();
I have come across an issue with arraylists. I am writing a text based RPG game as something to start with ...
Initially I had a single zone which was all stored in an arraylist and everything was working in regards to the player moving around. The problem I now have is how to add further zones to my game. Ideally I would like an arraylist for each zone, and would use the below to create each arraylist
public static ArrayList<RoomsClass> castleMap = new ArrayList<>();
The problem I now have is how to handle the player moving, initially with a single zone/arraylist I could reference that arraylist directly
public void findRoomCoords(int ID) { for (int i = 0; i < castleMap.size(); i++) { if (castleMap.get(i).roomID.equals(ID)) { PLAYER.setCurrentRoomZone(castleMap.get(i).roomZone); PLAYER.setCurrentRoomX(castleMap.get(i).roomX); PLAYER.setCurrentRoomY(castleMap.get(i).roomY); PLAYER.setCurrentRoomZ(castleMap.get(i).roomZ); } } }
My initial thought was to use a getter/setter to remove the reference of castleMap from my movement code in order to access different arraylists, however this is where things have fallen over, I can't seem to work out how to get the arraylist name to change, depending on the outcome of the setZoneMap() method.
public void setZoneMap() { switch (PLAYER.getCurrentRoomZone()) { case 0: { zoneMap = Castle.castleMap; break;
I am developing an application to share my client screen with server, it is working well on swing. But i want to develop as web application, i am trying to using applet. But i am facing the fallowing problem..,
1) The Applet screen also open and project also running well on server mechine. But unable to see the client screen on the server.
2) The problem may be to display the JDesktopPane or JInternalFrame.
My working Server Code extends withe JFrame..Java Code:
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";
Why in my program keys are not working, what I forgot to write?
import javax.swing.JFrame; public class Main { public static void main(String args[]) { JFrame frame = new JFrame("Stickman"); frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE); frame.setSize(450, 490);
I am working on a fairly simple program where I have a colour change three times using the red green blue spectrum. The problem is that I keep getting a result of zero no matter what I do.
import java.awt.*; class RectangleMain { public static void main (String[] args) { ColouredRectangle blocky = new ColouredRectangle(50, 100, 20, 40, Color.red); System.out.println(blocky.getColour()); blocky.mixColour(Color.blue);
I'm programming a game, but the keyListener doesn't work. Here is the source code:
import java.awt.event.KeyEvent; import java.awt.event.KeyListener; public class InputHandler implements KeyListener{ public InputHandler(Game game) { game.addKeyListener(this);
[code]....
My Question is: Why will it not say "up", if I press "w"?
I'm having a problem where an if statement isn't working. In the Person class boolean olderThan ignores my if statement so it always returns false and I just don't get why that's happening.
import java.util.Calendar; public class Person { private String name; private MyDate birthday; public Person(String name, int pp, int kk, int vv) { this.name = name;
I have added a Simple Jar file in Eclipse Proect->BuildPath->jar file but class Inside that are not showing in My project this is my Project Structure and I have all ready checked in Order and Export..But jar file is not working.
I am learning out design patterns and doing a little fun project on Model Control View (MCV). I got the concept down, it is pretty simple for the most part. However my buttons are not working.
Here is the code:
public class Controller { private Model model; private View view; Controller(Model model, View view) { this.model = model; this.view = view;
[code]....
It runs but nothing. My other questions is how can I make a box that will print the results.
I need to find out if one array list is a sub-sequence of another. The elements in the first list all need to be in the second list and must be in the same order. So s1<n, t, a> is a sub-sequence of s2<q, n, f, r, t, d, a>, but s1<a, a, t> is not a sub-sequence of s2<a, t, a>. I need to use iterators to go through each list, and I should only go through each list once (since it has to be in the same order) so nested loops don't seem like they would work because it would start at the beginning of one list every time it moved to another element in the outer loop's list.I seem to have an issue where the itr1. next() is ignored when in an if statement.
My current code just stalls and will never stop running. I've also switched things around and put the not equal check after the if it is equal and it throws a NoSuchElementException.
import dataStructures.*; public class Subsequence3 { public static void main(String[] args) { ArrayList<Character> s1 = new ArrayList<Character>(); s1.add('n'); s1.add('p'); s1.add('a');
the problem which im facing when executing jar file is it is not working same as when i run file using the IDE.When run jar file, it won't open the new frame even the user and pass combination correct.But when i'm compiling using the IDE, it works as charm. The main menu popped up after i logged in.I've tried Clean and Build and it's not working too.
I code a program using Eclipse Keppler with Java 8.0. I made a program with 2 JPanel. The first JPanel is working well. From a button in first JPanel, I excute second JPanel, but It is not working. No error when I compile the code. Here is, I attached the source code.
working on a project but cant seem to get my while loop to restart i want to restart this guessing game if the user inputs y at the end otherwise it will end.
import java.util.Scanner; import java.util.Random; public class GuessingGame{ public static void main(String[] args){ Scanner in = new Scanner(System.in); String again = "y"; while(again=="y"){
i am trying to make taxi meter which shows the current price.Rightnow I have to click startmeter afterevery 1 minute than it's update the new price but I want it to update automatically once the price change after 1 minute instead of me pressing startmeter everytime.This is my 1st time I am using timer class. I am not sure why timer is not working.
i have a problem with the jsf 2.0 version with inplace select,in jsf 1.2 it was working, but in jsf 2.0 it is not
problem: when select one of the item in inplace select dropdown,I am trying to update it with the selected value using the a4j:ajax tag, using but the control is not calling the update() method
<rich:column id = "locationClmn"> <f:facet name = "header"> <h:outputText id = "LocationHeder" styleClass = "headerText" value = "#{messagesRefdata['notifications.locations']}"/> </f:facet> <c:set var = "locations" value = "#{notificationConfigurationBean.listOfLocations(ntc.notification)}"/> <rich:inplaceSelect value = "#{ntc.location}" showControls = "true"
[code]....
I have even tried f:ajax, execute= "@this", immediate = true.
there is no divider in the operation. Iadded a print i to confirm the loop works. I tried with and without the brackets..Can you use the i in the operations of the loop? I figured I could since printing it out give me a list of numbers
public class harmonique { public static void afficherHarmonique( int wholeNumber ) { int harmonique = 1; for( int i = 2; i <= wholeNumber + 1; i = i + 1 ) { System.out.println ("i =" + i); harmonique = harmonique + (1/i); System.out.println ("harmonique =" + harmonique);
Currently the while near the end is not working in netbeans. It is saying illegal start of type. This whole section was working before when it was within the public static void method. I moved it to a separate class to try and clear up a, static variable problem. My question is can i fix it to keep it structured this way. Or do I have to put it back into the main method and try to work out the static variable problem a different way.
public class InventoryProgram { double[] dvdprice; // defines variables int[] dvdnum; int[] dvdstock; String[] dvdnames; int count; double total;
I'm trying to get a progress bar to work on my GUI.
This is what I have so far, the parameters are taken from another class that takes in an image in packets from a Raspberry Pi and stores them to a file on PC.
public void ImageInfoReceivedHandler(int sizeOfFile) { progressBar.setMinimum(0); progressBar.setMaximum(sizeOfFile); progressBar.setIndeterminate(false);
[Code] .....
The println are printing out the correct values and they are being implemented in the methods, but nothing is happening in the GUI.
I have a thread setup in the GUI when a button is pressed
getImageButton.setText("Timer Started"); transmit = new transferImage(port); lblImgProcess.setText("Getting Image, Please Wait"); transferThread = new Thread(transmit); transferThread.start();
So the thread starts and image is then transmitted, does the progress bar need to be in that event handler?