• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

TicTacToe program

 
karina val
Greenhorn
Posts: 6
  • 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
Posts: 20980
31
Eclipse IDE Firefox Browser MySQL Database
  • 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
  • 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: 5590
55
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic