wood burning stoves 2.0*
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
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
Bartender

Joined: Oct 14, 2005
Posts: 18563
    
    8

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: 3646
    
  16

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: TicTacToe program