Skip to content

Commit

Permalink
pull prints out of game
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Liddle committed Dec 28, 2011
1 parent 8a50f2f commit 61f19c0
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 20 deletions.
18 changes: 6 additions & 12 deletions lib/game.ik
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ use("lib/machine_player")

Game = Origin mimic

Game initialize = method(game_type,
Game initialize = method(game_type, illustrator,
self board = Board mimic(3)
self illustrator = illustrator
self player1 = nil
self player2 = nil
cond(
Expand Down Expand Up @@ -37,13 +38,13 @@ Game play = method(
until(Rules game_over?(board),
take_turn
)
display_board
print_game_over_message
self illustrator display_board(self board)
self illustrator game_over_message(self board)
)

Game take_turn = method(
display_board
move = player_by_turn get_move(board)
self illustrator display_board(self board)
move = player_by_turn get_move(self board)
make_move(move[0], move[1])
)

Expand All @@ -57,10 +58,3 @@ Game player_by_turn = method(
Game make_move = method(row, column,
if(self board get_space(row, column) == 0,
self board set_space(row, column, player_by_turn marker_value)))

Game display_board = method(
Illustrator draw(self board) print)

Game print_game_over_message = method(
Illustrator game_over_message(self board) println
)
3 changes: 2 additions & 1 deletion lib/game_runner.ik
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use("lib/game")
use("lib/illustrator")

GameRunner = Origin mimic

Expand All @@ -7,7 +8,7 @@ GameRunner get_game_type = method(
game_type = System in read asText
if(game_type == "0",
System exit,
Game mimic(game_type)
Game mimic(game_type, Illustrator mimic)
)
)

Expand Down
9 changes: 8 additions & 1 deletion lib/illustrator.ik
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use("lib/rules")

Illustrator = Origin mimic

Illustrator draw = method(board,
Expand All @@ -6,7 +8,8 @@ Illustrator draw = method(board,
row each(space,
illustration += "[" + space_marker(space) + "]")
illustration += "\n")
illustration += "\n")
illustration += "\n"
)

Illustrator space_marker = method(space_value,
cond(
Expand All @@ -22,3 +25,7 @@ Illustrator game_over_message = method(board,
Rules winner(board) == 0, "Cat's Game...\n"
)
)

Illustrator display_board = method(board,
draw(board) print
)
1 change: 1 addition & 0 deletions lib/machine_player.ik
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use("lib/board")
use("lib/rules")

MachinePlayer = Origin mimic

Expand Down
12 changes: 6 additions & 6 deletions spec/game_spec.ik
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use("lib/game")

describe("Game",

before(game = Game mimic("1"))
before(game = Game mimic("1", Illustrator mimic))

it("initializes a game with a board",
game board should not be nil
Expand All @@ -14,7 +14,7 @@ describe("Game",
)

it("draws the board when game is started",
Game should receive display_board
game illustrator should receive display_board(game board)
game player1 should receive get_move(game board) andReturn([2,1])
game take_turn
)
Expand All @@ -36,13 +36,13 @@ describe("Game",
)

it("creates 1 machine player and 1 human player for game type 2",
game1 = Game mimic("2")
game1 = Game mimic("2", Illustrator mimic)
game1 player1 kind should == "MachinePlayer"
game1 player2 kind should == "HumanPlayer"
)

it("creates 1 human player and 1 machine player for game type 3",
game2 = Game mimic("3")
game2 = Game mimic("3", Illustrator mimic)
game2 player1 kind should == "HumanPlayer"
game2 player2 kind should == "MachinePlayer"
)
Expand All @@ -54,8 +54,8 @@ describe("Game",
game board set_space(1,0,-1)
game board set_space(2,0,-1)

game should receive(display_board)
game should receive(print_game_over_message)
game illustrator should receive display_board(game board)
game illustrator should receive game_over_message(game board)

game play
)
Expand Down
1 change: 1 addition & 0 deletions spec/human_player_spec.ik
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use("ispec")
use("lib/human_player")
use("lib/board")

describe("HumanPlayer",

Expand Down
1 change: 1 addition & 0 deletions spec/illustrator_spec.ik
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use("ispec")
use("lib/illustrator")
use("lib/board")

describe("Illustrator",

Expand Down

0 comments on commit 61f19c0

Please sign in to comment.