Unity3d mobile phone bucket landlord game development Combat (03) _ Landlord card display and card logic (not regularly updated in ~ ~ ~)

Source: Internet
Author: User

Hi, before a classmate said to me to send out the source code, then I put the semi-finished source of the link at the end of each document, interested can refer to the reference, there is a problem with my private message, can also pay attention to my personal public number, communicate with each other. And, of course, the code is continually improving.

In the last period we realized that the landlord function, but left a small function: Call the landlord after completion, to show the landlord's 3 cards, this period first to make up the function of this piece;

Then we have to go into the development of the card logic development phase, well, no nonsense to say, continue our struggle Landlord development Tour ~

The display of the landlord card

We placed a new gameobject in the top middle of the player interface, named Bidcards, to record the display position of the 3 landlords.

So we reconstructed the Cardmanager in the licensing method, in the landlord licensing at the same time, the generation of the landlord card instance, placed in the bidcards corresponding position:

    /// <summary>    ///Licensing on the heap (if now is not the landlord stage, the ordinary card, if it is, the landlord card)/// </summary>    /// <returns></returns>    PrivateIEnumerator Dealheapcards (BOOLifforbid) {        //stack of display cardsHeapPos.gameObject.SetActive (true); Playerheappos.tolist (). ForEach (S= = {S.gameobject.setactive (true);        }); varcardnamesneeded =Ifforbid? Cardnames.skip (Cardnames.length-3). Take (3)//if it's a landlord card, take the last 3.: Cardnames.take (Cardnames.length-3);//if the card is first issued//calculate the position of each host card        intCardindex =0; varwidth = (bidcards.getcomponent<recttransform> (). sizedelta.x- -) /3; varCenterbidpos =Vector3.zero; varLeftbidpos = Centerbidpos-vector3.left *width; varRightbidpos = Centerbidpos + vector3.left *width; List<Vector3> Bidposs =NewList<vector3>{leftbidpos, centerbidpos, rightbidpos}; foreach(varCardnameinchcardnamesneeded) {            //send a card to the current playerPlayers[termcurrentindex].            Addcard (Cardname); varCover =Instantiate (Coverprefab, Heappos.position, quaternion.identity, heappos.transform); Cover. Getcomponent<RectTransform> (). Localscale =Vector3.one; //move animation, auto-destroy after animation ends            varTween = Cover.transform.DOMove (Playerheappos[termcurrentindex].position,0.3f); Tween. OnComplete (()=Destroy (cover)); yield return NewWaitforseconds (1/dealcardspeed); //If the landlord is licensed,            if(ifforbid) {//Show landlord Card                varBidcard =Instantiate (Cardprefab, BidCards.transform.TransformPoint (Bidposs[cardindex]), quaternion.identity,                Bidcards.transform); Bidcard. Getcomponent<Card> (). Initimage (NewCardinfo (cardname)); Bidcard. Getcomponent<RectTransform> (). Localscale = Vector3.one *0.3f; }            Else            {                //The next person to be licensedSetnextplayer (); } Cardindex++; }        //Hidden Card HeapHeapPos.gameObject.SetActive (false); playerheappos[0].gameobject.setactive (false); //send a regular card        if(!ifforbid) {            //Show player Handshowplayerselfcards ();        Startbiding (); }        //To send a landlord card        Else        {            if(Players[bankerindex] isplayerself) {                //Show player Handshowplayerselfcards ();        } startfollowing (); }    }

Okay, we've got no problem with the landlord card, and then we're going to implement the card turn logic

Implementation of the card turn function

The licensing round is actually called the landlord round similar, also can abstract 3 kinds of methods: Enter the card stage, cards, not out (compare into the landlord stage, call the landlord, not to call the landlord);

Therefore, we refer to the logic called the landlord, and then realize the card logic:

Adjust the player base class, add to start the card tofollowing, card forfollow, not out Notfollow

Tofollowing: Enter your own turn, close other people's countdown, enter their own countdown stage;

Forfollow: Turn off your countdown, then add the selected card to the card area and jump out of your own turn;

Notfollow: Turn off your countdown and jump out of your own turn;

    /// <summary>    ///Start the card/// </summary>     Public Virtual voidtofollowing () {ismyterm=true; //Close CountdownStopcountdown (Countdowntypes.follow); //start the countdown .Startcountdown (Countdowntypes.follow); }    /// <summary>    ///the card/// </summary>     Public voidForfollow () {//Close CountdownStopcountdown (Countdowntypes.follow); //selected cards, added to the area of the card        varSelectedcards = Cardinfos.where (s = =s.isselected).        ToList (); varoffset =5;  for(inti =0; I < Selectedcards.count (); i++)        {            varCard = Instantiate (Prefabsmall, smallcardpos.position + vector3.right * Offset *I, quaternion.identity, smallcardpos.transform); Card. Getcomponent<RectTransform> (). Localscale = Vector3.one *0.3f; Card. Getcomponent<Image> (). Sprite = Resources.load ("images/cards/"+ Selectedcards[i].cardname,typeof(Sprite)) asSprite;            Card.transform.SetAsLastSibling ();        Smallcards.add (card); } Cardinfos= Cardinfos.where (s = =!)s.isselected).        ToList (); Cardmanager._instance.        Forfollow (); Ismyterm=false; }    /// <summary>    ///not out/// </summary>     Public voidNotfollow () {//Close CountdownStopcountdown (Countdowntypes.follow); Cardmanager._instance.        Notfollow (); Ismyterm=false; }    /// <summary>    ///destroying a card object/// </summary>     Public voiddropallsmallcards () {Smallcards.foreach (Destroy);    Smallcards.clear (); }
Adjust the Playerself class to achieve tofollowing

Call the base class's tofollowing and display the card button for the player to select

    /// <summary>    /// start the card     /// </summary>     Public Override void tofollowing ()    {        base. Tofollowing ();        Cardmanager._instance. Setfollowbuttonactive (true);    }
Adjust the Playerother class to simulate the card

Randomly select one of the cards except the hand

    voidUpdate () {//if it's your turn now, simulate your opponent's call.        if(ismyterm) {if(Cardmanager._instance.cardmanagerstate = =cardmanagerstates.bid) {if(Input.getkeydown (KEYCODE.Q))//Call Card{forbid (); }                if(Input.getkeydown (KEYCODE.W))//Don't call{notbid (); }            }            if(Cardmanager._instance.cardmanagerstate = =cardmanagerstates.playing) {if(Input.getkeydown (KEYCODE.Q))//the card                {                    varRd1 = Random.range (0, Cardinfos.count); Cardinfos[rd1].isselected=true;                Forfollow (); }                if(Input.getkeydown (KEYCODE.W))//not out{notfollow (); }            }        }    }
Adjust Cardmanager, realize card management to control player's card

After the completion of the landlord card, the beginning of the card stage, the landlord first out of cards;

After the player chooses to play the card, it will empty the player's stack, and add the selected card to its own pile, and rotate it to the next player.

Players choose not to play cards, will be the player's card stack empty, rotate to the next player;

    /// <summary>    ///start the card stage/// </summary>    Private voidstartfollowing () {cardmanagerstate=cardmanagerstates.playing; //the landlord cards first .Players[bankerindex].    Tofollowing (); }    /// <summary>    ///Players play Cards/// </summary>     Public voidForfollow () {setfollowbuttonactive (false); //the player on the wheel clears the cardplayers[(Termcurrentindex + players.length-1) %3].        Dropallsmallcards (); if(Players[termcurrentindex] isplayerself)        Showplayerselfcards ();        Setnextplayer (); Players[termcurrentindex].    Tofollowing (); }    /// <summary>    ///the player does not/// </summary>     Public voidNotfollow () {setfollowbuttonactive (false); //the player on the wheel clears the cardplayers[(Termcurrentindex + players.length-1) %3].        Dropallsmallcards ();        Setnextplayer (); Players[termcurrentindex].    Tofollowing (); }
Code Grooming

Now our code has a certain size, in order to facilitate better management, the existing code re-organized, and functional classification, such as:

Summarize

Well, so far today, we have to test the verification, of course, the current only to achieve the function of the card, there is no card to check the force and the control of the card, the opponent players randomly simulated cards, has not joined the AI. We will gradually come to realize ~ to see the effect of this period ~

Resources

Project Source

Unity3d mobile phone bucket landlord game development Combat (03) _ Landlord card display and card logic (not regularly updated in ~ ~ ~)

Related Article

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.