• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

This topic is now archived and is closed to further replies.

Smoo

[java] 2 questions

11 posts in this topic

Greets, I''ve got a couple of questions that I hope you folks''ll be able to help me out with. First question: Is it possible to have a case statement use strings or chars? (i.e non numerics)? I know the docs say it needs a numeric value but is there a way to bypass this? Second question (for 10 points): Is it possible to have create docking frames with just plain ol java (i.e not swing or any other extra package)? If so, are there any tutorials, docs, samples, demos, anything that covers this and where can I find them? Thanks for playing who wants to be a... 10 point winner(?) *blink* *blink*... anyways if you have answers I would appreciate em. Thanks, Smoo
0

Share this post


Link to post
Share on other sites
First Q:
It is possible, but not really a case statement...
The easiest way I can think to do this is
I. Create an abstract class or interface for the function you want to call in the body of case
II. Put instances of the class into a Hashtable then get them out according to input

Second Q:
It is possible, but not easily accomplished from stuff that I have done. Ya can do it, but you would likely end up rolling your own implementation of it.
0

Share this post


Link to post
Share on other sites
Okay, thanks anon. For the first answer, well.. I have no clue how to make hashtables et. al. so I think I''ll just pass for now and use plain old if statements until I actually look at docs for hashtables. I didn''t even know where to start but that''s a place where I''ll look.

As for the second answer I believe I will take your advice and leave that one alone for now too. It''s not critical that I have a docking windows and an incredibly fancy GUI, this is but a lowly map editor that I''ve been working on for myself (and others when it''s done).

I have a third question that comes up now that I have found very little helpful documentation for. Basically I have:
File file1 = new File("Maps/");
String stArray[] = file1.list();
but I want to have a filter for *.txt files. How could I accomplish this? I have looked into a lot of crap which resulted in.. well crap. As I said, the docs were useless. Just a small little code snipet would have been great but that''s one thing that''s lacking unfortunately.

So if anyone could explain, show a small code sample on how to create a filter for something such as *.txt, I would appreciate it alot.

Thanks,
Smoo
0

Share this post


Link to post
Share on other sites
you could use integer constants. Something like this:

public static final int NORTH = 1;
public static final int SOUTH = 2;
public static final int WEST = 3;
public static final int EAST = 4;

ok so say these variables are declared somewhere in class h. h could be the class related to the thing or just a class simply to define these things for all your classes.

so you do your case statement but instead of putting say 3, you''d put for case h.WEST, which happens to be 3. So say this is a umm wind simulation. Instead of setting the wind to south using a string you''d just set it to h.SOUTH, then next time your case thing reads it everything works out. You don''t even need to remember which word equals which number.
0

Share this post


Link to post
Share on other sites
You can use char''s in a case statement(I could swear) just if you
are writing the charachter put it in with the char markers around it case ''a'':
If you do want to know how to use Hashtables I could post how.

A easy way to filter files is to use the JFileChooser to find the file. It''s a open file GUI dialog box. Say something like

JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new File("."));

chooser.setFileFilter(new javax.swing.filechooser.FileFilter()
{ public boolean accept(File f)
{ String name = f.getName().toLowerCase();
return name.endsWith(".txt")
// f.isDirectory();
}
public String getDescription()
{ return "Text files";
}
});

int r = chooser.showOpenDialog(this);
if(r == JFileChooser.APPROVE_OPTION)
{
String name = chooser.getSelectedFile().getAbsolutePath();
//name is the name of the file you selected
}



Also what do you mean by docking windows. Do you mean when there''s other window inside the frame like in Photoshop when you
have multible images open?
0

Share this post


Link to post
Share on other sites
quote:
Original post by Icculus
A easy way to filter files is to use the JFileChooser to find


He said he doesn''t want to use Swing. If he was OK with Swing, the whole docking window thingie would be *much* easier.

Hashtables are simple mappings from key objects to value objects. I put in a key object and a value object, I then use the key object to lookup the value object. Keys must be unique, so you can''t put in duplicate keys. If you need to place multiple items in under one key, you can use another collection type that supports duplicate keys, or you can use an array object or collection as the value object, so your key lookup gives you an array of objects.


java.util.HashTable ht = new java.util.HashTable();
ht.put(new Integer(10),"Yo");
ht.put(new Double(10.10),"Qiero");
ht.put("Cool","Tacobell");
System.out.println(ht.get(new Integer(10));
System.out.println(ht.get(new Double(10.10));
System.out.println(ht.get("Cool"));


Well, you get the idea.

In context, AP is probably suggesting you create the hashtable, placing Integer objects with your Strings as keys. You would use the String to look up the Integer, get the int value of the Integer, then switch on that. Integer constants would be simpler, but less flexible. You might try using polymorphism or evaluation classes to accomplish the same thing.


Choices[] desc = new Choices[10];
//stuff array here
boolean foundOne = false;
int i=0;
for (;((i foundOne=desc.evaluate(inputString);
}
//if foundOne is true, i = number of choice picked
//another option is to subclass the choices and override
//some execute method then call it if evaluate is true.


ManaSink
0

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster

[quote] Original post by Icculus
A easy way to filter files is to use the JFileChooser to find


He said he doesn''t want to use Swing. If he was OK with Swing, the whole docking window thingie would be *much* easier.

Hashtables are simple mappings from key objects to value objects. I put in a key object and a value object, I then use the key object to lookup the value object. Keys must be unique, so you can''t put in duplicate keys. If you need to place multiple items in under one key, you can use another collection type that supports duplicate keys, or you can use an array object or collection as the value object, so your key lookup gives you an array of objects.


java.util.HashTable ht = new java.util.HashTable();
ht.put(new Integer(10),"Yo");
ht.put(new Double(10.10),"Qiero");
ht.put("Cool","Tacobell");
System.out.println(ht.get(new Integer(10));
System.out.println(ht.get(new Double(10.10));
System.out.println(ht.get("Cool"));


Well, you get the idea.

In context, AP is probably suggesting you create the hashtable, placing Integer objects with your Strings as keys. You would use the String to look up the Integer, get the int value of the Integer, then switch on that. Integer constants would be simpler, but less flexible. You might try using polymorphism or evaluation classes to accomplish the same thing.


Choices[] desc = new Choices[10];
//stuff array here
boolean foundOne = false;
int i=0;
for (;((i<desc.length)&&(!foundOne));i++){
foundOne=desc.evaluate(inputString);
}
//if foundOne is true, i = number of choice picked
//another option is to subclass the choices and override
//some execute method then call it if evaluate is true.


ManaSink

0

Share this post


Link to post
Share on other sites
Well, you guys have alot of input here and I''m happy about that. It looks like docking will just have to wait for another time. I will also look into hashtables later, right now I have my faithful if statements.

Getting back to the file filters though, Icculus, as ManaSink mentioned I am not using swing but I am also not looking to use filters for a dialog box. It will be something that I want to apply to this:
FilenameFilter filter = new FilenameFilter()
File file1 = new File("Maps/");
String stArray[] = file1.list(filter);

I want *.txt to go in the filter. If someone knows how to do that, I would appreciate it greatly.

I apparently cannot do
FilenameFilter filter = new FilenameFilter();
It gives errors claiming the FilenameFilter is an interface.

If I just have
FilenameFilter filter;
filter.accept(stuff);
it says filter hasn''t been initialized yet.

Well, if anyone can demystify this stuff for me, I would very much appreciate it.

Thanks,
Smoo
0

Share this post


Link to post
Share on other sites
Smoo,

I posted to your last question about filename filters. Maybe you didn''t see it because i was the last one to post to it.
http://www.gamedev.net/community/forums/topic.asp?topic_id=15611&forum_id=24&Topic_Title=List+dirs&forum_title=Java+Development&M=False&S=True
That''s it. Basically what you have to do is have your class implement the interface FilenameFilter, then you need to override one method
boolean accept(File f)
just return true if it ends in .txt or false otherwise.

for the question about docking frames, is that where if the frame or window is within a certain distance from another it will ''stick'' to it? Because AWT uses native components, you will probably not be able to detect the dragging of an outermost container. But you can mess around with java.awt.event.MouseMotionListener.

If you don''t want to use many if statements, is it possible to invoke methods based on the string or char input? for example, you have a string of value "Employee" and a method "processEmployee", you can do the following

java.lang.reflect.Method m = getMethod("process"+ string,this);
m.invoke(this,null);

or something.
0

Share this post


Link to post
Share on other sites
I haven't worked with tyhe file system but, It seems to me that:

File file1 = new File("Maps/");
String stArray[] = file1.list();


stArray[] contains a text array of file names...
couldn't you just make a loop that does something like this...

File file1 = new File("Maps/");
String stArray[] = file1.list();
int counter = stArray.length;
int counter2 = 0;
String stArray2[] = new String[counter];
for(int x = 0; x < counter; x++){
if(stArray[x].endsWith(".txt")){
stArray2[counter2] = stArray[x];
counter2++;
}
}


This should fill a second array with only the files that end in .txt

War doesn't determine who is right, war determines who is left.

Edited by - Wrathnut on June 28, 2000 11:13:04 AM
0

Share this post


Link to post
Share on other sites
Sure you can pass chars to a switch. I just made a sameple project confirming this. Heres the code:

#include

void main()
{
char letter = NULL;

cout << "Enter a letter." << endl;
cin >> letter;

switch(letter)
{
case ''a'': cout << "Hello" << endl; break;
case ''b'': cout << "Bye Bye" << endl; break;

default: cout << "I dont understand" << endl; break;
}
}

I think you can also pass strings and in the case part you would do this case "string": but i dont remember if i have ever done that or not.

-Snyper



0

Share this post


Link to post
Share on other sites
Not too shabby Snyper, but he''s doing his proggie in java

War doesn't determine who is right, war determines who is left.
0

Share this post


Link to post
Share on other sites