GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes Class Practice Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Class Practice Help" Watch "Class Practice Help" New topic
Author

Class Practice Help

Bryce Heath
Greenhorn

Joined: Sep 16, 2011
Posts: 19
Hi guys
I'm working on making a very simple game to practice what I have learned so far programming. So far what I have done is made an enemy class, a hero class, a class I called gameplay that I figured would contain methods for fights ect, and the main. So I think my classes for hero/enemy are fine, and went on to make a very basic fight method using loops, and have relized in order to do this I beleive I will have to create the hero and the enemy object in this method (please correct me if im wrong) the problem with that is how can the main method access these objects? I dont think i want to create new ones in the main because they would not produce the right life ect from a battle that happened. Hope this made sense ill post some code be kind lol.

GamePlay class


Orc class



Hero class

Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  16

Hi Bryce. You have to think on a bit more of a conceptual level. Don't dig into the programming straight away. First write down on paper what you want everything to look like. Ask yourself questions.

There are orcs. There are heroes. Who knows about their whereabouts? Are there levels? Are there areas, such as caves or forests? Is it just one game in which we only care about one orc and one hero? How are orcs and heroes different?

Now, let's say that all that we want to do when we run the program, is perform one fight exactly, and print who wins. Now you know enough to have a good idea of what you want your application to look like:
You see? With the method declarations alone we already have a really good idea of how we want everything to work. We construct a new game using two fighters. A fighter has a name and some stats. The main method then simply looks like this:
The Game class knows enough about the two fighters to be able to determine the outcome of a random battle. All it needs are the methods provided by the Fighter class. If you want, you can also add methods setHealth()/setStrength() to the Fighter class to edit these properties after a battle is done.

I hope this answers some of your questions.
 
GeeCON Prague 2014
 
subject: Class Practice Help