So I'm making a combat system for a game I'm working on.The combat is basically like old-school Runescape's, where the 2 participating combatants take turns hitting each other.Except, in this game, I'm trying to make it so you can only fight one enemy at a time, no matter what. I'm trying to make so if you're fighting a mob and you try to attack another, your action is ignored and you continue your current fight.
I'd post the code I have, but it is such a mess with all the booleans and other variables being in other classes that I'd have to post the whole project itself.
Here's the sequence I have:
1. I try to fight an enemy. (Once I'm in their "fight radius" and press space)
2. They fight me back. (Executes their combat-style method, in this case, non-hostile)
3. I walk away and try to fight another enemy. (I'm still in the other enemy's "chase radius" and they follow me as I try to attack another enemy)
4. I'm able to fight the other enemy, resulting in a 1 vs 2 fight. (The second enemy executes the same non-hostile combat method to fight back)
I don't want that. This is my goal:
1. I try to fight an enemy. (Once I'm in their "fight radius" and press space)
2. They fight me back. (Executes their combat-style method, in this case, non-hostile)
3. I walk away and try to fight another enemy. (I'm still in the other enemy's "chase radius" and they follow me as I try to attack another enemy)
4. I'm unable to start another fight because I'm already fighting a different mob. (The second enemy just ignores as the enemy I attacked first walks up to me and continues to attack until I kill it or run away)
Is this because of static/non-static methods and values? Instances?
I tried everything but I cannot get this 1-enemy-per-fight limit to work.
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;
I'm working on a Java 2D game which requires a max of six keys be held down at the same time.
The game is for two players on the same keyboard, playing simultaneously.
However, all three computers I ran the program on only allow a max of three keys held at a time. They all have trouble with reacting to more than three keys being held.
It seems that pressing a new key after three are already held, either cancels some other key-holding or is ignored.
I've been told that this is a hardware issue. Most keyboards can't handle more than three keys held at a time. But a lot of games do require this, and they do not require special gaming-keyboards to run on my computer without problems.
So there has to be a solution that will make the game playable on any standard keyboard.
(I use Key Bindings).
The game's controls:
Player 1
- Rotate sprite and set angle of movement: LEFT arrow
- Rotate sprite and set angle of movement: RIGHT arrow
- Move forward: UP arrow
- Shoot missile: ENTER key
Player 2
- Rotate sprite and set angle of movement: 'A' key
- Rotate sprite and set angle of movement: 'D' key
- Move forward: 'W' key
- Shoot missile: 'T' key
Relevant code:
The Key Bindings part:
Java Code:
// An action for every key-press. // Each action sets a flag indicating the key is pressed. leftAction = new AbstractAction(){ public void actionPerformed(ActionEvent e){ keysPressed1[0] = true;
[Code] .....
This is mostly how reacting to key-presses and key-releases works in my program. When a key is pressed or released, a flag is set. The Board class reades the flags every game-loop cycle and reacts accordingly.
As I said, the program doesn't react correctly to more than 3 keys held at a time, probably because of the keyboard. Is there a way to code a solution?
I want to work on a project related to MMO real-time strategy social game as a college project but i dont have enough knowledge on it starting from 3d object coding to server.
Also i would like to know what are things to be cosidered as its an online game whether the camera angel affect what are problems that might occur and how to outrun it. How to split the server so that in one server depending upon the geo-location some number of users will be connected and will be splitted in different servers depending on the location
I want the actions to be cloud based but the actions of the characters will be coded within the game and in every server maximum of 100 users can connect.
I am working on an assignment that I can't seem to figure out the final part to. The program takes in course data such as the time the class starts and how long it lasts. The time is in military time (0000 - 2400)
I need the output time to be the time the class started, plus the length of the class, and displayed in military time.
I can't for the life of me figure out how to do this. I have gotten a program that works for this time and minutes, and displays the correct 1020. But when I change the information to say
Start time: 0700 Length = 90 minutes
I get:
Endtime = 90
90 is technically correct, the way the formula is setup, but I need it to display 0900 not 90.
Here is the code that I have. Be easy, I'm still learning, and this is just the file I created to get the formula to work. Also, the verbose in here is just for my own debugging to make sure values should be what I'm expecting them to be.
public class calc { public static void main(String[] args) { double hours, minutes, length; double temp; int time = 2400; hours = time / 100; System.out.println("Hours are: " + hours);
I have two classes. time_runner is used for testing my code.
This is what I'm using to test my code:
class time_runner { public static void main(String str[]) throws IOException { Time time1 = new Time(14, 56); System.out.println("time1: " + time1); System.out.println("convert time1 to standard time: " + time1.convert()); System.out.println("time1: " + time1); System.out.print("increment time1 five times: "); time1.increment();
[code]....
The two constructors are "Time()", which is the default constructor that sets the time to 1200, and "Time(int h, int m)" Which says If h is between 1 and 23 inclusive, set the hour to h. Otherwise, set the hour to 0. If m is between 0 and 59 inclusive, set the minutes to m. Otherwise, set the minutes to 0. Those are my two constructors that I pretty much have down. The three methods however I'm having trouble with. The "String toString()" Returns the time as a String of length 4. The "String convert()" Returns the time as a String converted from military time to standard time. The "void increment()" Advances the time by one minute.
public class Time { private int hour; private int minute; public Time(int h, int m) { if(h > 1 && h < 23) hour = h;
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";
Below is the main class of a project ive been working on, the goal is to start a countdown specified by the user. When the countdown reaches zero the base drops in the song that is being played. (Its not done yet) The main problem that arises is the fact that my song plays, and AFTER that, the timer starts.
Output:
Please input countdown in HH:mm:ss format. 00:00:41 Start? Yes
The name of of the song is: Skrillex & Damian "Jr Gong" Marley - "Make It Bun Dem"
The time of base drop is: 00:00:41 //Song starts here
//Song is done //Then timer starts 00:00:41 00:00:40 00:00:39
I would like to set a specific time for a Calendar instance. My below code will set a time one minute ahead of the current time, and format it to ISO8601 standard.
I now want to set another variable(deadlineDate), but to a specific time, say 5 minutes ahead. I would like to hardcode this in so I dont want it to change as a result of getting the instance of the Calendar(which sets it to the current time)
Essentially I am trying to regenerate the above code every minute and increment itself each cycle until it reaches the deadlineDate, which is a fixed datetime.
I am writing a code that tries to figure out the users password by going through every possible key (brute force). Although I think its going to work, it looks EXTREMELY inefficient to me, since its just a huge switch statement for each character -- 94 total, including the shift values. Is there a built in method in the JAVA API that goes through every key or something?
Here is my code for that segment:
public char[] HackingPassword(){ char[] passChars = this.password.toCharArray();//convert the password to char[] char[] hacking = new char[passChars.length];//make the hacking variable same size as users password int nextCharValue = 0;//this is used to cycle through the keyboard //check each letter of hacking to match with password for(int i = 0; i < passChars.length; i++){
Yes my JPanel is not displaying all the time like you would think it would. Before you beat me up yes I am a bit new I am just working on the GUI part of java over my summer break. Obviously it is not suppose to do that. Secondly, As you can see i am using the alphabet to create JButtons. Shouldnt there be an easier way to use a for( loop) . I tried before but I didn't want to get too side tracked.
Java Code:
import javax.swing.*; import java.awt.*; public class hello { private JFrame alphaframe1; private JFrame alphaframe2;
I'm having an issue with this little bit of conversion. I'm converting a string (_dateString) into a Calendar time. I am using DateFormat and SimpleDateFormat to accomplish this task. Everything seems to be working great, except for it figuring out whether it is AM or PM. According to SimpleDateFormat (Java Platform SE 7 ) I am using "aa" to get my AM or PM marker. How come in my output then, it believes it to be 4:45 am instead of 4:45 pm? Hour of Day should return the 24 hour clock, which should show 16 instead of 4. I have posted the output below my code.
Java Code:
import java.text.*; import java.util.*; public class Time{ static String _dateString = "08 Feb 2014, 4:45pm"; public static void main(String args[]){ Calendar cal=Calendar.getInstance();
[Code] ....
Output:
Java Code:
Today is Sat Feb 08 04:45:00 EST 2014 Year: 2014 Month: 1 Day of Month: 8 Day of Week: 7 Week Of Year: 6 Week of Month: 2 Hour: 4 Hour of Day: 4 Minute: 45 Second: 0 Millisecond: 0 mh_sh_highlight_all('java');
I'm working on creating a dice game and getting the users input is giving me a really hard time. I have the main game working but this part I'm stuck on. The problem is that it's not giving me the chance to enter the second input when I ask for the game.
//Create Scanner object Scanner keys = new Scanner(System.in); //Get chips System.out.print("How much money would you like to change? "); int chips = keys.nextInt(); System.out.println("You now have $" + chips + " in chips.");
[code]...
This is what I get when I run it run/How much money would you like to change?
I work as a golf staff I would like to create application which would tell me the playing time and the time when players need to reach certain playing field/hole. my ideas is to make a program which would ask the user to input their starting time and than select the hole number, where the end result would be amount of actuall time.
I have been having hard time to figure out howe to properly structure the input conversion so it is recognized as a time (Exampke: 10:15). Do I need to use the calendar method in Java or ?
I am trying to to insert time onto my jFrame (Netbeans) by using textfields. this is the code i've tried to put into the textfield so whenever i run the program it automatically shows the time.
I Have one query regarding OTP, In my project while registration the otp should be generate and send to the mobile number of user which is registered the form.
I have this code that prints the run time for each for loop iteration but how do I find the fastest time store it in a variable and the print that variable at the end? This is what I have currently.
for (int i = 1; i <= 14; i++) { int n = (int) Math.pow(2, i); int[] list = new int[n]; for (int j = 0; j < list.length; j++) { list[j] = (int) (Math.random() * 2000); } int length = list.length; double radixTime = radixSort(list, length); System.out.println("For base " + i + " the time was " + radixTime); }