Exemplo n.º 1
0
        public bool salvarDadosObj(string _id, string _nome, DateTime _dataIniciar, DateTime _dataExpiracao, bool ativo, Dictionary <string, object> _listaMiniGames)
        {
            ObjectId      objToFind = new ObjectId();
            ObjetivoModel objModel  = new ObjetivoModel();

            try
            {
                var _obj = _db.GetCollection <ObjetivoModel>("Objetivo");

                if (_id != null && _id != "")
                {
                    objToFind = new ObjectId(_id);

                    objModel = _obj.AsQueryable().Where(c => c._id.Equals(objToFind)).FirstOrDefault <ObjetivoModel>();
                }


                if (objModel != null && objModel._id.Contains(_id))
                {
                    var update = Builders <ObjetivoModel>
                                 .Update
                                 .Set(u => u.nome, _nome)
                                 .Set(u => u.dataCadastro, objModel.dataCadastro)
                                 .Set(u => u.dataAlteracao, new Utils().convertDatePtBr(DateTime.Now.ToLocalTime()))
                                 .Set(u => u.dataIniciar, new Utils().convertDatePtBr(_dataIniciar))
                                 .Set(u => u.dataExpiracao, new Utils().convertDatePtBr(_dataExpiracao))
                                 .Set(u => u.ativo, ativo);

                    var result = _obj.UpdateOne <ObjetivoModel>(u => u._id.Equals(objToFind), update);


                    return(true);
                }
                else
                {
                    objModel.nome          = _nome;
                    objModel.dataIniciar   = _dataIniciar;
                    objModel.dataExpiracao = _dataExpiracao;
                    objModel.ativo         = ativo;

                    foreach (dynamic dmg in _listaMiniGames)
                    {
                        dynamic       mg      = dmg.Value;
                        MiniGameModel dadosMg = new MiniGameModel(mg.id + " - " + mg.nome, true, mg.parametroObjCompletado, mg.vlrCashIn);

                        objModel.adicionaNaListaMiniGame(dadosMg);
                    }

                    objModel.listaMiniGames = objModel.retornaListaMiniGame();

                    _obj.InsertOne(objModel);

                    return(true);
                }
            }
            catch (Exception xp)
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        public void Initialize()
        {
            BallsContainerInstance = Instantiate(
                _ballsContainerPrefab,
                GameManager.Instance.UserInterfaceManager.CanvasInstance.transform);

            var interactableBlueprints = BallsContainerInstance.Instances.Select(x =>
                                                                                 x.GetComponent <IInteractable>()).ToList();

            _miniGameModel = new MiniGameModel(_startStepsCount, _finishStepsCount, interactableBlueprints);

            Subscribe();

            Debug.Log($"Mini game is started");

            RestartPlayingOfNextUnPlayedSequence();
        }
Exemplo n.º 3
0
        private double validaTempoJogando(MiniGameModel objValores)
        {
            double        diffInSeconds   = 0.0;
            MiniGameModel objTrataValores = objValores;

            string objId         = (string)objTrataValores._id;
            double secondsTarget = objTrataValores.targetForPayment;

            diffInSeconds = (new Utils().convertDatePtBr(DateTime.Now.ToLocalTime()) - objTrataValores.objDataFinalizado.ToLocalTime()).TotalSeconds;

            if (diffInSeconds <= 60)
            {
                diffInSeconds = objTrataValores.objTempoJogando + (new Utils().convertDatePtBr(DateTime.Now.ToLocalTime()) - objTrataValores.objDataFinalizado.ToLocalTime()).TotalSeconds;
            }
            else
            {
                diffInSeconds = objTrataValores.objTempoJogando;
            }

            return(diffInSeconds);
        }
        //page that executes minigame script, set MiniGame model
        public ActionResult MiniGame()
        {
            MiniGameModel   model     = new MiniGameModel();
            Random          random    = new Random();
            List <MiniGame> minigames = new List <MiniGame>();

            if (User.Identity.IsAuthenticated)
            {
                Options profileSettings = _options.Get((int)Session["profileID"]);
                int     catID           = 0; //category id

                //get subject filter for profile, if no filter, randomly choose a subject for minigame
                if (profileSettings.SubjectFilter == "Reading")
                {
                    catID = 1;
                }
                else if (profileSettings.SubjectFilter == "Math")
                {
                    catID = 2;
                }
                else
                {
                    catID = random.Next(1, 3); //no subject filter, randomly choose a minigame category
                }
                //get a list of minigames that adheres to subject filter and difficulty level
                if (catID == 1)
                {
                    minigames        = _minigame.GetListPlayable(catID, profileSettings.ReadingDifficultyLevel); //catID, difficulty level
                    model.Difficulty = profileSettings.ReadingDifficultyLevel;                                   //difficult level for model
                }
                else if (catID == 2)
                {
                    minigames        = _minigame.GetListPlayable(catID, profileSettings.MathDifficultyLevel); //catID, difficulty level
                    model.Difficulty = profileSettings.MathDifficultyLevel;                                   //difficulty level for model
                }
                //get list or recently played minigames
                List <int> playedgames = _minigame.GetListRecentlyPlayed((int)Session["profileID"]);

                //randomly choose a minigame that isn't in list of recently played, assign a minigame to the model
                int ranGame = random.Next(0, minigames.Count()); //generate an index between 1 and num of playable games

                //continue generating random gameID while recently played game is randomly selected
                bool played      = true;
                int  loopCounter = 0;
                while (played == true)
                {
                    played = false;
                    for (int i = 0; i < playedgames.Count(); i++)
                    {
                        if (minigames[ranGame].ID == playedgames[i])
                        {
                            //generate an index between 0 and num of playable games
                            ranGame = random.Next(0, minigames.Count());
                            played  = true;
                        }
                    }
                    loopCounter++;         //increment number of times through loop
                    if (loopCounter >= 50) //Ensure that game doesn't get stuck in endless loop if not enough minigames
                    {
                        played = false;
                    }

                    //choose a different minigame if device is mobile and chosen game isn't mobile friendly
                    //letter sound racing, typing, tangram
                    if (DetectMobile() && (minigames[ranGame].ID == 18 || minigames[ranGame].ID == 19 ||
                                           minigames[ranGame].ID == 4))
                    {
                        played = true;
                    }

                    //if the browser isn't chrome and tangram is played
                    if (!IsBrowserChrome() && minigames[ranGame].ID == 19)
                    {
                        played = true;
                    }
                }
                model.MiniGameID = minigames[ranGame].ID;
                model.CategoryID = minigames[ranGame].MiniGameCategoryID;
                model.MiniGame   = minigames[ranGame].MiniGamePath;
            }
            else                                                 //free play mode
            {
                minigames = _minigame.GetAllMinigames();         //get a list of all minigames from database

                int ranGame = random.Next(0, minigames.Count()); //generate an index between 0 and num of games

                //choose a different minigame if device is mobile and chosen game isn't mobile friendly
                //letter sound racing, typing, tangram
                while ((DetectMobile() && (minigames[ranGame].ID == 18 || minigames[ranGame].ID == 19 ||
                                           minigames[ranGame].ID == 4)) || (!IsBrowserChrome() && minigames[ranGame].ID == 19))
                {
                    ranGame = random.Next(0, minigames.Count()); //generate an index between 0 and num of games
                }

                model.MiniGameID = minigames[ranGame].ID;
                model.MiniGame   = minigames[ranGame].MiniGamePath;
                model.CategoryID = minigames[ranGame].MiniGameCategoryID;
                model.CategoryID = minigames[ranGame].MiniGameCategoryID;
                model.Difficulty = 0;                                           //difficulty doesn't apply to free play mode
            }
            model.ToggleSound = Convert.ToString((bool)Session["toggleSound"]); //set model's toggle value for sound
            model.ToggleMusic = Convert.ToString((bool)Session["toggleMusic"]); //set model's toggle value for music

            return(View(model));
        }
Exemplo n.º 5
0
        private bool persistirBancoDeDados(string infoDoc, string infoObj)
        {
            string codMiniGame = string.Empty;
            bool   resp        = false;

            try
            {
                startModelo();
                var _obj = _db.GetCollection <ObjetivoMiniGameModel>("ObjetivoIniciado");

                ObjetivoModel dadosObjModel = this.findObjetivoPrincipal(infoObj);

                if (dadosObjModel != null)
                {
                    string nomeObj = infoDoc + "-" + infoObj;
                    ObjetivoMiniGameModel objFound = this.findObjMiniGameInUser(infoDoc, infoObj);

                    if (objFound == null)
                    {
                        objModel.nome = nomeObj;
                        objModel.setUsuarioGame(new UsuarioModel {
                            nome = infoDoc, documento = infoDoc
                        });
                        objModel.setObjetivoGame(dadosObjModel);

                        dynamic dynList = dadosObjModel.retornaListaMiniGame();

                        foreach (dynamic objList in dynList)
                        {
                            dynamic obj = objList;
                            objModel.addMiniGames(objList);
                        }

                        codMiniGame = objModel._id.ToString();
                        _obj.InsertOne(objModel);

                        resp = true;
                    }


                    var posicaoLista = (objFound != null ? objFound.ListaMiniGames.FindIndex(f => f.nome.Contains(infoObj)) : 0);
                    if (objFound != null && objFound.ativo && resp == false && posicaoLista >= 0)
                    {
                        int posicao = posicaoLista; // objFound.ListaMiniGames.FindIndex(p => p.nome.Contains(infoObj));

                        codMiniGame = objFound._id.ToString();

                        var listaAtualMiniGames = objFound.listarMiniGames();


                        MiniGameModel objTrataValores = listaAtualMiniGames.ElementAt(posicao);

                        if (objTrataValores.ativo && objTrataValores.CashInSent.Equals(false))
                        {
                            string objId         = (string)objTrataValores._id;
                            double secondsTarget = objTrataValores.targetForPayment;
                            double diffInSeconds = this.validaTempoJogando(objTrataValores);


                            var update = Builders <ObjetivoMiniGameModel>
                                         .Update
                                         .Set(u => u.dataCadastro, objFound.dataCadastro)
                                         .Set(u => u.dataAlteracao, new Utils().convertDatePtBr(DateTime.Now.ToLocalTime()))
                                         .Set(u => u.ObjUsr.dataCadastro, objFound.ObjUsr.dataCadastro)
                                         .Set(u => u.ObjUsr.dataAlteracao, new Utils().convertDatePtBr(DateTime.Now.ToLocalTime()))
                                         .Set(u => u.ObjParametros.dataCadastro, objFound.ObjParametros.dataCadastro)
                                         .Set(u => u.ObjParametros.dataAlteracao, new Utils().convertDatePtBr(DateTime.Now.ToLocalTime()))
                                         .Set(u => u.ListaMiniGames.ElementAt(posicao).dataCadastro, objFound.ListaMiniGames.ElementAt(posicao).dataCadastro)
                                         .Set(u => u.ListaMiniGames.ElementAt(posicao).dataAlteracao, new Utils().convertDatePtBr(DateTime.Now.ToLocalTime()))
                                         .Set(u => u.ListaMiniGames.ElementAt(posicao).objDataIniciado, objFound.ListaMiniGames.ElementAt(posicao).objDataIniciado)
                                         .Set(u => u.ListaMiniGames.ElementAt(posicao).objDataFinalizado, new Utils().convertDatePtBr(DateTime.Now.ToLocalTime()))
                                         .Set(u => u.ListaMiniGames.ElementAt(posicao).objTempoJogando, diffInSeconds);

                            var result = _obj.UpdateOne <ObjetivoMiniGameModel>(u => u._id == objFound._id, update);



                            resp = true;
                        }
                    }
                    else if (resp == false && objFound != null && objFound.ativo)
                    {
                        int posicao = posicaoLista; // objFound.ListaMiniGames.FindIndex(p => p.nome.Contains(infoObj));

                        if (posicao >= 0)
                        {
                            codMiniGame = objFound._id.ToString();

                            MiniGameModel objTrataValores = objFound.listarMiniGames().ElementAt(posicao);

                            if (objTrataValores != null && objTrataValores.ativo && objTrataValores.CashInSent.Equals(false))
                            {
                                string objId         = (string)objTrataValores._id;
                                double secondsTarget = objTrataValores.targetForPayment;
                                double diffInSeconds = this.validaTempoJogando(objTrataValores);


                                var update = Builders <ObjetivoMiniGameModel>
                                             .Update
                                             .Set(u => u.dataCadastro, objFound.dataCadastro)
                                             .Set(u => u.dataAlteracao, new Utils().convertDatePtBr(DateTime.Now.ToLocalTime()))
                                             .Set(u => u.ObjUsr.dataCadastro, objFound.ObjUsr.dataCadastro)
                                             .Set(u => u.ObjUsr.dataAlteracao, new Utils().convertDatePtBr(DateTime.Now.ToLocalTime()))
                                             .Set(u => u.ObjParametros.dataCadastro, objFound.ObjParametros.dataCadastro)
                                             .Set(u => u.ObjParametros.dataAlteracao, new Utils().convertDatePtBr(DateTime.Now.ToLocalTime()))
                                             .Set(u => u.ListaMiniGames.ElementAt(posicao).dataCadastro, objFound.ListaMiniGames.ElementAt(posicao).dataCadastro)
                                             .Set(u => u.ListaMiniGames.ElementAt(posicao).dataAlteracao, new Utils().convertDatePtBr(DateTime.Now.ToLocalTime()))
                                             .Set(u => u.ListaMiniGames.ElementAt(posicao).objDataIniciado, objFound.ListaMiniGames.ElementAt(posicao).objDataIniciado)
                                             .Set(u => u.ListaMiniGames.ElementAt(posicao).objDataFinalizado, new Utils().convertDatePtBr(DateTime.Now.ToLocalTime()))
                                             .Set(u => u.ListaMiniGames.ElementAt(posicao).objTempoJogando, diffInSeconds);

                                var result = _obj.UpdateOne <ObjetivoMiniGameModel>(u => u._id == objFound._id, update);

                                resp = true;
                            }
                        }
                        else
                        {
                            var listaAtualMiniGames = dadosObjModel.retornaListaMiniGame(); // objFound.listarMiniGames();

                            MiniGameModel novoMiniGame = new MiniGameModel();

                            foreach (dynamic objList in listaAtualMiniGames)
                            {
                                novoMiniGame = new MiniGameModel {
                                    nome = objList.nome, ativo = true, targetForPayment = objList.targetForPayment, CashPayment = objList.CashPayment
                                };
                                objModel.addMiniGames(novoMiniGame);
                            }

                            List <MiniGameModel> novaListaMiniGames = objModel.listarMiniGames();

                            var update = Builders <ObjetivoMiniGameModel>
                                         .Update
                                         .Set(u => u.dataCadastro, objFound.dataCadastro)
                                         .Set(u => u.dataAlteracao, new Utils().convertDatePtBr(DateTime.Now.ToLocalTime()))
                                         .Set(u => u.ObjUsr.dataCadastro, objFound.ObjUsr.dataCadastro)
                                         .Set(u => u.ObjUsr.dataAlteracao, objFound.ObjUsr.dataCadastro)
                                         .Set(u => u.ObjParametros.dataCadastro, objFound.ObjParametros.dataCadastro)
                                         .Set(u => u.ObjParametros.dataAlteracao, new Utils().convertDatePtBr(DateTime.Now.ToLocalTime()))
                                         .Push(p => p.ListaMiniGames, novoMiniGame);

                            var result = _obj.UpdateOne <ObjetivoMiniGameModel>(u => u._id == objFound._id, update);

                            resp = true;
                        }
                    }

                    if (resp == true)
                    {
                        this.validaDefineObjetivoConcluido(infoDoc, codMiniGame);
                    }
                }


                return(resp);
            }
            catch (Exception xp)
            {
                return(false);
            }
        }