• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Class Practice Help

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic