Multi-Player Game With Multiple Worlds - Unhandled Packets
Sep 16, 2014
So I am trying to create a Multi-Player game in java, and I have a Game server and a Client. They normally connect with either but I would like to add a login server so that there can be an option to go to a different world then just the main one. It will have the same map and data but will be separate from the Players that are on world one per say. Now if you are on world two I would like it to have the option for you to be able to Private message players that are on World one. That is where the login server comes in to play.
I am still new at Java and would like to be able to understand Packets and how to handle them more clearly. So far I have gotten the basis of the login server connected to the server and the client connects to the server via the login server. But I am getting a bunch of "unhandled packets" and I would like to know how to handle them. Here are some bits of the code.
I wrote a single player blackjack code and i want to play this game with multiplayers, which steps should i take to do this
package blackjack; import java.util.Random; import java.util.Scanner; public class Blackjack { public static void main(String[] args) { Random kagit=new Random ();
I am creating a hangman code. So the game i am creating is 2 player, first player enters the word and second player guesses. i made the code but i don't know how to restrict the first player from adding random characters into the secret word because for my project the word can only contain letters. so i need making the code so the player 1 can only enter letters.
My code is below:
/** * Auto Generated Java Class. */ import java.util.Scanner; public class Hangman { public static void main(String[] args) { Scanner input= new Scanner(System.in); String player1,player2; int wrongguessamount = 0; //keeps the count of the amount of wrong guesses int correctguessamount = 0; //keeps count of the amount of correct guesses int maxincorrect=6;//makes sure the user cant guess more than 6 times
I am trying to design a monopoly board game with a class and a main program. I can not make the method to keep track of the player's position after every roll. After every roll it prints "Previous position: 0".The player should also not go over 14th spot because the board is just 15 including 0. That is what I have (just the particular method and the part from the main program which call it).
public int getpospl1() { System.out.println( getplayer1name() + " Rolls " + "Dice 1: " + getrolld1() + "" + "Dice 2: " + getrolld2() + "" ); int spot1 = 14; //The end spot int start = 0; int previousPosition = start;
I created a simple Hangman game. It functions correctly, the only issue is when the file contains a phrase (2 or more words), spaces are not displayed when the program is run. For example, if the phrase was Java Programming Forums.
It would appear as _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.
I want there to be spaces in between the words. How could I fix this? What would I need to add to my code?
import java.util.Scanner; import java.io.*; public class hangman{ public static void main (String[] args) throws FileNotFoundException{ Scanner kb = new Scanner(System.in); String guess; String guesses = ""; int wrongGuess = 8;
I am trying to make a Connect Four game with java swing, but I am getting an error with my attempt at making an multi D panel maker when I try to run it.
I have been working on this function and i can't get it to work. It's a little bit complicated so let me first explain what this is about:
1. As a little exam in my studies i have to program a halma console game with KI an stuff.
2. Everything is finished and works except for the Move-Calculation.
3. A Move is a Move from Field a to Field b which a player can perform in one round based on the game rules (Careful: We are not using the standard halma rules, we use different ones).
4. Class Move consists of the Starting Cell where the Figure before the Move stands and a target Cell where the figure will stay on at the Move end. It may include an Array of serveral Cells, the stop cells which the figure passes from start -> target since several jumps can be performed in one Move.
Valid Examples for Moves:
a -> b (From Field a to Field b) d -> f through g,h,i (From Field d to Field f through the Field g,h,i
My Move Calculation where all possible Moves are calculated for a given figure consists of 2 parts. An expand() function which will generate all possible moves (works perfectly) and a jumpFix() function which isn't working properly.
Example:
After expand() I'm getting something like that:
a -> b b -> c c -> d s -> t
This is however not finished, because the first 3 Moves are actually 1 Move. Because the player can Move from a -> d in one turn because those 3 are consecutive Move. The fixed Move would look like that:
a -> d through b,c
jumpFix() is also perfectly working for that situation, however there is one specific situation when it doesn't work. Let's say we have this situation.
a -> b b -> c c -> d b -> e e -> f f -> g s -> t
Then the only valid jumpFix() output would be:
a -> d through b,c a -> g through b,e,f s -> t
However i can not get it to work yet. Note: It definitely needs to be iterative, not rekursive else i would get an StackoverflowError.
This is my current Code of jumpFix():
Java Code:
/** * Takes a look into all calculated moves and finds those which should be seen as one move, but are still considered to be more than one move (several jumps in one move) */
public static List<Move> jumpFix(List<Move> moves) { Set<Move> result = new HashSet<Move>(); Set<Move> remove = new HashSet<Move>(); int lastSize = -1; // repeat action until no moves could be merged while (lastSize != remove.size()) {
[Code] ....
How to implement the special case where a Move splits into 2 or more branches and jumpFix() able to handle this case.
Its a basic program that is played by 2 people. Player one is suppose to type a number and the second player is suppose to guess the number. However after I test it out, and if I guess too low or too high I get stuck in "Your guess is too low, try again." infinite loop, what is wrong.
import java.io.*; class GuessingGame { public static void main (String[] args) throws IOException { BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in)); String firstPlayer, secondPlayer; int firstInput, secondInput; int guessCount = 0;
I am creating a roulette program that I converted from C++ to Java. Why its not finding the main class. Therefore it will not compile. Heres the code:
import java.util.Scanner; public class P1RouletteDB { // This program demonstrates the use use multiple arrays to play a roulette game. //Also a random number will generated to be used as the ball in the game. The user will be provided the random number to test the win algorithms // Program Set 2 Roulette Game
// Global constants public static final int COLS = 3; // Number of columns in each array
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 need a java library function that searches the stream of tcp packets coming to my computer from a particular ip address, so i can perform regular expressions on the contents of those packets.
I have to write a client and server class for a UDP protocol sending integer numbers by UDP packets. So far i have this;
Client Code:
import java.io.*; import java.net.*; class UDPClient { public static void main(String args[]) throws Exception { BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
[Code] ....
But i now need to change this so that:
The client;
1. Reads an integer from keyboard input and stores its value in a UDP packet. // byte[] send = ByteBuffer.allocate(4).putInt(num).array(); ???
2. Sends the UDP packet to the server, on port number 1999;
3. Listens for UDP packets from the server (until it receives a packet with a non-positive number; see step (b) below). While listening:
(a) Once it receives a UDP packet from the server, it subtracts 2 from the integer value num contained in it. // int num = ByteBuffer.wrap(receive).getInt(); ??? (b) Checks the integer value num: if the value is greater than 0 (num>0) then the client stores it in a new UDP packet and sends the packet to the server; otherwise (num<=0) the client terminates.
The Server;
1. Listens on port 1999;
2. For each UDP packet it receives from a client: (a) extracts the integer value n contained in it; (b) decreases the value of n by 2; (c) sends back to the client a UDP packet containing the new value of n.
I decided to write a small Java program to experiment around with BorderLayout, because I'm developing a Java game and I need to have 2 objects placed in a single JFrame at the same time, and everyone I asked said I need BorderLayout to do that.Before you answer: Also, is using BorderLayout the best option for adding multiple video game oriented objects such a sprites to a JFrame?
So the Java program I wrote is supposed to place a JButton on the JFrame and ALSO place a graphic component (a rectangle in this case). The problem is, only the button shows up, as can be seen in the image link below: URL....
Here is the code:
**main.java** --> The main method class + JFrame/JPanel/JButton constructor import java.awt.BorderLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class main {
I am using the Netbeans IDE for Java creations. What are the steps of creating a media player using Java thru Netbeans as i don't understand most of the jargon and the forms,classes,etc.I don't want to use JavaFx but plain Java Application.I am coming from a Delphi pascal background.
I am trying to create an MP3 player with a totally customized look and feel to it. I know how to do this with .net, but I must be missing something in Java.
I want to be able to NOT have to present the user with the default mediaPlayer.getControlPanelComponent() in order to control the media player. I want to be able to code it to when the user clicks on my "Play" button, I can tell the player to play the song, and so on.
So I have a player an enemy and enemy bounds the enemy can go. I need to have the enemy track my position and when I go into the position (I am using a collision method for this) the enemy comes over at a speed of 1. My problem is the enemy jumps to me and then follows at speed of 2 (2 is the player speed). The code is wrong this is why it is jumping and I have my other problems. so my question is what is a good solution for this? I am trying to make a method to track playerposition() so what I am thinking I could do is find x, y of player then store those into an array and return the array to Enemy so he tracks.
player.java public class Player{ int x = 100; // Location of player int y = 200; // location of player int xa = 0; // Representation of where the player goes int ya = 0; // Representation of where the player goes private int speed = 2;
[Code] .....
Please note this is not the entire code I have cut some things out that did not need to be there. Also, the code is just to get an idea of what I was thinking of doing. The ideas that are came up with are not meant to be a reflection of what I already have but, what I could add or replace.
I am currently building a java music player and need getting the volume control to work. I want to be able to set the computers volume directly using an integer. I've created a slider and put the value into an integer. The part that I am having trouble with is getting the volume to work.
I have made a server/multi Clients where Clients send Double data but my problem is that the clients send this data to Server only wonce, and the server waits again the connection from client. (I have to run the clients manually each time)what i'm looking: the client should always send data to server. like an infinite loop.
import java.awt.Color; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class Screen implements ActionListener { public JButton[][] b=new JButton[200][200];
[Code] ....
I am trying to create the A* Algorithm and I REALLY need a 2D array to handle this.
This is the error:
Java Code:
at java.awt.AWTEventMulticaster.componentShown(AWTEventMulticaster.java:162) at java.awt.AWTEventMulticaster.componentShown(AWTEventMulticaster.java:162) at java.awt.AWTEventMulticaster.componentShown(AWTEventMulticaster.java:162) at java.awt.AWTEventMulticaster.componentShown(AWTEventMulticaster.java:162) at java.awt.AWTEventMulticaster.componentShown(AWTEventMulticaster.java:162) mh_sh_highlight_all('java');
I am trying to program an A* algorithm and I cannot even get past the buttons. I need a 2D array of buttons to handle this problem but I am getting the following errors.
at java.awt.AWTEventMulticaster.componentShown(AWTEventMulticaster.java:162) at java.awt.AWTEventMulticaster.componentShown(AWTEventMulticaster.java:162) at java.awt.AWTEventMulticaster.componentShown(AWTEventMulticaster.java:162) at java.awt.AWTEventMulticaster.componentShown(AWTEventMulticaster.java:162)
I have already tried every possible way for removing this bug but all failed. The problem is that sometimes my player passes through the map tiles, i mean, the algorithm is like -- if not colliding, move in required direction; else if colliding, move in opposite direction. But sometimes the second condition fails i dont understand why.
I have been practicing writing java code, my university course is going to cover socket programming and multi-threading.
I am presently just starting to write myself a framework for all multiplayer games I may make in the future, my aim really is simply to practice and understand better and this time, im not using an ide, just sublime text, all new grounds for me, I have a good basic understanding of the subject but I want to be fluent.
import java.net.*; import java.util.ArrayList; import java.io.*; /*SMOOTH THREAD SAFE MULTI CLIENT HANDLING CLASS. * *This class will create connection objects when a connection is detected, these connections will run in a separate thread and update an array list in their parent class containing their last sent data