private void _onData(byte[] Data, int Count, string MessageType) { NorenStreamMessage wsmsg; try { if (Count == 0) { return; } wsmsg = Deserialize <NorenStreamMessage>(Data, Count); if (wsmsg.t == "ck") { Console.WriteLine("session established"); onStreamConnectCallback?.Invoke(wsmsg); } else if (wsmsg.t == "om" || wsmsg.t == "ok") { NorenOrderFeed ordermsg = Deserialize <NorenOrderFeed>(Data, Count); OnOrderCallback?.Invoke(ordermsg); } else { NorenFeed feedmsg = Deserialize <NorenFeed>(Data, Count); OnFeedCallback?.Invoke(feedmsg); } } catch (JsonReaderException ex) { Console.WriteLine($"Error deserializing data {ex.ToString()}"); return; } }
/// <summary> /// Двигает змейку в текущем направлении, изменяя клетку карты. Освобождает клетку на карте с индексом из очереди tailIndexesQueue, /// кроме случаев, когда змейка становится на клетку с едой. Вызывает OnFeed, когда змейка становится на клетку с едой. /// Вызывает Die(), если змейка становится на клетку со змейкой или на клетку, которая находится за пределами карты. /// </summary> private void Move() { var nextCellPosition = map.ConvertIndexToVector2Int(headPositionIndex) + moveVector; if (map.IsInMapBounds(nextCellPosition)) { var nextCellIndex = map.ConvertVector2IntToIndex(nextCellPosition); var nextCellContent = map.GetCellContentType(nextCellIndex); if (nextCellContent != CellContentType.snake) { TakeCell(nextCellIndex); if (nextCellContent == CellContentType.food) { OnFeed?.Invoke(); } else { RemoveTail(); } return; } } Die(); }
// Called when the animal is fed public override void TakeHit(int damage) { OnFeed?.Invoke(); base.TakeHit(damage); }