• 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
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Problem with tic tac toe game  RSS feed

 
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







 
Ranch Hand
Posts: 235
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
 
Bartender
Posts: 703
10
  • 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.
 
lowercase baba
Posts: 12745
51
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"
 
Sheriff
Posts: 67257
170
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!