public byte[] ToByteArray() { var boardBytes = new List <Byte> { 0x62, 0x6F, 0x61, 0x72, 0x64, 0x4C, 0x61, 0x79, 0x6F, 0x75, 0x74, 0x08, 0x00, 0x00, 0x00, 0x31, 0x00, 0x01 }; var boardNumber = 0; var tens = 0; var digit = 0; for (var i = 0; i < 7; i++) { for (var j = 0; j < 7; j++) { if (tens > 0) { boardBytes.Add(DigitTranslator.IntToByte(tens)); } boardBytes.Add(DigitTranslator.IntToByte(digit)); if (digit == 9) { tens++; digit = 0; } else { digit++; } var bytes = _boardLayout[i, j].GetBytes(); boardBytes.AddRange(bytes); boardBytes.Add(0); boardBytes.Add(0); boardBytes.Add(0); boardBytes.Add(0); boardBytes.Add(0); boardBytes.Add(0); if (boardNumber <= 8) { boardBytes.Add(0x01); } else if (boardNumber == 48) { boardBytes.Add(0x00); boardBytes.Add(0x09); boardBytes.Add(0x00); boardBytes.Add(0x00); boardBytes.Add(0x0B); } else { boardBytes.Add(0x02); } boardNumber++; } } return(boardBytes.ToArray()); }
public byte[] ToByteArray() { var queueBytes = new List <Byte> { 0x70, 0x69, 0x65, 0x63, 0x65, 0x73, 0x51, 0x75, 0x65, 0x75, 0x65, 0x08, 0x00, 0x00, 0x00, }; queueBytes.Add(Convert.ToByte(_piecesInQueue.Count)); queueBytes.Add(0x00); queueBytes.Add(0x01); var tens = 0; var digit = 0; var boardNumber = 0; foreach (var piece in _piecesInQueue) { if (tens > 0) { queueBytes.Add(DigitTranslator.IntToByte(tens)); } queueBytes.Add(DigitTranslator.IntToByte(digit)); if (digit == 9) { tens++; digit = 0; } else { digit++; } var pieceBytes = PieceTranslator.PieceToByte(piece); queueBytes.AddRange(pieceBytes); queueBytes.Add(0); queueBytes.Add(0); queueBytes.Add(0); queueBytes.Add(0); queueBytes.Add(0); queueBytes.Add(0); if (boardNumber == _piecesInQueue.Count - 1) { //Laatste queueBytes.Add(0x00); queueBytes.Add(0x09); queueBytes.Add(0x00); queueBytes.Add(0x00); queueBytes.Add(0x11); } else if (boardNumber <= 8) { queueBytes.Add(0x01); } else { queueBytes.Add(0x02); } boardNumber++; } return(queueBytes.ToArray()); }