File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

TicTacToe program

 
karina val
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20177
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Stephan van Hulst
Bartender
Pie
Posts: 4826
34
Chrome Netbeans IDE Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic