Example #1
0
 // update ui text & win number
 public void UpdateUI()
 {
     textLine.text     = Slot.Line.ToString();
     textBet.text      = Slot.RealBet.ToString("#0.00");
     textTotalBet.text = Slot.TotalBet.ToString("#0.00");
     Win.ChangeTo(Slot.gameResult.GameWin);
 }
Example #2
0
        public void CapacityCheck()
        {
            int GoldCapacityTotal = BEGround.instance.GetCapacityTotal(PayType.Gold);
            //Debug.Log ("iGoldCapacityTotal:"+GoldCapacityTotal.ToString ());
            int ElixirCapacityTotal = BEGround.instance.GetCapacityTotal(PayType.Elixir);

            //Debug.Log ("ElixirCapacityTotal:"+ElixirCapacityTotal.ToString ());

            Gold.MaxSet(GoldCapacityTotal);
            if (Gold.Target() > GoldCapacityTotal)
            {
                Gold.ChangeTo(GoldCapacityTotal);
            }
            Elixir.MaxSet(ElixirCapacityTotal);
            if (Elixir.Target() > ElixirCapacityTotal)
            {
                Elixir.ChangeTo(ElixirCapacityTotal);
            }

            BEGround.instance.DistributeByCapacity(PayType.Gold, (float)Gold.Target());
            BEGround.instance.DistributeByCapacity(PayType.Elixir, (float)Elixir.Target());
        }
Example #3
0
 public static void Load()
 {
     if (PlayerPrefs.HasKey("MusicVolume"))
     {
         MusicVolume     = PlayerPrefs.GetInt("MusicVolume");
         SoundVolume     = PlayerPrefs.GetInt("SoundVolume");
         StageRunCount   = PlayerPrefs.GetInt("StageRunCount");
         ShowInstruction = PlayerPrefs.GetInt("ShowInstruction");
         float fGold = PlayerPrefs.GetFloat("Credit");
         Gold.ChangeTo(fGold);
         //Debug.Log ("BESetting::Load Gold:"+Gold);
     }
     else
     {
         Save();
         bFirstRun = true;
     }
 }
Example #4
0
        void Start()
        {
            // set range of numbers and type
            BESetting.Gold.AddUIText(textGold);
            Win = new BENumber(BENumber.IncType.VALUE, "#,##0.00", 0, 10000000000, 0);
            Win.AddUIText(textTotalWin);

            //set saved user gold count to slotgame
            Slot.Gold = (float)BESetting.Gold.Target();
            //set win value to zero
            Win.ChangeTo(0);

            UpdateUI();

            //double button show only user win
            btnDouble.gameObject.SetActive(false);
            textInfo.text = "";
        }
Example #5
0
        public void Load()
        {
            string xmlFilePath = BEUtil.pathForDocumentsFile(configFilename);

            if (!File.Exists(xmlFilePath))
            {
                Save();
                bFirstRun = true;
            }
            else
            {
                bFirstRun = false;
            }

            InLoading = true;
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load(xmlFilePath);

            // ####### Encrypt the XML #######
            // If the Xml is encrypted, so this piece of code decrypt it.
            if (xmlDocument.DocumentElement.ChildNodes.Count <= 1)
            {
                if (UseEncryption)
                {
                    string data = BEUtil.Decrypt(xmlDocument.DocumentElement.InnerText);
                    xmlDocument.DocumentElement.InnerXml = data;
                }
            }
            //################################


            if (xmlDocument != null)
            {
                XmlElement  element = xmlDocument.DocumentElement;
                XmlNodeList list    = element.ChildNodes;
                foreach (XmlElement ele in list)
                {
                    if (ele.Name == "ConfigVersion")
                    {
                        ConfigVersion = int.Parse(ele.GetAttribute("value"));
                    }
                    else if (ele.Name == "Time")
                    {
                        DateTime dtNow   = DateTime.Now;
                        DateTime dtSaved = DateTime.Parse(ele.GetAttribute("value"));
                        //Debug.Log ("dtNow:"+dtNow.ToString());
                        //Debug.Log ("dtSaved:"+dtSaved.ToString());
                        TimeSpan timeDelta = dtNow.Subtract(dtSaved);
                        //Debug.Log ("TimeSpan:"+timeDelta.ToString());
                        BETime.timeAfterLastRun = timeDelta.TotalSeconds;
                    }
                    else if (ele.Name == "ExpTotal")
                    {
                        ExpTotal = int.Parse(ele.GetAttribute("value"));
                    }
                    else if (ele.Name == "Gem")
                    {
                        Gem.ChangeTo(double.Parse(ele.GetAttribute("value")));
                    }
                    else if (ele.Name == "Gold")
                    {
                        Gold.ChangeTo(double.Parse(ele.GetAttribute("value")));
                    }
                    else if (ele.Name == "Elixir")
                    {
                        Elixir.ChangeTo(double.Parse(ele.GetAttribute("value")));
                    }
                    else if (ele.Name == "Shield")
                    {
                        Shield.ChangeTo(double.Parse(ele.GetAttribute("value")));
                    }
                    else if (ele.Name == "Building")
                    {
                        int Type  = int.Parse(ele.GetAttribute("Type"));
                        int Level = int.Parse(ele.GetAttribute("Level"));
                        //Debug.Log ("Building Type:"+Type.ToString()+" Level:"+Level.ToString());
                        Building script = BEGround.instance.BuildingAdd(Type, Level);
                        script.Load(ele);
                    }
                    else
                    {
                    }
                }
            }

            InLoading = false;
        }
Example #6
0
        void Update()
        {
            // get delta time from BETime
            float deltaTime = BETime.deltaTime;

            // if user pressed escape key, show quit messagebox
            if (!UIDialogMessage.IsShow() && !isModalShow && Input.GetKeyDown(KeyCode.Escape))
            {
                UIDialogMessage.Show("Do you want to quit this program?", "Yes,No", "Quit?", null, (result) => { MessageBoxResult(result); });
            }

            // if in camera animation
            if (InFade)
            {
                //camera zoom in
                FadeAge += Time.deltaTime * 0.7f;
                if (FadeAge > 1.0f)
                {
                    InFade      = false;
                    FadeAge     = 1.0f;
                    zoomCurrent = 64.0f;                       // 游戏开始时放大倍数(最终值)
                }

                goCameraRoot.transform.position  = Vector3.Lerp(new Vector3(-5.5f, 0, -5), Vector3.zero, FadeAge);
                goCamera.transform.localPosition = Vector3.Lerp(new Vector3(0, 0, -128.0f), new Vector3(0, 0, -64.0f), FadeAge);             // 游戏开始时放大倍数(中间值)
            }

            Exp.Update();
            Gold.Update();
            Elixir.Update();
            Gem.Update();
            Shield.ChangeTo(Shield.Target() - (double)deltaTime);
            Shield.Update();
            HouseInfo.text = BEWorkerManager.instance.GetAvailableWorkerCount().ToString() + "/" + BEGround.instance.GetBuildingCount(1).ToString();

            if (UIDialogMessage.IsShow() || isModalShow)
            {
                return;
            }
            //if(EventSystem.current.IsPointerOverGameObject()) return;

            if (Input.GetMouseButton(0))
            {
                if (EventSystem.current.IsPointerOverGameObject())
                {
                    //Debug.Log("left-click over a GUI element!");
                    return;
                }

                //Click MouseButton
                if (!bInTouch)
                {
                    bInTouch         = true;
                    ClickAfter       = 0.0f;
                    bTemporarySelect = false;
                    Dragged          = false;
                    mousePosOld      = Input.mousePosition;
                    mousePosLast     = Input.mousePosition;
                    vCamRootPosOld   = goCameraRoot.transform.position;

                    //when a building was selected and user drag mouse on the map
                    //check mouse drag start is over selected building or not
                    //if not do not move selected building
                    Ray        ray = Camera.main.ScreenPointToRay(mousePosOld);
                    RaycastHit hit;
                    if (Physics.Raycast(ray, out hit) && (hit.collider.gameObject.tag == "Building"))
                    {
                        MouseClickedBuilding = BuildingFromObject(hit.collider.gameObject);
                    }
                    else
                    {
                        MouseClickedBuilding = null;
                    }

                    //Debug.Log ("Update buildingSelected:"+((buildingSelected != null) ? buildingSelected.name : "none"));
                }
                else
                {
                    //Mouse Button is in pressed
                    //if mouse move certain diatance
                    if (Vector3.Distance(Input.mousePosition, mousePosLast) > 0.01f)
                    {
                        // set drag flag on
                        if (!Dragged)
                        {
                            Dragged = true;

                            // show tile grid 显示建筑物降落网格(亮度变0.3)
                            if ((buildingSelected != null) && (MouseClickedBuilding == buildingSelected))
                            {
                                BETween.alpha(ground.gameObject, 0.1f, 0.0f, 0.3f);
                                //Debug.Log ("ground alpha to 0.1");
                            }
                        }

                        mousePosLast = Input.mousePosition;

                        // if selected building exist
                        if ((buildingSelected != null) && (MouseClickedBuilding == buildingSelected))
                        {
                            Ray   ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                            float enter;
                            xzPlane.Raycast(ray, out enter);
                            Vector3 vTarget = ray.GetPoint(enter);
                            // move selected building
                            buildingSelected.Move(vTarget);
                        }
                        // else camera panning
                        else
                        {
                            if (camPanningUse)
                            {
                                Vector3 vDelta   = (Input.mousePosition - mousePosOld) * 0.008f;
                                Vector3 vForward = goCameraRoot.transform.forward;      vForward.y = 0.0f; vForward.Normalize();
                                Vector3 vRight   = goCameraRoot.transform.right;          vRight.y = 0.0f; vRight.Normalize();
                                Vector3 vMove    = -vForward * vDelta.y + -vRight * vDelta.x;
                                goCameraRoot.transform.position = vCamRootPosOld + vMove;
                            }
                        }
                    }
                    // Not Move
                    else
                    {
                        if (!Dragged)
                        {
                            ClickAfter += Time.deltaTime;
                            if (!bTemporarySelect && (ClickAfter > 0.5f))
                            {
                                bTemporarySelect = true;
                                //Debug.Log ("Update2 buildingSelected:"+((buildingSelected != null) ? buildingSelected.name : "none"));
                                Pick();
                            }
                        }
                    }
                }
            }
            else
            {
                //Release MouseButton
                if (bInTouch)
                {
                    bInTouch = false;

                    // if in drag state
                    if (Dragged)
                    {
                        // seleted building exist
                        if (buildingSelected != null)
                        {
                            // hide tile grid
                            if (MouseClickedBuilding == buildingSelected)
                            {
                                BETween.alpha(ground.gameObject, 0.1f, 0.3f, 0f);
                            }

                            if (buildingSelected.Landable && buildingSelected.OnceLanded)
                            {
                                BuildingLandUnselect();
                            }
                        }
                    }
                    else
                    {
                        if (bTemporarySelect)
                        {
                            // land building
                            if ((buildingSelected != null) && (MouseClickedBuilding != buildingSelected) && buildingSelected.OnceLanded)
                            {
                                BuildingLandUnselect();
                            }
                        }
                        else
                        {
                            // land building
                            if ((buildingSelected != null) && (MouseClickedBuilding != buildingSelected) && buildingSelected.OnceLanded)
                            {
                                BuildingLandUnselect();
                            }

                            //Debug.Log ("Update3 buildingSelected:"+((buildingSelected != null) ? buildingSelected.name : "none"));
                            Pick();
                        }
                    }
                }
            }

            //zoom
            if (!InFade)
            {
                zoomCurrent -= Input.GetAxis("Mouse ScrollWheel") * zoomSpeed;
                zoomCurrent  = Mathf.Clamp(zoomCurrent, zoomMin, zoomMax);
                goCamera.transform.localPosition = new Vector3(0, 0, -zoomCurrent);
            }

            // pinch zoom for mobile touch input
            if (Input.touchCount == 2)
            {
                // Store both touches.
                Touch touchZero = Input.GetTouch(0);
                Touch touchOne  = Input.GetTouch(1);

                // Find the position in the previous frame of each touch.
                Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
                Vector2 touchOnePrevPos  = touchOne.position - touchOne.deltaPosition;

                // Find the magnitude of the vector (the distance) between the touches in each frame.
                float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
                float touchDeltaMag     = (touchZero.position - touchOne.position).magnitude;

                // Find the difference in the distances between each frame.
                float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;

                zoomCurrent += deltaMagnitudeDiff * perspectiveZoomSpeed;
                zoomCurrent  = Mathf.Clamp(zoomCurrent, zoomMin, zoomMax);
                goCamera.transform.localPosition = new Vector3(0, 0, -zoomCurrent);
            }
        }