Learn VB .NET Through Game Programming [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Learn VB .NET Through Game Programming [Electronic resources] - نسخه متنی

Matthew Tagliaferri

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
توضیحات
افزودن یادداشت جدید





Listing 7-6 on how to set up this separate thread). Listing 7-11 shows how this method looks for data and then converts it into a ReversiPiece class instance.


Listing 7.11: Deserializing Data from the TCPClient and Rehydrating Back into a ReversiPiece Object Instance



Public Sub LookForTurn()
Do
If FStream.DataAvailable Then
Dim cPiece As String
Dim oPiece As New ReversiPiece
Dim oSer As New XmlSerializer(oPiece.GetType)
Dim oRead As StreamReader
oRead = New StreamReader(FStream)
cPiece = oRead.ReadLine
oPiece = oSer.Deserialize(New StringReader(cPiece))
RaiseEvent MyMoveLoc(Me, oPiece.Location.X, oPiece.Location.Y)
End If
System.Threading.Thread.Sleep(250)
Loop Until False
End Sub



This method reverses the process found in the SendMyTurnToOpponent method. It first uses the ReadLine method of the TCPClient class to retrieve a complete line of text from the network connection (remember, the XML class definition exists in a single line of text because you removed all of the carriage return/line feeds). This string is stored in the string variable cPiece. Then, an XMLSerializer class instance converts the string variable back into a ReversiPiece instance named oPiece.

After retrieving the ReversiPiece object, the code raises the event that moves the current player, MyMoveLoc. This event handler requires the player moving and the x, y coordinate of the piece to which the player is moving. The coordinates from the ReversiPiece object that were sent over the wire are the coordinates sent to the event handler.

/ 106