Region Is Created Dynamically Using Combination Of Pre-existing Region

May 8, 2014

I'm trying to add a feature to my game where a region is created dynamically using a combination of a pre-existing region.This part of the game will be a sort of adventure where the place is different every time.This is a picture of the original location, when called, the server would copy parts of this region and make an instance of a new region.This new region will always have the coordinates [6, 6] as the starting room. Each room has a certain number of doors used to get across each room.Here's a picture of the new region and all the potential spots the rooms can be placed.

new DungeonFloor(new int[] { 8, 632 }, FloorType.BASE_FLOOR, new int[] { NORTH, SOUTH, EAST, WEST }),
new DungeonFloor(new int[] { 8, 630 }, FloorType.BASE_FLOOR, new int[] { NORTH, SOUTH, WEST }),
new DungeonFloor(new int[] { 8, 628 }, FloorType.BASE_FLOOR, new int[] { NORTH, SOUTH, }),
new DungeonFloor(new int[] { 8, 626 }, FloorType.BASE_FLOOR, new int[] { SOUTH, WEST }),
new DungeonFloor(new int[] { 8, 624 }, FloorType.BASE_FLOOR, new int[] { SOUTH }),

Here's a picture of the dungeons.The parameters are as follows

[] { regionX and regionY } // Used to copy the original location
Type of floor
The door directions of that original location

These are all the same room except the doors are different. Each room can be rotated to make the doors work.The problem:I need an algorithm that finds a starter floor with the correct number of doors, places it at (6, 6).Places the best boss floor at any region makes a map around the boss floor covering x number of rooms. x being a parameter that's sent with the method call.

The code so far:

List<DungeonFloor> allFloors = Arrays.asList(DungeonRepository.DUNGEON_FLOORS);
List<DungeonFloor> starterRooms = new LinkedList<DungeonFloor>();

for (DungeonFloor floor : allFloors) {
if (floors.type() == FloorType.BASE_FLOOR)
starterFloors.add(floor);
}

View Replies


ADVERTISEMENT

LWJGL - Selecting Specific Region Of Image

Jan 20, 2014

I want to render a specific region of an image in LWJGL,

View Replies View Related

While Loop In Combination With A Scanner

May 17, 2014

I have the following task given to me (to be solved in NetBeans) :

View the contents of the file tuinman.txt: each line has a (real) number, followed by a line text.

Write the readGardener () method that reads the file completely. Only if the number is negative, write the rest of the line. (For each input line, a new line output.)

Extra: Adjust your method so you get the text after each negative number, written "word by word", among themselves. A word can contain characters that are not "letters" are (,,. '") - ,this you may ignore.

"tuinman.txt" is dutch for "gardener.txt". This txt file is located in the same map where build,nbproject,src, etc... are located. I couldn't solve this task so i looked at the solution. It didn't work... So i tried the solution of the extra bit:

package labo.pkg2;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Methods {
public void readGardener() throws FileNotFoundException {

[Code] ....

The txt file is added as an attachment to this post.

The weird thing is, the first thing the program prints is "Van" "morgen" "ijlt",... wich are words from line 19 in the txt file. All the ones before line 19 the program won't print, even if the number is negative. Even weirder, the next thing that is printed after line 19 is the NUMBER from line 20, nowhere in this code do i tell the program to print a number, and yet it does... But that's not all! From line 19 on, he just prints every single thing in the document except for the negative number, if your mind didn't explode already, it sure did now!

So in short: I need some code that prints all the lines from the txt files that start with a negative number. Only the text may be printed though, there may be no numbers in the output!

The txt file, i couldn't add it as a attachment

123
-456,12 De tuinman en de dood
184,67 was hij, Kees, de enige die het zag, want niemand lette d'r op...
-845,14
-8,12452 Een Perzisch Edelman:
157,24 Dus daar gaan we dan.

[Code] ....

View Replies View Related

Setting Up A Test For Combination Method

Nov 18, 2014

I'm having trouble setting up a test for my combination method.Here's the method (It basically finds the most amount of characters that both substrings share and combines the two using the number of shared characters as a breaking point):

public static String combination(String str1, String str2, int overlap) {
assert str1 != null : "Violation of: str1 is not null";
assert str2 != null : "Violation of: str2 is not null";
assert 0 <= overlap
&& overlap <= str1.length()
&& overlap <= str2.length()
&& str1.regionMatches(str1.length() - overlap, str2, 0, overlap) : ""
+ "Violation of: OVERLAPS(str1, str2, overlap)";

[code]....

View Replies View Related

Passing Object As Parameter - Combination Values Are All Zero

Mar 8, 2015

I have an object that has an instance of another object class as its parameter :

CombinationLock oneHundred = new CombinationLock(28,17,39);
Locker Mickey = new Locker(100, "Mickey", 3, oneHundred);

This is for a locker, which has a combination assigned to the student. Within the locker class I have the following constructor:

public Locker(int locker, String student, int numberOfBooks, CombinationLock combo) {
this.locker = locker;
this.combo = combo;
this.student = student;
this.numberOfBooks = numberOfBooks;
}

combo is the private CombinationLocker object I created within the Locker class. Do I need to pass the combo object on to the CombinationLock class? For reason, I do not comprehend, the combination password from the main class is not passing through to the CombinationLock class, and the combination values are all zero.

View Replies View Related

Repaint Work In Combination With PaintComponent (Graphics)?

Oct 3, 2014

I am teaching myself AWT/Swing ... It concerns an application that creates dynamic graphics using the Graphics class. I understand that the code that creates graphics should be put in a "paintComponent" method of a (descendant of a) JPanel class. And that when you want to change something on this panel outside "paintComponent", you have to call the "repaint" method, that somehow causes "paintComponent" to be invoked.

However, I don't fully understand the explanation of the example at [URL]... . It concerns an application that moves a red square when a mouse button is clicked. The code can be found at the link, but I also repeat it below.

package painting;
import javax.swing.SwingUtilities;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseEvent;

[Code]...

This code indeed works. However, I don't understand why. The explanation at the Oracle site is the following.

Because we are manually setting the clip, our moveSquare method invokes the repaint method not once, but twice. The first invocation tells Swing to repaint the area of the component where the square previously was (the inherited behavior uses the UI Delegate to fill that area with the current background color.) The second invocation paints the area of the component where the square currently is.

However, what I don't understand: when repaint is first invoked, squareX and squareY still have their old values. If the invocation of repaint simply causes an invocation of paintComponent, then paintComponent should draw a red square at (squareX, squareY). Just like the second invocation of repaint causes paintComponent to draw a red suare at the new values of (squareX, squareY). Instead, the first invocation results in the red square being wiped out by the background color.

So apparently, the first invocation of repaint does not simply cause an invocation of paintComponent. What does it do?

View Replies View Related

Swing/AWT/SWT :: Creating A Combination Lock That Consist Of Three Strings

Oct 23, 2014

I need to use a counter to keep track of user's input. In this class I am trying to create a combination lock that takes three strings. In the tester class the user inserts three strings and both are compared to see if users input matches correct combination. I have no errors only problem is the setPosition method. My output is always false.

public class CombinationLock {
private String first;
private String second;
private String third;
private String firstGuess;
private String secondGuess;
private String thirdGuess;
private boolean open;
private int counter;

[code]....

View Replies View Related

Image Processing Pattern Matching / Combination Algorithm

Jun 9, 2014

The problem I am trying to solve relates to block-matching or image-within-image recognition. This is an algorithm problem I am working on in java, but computationally, my computer can't handle generating all the combinations at one time.

I see an image, extract the [x,y] of every black pixel and create a set for that image, such as

{[8,0], [9,0], [11,0]}

The set is then augmented so that the first pixel in the set is at [0,0], but the relationship of the pixels is preserved. For example, I see {[8,0], [9,0]} and change the set to {[0,0], [1,0]}. The point of the extraction is that now if I see {[4,0], [5,0]}, I can recognize that basic relationship as two vertically adjacent pixels, my {[0,0], [1,0]}, since it is the same image but only in a different location.

I have a list of these pixel sets, called "seen images". Each 'seen image' has a unique identifier, that allows it to be used as a nested component of other sets. For example:

{[0,0], [1,0]} has the identifier 'Z'

So if I see:

{[0,0], [1, 0], [5,6]}

I can identify and store it as:

{[z], [5, 6]}

The problem with this is that I have to generate every combination of [x,y]'s within the pixel set to check for a pattern match, and to build the best representation. Using the previous example, I have to check:

{[0,0], [1,0]},
{[0,0], [5,6]},
{[1,0], [5,6]} which is {[0,0], [4,5]}
{[0,0], [1,0], [5,6]}

And then if a match occurs, that subset gets replaced with it's ID, merged with the remainder of the original set, and the new combination needs to be checked if it is a 'seen image':

{[z],[5, 6]}

The point of all that is to match as many of the [x,y]'s possible, using the fewest pre-existing pieces as components, to represent a newly seen image concisely. The greedy solution to get the component that matches the largest subset is not the right one. Complexity arises in generating all of the combinations that I need to check, and then the combinations that spawn from finding a match, meaning that if some match and swap produces {[z], [1,0], [2,0]}, then I need to check (and if matched, repeat the process):

{[z], [1,0]}
{[z], [2,0]}
{[1,0], [2,0]} which is {[0,0], [1,0]}
{[z], [1,0], [2,0]}

Currently I generate the pixel combinations this way (here I use numbers to represent pixels 1 == [x,y]) Ex. (1, 2, 3, 4): Make 3 lists:

1.) 2.) 3.)
12 23 34
13 24
14

Then for each number, for each list starting at that number index + 1, concatenate the number and each item and store on the appropriate list, ex. (1+23) = 123, (1+24) = 124

1.) 2.) 3.)
12 23 34
13 24
14
---- ---- ----
123 234
124
134

So those are all the combinations I need to check if they are in my 'seen images'. This is a bad way to do this whole process. I have considered different variations / optimizations, including once the second half of a list has been generated (below the ----), check every item on the list for matches, and then destroy the list to save space, and then continue generating combinations. Another option would be to generate a single combination, and then check it for a match, and somehow index the combinations so you know which one to generate next.

How to optimize what I am doing for a set of ~million items. I also have not yet come up with a non-recursive or efficient way to handle that each match generates additional combinations to check.

View Replies View Related

How To Generate Alternate Color Of Balls Combination For 3 Boxes

Feb 24, 2014

I am working on a project in which I have three box (as of now) and each box will have some color of balls. So I am storing them in a Map of String and List of String as mention below.

Map<String, List<String>> boxBallMap = new LinkedHashMap<String, List<String>>();

Data in the above map is like this -

Java Code:

{box1=[blue, red, orange]}
{box2=[blue, red]}
{box3=[blue, red, orange]} mh_sh_highlight_all('java'); ProblemStatement:-

Basis on the above input, I need to return a mapping which will be List<Map<String, String>>, let's say for above input, below mapping would be return as an output -

Java Code:

[{box1=blue, box2=red, box3=orange},
{box1=red, box3=blue},
{box1=orange, box2=blue, box3=red}] mh_sh_highlight_all('java');

Here if you see, each row has alternate color of balls for each box - meaning blue for box1, red for box2, orange for box3 in first row. I cannot have same color of balls in each row. So this combination is not possible as it has same color of balls for two boxes in one row.

Java Code: {box1=blue, box2=blue, box3=orange} mh_sh_highlight_all('java');

And also, in the second row, I won't use those balls which have been used in the first row for that box. In second row, box1 has red why? bcoz blue was already used in the first row for box1 and box3 has blue and no box2 in second row.

The output combination is getting generated basis on the input being passed as shown above.

I started with the below code -

Java Code:

List<String> balls1 = Arrays.asList("red", "blue", "orange");
List<String> balls2 = Arrays.asList("red", "blue");
List<String> balls3 = Arrays.asList("red", "blue", "orange");
Map<String, List<String>> maps = new LinkedHashMap<String, List<String>>();

[Code] ....

Below is my method in which the crux of logic should be there

Java Code:

private static List<Map<String, String>> generateMappings(Map<String, List<String>> map) {
return null;
} mh_sh_highlight_all('java');

Below algorithm might work but still not sure how should I fit this in the code -

- sort the boxes by the number of balls they have in it (ascending, from the smallest to the largest box).
- while there are colors left
- loop over the sorted list of boxes
- in each iteration pick a color from the box (if there is one left), that is not already picked in the current iteration (of the while loop)

View Replies View Related

Validate String Whether It Is Combination Of Lowercase And Uppercase And Has Character

Jun 22, 2014

I have to validate a string whether it is a combination lowercase and uppercase and has the character '_'.

I m having trouble in framing the expression for these conditions in the matches function.

How it can be done..?? How to frame a the correct expression.

View Replies View Related

Telephone Number - Write To A File Every Possible Seven-letter Word Combination

Nov 23, 2014

I am having some trouble with this program. The assignment is to write a program, given a seven-digit phone number, uses a PrintStream object to write to a file every possible seven-letter word combination that corresponds to that number. I have to avoid using 0 or 1. Here is my code.

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Scanner;
public class TelephoneGenerator
{
String phoneNumber;
char numberLetters[][] = {

[Code] ....

I am getting an error dealing with the main class.

View Replies View Related

Create N Number Of Flows With Any Combination Of Values - Search Match

Apr 12, 2015

I have a requirement like to attach most suitable flow  to a request
  
Flows should be like below (eg:Flow1) .We can create n number of flows with any combination of values.

When I tried to create a request that have all the  features in the flow. And I have to attach the most suited flow to that request.

Suppose my request have the feature  Place = Place1 and company =Comp1 and Job=Job1 .here most suitable flow is Flow1.

So my question is how can I implement the logic in java for getting the most suitable match.

View Replies View Related

Retrieving Result By User Input Different Combination Using String Tokenizer (MYSQL)

Mar 30, 2014

I am creating a simple Symptom Checker application. The problem I have is that I'm trying to retrieve user input (JTextField) by comma's using StringTokenizer which contacts the database for a result which matches the user's input (SELECT * FROM DIAGNOSIS WHERE ?, ?, ?) . It successfully finds the correct result however only in a particular format. Not different combinations....

for example, if I enter say within the JTextField: "tearful, nausea, lack of motivation" it will find the result successfully (as that is how it is formatted within the particular column (in the database table) i wish to display a result from) however, if i enter a different combination of these symptoms: "nausea, lack of motivation, tearful" - it will not find any result. I'm very unsure how to make it work regardless of what is inputted first, second or last.

Here is the code:

public void actionPerformed(ActionEvent e) {
try {
String abc = fieldsymp1.getText();
StringTokenizer str = new StringTokenizer(abc);
while (str.hasMoreTokens()) {
str.nextToken((", ")).trim();
 
[Code] ....

View Replies View Related

Vending Machine - Tell User Combination Of Coins That Equals To Amount Of Change

Jan 25, 2012

I have a simple java program to write which tells the user combination of coins that equals to the amount of change i.e:

user input 87

output:

3 quarters
1 dime
0 nickels
2 pennies

How the program remembers the remainder which is passed to the next column of let say dime

i.e

originalAmount = amount;
quarters = amount /25;
amount = amount % 25; <---- this is confusing for me?!?! how can the integer = integer % 25
dimes = amount / 10; <--- HOW THE PROGRAM remembers the "remainder" instead of the original user input as the code it self tells you dimes = amount where "amount" is what user input NOT remainder.

amount = amount % 10;
so on ....;

What I don't understand is HOW this algorithm works. I mean we have int amount where user inputs the number we get the first calculation amount/25 = how many quarters and then amount %25 WILL tell us about the reminder. By looking at this piece of code I would say that the system should start the calculation for the dimes again from the original number since the code says dimes = amount/10 AND amount = amount%10. My understanding is that the calculation should be done from the original user input.

Book or code it self is not clear for me how the reminder is "REMEMBERED" and then pass on to the next calculation>!?!?

UNLESS the code: amount=amount%25 gets the remainder so the next code under it is REQUIRED to read from the last prompt code.

View Replies View Related

How To Create New XML DOC With Properties From Existing One

Mar 13, 2014

I have an XML doc that looks like this:

Java Code:

<?xml version="1.0" encoding="UTF-8"?>
<model>
<id>_1</id>
<nodes>
<id>_2</id>
<stencil>TASK</stencil>
</nodes>
<nodes>
<id>_3</id>
<stencil>TASK</stencil>
</nodes>
</model> mh_sh_highlight_all('java');

I have to create another xml doc with the properties of nodes from the first doc. For the new doc I have to create a parent node called "definitions". Instead of the "model" node in the first doc I have to create a "process" node in the new doc that has an attribute "id" which value is the same as the content of the "id" child node of model. For each "nodes" node in the first doc if their "stencil" child node content equals "TASK" I create a "task" node in the new xml doc.

Java Code: <?xml version="1.0" encoding="UTF-8"?>
<definitions>
<process id="_1">
<task id="_2">
</task>
<task id="_3">
</task>
</process>
</definitions> mh_sh_highlight_all('java');

[code]....

I just wanted to know if this is the correct way to define the respective classes.any way to create and fill the nodes for the new doc using this classes? I am used with DOM parser and I know how to create nodes and fill attribute values, but I have always done this job in a single class, not using different classes for the elements.

View Replies View Related

Can A Null Value Be Concatenated With Existing String

Jan 16, 2014

static public String populateVehicleDetails(Vehicle vehicle){
String returnString = new String()
String existingString = "Chevy Uplander "
String nl = "
"
returnString.concat(existingString+nl).
concat("Color: "+ vehicle.color + nl)
  return returnString
}

In the case that vehicle.color is null what will happens? A null pointer error?

null will be concatenated to the string in vehicle.color place? or will not concatenate anything in the place of vehicle.color I'm asking that because I do not know if I have to check for null in each property of vehicle that I must concatenate (there are a lot of properties in the Vehicle object and some may not been set (they will return null).

View Replies View Related

Adding Logo Into Existing Program

Mar 15, 2014

So I am trying to add a logo to my existing program. However nothing shows up when I run it. I am getting no errors and everything else seems to be fine. This is just the logo part if you need the whole code it will be separate (just trying to make things easier.

class Logo extends JPanel {
public Logo() {
super();
setPreferredSize(new Dimension(200,200));
}
public void paint(Graphics g) {
g.setColor(Color.red);
g.fillRoundRect(60,60,110,90,5,5);
g.setColor(Color.black);
g.drawString("DEAD BUG", 70, 105);

[code]....

View Replies View Related

EJB / EE :: Generating Client Artifacts For Existing Project

Jul 23, 2014

I have an EJB project which is deployed in Webaphere 7 and i do not have source code for that project.I know the EJB session bean class name, can i generate the client for this class/project to invoke the session bean?

View Replies View Related

Incremental Change To Existing Java Program

Aug 8, 2014

I would like to make an incremental change to an existing Java program. And the program has been installed on the user's machine. Now I only want to do an incremental download (to minimize the download time) to update the program.

View Replies View Related

Adding User-defined Int To Existing Array?

Apr 7, 2015

how to add an a user defined int into my existing array. Ive heard of using ArrayList but not sure how to implement it.

View Replies View Related

I/O / Streams :: Appending To Existing File Instead Of Overwriting It

Jul 24, 2014

I do most of my file I/O with {Scanner} for input and {PrintWriter} for output. I've got lots of places in my code that looks like:

Scanner source = new Scanner( new File( sourceName));
PrintWriter dstntn = new PrintWriter( new BufferedWriter( new FileWriter( dstntnName)));

But when I call the constructor for {PrintWriter} up above, it overwrites whatever the original contents of the file designated by {dstntnName} were, doesn't it? Is there a way to call the constructor so that any future writes to it simply append to the original contents, instead of overwriting them?

View Replies View Related

Swing/AWT/SWT :: Creating New Window Or Call Existing One

Oct 13, 2014

Will the code below just create a new blank window rather than call the one I have? I want to call the one I have from my main method ideally.

JMenuItem menuDelete = new JMenuItem("Delete");
menuDelete.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DeleteEnvironmentWindow deleteEnv = new DeleteEnvironmentWindow();
deleteEnv.setVisible(true);
}

View Replies View Related

EJB / EE :: Mavenize Existing Enterprise Application Containing Web Project

Apr 14, 2014

I am trying to mavenize an existing enterprise application and this application has EJB, MDB and MQs. As far as the folder structure is concerned, it has a project that creates an ear file, and has one for project for web and another project for EJBs. there is one more project that holds some property file.

I am trying to mavenize this this application, so that I am able to create an ear of application containing the war of web project, jars of property project and ejb project and I am badly stuck.

View Replies View Related

Adding Elements To Existing JList Under Java 7

Mar 14, 2014

I know there was a change in the later versions of Java where the C++ equivalent of a <template type> was added. Unfortunately the change has 'broken' my older code. If I have a JList and I want to add elements to it then now I should specify the type e.g., the list will store Strings. When I do this and then add data to the list (or actually the list model) the code is ''fixed". However if after adding those new elements to the list I later need to add more elements, which isn't unreasonable for a list...to have elements added dynamically at run time then I again get the same compiler error message that I haven't correctly specified the type:
 
// Error message during compilation
Note: Driver.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
 
// My code
 
// Problem here: I try to add new elements to the list. It's the very last line of the method that results in the error. I tried various things such as:

// model.addElement(<String> s);
// but   so far nothing has worked. How do I add new elements to the list (model)?   
public static void m2(JList <String> list)
    {
    String s;
    int i;
    String [] array = new String[10];

[Code] ....
 
// Code is OK: Create the array of strings to add to constructor of the JList

public static String[]  m1(){    String s;
    int i;
    String [] array = new String[10];
    for (i = 0; i < 5; i++)
    array[i] = i + "*";    return(array);

[Code] ....

// The change I had to make when compiling under the newer version of Java to indicate that the list would store strings
 
   // Things are okay here now but then when I try to add new elements to the model via method 'm2' that's where I get the compiler error

View Replies View Related

Allow Users To Create JButtons To Existing Frame

Jun 2, 2013

I am trying to create a code which allows the users to create JButtons to a an existing frame.So what I want is that users can create buttons wihch opens a URL. The user need to be able to click on an Existing JButton called "Add Favorite", insert the name of the favorite and URL and the button is added with the functionality to open the URL in Internet Explorer.

I already have a beginning but have no clue how to add that functionaly to create JButton by pressing on button "Add Favorites" with the needed functionality The functionality needes to be added to Button4 ("add Favorite" ). As you can see, Button4 ("add Favorite") opens two inputShowDialog which allows the users to insert the name of the favorite and URL.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JButton.*;
import java.awt.Dimension.*;
import java.lang.RuntimeException.*;
import javax.swing.JOptionPane;
public class Favorites extends JFrame implements ActionListener{
//private JPanel panel1 = new Jpanel ("Add Favorite");

[Code]...

View Replies View Related

Closing Old Pop Up Frame With Existing Action Button

May 27, 2015

I am modifying existing code to display graph after pressing calculate button. The graph pop ups in new controller/window.  The pop up disappears after closing the application entirely.  However I have trouble figuring out if it is possible to close that old/previous pop up and new pop up appears when calculate button is pressed again.  Or at least reuse the pop up to display a new graph. 

public class AdamCalculationApp extends AbstractCalculation {
  /**
   * Does a calculation.
   */
  public void calculate() { // Does a calculation   
control.println("Adam Calculation button pressed.");
double k = control.getDouble("k value"); // String must match argument of setValue
control.println("k*k = "+(k*k));
control.println("random = "+Math.random());  

[Code]...

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved