This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Customer Requirements for Developers and have Marcho Behler on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes TicTacToe program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "TicTacToe program" Watch "TicTacToe program" New topic
Author

TicTacToe program

karina val
Greenhorn

Joined: Sep 02, 2011
Posts: 6
I have to make a program that allows two players to play tictactoe. The game board has to be done using ASCII, which I've already done. However, since it's not an array with indexes, how do I access each place on the board?..for example if the player wants to place an X on row 3, column 2...?
Paul Clapham
Sheriff

Joined: Oct 14, 2005
Posts: 19693
    
  10

If the board isn't an array with indexes, then what is it? There's no way for anybody to know how to access data from a "board" when all we know about it is its name.
Jon Avadis
Ranch Hand

Joined: Jul 20, 2011
Posts: 49

Its ASCII Paul

Which i guess could easily be represented by Strings, 1 String represents 1 Line of the board.



If its something like that, then your row is String1, String2 or String3, and your "column"
is Character of index '1', '3' or '5' in that string.

Im sure there are much more elegant and flexible ways, but if i'd have to do it quick&dirty,
i.e. for testing if the rest of the program works, i'd do it this way.


Knowledge Reigns Supreme
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3905
    
  18

It's much better to use an array of an enum type. Then you can very simply change the board, and if you need ASCII you can let the TicTacToe class convert the board to a String in its toString() method.


The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: TicTacToe program
 
It's not a secret anymore!