AdSense

Monday 20 May 2013

Panzerkampf

(Deutsche Version) Some years ago, I programmed a game for Linux called Panzerkampf (translated: Tank fight). The basic idea was to navigate a tank via arrows/WASD through the environment and try to kill the other player. Sadly this project was limited by many factors: A single keyboard cannot handle enough keys so it could happen that one player could not shoot anymore.

About two weeks ago, I started to program the game again. The game is written in C# and can be played via internet or local area network. The network communication is running with sockets, here the basic code snippet:

Client:

System.Net.Sockets.TcpClient clientSocket = new System.Net.Sockets.TcpClient();
clientSocket.Connect("mein.server.de", port);
NetworkStream serverStream = clientSocket.GetStream();
byte[] outStream = System.Text.Encoding.ASCII.GetBytes("message to server");
//Nachricht an Server senden
serverStream.Write(outStream, 0, outStream.Length);
serverStream.Flush();
byte[] inStream = new byte[70000];
//inStream anpassen (größe an clientSocket.ReceiveBufferSize anpassen)
Array.Resize(ref inStream, clientSocket.ReceiveBufferSize);
//Nachricht vom Server empfangen
serverStream.Read(inStream, 0, clientSocket.ReceiveBufferSize);
string dataFromServer = System.Text.Encoding.ASCII.GetString(inStream);
clientSocket.Close();


Server:

TcpListener serverSocket = new TcpListener(port);
TcpClient clientSocket = default(TcpClient);
serverSocket.Start();
clientSocket = serverSocket.AcceptTcpClient();
NetworkStream networkStream = clientSocket.GetStream();
byte[] bytesFrom = new byte[10025];
Array.Resize(ref bytesFrom, clientSocket.ReceiveBufferSize);
networkStream.Read(bytesFrom, 0, clientSocket.ReceiveBufferSize);
string dataFromClient = System.Text.Encoding.ASCII.GetString(bytesFrom);
Byte[] sendBytes = Encoding.ASCII.GetBytes("message to Client");
networkStream.Write(sendBytes, 0, sendBytes.Length);
networkStream.Flush();
clientSocket.Close();


For the sounds I used sounds from freesound.org which are under the Creative Commons 0 license, I do not have to refer to the creators but I am not allowed to say that the sounds would belong to me.

The graphics are made with windows forms.

The download for the client is here: http://physudo.bplaced.net/Panzerkampf/publish.htm
And for the server here: http://physudo.bplaced.net/PanzerkampfServer/publish.htm

If anyone plays Panzerkampf, I would be glad to receive a small feedback (maybe as comment to this post)

No comments:

Post a Comment