Skip to content

Instantly share code, notes, and snippets.

@darekmydlarz
Last active October 20, 2017 07:37
Show Gist options
  • Save darekmydlarz/54769e5dd6d8261f9193bc337db1b914 to your computer and use it in GitHub Desktop.
Save darekmydlarz/54769e5dd6d8261f9193bc337db1b914 to your computer and use it in GitHub Desktop.
OOP Tic Tac Toe Draft - based on Elegant Objects by @yegor256
interface Board {
Board movement(Movement movement);
Player winner();
}
public static void main() {
Player black = new Player("Black");
Player white = new Player("White");
Board board = new Board(black, white);
Movement movement = new Movement(black, board).position();
while(!board.hasWinner()) {
board = board.movement(new Movement(black, board));
if(!board.hasWinner()) {
board = board.movement(new Movement(white, board));
}
}
System.out.println("Congratulations! The winner is: " + board.winner());
}
@darekmydlarz
Copy link
Author

darekmydlarz commented Oct 20, 2017

sounds like a good idea for a talk on OOP ;)
start with procedural for-loops approach and go towards this one
just live coding ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment