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


ADVERTISEMENT

Repaint Won't Call PaintComponent

Oct 25, 2014

Java Code:

package com.cjburkey.games.war.g;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

[code]....

Why is paintComponent not being called by repaint();? Also, paintComponent is called twice when the program starts, that works, repaint is the thing that doesn't work.

View Replies View Related

Swing/AWT/SWT :: Call Repaint 200 Times In Loop And It Only Calls PaintComponent Once?

Dec 2, 2014

I have been baffled by the functioning of repaint() - and the SwingPaintDemo3 with the moving square seems mysterious - you call repaint(x,y,w,h) twice and the first time it clears the clip area and the 2nd time it paints the red box. The code in paintComponent tells it to paint the box both times, yet somehow it ignores the initial box and only paints the 2nd one.

I've been writing code to bounce some balls in a box to try and understand the behavior. I set up an array of ball objects, loop through them, move them adjusting for collisions with walls and each other, then repaint(). I call repaint x2 for each ball, just like in the example. In my paintComponenet code, if I try to just paint the current ball only one ball will move, even if I send a different ball object each time. The only way to get all the balls to show up is to put a loop in paintComponenet that goes through all 100 balls every time I call it. I was worried that to move 100 balls I was painting 100x100 times.

So I put some System.out.println commands in my ball move loop, inside my object ball draw commands, and inside the paint component.

private void calculateMoveBall(BoxBalls oneBall) {
System.out.printf("
Entering calculateMoveBall [%1$2d]
",

[Code].....

So even though I called repaint() 200 times (twice for each ball), repaint was actually only called once, drew all the balls at once, and then went back. And I just noticed it appears to have waited until I exited the calculateMoveBall loop to go into paintComponent! The spooky things is how does it know to do that? Does the Java machine 'see' that it is inside of a loop, and perhaps also sees the loop inside of paintComponent, and somehow correctly guesses that it doesn't have to do it 200 times, but can wait and do it once? If I attempt to do the same thing in code, take the loop out of paintComponent() and call repaint() with the current ball, expecting the machine to do exactly what I tell it, it refuses and does it's own thing, waiting to call paintComponent on the 100th ball, drawing only the last ball (so I guess the loop inside paintComponent is not in the logic).

So a call to repaint() is a request for a higher being to decide if it has the time or energy to repaint the clip. If not, it ignores the call, or stacks them up for later (maybe I should try a million and see if it has room for that!) - well so far up to 4000 it behaves the same. This is useful if you are happy with "this is how it works so use it that way". However I really don't like having some kind of hidden logic that I have to trust to work the right way. If I don't want it to wait until later I'm not sure what to do. And I don't trust the machine to do whatever whenever. How do you debug that???

Questions: Is there documentation to know what repaint() will do or how it decides when to call paintComponent? The Swing tutorial gives the example but not the why. "By now you know that the paintComponent method is where all of your painting code should be placed. It is true that this method will be invoked when it is time to paint" "An important point worth noting is that although we have invoked repaint twice in a row in the same event handler, Swing is smart enough to take that information and repaint those sections of the screen all in one single paint operation. In other words, Swing will not repaint the component twice in a row, even if that is what the code appears to be doing." (What the code appears to be doing - now we have to guess what it is doing)

Is there a way to force repaint() to call paintComponent on a clip rectangle (not just on the whole thing?) I would think invalidate() would force repainting of the whole componenet.

Perhaps this is when you draw to a bitmap in memory and paint the whole thing on the screen...

View Replies View Related

Swing/AWT/SWT :: How To Call PaintComponent In JPanel

Nov 7, 2014

How can I make a call to paintComponent within the JPanel-class, from another Class?

In class TestClass:

public class TestClass {
public TestClass() {
JFrame frame = new JFrame();
frame.setLayout(new BorderLayout());
frame.setSize(500,500);
initComponents();

[Code] .....

View Replies View Related

How To Tell Another Class To Repaint

Jan 24, 2014

It has to be from another class because the other class controls the fps timer, and I want it to repaint() the panel every tick. However, I cannot seem to find a way to do this because repaint() is not static, and therefor can not be called in any way from another class.

View Replies View Related

Repaint Window From Another Class?

Mar 31, 2014

I am trying to repaint a window from another class. the class Window handles an interface that displays pictures of movies. Via a JMenuBar you can add a new movie and its picture but in order for it to show in the Window i need to repaint certain aspects in the Window class GUI;

The window class constructor:

public Window() {
addComponents();
configurFrame();
addMenu();
}

The functions i want to repaint:

public void repaintWindow() {
this.getContentPane().validate();
this.getContentPane().repaint();
}

From my other class where i add a movie to an ArrayList i have made a "private Window myWindow;" there i call the function repaintWindow via mywindow.repaintWindow(); But this gives me an NullPointerException related to the repaintWindow function.

View Replies View Related

GUI - Swap Bar Arrays And Repaint

Nov 13, 2014

So as of right now, I'm trying to swap my bar arrays and repaint it. For now, I'm using the index 5 and swapping it with index 23. When I click the shuffle button, It swaps, but the highest bar still remains the same.

Here's my code.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class AssortedAssortmentsOfSorts extends JFrame

[Code] ......

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

Swing/AWT/SWT :: Trigger A Repaint From Another Method?

Mar 5, 2014

I have two classes. One constructs my a rectangle using Graphics2D (the class is called Rectangles). The second takes a user input for the triangle, which I am passing back to the first class. I am trying to trigger a repaint of class one from the action listener I have on a button in the second class. how to trigger this event?

View Replies View Related

Swing/AWT/SWT :: Repaint Causes Stack Over Flow

Feb 26, 2014

I have the following code where I call panel repaint method from the action listener of the calc button but it causes stack over flow but when I modify it to call paint component method and removing the super term, the program executes. here is the code

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Box;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.BoxLayout;

[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

Swing/AWT/SWT :: Drawing Various Shapes - Repaint Not Working

Jan 16, 2015

I'm trying to make a simple program that will feature some graphics. It will have a JCombobox that the user selects to draw various shapes. I can't get the repaint function to work however.

package selectingshapes;
import java.awt.Graphics;
import java.awt.Color;
import javax.swing.JPanel;
import java.awt.Graphics2D;

[Code] .....

View Replies View Related

Swing/AWT/SWT :: JTable - How To Repaint With Updated Data

Jun 5, 2014

Here's what I would like to happen:

Java/Swing dialog box appears on the user's screenIt allows the user to enter 2 values into labelled text fields (fname/sname)They select a "Click Me" push button which I hope will write the data into the table. But the table does not get refreshed.

If I minimise the dialog box and then open it again, the data still does not appear.

The code I originally built using eclipse/WindowBuilder. I've cut it back and tried to isolate the issue. But I still cannot figure it out.

I've added some diagnostic log messages to ensure that I am seeing the various events I think I need to see and have put code in the action callbacks etc.

import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.GridBagLayout;

[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

JavaFX 2.0 :: JFreeChart - When Zoom In Or Out Repaint Works Not Well

May 8, 2015

I have a problem using JFreeChart with JavaFX. I wrote a small program here . At first the graph likes this:

I use fullScreen function to display the JFreeChart Line Chart Demo 2. Here I use SwingNode, ChartPanel to embedded JFreeChart into JavaFX Panel.(Detail part will be included in code later)

Then I press ESC to exit fullScreen. Then it looks like this:

So far, it's as expected. Then I use mouse drag to enlarge the window. Here comes the problem, as the following picture.
 
Can you see that, seems like appear another graph. And I must click on the window, then everything will become good. I wish the graph shows well even when I drag the window to enlarge, is there something I missed? And here is my code:

package testxychart; 
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

[Code] ....

I think, when I use several graphs in one JavaFX Panel, this will becomes a big problem.

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

Swing/AWT/SWT :: Repaint Method Is Automatically Erasing Old Circle?

Feb 19, 2014

This code is shown to eliminate "smearing":

public void paintComponent (Graphics g) {
g.setColor(Color.white);
g.fillRect(0,0,this.getWidth(), this.getHeight());
g.setColor(Color.green);
g.fillOval(x, y, 40, 40);
}

I had done all the previous code (in my own style) and found that the background rectangle was either being redrawn on its own, or there was something else removing the old circles from the screen. I then typed in the code from the previous page exactly as it was, to see if I had some change in syntax that would cause this, and it did the same thing.

Here's my code:

import javax.swing.*;
import java.awt.*;
public class SimpleAnimation {
int x, y;
private static final int HEIGHT = 600;
private static final int WIDTH = 600;

[Code] .....

Is this because I'm using JRE7? I can't find any documentation that indicates the repaint() method has changed since Java 5.

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

Swing/AWT/SWT :: How To Update JPanel Rather Than Refresh It Every Time On Calling Repaint

Jan 4, 2015

I would like to be able to draw things onto the panel (via paintComponent), but I'd like it to draw 'on top' of what's already there. The default seems to be that it resets every time I call repaint.

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

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 View Related







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