• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with tic tac toe game  RSS feed

 
D Chandler
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All,

I am a newbie. I have enclosed some code I am working on. It is the beginning of a tic tac toe game. When I enter two different names, the program only reports the second entered name as both players. What in the frig am I missing?? Thanks for any insight.

David C







 
Robert D. Smith
Ranch Hand
Posts: 221
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at lines 5 and 22 in the Player class.You have two players but only one place to store the name.

I'd probably go about things a little differently, but it runs and you don't fix what a'int broke.

Regards,
Robert
 
D Chandler
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Robert,

Thanks for the reply. I would be curious to see your "I'd probably go about things differently." As a newbie, I am always curious to see ways that may be more common, efficient, more generally accepted, and etc. If it is not too much trouble, would you mind offering your suggestion?

Thanks,

David C
 
Fred Kleinschmidt
Bartender
Posts: 560
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The playerNum and name fields of class Player should be instance variables, not static (class) variables.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Robert D. Smith wrote:, but it runs and you don't fix what a'int broke.

Today's XKCD has a great quote about "well, it runs fine for now":

"So does a burning bus"
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fred Kleinschmidt wrote:The playerNum and name fields of class Player should be instance variables, not static (class) variables.


As should the methods.

And I would argue that this is very much broke. "Running" is not the same a "not broken".

My rule for novices using "static" is "don't"*


* Except for main, of course
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!