示例#1
0
    //this method signature means swap
    public void PerformMyDecision(Mask myMaskToSwap, Individual swapW)
    {
        if (myMaskList.Count > 0 && swapW.myMaskList.Count > 0 && myMaskToSwap.MyOwner.Index != swapW.Index)
        {
            //Debug.Log ("Performing a swap decision. " + Index);
            int myRand    = Random.Range(0, myMaskList.Count);
            int theirRand = Random.Range(0, swapW.myMaskList.Count);

            Individual orig_parent = myMaskToSwap.MyOwner;
            if (swapW.Index == Index)
            {
                //Debug.Log ("I'm swapping WITH MYSELF!!");
            }

            if (GameManager.instance.TurnPosition == 0)
            {
                //Debug.Log ("Swap on turn position = " + GameManager.instance.TurnPosition);
                //mySwapMask = myMaskToSwap;
                myRand = myMaskList.IndexOf(myMaskToSwap);
            }

            //first store both the masks to be swapped in temp variables
            Mask myPotentialMaskToSwap    = myMaskList [myRand];
            Mask theirPotentialMaskToSwap = swapW.myMaskList [theirRand];

            myMaskList.Remove(myPotentialMaskToSwap);
            swapW.myMaskList.Remove(theirPotentialMaskToSwap);


            myMaskList.Insert(myRand, theirPotentialMaskToSwap);
            swapW.myMaskList.Insert(theirRand, myPotentialMaskToSwap);

            //tell me everything in my list
            foreach (Mask msk in myMaskList)
            {
                //Debug.Log (" my Mask List after INSERT"+ msk.MyMaskType);
                switch (msk.MyMaskType)
                {
                case MaskType.Attack:
                    msk.GetComponent <Image>().sprite = msk.myPossibleMaskImages[0];
                    break;

                case MaskType.Defend:
                    msk.GetComponent <Image>().sprite = msk.myPossibleMaskImages[1];
                    break;

                case MaskType.Switch:
                    msk.GetComponent <Image>().sprite = msk.myPossibleMaskImages[2];

                    break;

                default:
                    break;
                }
            }
            foreach (Mask msk in swapW.myMaskList)
            {
                //Debug.Log (" their mask list after INSERT " + msk.MyMaskType);
                //tell me everything in their list
                switch (msk.MyMaskType)
                {
                case MaskType.Attack:
                    msk.GetComponent <Image>().sprite = msk.myPossibleMaskImages[0];
                    break;

                case MaskType.Defend:
                    msk.GetComponent <Image>().sprite = msk.myPossibleMaskImages[1];
                    break;

                case MaskType.Switch:
                    msk.GetComponent <Image>().sprite = msk.myPossibleMaskImages[2];
                    break;

                default:
                    break;
                }
            }
            //Set the new parent
            theirPotentialMaskToSwap.gameObject.transform.SetParent(orig_parent.transform, false);
            theirPotentialMaskToSwap.gameObject.GetComponent <RectTransform>().localPosition = new Vector3(0, 0, 0);
            theirPotentialMaskToSwap.MyOwner = orig_parent;

            //Debug.Log ("*******Their mask to swap OWNER= "+theirPotentialMaskToSwap.MyOwner.Index );
            myPotentialMaskToSwap.gameObject.transform.SetParent(swapW.transform, false);
            myPotentialMaskToSwap.gameObject.GetComponent <RectTransform>().localPosition = new Vector3(0, 0, 0);
            myPotentialMaskToSwap.MyOwner = swapW;
            //Debug.Log ("********MY mask to swap OWNER= "+myPotentialMaskToSwap.MyOwner.Index );

            if (myMaskList[myMaskList.Count - 1] == null)
            {
                myMaskList.RemoveAt(myMaskList.Count - 1);
            }

            if (swapW.myMaskList[swapW.myMaskList.Count - 1] == null)
            {
                swapW.myMaskList.RemoveAt(swapW.myMaskList.Count - 1);
            }

            foreach (Mask msk in myMaskList)
            {
                if (msk == null)
                {
                    myMaskList.Remove(msk);
                }
            }

            foreach (Mask msk in swapW.myMaskList)
            {
                if (msk == null)
                {
                    swapW.myMaskList.Remove(msk);
                }
            }

            CheckPlayerState();
            swapW.CheckPlayerState();
            DisplayOnlyTopMask();
            swapW.DisplayOnlyTopMask();
        }
        else
        {
            //Debug.Log ("Passing on a swap Decision because SOMEONE DOES NOT HAVE ENOUGH MASKS. " + Index);
            PerformMyDecision();
        }
    }
示例#2
0
  //this method signature means swap
  public void PerformMyDecision (Mask myMaskToSwap, Individual swapW)
  {
    if (myMaskList.Count > 0 && swapW.myMaskList.Count > 0 && myMaskToSwap.MyOwner.Index != swapW.Index) {
      //Debug.Log ("Performing a swap decision. " + Index);
      int myRand = Random.Range (0, myMaskList.Count);
      int theirRand = Random.Range (0, swapW.myMaskList.Count);

      Individual orig_parent = myMaskToSwap.MyOwner;
      if (swapW.Index == Index) {
        //Debug.Log ("I'm swapping WITH MYSELF!!");
      }

      if (GameManager.instance.TurnPosition == 0) {
        //Debug.Log ("Swap on turn position = " + GameManager.instance.TurnPosition);
        //mySwapMask = myMaskToSwap;
        myRand = myMaskList.IndexOf (myMaskToSwap);
      } 

      //first store both the masks to be swapped in temp variables
      Mask myPotentialMaskToSwap = myMaskList [myRand];
      Mask theirPotentialMaskToSwap = swapW.myMaskList [theirRand];

      myMaskList.Remove (myPotentialMaskToSwap);
      swapW.myMaskList.Remove (theirPotentialMaskToSwap); 


      myMaskList.Insert (myRand, theirPotentialMaskToSwap);
      swapW.myMaskList.Insert (theirRand, myPotentialMaskToSwap);

      //tell me everything in my list
      foreach(Mask msk in myMaskList){
        //Debug.Log (" my Mask List after INSERT"+ msk.MyMaskType);
        switch(msk.MyMaskType){
        case MaskType.Attack:
          msk.GetComponent<Image>().sprite = msk.myPossibleMaskImages[0];
          break;
        case MaskType.Defend:
          msk.GetComponent<Image>().sprite = msk.myPossibleMaskImages[1];
          break;
        case MaskType.Switch:
          msk.GetComponent<Image>().sprite = msk.myPossibleMaskImages[2];

          break;
        default:
          break;
        }
      }
      foreach(Mask msk in swapW.myMaskList){
        //Debug.Log (" their mask list after INSERT " + msk.MyMaskType);
        //tell me everything in their list
          switch(msk.MyMaskType){
          case MaskType.Attack:
            msk.GetComponent<Image>().sprite = msk.myPossibleMaskImages[0];
            break;
          case MaskType.Defend:
            msk.GetComponent<Image>().sprite = msk.myPossibleMaskImages[1];
            break;
          case MaskType.Switch:
            msk.GetComponent<Image>().sprite = msk.myPossibleMaskImages[2];
            break;
          default:
            break;
        }
      }
      //Set the new parent
      theirPotentialMaskToSwap.gameObject.transform.SetParent (orig_parent.transform, false);
      theirPotentialMaskToSwap.gameObject.GetComponent<RectTransform>().localPosition = new Vector3(0,0,0);
      theirPotentialMaskToSwap.MyOwner = orig_parent;

      //Debug.Log ("*******Their mask to swap OWNER= "+theirPotentialMaskToSwap.MyOwner.Index );
      myPotentialMaskToSwap.gameObject.transform.SetParent (swapW.transform, false);
      myPotentialMaskToSwap.gameObject.GetComponent<RectTransform>().localPosition = new Vector3(0,0,0);
      myPotentialMaskToSwap.MyOwner = swapW;
      //Debug.Log ("********MY mask to swap OWNER= "+myPotentialMaskToSwap.MyOwner.Index );

      if(myMaskList[myMaskList.Count-1] == null){
        myMaskList.RemoveAt(myMaskList.Count-1);
      }

      if(swapW.myMaskList[swapW.myMaskList.Count-1] == null){
        swapW.myMaskList.RemoveAt(swapW.myMaskList.Count-1);
      }

      foreach(Mask msk in myMaskList){
        if(msk == null){
          myMaskList.Remove(msk);
        }
      }

      foreach(Mask msk in swapW.myMaskList){
        if(msk == null){
          swapW.myMaskList.Remove(msk);
        }
      }

      CheckPlayerState ();
      swapW.CheckPlayerState ();
      DisplayOnlyTopMask ();
      swapW.DisplayOnlyTopMask ();

    } else {
      //Debug.Log ("Passing on a swap Decision because SOMEONE DOES NOT HAVE ENOUGH MASKS. " + Index);
      PerformMyDecision ();
    }

  }