2D Game Development Using Java – Introduction

Introduction


Battle Tank was developed as a small 2D game which is controlled by an  AI (Artificial Intelligent) at client side and this game is a multiplayer game which allows to connect five maximum player and communication is handled by a central server which is developed in C# language.

Game Server

 serAr
Server architecture
A timer gets initiated when the first player resister for a game server.Client has to send a request to the sever saying JOIN# in order to connect to the server. Then the server replies following replies.
  • S:P<num>: < player location  x>,< player location  y>:<Direction># -Join accept message where directions are 0-North, 1-East, 2-South, 3-West.
  • —PLAYERS_FULL# – The maximum number of players are already connected to the server.
  • ALREADY_ADDED# – The player is already connected to the game server.
  • GAME_ALREADY_STARTED# – The player tries to join an already started game 
At the game initiation all other map details are sent in the following format.
  • I:P1; < player location  x>,< player location  y>;: …: P5< player location  x>,< player location  y>;: < x>,;< x>,;< x>,…..   < x>,: < x>,;< x>,;< x>,…..< x>,: < x>,;< x>,;< x>, …..< x>,# where players details:Brick details:Stone coordinates:Water coordinates.
When the client want to move or rotate its tank or shoot, client must issue the relevant command from —UP#, DOWN#, —RIGHT#, LEFT# or —SHOOT#. If the request of the client cannot be honoured server will be immediately communicated following messages.
  • —OBSTACLE# 
  • —CELL_OCCUPIED#
  • —DEAD#
  • —TOO_QUICK#
  • —INVALID_CELL#
  • —GAME_HAS_FINISHED#
  • —GAME_NOT_STARTED_YET#
  • —NOT_A_VALID_CONTESTANT#
Once per second the server broadcasts a global update to all the clients documenting its internal variables about the clients in following format.
  • G:P1;< player location  x>,< player location  y>;;< whether shot>;;< coins>;< points>: …. P5;< player location  x>,< player location  y>;;< whether shot>;;< coins>;< points>: < x>,,;< x>,,;< x>,,;< x>,,…..< x>,,#
The server sends C:<x>,<y>:<Life Time in milliseconds>:<Value># message to signal the appearing event of a pile of coins and sends L:<x>,<y>:<LT># message to signal the event of a life pack. —When the game ends, the player with most points will be declared the winner and the message GAME_FINISHED# broadcasts to all the clients.
Capture1
Capture
Download server here

No comments:

Post a Comment