A small 'battle' web application game.
A project to test the ability to pair program, TDD, OOD, in the web environment. Building an understanding of http request-response cycles, and MVC.
Ruby, Sinatra web framework. With Rpsec unit testing and Capybara feature tests.
As two Players,
So we can play a personalised game of Battle,
We want to Start a fight by entering our Names and seeing them
Objects | Messages |
---|---|
Player | name |
As Player 1,
So I can see how close I am to winning
I want to see Player 2's Hit Points
Objects | Messages |
---|---|
player_2 | hp |
As Player 1,
So I can win a game of Battle,
I want to attack Player 2, and I want to get a confirmation
Objects | Messages |
---|---|
Game | attack(player_2) |
As Player 1,
So I can start to win a game of Battle,
I want my attack to reduce Player 2's HP by 10
Objects | Messages |
---|---|
player_2 | receive_damage |
As two Players,
So we can continue our game of Battle,
We want to switch turns
Objects | Messages |
---|---|
Game | switch_turns |
As Player 1,
So I can see how close I am to losing,
I want to see my own hit points
Objects | Messages |
---|---|
player_1 | hp |
As Player 1,
So I can lose a game of Battle,
I want Player 2 to attack me, and I want to get a confirmation
Objects | Messages |
---|---|
Game | attack(player_1) |
As Player 1,
So I can start to lose a game of Battle,
I want Player 2's attack to reduce my HP by 10
Objects | Messages |
---|---|
player_1 | receive_damage |
As a Player,
So I can Lose a game of Battle,
I want to see a 'Lose' message if I reach 0HP first
Objects | Messages |
---|---|
Game | lose |
Controller:
require "sinatra/base"
require "./lib/player"
require "./lib/game"
require "./lib/attack"
class Battle < Sinatra::Base
enable :sessions
before do
@game = Game.instance
end
get "/" do
erb :index
end
post "/names" do
player_1 = Player.new(params[:player_1_name])
player_2 = Player.new(params[:player_2_name])
@game = Game.play(player_1, player_2)
redirect "/play"
end
get "/play" do
erb :play
end
post "/attack" do
Attack.run(@game.opponent)
if @game.game_over?
redirect "/game-over"
else
redirect "/attack"
end
end
get "/attack" do
erb :attack
end
post "/switch-turns" do
@game.switch_turns
redirect("/play")
end
get "/game-over" do
erb :game_over
end
# start the server if ruby file executed directly
run! if app_file == $PROGRAM_NAME
end
Fork and clone repository.
Run bundle
in the terminal to install necessary gems from the Gemfile.
- So we can play a personalised game of Battle, We want to Start a fight by entering our Names and seeing them :white_check_mark
- So I can see how close I am to winning, I want to see Player 2's Hit Points :white_check_mark
- So I can win a game of Battle, I want to attack Player 2, and I want to get a confirmation :white_check_mark
- So I can start to win a game of Battle, I want my attack to reduce Player 2's HP by 10 :white_check_mark
- So we can continue our game of Battle, We want to switch turns at the start of the game :white_check_mark after player 1 attacks :white_check_mark
- So I can see how close I am to losing, I want to see my own hit points :white_check_mark
- So I can lose a game of Battle, I want Player 2 to attack me, and I want to get a confirmation :white_check_mark
- So I can start to lose a game of Battle, I want Player 2's attack to reduce my HP by 10 :white_check_mark
- So I can Lose a game of Battle, I want to see a 'Lose' message if I reach 0HP first :white_check_mark
-
Attack .run damages the player
-
Game .play should instantiate a Game object #player_1 returns the first player #player_2 returns the second player
#current_turn at the start of the game returns player 1 #switch_turns after player 1 attacks returns player 2 #opponent returns opponent of current_turn #game_over? returns false if no-one is at 0HP returns true if at least one player is at 0HP #loser returns a player on 0HP or lower
-
Player #name should return name #hp should return HP
Run rackup
from the command line. Enter player names. Take it in turns to attack until a player loses.