Silverlight + new WCF instance chess move-Rule supplement)

Source: Internet
Author: User

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

 

In the Silverlight + WCF novice instance, the chess pawn movement-rule [upper limit attached] (10), the rule proposed by Silenus-G has a bug:

The red car can go to the red horse's place: this is because when the mouse is located outside the place where the pawn is, what we produce is the moving of the pawn [not eating it], while moving it, we have not determined whether there are other pieces in the position to be moved, which leads to economic disputes. Therefore, to solve this problem, we only need to add a click event to determine whether the pawns do not exist.

In the mobile rule section, we will add the following two rules at the same time:

1: A few parentheses are missing in the judgment Statement of vehicles and guns ";

2: Increase the number of generals for face-to-face meals

 

 

Start as follows:

We can add an if code line to solve the problem of the red car grabbing the horse. We will go back to the Chess class and find the mouse click event:

Void control_MouseLeftButtonDown (object sender, MouseButtonEventArgs e)
{
If (e. OriginalSource is Canvas | e. OriginalSource is Line)
{
Chessman chessman = ReadyMoveChessman;
If (chessman! = Null)
{
Point fixPoint = FixPoint (e. GetPosition (null ));
If (FindChessman (fixPoint) = null) // a new row of judgment statement is added.
{
Action. MoveTo (chessman, fixPoint );
}

}
}
}

 

OK. We will solve the red car and horse snatching accident with a line of code. We will add brackets for the cars and guns of the original rules below:

Let's go back to the ChessRule rule class:

Vehicle Rule correction:

// This line is the car's original if judgment:
If (x1 = x2 & yCount = 0 | y1 = y2 & xCount = 0)

// Add brackets to correct the following:
If (x1 = x2 & yCount = 0) | (y1 = y2 & xCount = 0 ))

 

Gun rule correction:

// This is the original if statement of the gun.
If (x1 = x2 & (yCount = 0 &&! Exits) | (yCount = 1 & exits)
| Y1 = y2 & (xCount = 0 &&! Exits) | (xCount = 1 & exits ))

// The brackets are corrected as follows:
If (x1 = x2 & (yCount = 0 &&! Exits) | (yCount = 1 & exits ))
| Y1 = y2 & (xCount = 0 &&! Exits) | (xCount = 1 & exits )))

 

 

OK. Now we have added the General's face-to-face rules:

At the same time, it adds the same color of the pawn to determine [currently, this rule is useless. In the same color as the sub-rule, automatic switch will be made, and no sub-item will be generated]:

/// <Summary>
/// Move the rule
/// </Summary>
/// <Param name = "move"> pawn </param>
/// <Param name = "eat"> array of the Moving position </param>
/// <Returns> </returns>
Public bool IsCanMove (Chessman chessman, Point moveTo)
{
//... N rows omitted...
If (x2> = 0 & x2 <9 & y2> = 0 & y2 <10 &&! (X1 = x2 & y1 = y2) // It is not the original step in the checker.
{
Chessman man = Action. Parent. FindChessman (moveTo );
If (man! = Null & chessman. Color = man. Color) // adds the presence and Color of the pawn.
{
Return false;
}
ChessType chessType = GetChessTypeByName (chessman. Name );
Switch (chessType)
{
//... N rows omitted...
Case ChessType. Jiang:
// Face-to-face General
If (man! = Null & GetChessTypeByName (man. Name) = ChessType. Jiang)
{
OutCount (chessman. MovePoint, moveTo, out xCount, out yCount );
Return x1 = x2 & yCount = 0;
}
//... N rows omitted ...}
}
Return false;
}

We added the search for the pawns, and then checked in the generals to determine whether the pawns at the point of the Moving position were the generals of the other party. If yes, follow the rules of a similar vehicle to [move only vertically.

 

OK. This section ends.

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.