Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Net.Sockets;
- using System.Net;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- TcpListener server = null;
- try
- {
- int Zmey1direction = 2;
- int Zmey2direction = 3;
- int Zmey3direction = 4;
- int Zmey4direction = 1;
- int Start = 0;
- int BerryX = 15;
- int BerryY = 15;
- int port = 8888;
- IPAddress localAddr = IPAddress.Parse("127.0.0.1");
- server = new TcpListener(localAddr, port);
- server.Start();
- while (true)
- {
- string mess = "";
- Random rnd = new Random();
- TcpClient client = server.AcceptTcpClient();
- NetworkStream stream = client.GetStream();
- byte[] data = new byte[256];
- do
- {
- int bytes = stream.Read(data, 0, data.Length);
- mess += Encoding.UTF8.GetString(data, 0, bytes);
- } while (stream.DataAvailable);
- if (mess[0] != '?')
- {
- Console.WriteLine(mess);
- }
- if (mess == "Zmey1 1")
- Zmey1direction = 1;
- else if (mess == "Zmey1 2")
- Zmey1direction = 2;
- else if (mess == "Zmey1 3")
- Zmey1direction = 3;
- else if (mess == "Zmey1 4")
- Zmey1direction = 4;
- else if (mess == "Zmey2 1")
- Zmey1direction = 1;
- else if (mess == "Zmey2 2")
- Zmey1direction = 2;
- else if (mess == "Zmey2 3")
- Zmey1direction = 3;
- else if (mess == "Zmey2 4")
- Zmey1direction = 4;
- else if (mess == "Zmey3 1")
- Zmey1direction = 1;
- else if (mess == "Zmey3 2")
- Zmey1direction = 2;
- else if (mess == "Zmey3 3")
- Zmey1direction = 3;
- else if (mess == "Zmey3 4")
- Zmey1direction = 4;
- else if (mess == "Zmey4 1")
- Zmey1direction = 1;
- else if (mess == "Zmey4 2")
- Zmey1direction = 2;
- else if (mess == "Zmey4 3")
- Zmey1direction = 3;
- else if (mess == "Zmey4 4")
- Zmey1direction = 4;
- else if (mess == "Pause")
- {
- if (Start == 1)
- Start = 0;
- else
- Start = 1;
- }
- else if (mess[0] == '?')
- {
- string response = Zmey1direction.ToString() + Zmey2direction.ToString() + Zmey3direction.ToString() + Zmey4direction.ToString() + Start.ToString();
- data = Encoding.UTF8.GetBytes(response);
- stream.Write(data, 0, data.Length);
- }
- stream.Close();
- client.Close();
- }
- }
- catch (Exception ee)
- {
- Console.WriteLine(ee.Message);
- }
- finally
- {
- if (server != null) server.Stop();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement