Silverlight + WCF practice-room decoration in the final part of network chess-WCF terminal (2)

Source: Internet
Author: User

Online Demo address: Silverlight + WCF novice instance chess Online Demo

Last series of 40 indexes: Silverlight + WCF beginner instance chess topic Index

 

Buddha depends on gold, people need clothes, and the room should also add bricks. In this article, we will renovate the room to make it look professional!

 

I. effect preview. First

 

Here is the previous room image:

Picture of the room to be decorated today:

In the previous game:

 

II. Implementation

 

1: Newly Added Images

To achieve decoration, I have added three new images:
1: Room Image
2: picture of the game status in the room
3: QQ user profile picture
The image is copied from the installation program of QQ chess game. Because Silverlight only supports images of Certain types such as png, you can use ps to save the image as png.

 

This is the format of the image storage Folder:

 

2: Elements to be added for Room Decoration

The added elements include:

1: user avatar [field] [display QQ Avatar on the room seat]
2: Room game status [field] [display switch room background image]
3: the user in the room's seat [field] [display the user name in the upper and lower positions of the QQ Avatar]
There are a lot of code that needs to be modified to add these elements, so everyone should be more active.

 

Iii. Code implementation [WCF client]

 

1: WCF code: entity Modification

WCF: Player entity

/// <Summary>
/// Players passing by autumn
/// </Summary>
[DataContract]
Public class Player
{

//... Omitting the previous N entities...
[DataMember]
Public string Head
{
Get;
Set;
}
}

 

WCF: Room entity

[DataContract]
Public class Room
{
///... N lines of code are omitted... // <summary>
///// Whether there is a red seat
///// </Summary>
// [DataMember]
// Public bool RedInChair
//{
// Get;
// Set;
//}
///// <Summary>
//// Check whether there is a black seat
///// </Summary>
// [DataMember]
// Public bool BlackInChair
//{
// Get;
// Set;
//}
# Region fields added to the decoration room
[DataMember]
Public Player RedPlayer
{
Get;
Set;
}
[DataMember]
Public Player BlackPlayer
{
Get;
Set;
}
[DataMember]
Public bool IsGaming
{
Get;
Set;
}
# Endregion
}

 

Note:

Two players were added to the room, and a game status. Was there a field in the previous seat? [RedInChair/BlackInChair]? deleted [resulting in N lines of code to be modified].

 

OK. The field is simply changed. compile it and find that there are nearly N errors. You can only modify them one by one.

 

2: WCF: Service. cs code modification [the original code is commented out, and the modified Code is not commented out]

Method: EnterRoom

// If (! Room. RedInChair) // do you have any red seats in the room?
//{
// Room. RedInChair = player. ColorValue = 1;
//}
// If (! Room. BlackInChair) // is there a black seat in the room?
//{
// Room. BlackInChair = player. ColorValue = 2;
//}
If (room. RedPlayer = null & player. ColorValue = 1)
{
Room. RedPlayer = player;
}
Else if (room. BlackPlayer = null & player. ColorValue = 2)
{
Room. BlackPlayer = player;
}

 

Method: OutRoom

If (player. ColorValue = 1) // if the player exits, the player is in red.
{
// Room. RedInChair = false;
Room. RedPlayer = null;
}
If (player. ColorValue = 2) // if the player exits, the player is in red and black.
{
// Room. BlackInChair = false;
Room. BlackPlayer = null;
}

 

Method: StartGame [only added code]

Public void StartGame (Player player)
{
Notify. Game (player, GameType. Start );
// Add code for the following actions
If (player. AttachInfo = "11") // agree to start the game and start thread Scanning
{
RoomList [player. RoomID]. IsGaming = true; // The room settings are in the game.
Y. Room (roomList [player. RoomID]); // Notify everyone to update the Room status
}
}

 

Method: EndGame [only added code]

Public void EndGame (Player player)
{
Notify. Game (player, GameType. End );
// The code added for the following actions
If (player. AttachInfo = "0" | player. AttachInfo = "1" | player. AttachInfo = "2 ")
{
// The game ends and historical data is cleared.
RoomList [player. RoomID]. StepList. Clear ();
RoomList [player. RoomID]. IsGaming = false;
Y. Room (roomList [player. RoomID]); // Notify the Room to change to the game status;
}
}

Note:

OK. The modification on the WCF end is complete. Next, the Silverlight client will be added with more code N to be adjusted.
After the server end uploads data, the client must update the service reference. Then, because the two fields of the server end object are deleted, some minor errors will inevitably occur.

 

Statement:

For the Silverlight client, there are a lot of code to be adjusted, so wait for the next implementation, or the next article will be too long.

You are welcome to keep an eye on this series!

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.