• Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple game template  RSS feed

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey! I'm trying to learn java again and doing some exercises, I am struggling with understanding this task:
Write a code that handles tic-tac-toe game on a square board. I have a template like this:



my code:

rules: method setBoardSize should be called 1st, before calling setBoardSize, setO and setX should be ignored, calling toString() should return null, hasEmpty return false.

method setO - should set circle on board
method setX - should set X on board
method hasEmpty - return true untill board is full
method toString should generate actual board state and output smth like this (after calling System.out.println(reference to Test4)):
+-+-+-+
|O |X| |
+-+-+-+
| |X| |
+-+-+-+
| |O| |
+-+-+-+

program should communicate and ignore about wrong moves:
- 2 and more same moves (eg. Twice X in row)
- placing X/O outside the board
- placing X/O on a spot already taken
Starting position is (0,0) - upper left corner on board.
I do not need main method.
Thanks in advance for any help !
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That looks like the sort of code you get when you have weighed in and written code without thinking what you want to do. Why should you have a setX method at all? You need to go back and write down how one plays noughts and crosses. Write it down, in simple words. When you have written that description, you will be able to produce code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!