• Post Reply Bookmark Topic Watch Topic
  • New Topic

Am I introducing turns correctly between the players?  RSS feed

 
Raed Tabani
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm building a pokemon fight simulator, which is a turn based game where the user's pokemon fights with the android's pokemon. now I'm quite aware that in the actual game turn is based on the "speed" attribute but in my game I want to introduce chance ie Head or Tails. if user guess correctly he gets to play first, else android plays first.
so far I've come up with this code, it's not really object oriented but I guess I just to get things working first. and while it seems to be working fine, I really want to know if it's a good or bad way to introduce turns
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You are right, I am afraid, it is not object‑oriented code. You have fighter classes, I see (called Monster), but you need a Fight class, with the keyword static deleted throughout.
There are lots of ways to take turns. What about putting your protagonists into an array and having a count of turns? You can also dispense with the nasty break statements.I shall let you work out how to implement the bothPlayersInRunning() method.
If you have exactly two fighters you can use bitwise and with 1 instead of %.
The % operator will cause you problems if you have an overflow in the turns variable, because you will then get negative remainders. Since you need 2147483648 turns before that happens, you might regard that as a minor problem which you can ignore
 
Raed Tabani
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, glad to have found this place

but you need a Fight class, with the keyword static deleted throughout.

I never looked at it this way...tbh its easier for me to see why Monster or Moves, for example, would be classes , but for fight() it makes more sense to be a class method? is the reason for this is to have a non static method accessible by main? so far the only reason I've been using the keyword static is to get sth inside of main, which I believe is not the right way to use static.
anyways, I did create a fight class where I put both my fight() and turnSelection()in

Game Class


Fight Class



as for the turn selection, I will get back to you as sson as I implement it
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raed Tabani wrote: . . . but for fight() it makes more sense to be a class method? is the reason for this is to have a non static method accessible by main? . . .
Never make something static because otherwise it won't compile. If you don't have a good reason for something being static, then it is a mistake to mark it static. You are right when you say that is not the right way to use static.

You may have a Fight between two Monsters which fight each other. In the first case Fight is a noun and it makes sense to have a class of that name. In the second case fight is a verb and it makes sense for the Monster class to have a method of that name. But one Monster fights another Monster, so that method should not be static.

Don't say “sth”, but say “something”, please.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!