예제 #1
0
파일: TankGame.cs 프로젝트: Stran6/TankGame
        protected override void Initialize()
        {
            this.Window.Title = "Tank Diggity";

            uiManager = new UIManager(this);
            Components.Add(uiManager);

            screenManager = new ScreenManager(this);
            Components.Add(screenManager);

            soundManager = new SoundManager(this);
            Components.Add(soundManager);
            
            tankPos = new Vector2(60, 785);
            turretPos = new Vector2(tankPos.X + 45, tankPos.Y + 25);
            player1Tank = new Tank(this, tankPos,(float)Math.PI / 2);
            Components.Add(player1Tank);

            tankPos2 = new Vector2(2048 - 140, 785);
            turretPos2 = new Vector2(tankPos2.X + 45, tankPos.Y + 10);
            player2Tank = new Tank(this, tankPos2,-(float)Math.PI / 2);
            Components.Add(player2Tank);

            currentTank = player1Tank;

            camera = new Camera2d(graphics.GraphicsDevice);

            background = new Background(this);
            Components.Add(background);          

            powerUpManager = new PowerUpManager(this);
            Components.Add(powerUpManager);

            power = 0;

            chargingShot = false;
            chargingShot2 = false;
            shotFired = false;
            shotCollided = false;
            turnOver = false;
            gameRunning = false;
            rightSwap = false;
            leftSwap = false;
            debugGame = false;

            controller = GamePad.GetState(PlayerIndex.One);

            base.Initialize();
        }
예제 #2
0
        /// <summary>
        /// 使用物品
        /// </summary>
        /// <param name="Id">Identifier.</param>
        public void UseItem(int id)
        {
            db = OpenDb();
            string           itemId   = "";
            ItemType         type     = ItemType.None;
            int              num      = 0;
            SqliteDataReader sqReader = db.ExecuteQuery("select ItemId, Type, Num from BagTable where Id = " + id);

            if (sqReader.Read())
            {
                itemId = sqReader.GetString(sqReader.GetOrdinal("ItemId"));
                type   = (ItemType)sqReader.GetInt32(sqReader.GetOrdinal("Type"));
                num    = sqReader.GetInt32(sqReader.GetOrdinal("Num"));
            }
            db.CloseSqlConnection();
            if (type != ItemType.None && num > 0)
            {
                ItemData item;
                switch (type)
                {
                case ItemType.Food:
                    if (UserModel.CurrentUserData.PositionStatu == UserPositionStatusType.InArea)
                    {
                        Eat(id, num);
                        SoundManager.GetInstance().PushSound("ui0004");
                    }
                    else
                    {
                        AlertCtrl.Show("野外闯荡江湖时才能吃干粮");
                    }
                    break;

                case ItemType.Weapon:
                    item = JsonManager.GetInstance().GetMapping <ItemData>("ItemDatas", itemId);
                    if (AddNewWeapon(item.StringValue, ""))
                    {
                        WeaponData weapon = JsonManager.GetInstance().GetMapping <WeaponData>("Weapons", item.StringValue);
                        Statics.CreatePopMsg(Vector3.zero, string.Format("<color=\"{0}\">{1}</color>+1", Statics.GetQualityColorString(weapon.Quality), weapon.Name), Color.white, 30);

                        //删除兵器盒
                        db = OpenDb();
                        db.ExecuteQuery("delete from BagTable where Id = " + id);
                        db.CloseSqlConnection();
                        //重新加载背包数据
                        GetBagPanelData();
                        SoundManager.GetInstance().PushSound("ui0004");
                    }
                    else
                    {
                        AlertCtrl.Show("兵器匣已满,请先整理兵器匣");
                    }
                    break;

                case ItemType.Book:
                    item = JsonManager.GetInstance().GetMapping <ItemData>("ItemDatas", itemId);
                    BookData book = JsonManager.GetInstance().GetMapping <BookData>("Books", item.StringValue);
                    if (AddNewBook(item.StringValue, ""))
                    {
                        Statics.CreatePopMsg(Vector3.zero, string.Format("<color=\"{0}\">{1}</color>+1", Statics.GetQualityColorString(book.Quality), book.Name), Color.white, 30);

                        //删除秘籍盒
                        db = OpenDb();
                        db.ExecuteQuery("delete from BagTable where Id = " + id);
                        db.CloseSqlConnection();
                        //重新加载背包数据
                        GetBagPanelData();
                        SoundManager.GetInstance().PushSound("ui0004");
                    }
                    else
                    {
                        AlertCtrl.Show(string.Format("你已经习得<color=\"{0}\">{1}</color>, 无需再研读", Statics.GetQualityColorString(book.Quality), book.Name));
                    }
                    break;

                case ItemType.RandomSecre:     //打开随机诀要锦囊
                    item     = JsonManager.GetInstance().GetMapping <ItemData>("ItemDatas", itemId);
                    db       = OpenDb();
                    sqReader = db.ExecuteQuery("select count(*) as num from BookSecretsTable where BelongToRoleId = '" + currentRoleId + "'");
                    bool isSecretsFull = false;
                    if (sqReader.Read())
                    {
                        isSecretsFull = sqReader.GetInt32(sqReader.GetOrdinal("num")) >= MaxSecretNumOfBag;
                    }
                    if (!isSecretsFull)
                    {
                        //添加新的诀要
                        SecretData secret = Statics.CreateNewSecret(Statics.GetRandomSecretType(item.StringValue), QualityType.White);
                        db.ExecuteQuery("insert into BookSecretsTable (SecretData, T, Q, BelongToBookId, BelongToRoleId) values('" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObjectDealVector(secret)) + "', " + ((short)secret.Type) + ", " + ((short)secret.Quality) + ", '', '" + currentRoleId + "')");
                        PlayerPrefs.SetString("AddedNewBookFlag", "true");
                        PlayerPrefs.SetString("AddedNewSecretFlag", "true");
                        Messenger.Broadcast(NotifyTypes.MakeRoleInfoPanelRedPointRefresh);
                        Statics.CreatePopMsg(Vector3.zero, string.Format("<color=\"{0}\">{1}</color>+1", Statics.GetQualityColorString(secret.Quality), secret.Name), Color.white, 30);
                        db.ExecuteQuery("delete from BagTable where Id = " + id);
                        db.CloseSqlConnection();
                        //重新加载背包数据
                        GetBagPanelData();
                        SoundManager.GetInstance().PushSound("ui0004");
                    }
                    else
                    {
                        AlertCtrl.Show(string.Format("诀要背包上限为{0},请先清理背包", MaxSecretNumOfBag));
                    }
                    break;

                default:
                    AlertCtrl.Show("该物品不可使用!");
                    break;
                }
            }
        }
예제 #3
0
        IEnumerator Start()
        {
            if (Instance)
            {
                Destroy(gameObject);
                yield break;
            }
            Instance = this;

            if (DressUpSelecter.Instance)
            {
                HakoData = DressUpSelecter.Instance.Datas[DressUpSelecter.Current];
            }

            DontDestroyOnLoad(gameObject);
            if (SceneName != "")
            {
                yield return(LoadManager.Instance.LoadSceneAsync(SceneName));
            }
            UnityEngine.SceneManagement.SceneManager.MoveGameObjectToScene(gameObject, UnityEngine.SceneManagement.SceneManager.GetActiveScene());
            GameManager.Instance.GameState = GameManager.State.Game;

            SurvivalUI.Instance.Result.SetActive(false);
            Camera.main.orthographicSize = Data.CameraSize;
            yield return(null);

            SurvivalUI.Instance.ScoreDisplay.Value = 0;
            SurvivalUI.Instance.LevelDisplay.Value = 0;
            SurvivalUI.Instance.ModeName           = ModeName;
            while (!HakoManaer.Instance)
            {
                yield return(null);
            }
            HakoManaer.Instance.hakoMaxs = Data.MaxHakos;
            yield return(HakoManaer.Instance.SetupStream(HakoData, Data.Size));

            SurvivalUI.Instance.Meter.Set(HakoData, Data.Size);
            ScreenCurtain.Instance.SetColor(ScreenCurtain.State.Open);
            HakoManaer.Instance.AddHako(HakoType.X, Data.Size / 2);
            SurvivalUI.Instance.Meter.MaxHakos(Data.LevelUpScore[0]);
            SwipeMessage.Play("Ready...", new Vector3(), 56, 0.5f);
            yield return(new WaitForSeconds(1.0f));

            GamePlaying = true;
            SwipeMessage.Play("Go!", new Vector3(), 56, 0.5f);

            while (!Result)
            {
                HakoUpdate();
                yield return(null);

                if (Input.GetKey(KeyCode.Return))
                {
                    AddHakoRandom();
                }
                else
                {
                    yield return(new WaitForSeconds(1.0f));
                }
            }
            SwipeMessage.Play("GameOver!", new Vector3(), 56, 30.0f);
            // SurvivalUI.Instance.UserNameText.text = ScoreManager.Instance.PlayerName;
            SurvivalUI.Instance.UserName = "";
            SurvivalUI.Instance.Result.SetActive(true);
            SoundManager.SEPlay("over");
            UnityEngine.EventSystems.EventSystem.current.SetSelectedGameObject(SurvivalUI.Instance.ExitButton.gameObject);

            // ScoreContent _load = ScoreManager.Instance.LoadScore(ModeName);
            // if(Score > _load.Score)
            // {
            //     SwipeMessage.Play("New Record!", new Vector3(0, -1, 0), 28, 30.0f);
            //     ScoreManager.Instance.SaveScore(ModeName, new ScoreContent(Score));
            // }

            NCMB.HighScore myScore = new NCMB.HighScore(ModeName, ScoreManager.Instance.UserName.Id, ScoreManager.Instance.UserName.Name);
            myScore.fetch();

            for (int i = 0; i < Data.Size.x * Data.Size.y - 10; i++)
            {
                yield return(null);

                AddHakoRandom();
            }

            while (myScore.Score == -1)
            {
                yield return(null);
            }
            if (myScore.Score < Score)
            {
                myScore.Score = Score;
                myScore.Date  = ScoreManager.Instance.DateString();
                myScore.Name  = ScoreManager.Instance.UserName.Name;
                myScore.save();
                SwipeMessage.Play("New Record!", new Vector3(0, -1, 0), 28, 30.0f);
            }

            yield return(new WaitForSeconds(1.0f));

            SurvivalUI.Instance.ScoreButton.interactable = true;
        }
예제 #4
0
        /// <summary>
        /// Scenes the notify init.
        /// </summary>
        public static void SceneNotifyInit()
        {
            Messenger.AddListener <string>(NotifyTypes.GoToScene, (sceneName) => {
                SceneManagerController.GetInstance().ChangeScene(sceneName);
            });

            Messenger.AddListener <string>(NotifyTypes.DealSceneEvent, (eventId) => {
//				EventData eventData = JsonManager.GetInstance().GetMapping<EventData>("AreaEventDatas", eventId);
                EventData eventData = null;
                if (AreaMain.StaticAreaEventsMapping.ContainsKey(eventId))
                {
                    //判断静态事件是否禁用
                    if (!AreaMain.DisableEventIdMapping.ContainsKey(eventId))
                    {
                        eventData = AreaMain.StaticAreaEventsMapping[eventId];
                    }
                }
                else if (AreaMain.ActiveAreaEventsMapping.ContainsKey(eventId))
                {
                    eventData = AreaMain.ActiveAreaEventsMapping[eventId];
                }
                if (eventData != null)
                {
                    string[] fen;
                    switch (eventData.Type)
                    {
                    case SceneEventType.EnterArea:
                        fen = eventData.EventId.Split(new char[] { '_' });
                        if (fen.Length >= 3)
                        {
                            string areaName = fen[0];
                            int x           = int.Parse(fen[1]);
                            int y           = int.Parse(fen[2]);
                            Messenger.Broadcast <string, Vector2, System.Action <UserData> >(NotifyTypes.UpdateUserDataAreaInfo, areaName, new Vector2(x, y), (userData) => {
                                Messenger.Broadcast <string>(NotifyTypes.GoToScene, userData.CurrentAreaSceneName);
                                //清空临时事件
                                Messenger.Broadcast <List <SceneEventType> >(NotifyTypes.ClearDisableEventIdMapping, new List <SceneEventType>()
                                {
                                    SceneEventType.DisablePagoda
                                });
                            });
                        }
                        break;

                    case SceneEventType.Battle:
                    case SceneEventType.Pagoda:
                        Messenger.Broadcast <string>(NotifyTypes.CreateBattle, eventData.EventId);
                        break;

                    case SceneEventType.EnterCity:
                        Messenger.Broadcast <string>(NotifyTypes.UpdateUserDataCityInfo, eventData.EventId);
                        Messenger.Broadcast <System.Action <UserData> >(NotifyTypes.UpdateUserData, (userData) => {
//							Messenger.Broadcast<string>(NotifyTypes.EnterCityScene, userData.CurrentCitySceneId);
                            Messenger.Broadcast <string>(NotifyTypes.EnterCityScene, eventData.EventId);
                        });
                        break;

                    case SceneEventType.Task:
                        Messenger.Broadcast <string>(NotifyTypes.GetTaslDetailInfoData, eventData.EventId);
                        break;

                    case SceneEventType.EatFood:
                        Messenger.Broadcast <int>(NotifyTypes.EatFood, eventData.IntValue);
                        fen = eventData.Id.Split(new char[] { '_' });
                        if (fen.Length >= 3)
                        {
                            string areaName = fen[0];
                            int x           = int.Parse(fen[1]);
                            int y           = int.Parse(fen[2]);
                            //处理静态事件的预禁用操作
                            EventData disableEvent = new EventData();
                            disableEvent.Id        = eventData.Id;
                            disableEvent.Type      = SceneEventType.DisableEvent;
                            disableEvent.X         = x;
                            disableEvent.Y         = y;
                            Messenger.Broadcast <string, EventData>(NotifyTypes.PushDisableEvent, disableEvent.Id, disableEvent);
                        }
                        break;

                    case SceneEventType.Dialog:
                        switch (eventData.EventId)
                        {
                        case "dialog0001":
                            Messenger.Broadcast(NotifyTypes.OpenTowerGuiderPanel);
                            break;

                        default:
                            break;
                        }
                        break;

                    case SceneEventType.Store:
                        DbManager.Instance.GetStoreData(eventData.EventId);
                        break;

                    default:
                        break;
                    }
                }
            });

            Messenger.AddListener(NotifyTypes.FromCitySceneBackToArea, () => {
                if (UserModel.CurrentUserData != null)
                {
                    Messenger.Broadcast <string, Vector2, System.Action <UserData> >(NotifyTypes.UpdateUserDataAreaInfo,
                                                                                     UserModel.CurrentUserData.CurrentAreaSceneName,
                                                                                     new Vector2(UserModel.CurrentUserData.CurrentAreaX, UserModel.CurrentUserData.CurrentAreaY),
                                                                                     (userData) => {
                        UserModel.CurrentFoodNums    = userData.AreaFood.MaxNum;
                        UserModel.CurrentRebornTimes = 0;
                        //播放大地图背景音乐
                        Messenger.Broadcast(NotifyTypes.PlayBgm);
                    }
                                                                                     );
                }
                //清空临时事件
                Messenger.Broadcast <List <SceneEventType> >(NotifyTypes.ClearDisableEventIdMapping, new List <SceneEventType>()
                {
                    SceneEventType.DisablePagoda
                });
            });

            Messenger.AddListener <string>(NotifyTypes.EnterCityScene, (cityId) => {
                DbManager.Instance.CheckEnterCity(cityId);
                DbManager.Instance.GetCitySceneMenuData(cityId);
                Messenger.Broadcast(NotifyTypes.GetTasksInCityScene);
                Messenger.Broadcast(NotifyTypes.MakeTaskListHide);
            });

            Messenger.AddListener(NotifyTypes.GetTasksInCityScene, () => {
                CityScenePanelCtrl.GetTasksInCityScene();
            });

            Messenger.AddListener(NotifyTypes.HideCityScenePanel, () => {
                CityScenePanelCtrl.MakeFadeOut();
            });

            Messenger.AddListener <string>(NotifyTypes.GetStorePanelData, (cityId) => {
                DbManager.Instance.GetStorePanelData(cityId);
            });

            Messenger.AddListener <List <ItemData>, double>(NotifyTypes.GetStorePanelDataEcho, (items, silver) => {
                StorePanelCtrl.Show(items, silver);
            });

            Messenger.AddListener <string>(NotifyTypes.BuyItem, (itemId) => {
                DbManager.Instance.BuyItem(itemId);
            });

            Messenger.AddListener <string, double>(NotifyTypes.BuyItemEcho, (msg, silver) => {
                StorePanelCtrl.MakeBuyItemEcho(msg, silver);
                SoundManager.GetInstance().PushSound("ui0006");
            });

            Messenger.AddListener(NotifyTypes.MakeCheckNewFlags, () => {
                CityScenePanelCtrl.MakeCheckNewFlags();
            });
        }
예제 #5
0
        /// <summary>
        /// 直接用工坊资源结交侠客
        /// </summary>
        /// <param name="id">Identifier.</param>
        public void InviteRoleWithResources(int id)
        {
            ModifyResources();
            bool     invited = false;
            RoleData role    = null;

            db = OpenDb();
            SqliteDataReader sqReader = db.ExecuteQuery("select Id, RoleId, State from RolesTable where Id = " + id);

            if (sqReader.Read())
            {
                role = JsonManager.GetInstance().GetMapping <RoleData>("RoleDatas", sqReader.GetString(sqReader.GetOrdinal("RoleId")));
                RoleStateType state = (RoleStateType)sqReader.GetInt32(sqReader.GetOrdinal("State"));
                if (state == RoleStateType.NotRecruited)
                {
                    //兵器匣里并没有需要的兵器
                    WeaponData          weapon = JsonManager.GetInstance().GetMapping <WeaponData>("Weapons", role.ResourceWeaponDataId);
                    List <ResourceData> needs  = new List <ResourceData>();
                    ResourceData        need;
                    ResourceData        find;
                    for (int i = 0; i < weapon.Needs.Count; i++)
                    {
                        need = weapon.Needs[i];
                        find = needs.Find(item => item.Type == need.Type);
                        if (find == null)
                        {
                            needs.Add(new ResourceData(need.Type, need.Num));
                        }
                        else
                        {
                            find.Num += need.Num;
                        }
                    }
                    sqReader = db.ExecuteQuery("select Id, ResourcesData from WorkshopResourceTable where BelongToRoleId = '" + currentRoleId + "'");
                    List <ResourceData> resources = null;
                    int resourceId = 0;
                    if (sqReader.Read())
                    {
                        resourceId = sqReader.GetInt32(sqReader.GetOrdinal("Id"));
                        string resourcesStr = sqReader.GetString(sqReader.GetOrdinal("ResourcesData"));
                        resourcesStr = resourcesStr.IndexOf("[") == 0 ? resourcesStr : DESStatics.StringDecder(resourcesStr);
                        resources    = JsonManager.GetInstance().DeserializeObject <List <ResourceData> >(resourcesStr);
                    }
                    db.CloseSqlConnection();

                    if (resources != null)
                    {
                        bool   canAdd = true;
                        string msg    = "";
                        for (int i = 0; i < needs.Count; i++)
                        {
                            need = needs[i];
                            find = resources.Find(item => item.Type == need.Type);
                            if (find != null && find.Num >= need.Num)
                            {
                                find.Num -= need.Num;
                            }
                            else
                            {
                                canAdd = false;
                                msg    = string.Format("{0}不足!", Statics.GetResourceName(need.Type));
                                break;
                            }
                        }
                        if (canAdd)
                        {
                            db = OpenDb();
                            db.ExecuteQuery("update WorkshopResourceTable set ResourcesData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(resources)) + "' where Id = " + resourceId);
                            //结交侠客
                            db.ExecuteQuery("update RolesTable set State = " + ((int)RoleStateType.OutTeam) + ", SeatNo = 888 where Id = " + id);
                            invited = true;
                            db.CloseSqlConnection();
                        }
                        else
                        {
                            AlertCtrl.Show(msg, null);
                        }
                    }
                }
                else
                {
                    AlertCtrl.Show("你们已经结识!", null);
                }
            }
            db.CloseSqlConnection();
            if (invited && role != null)
            {
                Statics.CreatePopMsg(Vector3.zero, string.Format("你与<color=\"#FFFF00\">{0}</color>撮土为香,结成八拜之交!", role.Name), Color.white, 30);
                GetRolesOfWinShopPanelData(role.HometownCityId);
                SoundManager.GetInstance().PushSound("ui0010");
            }
        }