private static void StartGame(string playerName, string password, string hostname, int port) { if (string.IsNullOrWhiteSpace(playerName + password)) { throw new ConfigurationErrorsException("PlayerName and password must be set in App.config to connect to server."); } using (var client = new TcpClient()) { client.NoDelay = true; client.Connect(hostname, port); using (var writer = new StreamWriter(client.GetStream())) { writer.AutoFlush = true; using (var reader = new StreamReader(client.GetStream())) { var serverGateway = new AgarIoServerGateway(writer, reader); serverGateway.Login(playerName, password); serverGateway.JoinPlayer(); var agarIoPlayer = new AgarIoPlayer(serverGateway, playerName); agarIoPlayer.GameLoop(); } } } Console.ReadLine(); }
public void GameLoop() { var random = new Random(); while (true) { GetViewResponseDto getViewResponseDto; try { getViewResponseDto = _serverGateway.GetView(); } catch (SocketException e) { Console.WriteLine("Could not connet to server! Message: {0}", e.Message); continue; } switch (getViewResponseDto.ErrorCode) { case CommandErrorCode.NotJoined: _serverGateway.JoinPlayer(); continue; case CommandErrorCode.GameNotStarted: continue; } var foods = getViewResponseDto.Blobs.Where(x => x.Type == BlobType.Food); var players = getViewResponseDto.Blobs.Where(x => x.Type == BlobType.Food).OrderBy(b => b.Id); var viruses = getViewResponseDto.Blobs.Where(x => x.Type == BlobType.Virus); var myBlobs = getViewResponseDto.Blobs.Where(x => x.Type == BlobType.Player).Where(x => x.Name == _playerName); double destinationX = random.Next(-255, 256); double destinationY = random.Next(-255, 256); double speed = 1000; _serverGateway.Move(destinationX * speed, destinationY * speed); //_serverGateway.SplitMass(); //_serverGateway.EjectMass(); } }