Win a copy of High Performance Python for Data Analytics this week in the Python forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

For the holidays I decided to go through my already learned stuff

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi developers,

as for the holidays I decided to give myself a little break from gaining JAVA knowledge I decided to create a little program to strengthen my knowledge that I already have.
If you read the code below, do not think that I want to be a game designer of some sort, but from my point of view this was a very familiar topic to get my head around, so I decided to create a little "RPG fighting engine".



This one is by no means complete, but I am happy that it at least works somehow


Best regards,
Jens
 
Marshal
Posts: 71760
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry to appear negative, but I am afraid I can't see any object orientation in the design. Where are you creating a new Engine object (or Fighter object)? Why have you got so much code in the main() method?
Don't write println(...) repeatedly if you can combine several instructions into one printf(...) call. Remember you can replace println() with no argments by System.out.printf("...%n...").
Why are you using so many continues and breaks?
 
Jens Jensen
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Ritchie,

Only criticism makes us better. So thanks for sharing it.
For the object orientation I can say that I was simply sloppy. For the other parts I just do not know better. I have been working on java for the past 3 weeks only next to my job. So you can say that I am a bloody noob with no hands on experience. But I will improve the code. Thanks again for sharing

Best regards,
Jens
 
Saloon Keeper
Posts: 12628
273
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
  • Split up your code in classes that are responsible for one thing and one thing only.
  • Don't mix logic and presentation. Console inout/output should be performed by a dedicated class that responds to events from your game engine.
  • Make your classes final. Designing your classes so they can be properly extended is REALLY difficult, so just make them final instead.
  • NEVER use static fields for anything other than holding constant values. The hp and shield fields should be instance fields encapsulated by a Player/Combatant/Creature class.
  • Make your fields private.
  • Don't use long if-else ladders. Either use a switch statement or use polymorphism.
  • Don't use break or continue statements redundantly.
  • Use proper variable names. A variable named 'sword' implies to me that it holds an instance of a Weapon class, not an integer. Name it 'damage' instead.
  • Use compound assignment operators.
  •  
    Saloon Keeper
    Posts: 7622
    68
    Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    My nit...
    should be
     
    Ranch Foreman
    Posts: 2348
    12
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Instead of having this big class, I think one can move all the static methods barring the main method to a Helper class and call them from the class.
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 12628
    273
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Monica Shiralkar wrote:I think one can move all the static methods barring the main method to a Helper class and call them from the class.


    Besides the main method, there shouldn't be any static methods at all!
     
    Campbell Ritchie
    Marshal
    Posts: 71760
    312
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Stephan van Hulst wrote:. . . Besides the main method, there shouldn't be any static methods at all!

    And I would put the main method in a class all of its own, called GameDemo or similar.
     
    Monica Shiralkar
    Ranch Foreman
    Posts: 2348
    12
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Campbell Ritchie wrote:And I would put the main method in a class all of its own, called GameDemo or similar.



    Means having a class GameDemo with main method and from the main method calling the static methods of this class?  If so, then it sounds similar to what I was thinking of when I talked about Helper Class.
     
    Campbell Ritchie
    Marshal
    Posts: 71760
    312
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Monica Shiralkar wrote:. . . a class GameDemo with main method and from the main method calling the static methods of this class?  . . .

    No. See our FAQ/article.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic