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.
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.
World domination requires a hollowed out volcano with good submarine access. Tiny ads are optional.
a bit of art, as a gift, that will fit in a stocking