ChatdServerClientExample: Difference between revisions

Jump to navigation Jump to search
Content deleted Content added
No edit summary
No edit summary
Line 1: Line 1:
A very simple example for you, the lazy reader, who can't be bothered to read the manual!
A very simple example for you, the lazy reader, who can't be bothered to read the manual!<br>
But note, this example is by no way a substitute of HowToWriteGamesUsingArianne and it is only intended for readers that want a light introduction to Arianne.
But note, this example is by no way a substitute of HowToWriteGamesUsingArianne and it is only intended for readers that want a light introduction to Arianne.


!Server
=Server=
First we create the server class using python.
First we create the server class using python.
<pre>
<verbatim>
import marauroa.game.python.PythonRP
import marauroa.game.python.PythonRP


Line 41: Line 41:
def onTimeout(self, objectid):
def onTimeout(self, objectid):
return onExit(self,objectid)
return onExit(self,objectid)
</verbatim>
</pre>


Ok, most of it is just trivial stuff. The core code is at execute and nextTurn.
Ok, most of it is just trivial stuff. The core code is at execute and nextTurn.<br>
The execute method is the one called to execute the actions the client sends and it is really simple, it adds the messages content as a player attribute, and the trick thing is that is add the player a list so that it can be deleted the attribute in the next turn.
The execute method is the one called to execute the actions the client sends and it is really simple, it adds the messages content as a player attribute, and the trick thing is that is add the player a list so that it can be deleted the attribute in the next turn.


The nextTurn just delete the attributes that now are useless.
The nextTurn just delete the attributes that now are useless.


!Client
=Client=
The client is a bit more complex. We need to make it login and choose a character. We will use a curses wrapper for python.
The client is a bit more complex. We need to make it login and choose a character. We will use a curses wrapper for python.
_TODO:_ Improve it
'''TODO:''' Improve it
<pre>
<verbatim>
import pyarianne
import pyarianne
import curses
import curses
Line 213: Line 213:
uninitCurses(1,2)
uninitCurses(1,2)


</verbatim>
</pre>


And here you can see how it looks:
And here you can see how it looks:

[http://tribus.dyndns.org/~keiner/cursed-chat-client.png]
http://tribus.dyndns.org/~keiner/cursed-chat-client.png