This paper is a summary of the development of the C # Network version of the landlord.
The order of the cards is shown in the figure above.
The licensing permission can be represented by a bool value
In the player class, there is an attribute: Haveorder Indicates whether the player has permission to play the card.
Also need to consider a point, when a player after the card, the other players are not up (pass), the player can not "do" themselves, so also need a bool type attribute "Isbiggest".
This attribute represents the largest number of cards that you have. How do you guarantee the validity of this value? In other words, the biggest can only have one. So whenever you make a card, you set the value to true as long as your cards are bigger than others. When this value is true, sending information to other players indicates that their cards are bigger than yours, and that other players have their own Isbiggest property set to False when they receive the message, thus realizing the proper transfer of the licensing permissions.
The implementation methods are as follows:
This article requires some of the code in the Player class:
private bool _haveorder;
public bool Haveorder
{
Get
{
return _haveorder;
}
Set
{
_haveorder = value;
}
}
private bool _isbiggest;
public bool Isbiggest//
{
Get
{
return _isbiggest;
}
Set
{
if (value)//Isbiggest is assigned true
{
if (dconsole.client!= null)//When player is client
{
DConsole.client.SendDataForServer ("iamisbiggest");/what about the server side? Please see below.
_isbiggest = value;
}
if (dconsole.server!= null)//If player is server
{
DConsole.server.SendDataForClient ("Nobiggest", 1);
DConsole.server.SendDataForClient ("Nobiggest", 2);/Tell the client, you are not biggest, how to deal with the client? Please see below
_isbiggest = value;
}
}
Else
{
_isbiggest = value;
}
}
}
public bool Leads ()//licensing method
{
dconsole.leadpokers = leadpokers;
This.leadPokers.Clear ();
foreach (int selectpoker in this.selectpokers)//Iteration loop adds selected cards to Leadpokers
{
This.leadPokers.Add (This.pokers[selectpoker]);
}//The above code is to construct the selected card into a Pokergroup object
if (Dconsole.isrules (this.leadpokers))//Verify that the selected card is in accordance with the rules of the game, about the rules in the future of the article explained in detail
{
if (DConsole.player1.isBiggest | | Dconsole.leadpokers > Dconsole.leadedpokergroups[dconsole.leadedpokergroups.count-1])//player can play the cards in two cases is 1, The cards that you rotate are the biggest, others don't. 2, their own round out of the card than other people's big.
{
if (DConsole.leadPokers.type = = Pokergrouptype. Bomb)//When the type of the deck is bomb, double
{
dconsole.multiple *= 2;
}
if (DConsole.leadPokers.type = = Pokergrouptype. Double King)//When the type of the deck is double king, turn three times times
{
dconsole.multiple *= 3;
}
DConsole.player1.isBiggest = true;//as long as their own cards out of the assumption that they are the largest, once their own cards are someone else's tube, will be set to False, see below
this. Bakpoker (); Back up the existing pokers, the next time you need to use the
foreach (int selectpoker in this.selectpokers)//Remove the cards that have been played in Pokers
{
This.pokers.Remove (This.bakpokers[selectpoker]);
}
this.selectPokers.Clear (); Empty selected cards
return true;
}
Else
{
this.leadPokers.Clear ();
return false; The card group returns false when smaller than others
}
}
Else
{
this.leadPokers.Clear ();
return false; Returns false
if the rule is not met
}
}