BombermanClient Module

Example

This show how the textual mode looks like during the game :
_images/exempletextual_client.png

How to ?

The program accept some command line options.

The simpliest way to use it is:
$ ./BombermanClient.py –server bomberman.crans.org –port 12885

This will launch the client on the server bomberman.crans.org (assuming that a server is already launched there), on the port 12885 (idem, it have to be the listening port of the server).

Customization of the player

You can also specify two parameters to your player :
  1. your pseudo : with the option –pseudo. A pseudo can be as long as you want (but it will be cut at 32 caracters), can contain UTF caracters, but no spaces or specials caracters. The pseudo is used for communication, to identify yourself easily; and for textual mod (the first letter will be displayed on the board)
  2. and your player’s color : with the option –color. A valid color is one of black, red, green, yellow, blue, magenta, cyan or white.
So, you can be Luke Skywalker:
$ ./BombermanClient.py –server bomberman.crans.org –port 12885 –pseudo Luke –color cyan

PyRlwrap

The client have to be launched from the command line, and during the game the stdin (i.e. the keyboard) is listened.

So you can send messages yo your server, directly from the command line. The script PyRlwrap.py provide a readline wrapper for this command line interface. It brings:

  • shortcut, “a la Nano” (^A: begin line, ^E: end line etc);
  • history (Up & Down show previous message).
You can launch the client with PyRlwrap.py like this (and be Mario) :
$ ./PyRlwrap.py ./BombermanClient.py –server 138.231.134.230 –port 9312 –pseudo Mario –color red

Options for textual mod

The following options can change how the textual mod looks like :
  • –noUTF : disabled UTF caracters for the board. And, warning for pseudos, if one begins with a non-ascii caracter, the id of the player is used (an integer, between 0 and the number of player -1).
  • –noANSI or –ANSI : force to disable or enable the colors. Normally, you don’t have to use them, because the ANSIColors module can detect cleverly if colors are supported. (_Note:_ this have been tested with Linux, Cygwin, but not with Mac OS X)

Options for graphical mod

The following option(s) can change how the graphical mod looks like :
  • –music or –nomusic : try to enable the music or force to not use it.
  • –soundeffect or –nosoundeffect : try to enable the music effects (when a bomb blow) or force to not use it.

For more details about graphical mod, cf the AffichPygame module.

About

Getting some help

This program uses a high-level command line parser : ParseCommandArgs, based on argparse from the standard distribution.

Therefore, the help for this program can be obtained simply with ::
$ ./BombermanClient.py –help
The help embed some colors, and it can be read through a pipe :
$ ./BombermanClient.py -h | less -r

Choices

  • For handling multi channels listening and sending in step 1 and 2, thread.thread is used.

    Both for the step 1 and 2.

  • The syntax of messages is :
  • The specification of the game protocole is also detailed in the slides (and mainly it explains why we use TCP).

Warning

Warning

This script is not yet fully concluded. So, it might end badly on some untests behaviour. I ran many tests, but I can’t ensure everything is all right...

TODOs:

  • Make the option ‘–nowindow’ available (by now, it fails).
  • Make sure the winner player is well get from the last message.

TODOs ?:

  • ? Conclude the parser (add –keys to parametrize the KeyBinding).
  • ? Implement the bonus system.
  • ? Make the music smoother.
  • ? Use a smart update for the sprites (and not recompute all each time).
BombermanClient.create_socket_client(server=('0.0.0.0', 12882))[source]

Create a socket designed to be a client, and connect it to @server. Return a socket.

BombermanClient.action_on_readstr(readstr, pl_client, List_ReceivedMessages=[], List_SentMessages=[], verb=False)[source]

Reaction to special message read from the keyboard !

BombermanClient.initGame(lx=LX_CST, ly=LY_CST, nb=NB_PLAYER) -> (nbmax, lx, ly, pl, board, Mi, Mj)[source]

Creating all Game variables. Here there is no random in the map yet.

BombermanClient.run_client(msocket, server, player, PRINT_ALL_MESSAGE = PRINT_ALL_MESSAGE, double_thread=False) → player, nbmax0, lx0, ly0, pl0, board0, Mi0, Mj0, List_ReceivedMessages, List_SentMessages[source]

An infinite loop over the @msocket, which have to be a client socket assumed te be connected with @server (just used to print some usefull informations). Concurrently, read from stdin on client and write on stdout on server, and read on stdin on server and write on stdout on client. Use thread.

If PRINT_ALL_MESSAGE, the client print all messages with a pretty workaroung.

Moreover, it begins the construction of the board, and wait for more informations about it from the server.
When this phasis is conclude, create the board (and the others variables) and returns it.

double_thread is just an experiment about two additionnal threads for the listening part.

BombermanClient.waiting_room(server=('0.0.0.0', 12882), pseudo='Luke', color='cyan', lx=11, ly=11)[source]

Create a socket on the server server, and run a client on it.

Here the client will enter in a wainting room, connect to a server,
then initialize all game variables (the map, the players etc), and when all players will be ok, this function return all those variables, to start the game.

FIXME: this function is quite long, make sure it is ok.

BombermanClient.affich_loop(background, screen, clock, board, pl, player, keyBinding, num_thread=0, USE_MUSIC=False)[source]

Launch an infinite loop to display the game.

This function will be launched with an additionnal thread.

The parameters background, screen and clock are PyGame objetcs. And board,*pl* represents the board and the list of players.

BombermanClient.main(player, nbmax, lx, ly, pl, board, Mi, Mj, List_ReceivedMessages, List_SentMessages, keyBinding=KeyBinding.arrows(), verb2=True) -> Exception (no values returned, only an exception)[source]

Initialize Pygame and the music, and then launch the game. The display is done with a threaded function.

Parameters:
  • [player] The player representing the client,
  • [nbmax] Is max number of players,
  • [lx], [ly] Are lenght of the board,
  • [pl] Is the list of player (represented as Player.Player instances),
  • [board] Is the board (represented as Board.Board instance !),
  • [Mi], [Mj] Are list of players’ position to initiate the game,
  • [List_ReceivedMessages], [List_SentMessages] To continue logging all inputs and outputs.
  • [keyBinding] Is a KeyBinding.KeyBinding to map key to moves.