File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Collecting Ores Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Collecting Ores" Watch "Collecting Ores" New topic

Collecting Ores

Steven Joost

Joined: Sep 29, 2012
Posts: 28
Hi, I'm writing a game, because I am bored^^ Now, I want that every ore is just ten times generated, and collectable. If I collect an ore now, it generates on another place on the map If this is real, this would make me rich, but it isnt , so how can I avoid this?

Darryl Burke

Joined: May 03, 2008
Posts: 5115

Steven Joost wrote:how can I avoid this?

Avoid what, exactly?

Some other notes:
Using generics for your ArrayLists would remove the need for casting and make your code typesafe.
Use of Random#nextint(...) would give shorter and cleaner code when compared to your present code using Math#random().
Consistent indenting and whitespace would make your code much more readable. See
All Swing constructors and methods should be invoked on the EDT. Not on the Main thread.

luck, db
There are no new questions, but there may be new answers.
Steven Joost

Joined: Sep 29, 2012
Posts: 28
Avoid, That the Ore is regerneratet If you collect it
Winston Gutkowski

Joined: Mar 17, 2011
Posts: 8946

Steven Joost wrote:Avoid, That the Ore is regerneratet If you collect it

Erm...change the code so that it doesn't do it?

If this is your own code, surely you know how to do that?

However, I have two general tips for you, which are not related to your specific question:
1. StopCoding (←click).
2. Get rid of all that Swing code - It's simply cluttering your mind, and distracting you from the real issue, which is your game.
Get the game logic working first, even if it means just using the console, and only add your Swing stuff back in when you KNOW it's working. And even then, keep the game logic separate from your display.



Bats fly at night, 'cause they aren't we. And if we tried, we'd hit a tree -- Ogden Nash (or should've been).
Articles by Winston can be found here
Steven Joost

Joined: Sep 29, 2012
Posts: 28
If I know, I wouldn't ask
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

Few people (if any) are going to slog through 200 lines of code trying to figure out an answer to a question that is, at best, vaguely hinted at.

When you post something here, you want to make it as EASY as possible for folks to help you.

I would suggest that, at minimum, you read our HowToAskQuestionsOnJavaRanch FAQ, follow all of Winston's advice, and add a new reply with your trimmed down code and a clear, concise question.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
I agree. Here's the link:
subject: Collecting Ores
It's not a secret anymore!