Exemplo n.º 1
0
        public GameViewModel()
        {
            ReadyCommand        = new Command(ReadyCommandExcute);
            BackCommand         = new Command(BackCommandExcute);
            RestartCommand      = new Command(RestartCommandExcute);
            LaunchCommand       = new Command(LaunchCommandExcute);
            PlayCommand         = new Command(PlayCommandExcute);
            TimeDifferencesList = new List <double>();
            stopwatch           = new Stopwatch();

            DrawLevels();
            MessagingCenter.Subscribe <NextPopupViewModel>(this, "nextLevel", (sender) =>
            {
                JumpButtonText            = "Hold";
                JumpButtonBackgroundColor = Color.FromHex("#E8A24F");
                JumpButtonBorderColor     = Color.FromHex("#4F3824");
                LevelNumber  = Preferences.Get("levelNumber", 1) + 1;
                LevelTime   += 1;
                LaunchText   = "Hold for " + LevelTime + " seconds and release to launch parachute";
                IsRestarting = true;
                foreach (var item in DotsList)
                {
                    if (item.LevelNumber == LevelNumber.ToString())
                    {
                        item.IsCompleted     = true;
                        item.BackgroundColor = Color.FromHex("#C5C5C5");
                    }
                }
            });
            MessagingCenter.Subscribe <RestartPopupViewModel>(this, "restartGame", (sender) =>
            {
                LevelNumber = 1;
                CheckLevelTime();
                IsRestarting = false;
                DrawLevels();
            });
            MessagingCenter.Subscribe <LoseViewModel>(this, "tryAgain", (sender) =>
            {
                JumpButtonText            = "Hold";
                JumpButtonBackgroundColor = Color.FromHex("#E8A24F");
                JumpButtonBorderColor     = Color.FromHex("#4F3824");
                LaunchText = "Hold for " + LevelTime + " seconds and release to launch parachute";
            });
            //this part for check level and add level time according to choosen difficulity
            CheckLevelTime();
            PageTitle = "GamePage";
            Analytics.TrackEvent("Page", new Dictionary <string, string> {
                { "Value", PageTitle }
            });
            CheckMusicIsPlaying();
        }
Exemplo n.º 2
0
        private void CheckLevelTime()
        {
            var x = Preferences.Get("levelNumber", 1);

            if ((Preferences.Get("levelNumber", 1) == 1))
            {
                LevelNumber  = 1;
                IsRestarting = (LevelNumber == 1) ? false : true;
                var difficulitylevel = Preferences.Get("difficulty", Difficulty.Easy.ToString());
                if (difficulitylevel == (Difficulty.Easy.ToString()))
                {
                    LevelTime = 5;
                }
                else if (difficulitylevel == Difficulty.Medium.ToString())
                {
                    LevelTime = 10;
                }
                else
                {
                    LevelTime = 15;
                }
            }
            else
            {
                LevelNumber = 1;
                LevelTime   = 5;
            }
            JumpButtonText            = "Hold";
            JumpButtonBackgroundColor = Color.FromHex("#E8A24F");
            JumpButtonBorderColor     = Color.FromHex("#4F3824");
            LaunchText = "Hold for " + LevelTime + " seconds and release to launch parachute";
            foreach (var item in DotsList)
            {
                if (item.LevelNumber == LevelNumber.ToString())
                {
                    item.IsCompleted     = true;
                    item.BackgroundColor = Color.FromHex("#C5C5C5");
                }
            }
        }
Exemplo n.º 3
0
        private void Parse(string content)
        {
            if (string.IsNullOrEmpty(content))
            {
                return;
            }

            foreach (string line in content.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries))
            {
                if (line.Contains("="))
                {
                    string[] values = line.Split('=');

                    if (values.Length < 2)
                    {
                        continue;
                    }

                    if (values[0] == "completed")
                    {
                        Completed = int.Parse(values[1]) == 1;
                    }

                    if (values[0] == "date")
                    {
                        SavedAt = DateTime.Now;
                        if (int.TryParse(values[1], out var unix))
                        {
                            SavedAt = DateTimeOffset.FromUnixTimeSeconds(unix).LocalDateTime;
                        }

                        // For folder name
                        DateTimeSafe = SavedAt.ToString("yyyy-MM-dd HH.mm.ss");

                        // For list view
                        DateTimeString = SavedAt.ToString("yyyy-MM-dd HH:mm:ss");
                    }

                    if (values[0] == "difficulty")
                    {
                        Difficulty = int.Parse(values[1]);
                        DiffToString(Difficulty);
                    }

                    if (values[0] == "mapDesc")
                    {
                        MapDesc = values[1];
                    }

                    if (values[0] == "mapName")
                    {
                        MapName = values[1];
                    }

                    if (values[0] == "time")
                    {
                        PlayedTime = new TimeSpan(0, 0, int.Parse(values[1]));
                    }
                }
            }

            if (MapDesc != "")
            {
                MapSafe = MapDesc;
            }

            foreach (char invalidPathChar in System.IO.Path.GetInvalidPathChars())
            {
                MapSafe = MapSafe.Replace(invalidPathChar, ' ');
            }

            LevelNumber = MapComparer.MapNameToLevel(MapName);
            if (LevelNumber > 0)
            {
                MapSafe = LevelNumber.ToString().PadRight(2) + " - " + MapSafe;
            }
        }
Exemplo n.º 4
0
 public void CheckHeroCollisions()
 {
     for (int i = 0; i < Masks.Count; i++)
     {
         if (Hero.CheckMask(Masks[i]))
         {
             Masks.Remove(Masks[i]);
         }
     }
     for (int i = 0; i < Disinfectants.Count; i++)
     {
         if (Hero.CheckDisinfectant(Disinfectants[i]))
         {
             Disinfectants.Remove(Disinfectants[i]);
             ++Points;
         }
     }
     if (!Hero.IsMasked)
     {
         for (int i = 0; i < SickPersons.Count; i++)
         {
             if (Hero.CheckSickPerson(SickPersons[i]))
             {
                 SickPersons.Remove(SickPersons[i]);
                 ChangeHearts();
             }
             if (Hero.Lives == 0)
             {
                 IsEnabled = false;
                 CustomMessageBox cmb = new CustomMessageBox();
                 cmb.SetMessage("You lost all your lives. Game over!");
                 cmb.SetRetryButton(true);
                 cmb.Show();
                 break;
             }
         }
     }
     if (Hero.CheckDarkness(Darkness))
     {
         IsEnabled = false;
         CustomMessageBox cmb = new CustomMessageBox();
         cmb.SetMessage("The darkness caught you. Game over!");
         cmb.SetRetryButton(true);
         cmb.Show();
     }
     if (Goal.IsEnabled && Hero.CheckGoal(Goal))
     {
         IsEnabled = false;
         ++Game.CurrentLevel;
         if (LevelNumber < 5)
         {
             CustomMessageBox cmb = new CustomMessageBox();
             cmb.SetMessage(string.Format("Level {0} finished. Good job!", LevelNumber.ToString()));
             cmb.SetRetryButton(false);
             cmb.Show();
         }
         else
         {
             CustomMessageBox cmb = new CustomMessageBox();
             cmb.SetMessage("Game finished. Congratulations!");
             cmb.SetRetryButton(false);
             cmb.Show();
         }
     }
     if (!Goal.IsEnabled && Points >= RequiredPoints)
     {
         Goal.Enable();
     }
 }