Battle Game Server for CIS 219 Mobile III In-class lecture. Has an API for use by other clients, especially Android clients, that will allow players to connect and play each other or alternatively play against the "computer" which will be the server.
Will eventually be a "Battle" server for any type of turn based fighting game
http://www.hasbro.com/commoninstruct/battleship.pdf
All API calls must be prefixed with /api/v1/XXX
API Actions and Return Results
GET /api/v1/login.json
Uses basic authentication to login to the server.
Returns your user profile as a JSON object:
{
"id": 1,
"first_name": "Dave",
"last_name": "Jones",
"avatar_name": "Dr.Dave",
"level": 1,
"coins": 0,
"battles_won": 0,
"battles_lost": 0,
"battles_tied": 0,
"experience_points": 0,
"available": false,
"online": false,
"gaming": false,
"email": "dave@lockersoft.com",
"avatar_image": "avatars/davejones.jpg"
}
GET /api/v1/logout.json
Logs the user out from the server.
GET /api/v1/available_users.json
Returns list of available players.
GET /api/v1/all_users.json
Returns list of ALL players whether they are available or not.
GET /api/v1/available_ships.json
Returns a list of all of the available ships names and their respective sizes.
{
"carrier": 5,
"battleship": 4,
"cruiser": 3,
"submarine": 3,
"destroyer": 2
}
GET /api/v1/available_directions.json
Returns a list of all of the available directions for placing ships.
{
"north": 0,
"east": 2,
"south": 4,
"west": 6
}
GET /api/v1/challenge_computer.json
Returns the game id which is used in future calls.
{
"game_id": 7
}
GET /api/v1/game/:id/add_ship/:ship/:row/:col/:direction.json
e.g. /api/v1/game/7/add_ship/carrier/b/8/0.json
{
"game_id": 7,
"status": "carrier ship added"
}
{
"error": "illegal ship placement"
}
GET /api/v1/game/:id/attack/:row/:col.json
e.g. GET api/v1/game/34/attack/h/3.json
Send one attack sequence.
Returns hit/miss in addition to the computer's turn
{
"game_id": 34,
"row": "h", // Your Attack Row/Col
"col": 3,
"hit": true, // Did your attack hit a ship?
"comp_row": "c", // Computers Attack Row/Col
"comp_col": 5,
"comp_hit": false, // Did the computer hit your ship?
"user_ship_sunk": "no",
"comp_ship_sunk": "cruiser",
"num_computer_ships_sunk": 3,
"num_your_ships_sunk": 2,
"winner": "" //"computer", "you"
}
GET /api/v1/game/:id/status/:type.json
e.g. GET api/v1/game/42/status/all.json
Get the status of the boards and turns.
all
=> return both boardsdefend
=> return defending boardattack
=> return attacking boardturn
=> NOT YET IMPLEMENTED
Returns a string representing the board status with S
for a ship, -
for a Miss, *
for a Hit.
{
"game_id":42,
"attack_board":
" \n \n \n \n \n \n \n \n \n \n",
"defend_board":
" S \n S \n S SS \n S SS \n S SS S \n S \n \n \n \n SSSS \n"
}
returns acceptance?
returns acceptance?
send initial board setup from client
first_name
last_name
avatar_name
avatar_image
level
coins
battles_won
battles_lost
battles_tied
experience_points
available
online
gaming
email
admin
All Other Devise Fields
name
size
start_row
start_col
end_row
end_col
image
belongs_to :board
carrier: 5,
battleship: 4,
cruiser: 3,
submarine: 3,
destroyer: 2
height
width
cells (double array)
has_many ships
has_ship?
hit?
miss?
belongs_to player1, :class_name => 'User', :foreign_key => 'player_id_1'
belongs_to player2, :class_name => 'User', :foreign_key => 'player_id_2'
:has_many turns
game_time
winner
awarded_coins
belongs_to user
belongs_to game
content
(Full description of damage inflicted/received, etc.)
belongs_to :user
belongs_to :game
row
col
hit
sunk
ship
User makes themselves available to play or challenges a player Other player accepts challenge or chooses an available player to challenge