Esempio n. 1
0
 // ----------------------------------------------------------------------------------------------------------------
 // Begins the Activity specified by @param type.
 // @param type must be a type exisiting in Scar Arcade application.
 // @param valueTwo must be greater than or equal to 0.
 // Overrided method.
 public static void BeginActivity(Context c, Type type, string variableName, int value, string variableTwoName, int valueTwo)
 {
     try
     {
         if (valueTwo >= 0)
         {
             Intent intent = new Intent(c, type);
             if (type != typeof(MainActivity))
             {
                 intent.PutExtra(variableTwoName, valueTwo);
                 intent.PutExtra(variableName, value);
             }
             c.StartActivity(intent);
         }
         else
         {
             throw new Exception();
         }
     }
     catch
     {
         // because an error has happend at the Application level
         // We delegate the responsibility to the GlobalApp class.
         GlobalApp.Alert(c, 2);
     }
 }
        // ----------------------------------------------------------------------------------------------------------------
        // Adds LeaderBoard objects into a List, data will be extracted from @param list.
        // @param list will have been populated with data in the form of Position-Name-Diff-Score-Time
        private static List <LeaderBoard> addLeaderboardObjects(List <string> list, bool isOnline)
        {
            int count = 0;

            if (isOnline)
            {
                count = MAXNUMBEROFONLINESCORES;
            }
            else
            {
                count = MAXNUMBEROFLOCALSCORES;
            }
            // This list will be sorted;
            List <LeaderBoard> temp = new List <LeaderBoard>();

            for (int i = 0; i < count && i < list.Count; i++)
            {
                // Return the data (string) and index i;
                string line = list[i];

                temp.Add(new LeaderBoard
                {
                    lbPosition = Convert.ToInt32(GlobalApp.splitString(line, 0, '-')),
                    lbName     = GlobalApp.splitString(line, 1, '-'),
                    lbScore    = Convert.ToInt32(GlobalApp.splitString(line, 2, '-')),
                    lbDiff     = Convert.ToInt32(GlobalApp.splitString(line, 3, '-')),
                    lbTime     = GlobalApp.splitString(line, 4, '-')
                });
            }
            return(temp);
        }
Esempio n. 3
0
 // ----------------------------------------------------------------------------------------------------------------
 // Event handler
 private void OnTimedEvent(object sender, System.Timers.ElapsedEventArgs e)
 {
     delay--;
     if (delay == 0)
     {
         timer.Dispose();
         GlobalApp.BeginActivity(this, typeof(MainActivity), "", 0);
     }
 }
Esempio n. 4
0
        // ----------------------------------------------------------------------------------------------------------------
        // Predefined method to the create to build the Activity GameMenu.axml executes.
        protected override void OnCreate(Bundle savedInstanceState)
        {
            try
            {
                base.OnCreate(savedInstanceState);
                SetContentView(Resource.Layout.GameMenu);

                FullScreen            = FindViewById <LinearLayout>(Resource.Id.FullScreenLinLay);
                txtGameTitle          = FindViewById <TextView>(Resource.Id.txtGameTitle);
                txtDifficulty         = FindViewById <TextView>(Resource.Id.txtDifficulty);
                btnStart              = FindViewById <Button>(Resource.Id.btnStart);
                btnLeaderBoard        = FindViewById <Button>(Resource.Id.btnLeaderBoard);
                btnBack               = FindViewById <Button>(Resource.Id.btnGameSelect);
                imgBtnIn              = FindViewById <ImageButton>(Resource.Id.imgBtnIncrease);
                imgBtnDe              = FindViewById <ImageButton>(Resource.Id.imgBtnDecrease);
                gameDescription       = FindViewById <TextView>(Resource.Id.description);
                descriptionTitle      = FindViewById <TextView>(Resource.Id.desTextView);
                descriptionBackground = FindViewById <LinearLayout>(Resource.Id.descriptionLinLay);

                // get the index of the item the player has chosen.
                gameChoice = Intent.GetIntExtra(GlobalApp.getVariableChoiceName(), 0);

                game = GameInterface.getGameAt(gameChoice);

                if (game == null)
                {
                    throw new Exception();
                }

                difficulty         = game.gMinDifficulty;
                minDifficulty      = game.gMinDifficulty;
                maxDifficulty      = game.gMaxDifficulty;
                txtDifficulty.Text = String.Format("{0}", difficulty);
                txtGameTitle.Text  = game.gTitle;
                FullScreen.SetBackgroundResource(game.gMenuBackground);
                descriptionBackground.SetBackgroundColor(Color.Gray);

                // Event handlers.
                btnStart.Click       += ButtonClickStart;
                btnBack.Click        += ButtonClickSelect;
                btnLeaderBoard.Click += ButtonClickLeaderboard;
                imgBtnIn.Click       += ImageButtonIncrease;
                imgBtnDe.Click       += ImageButtonDecrease;

                // Add the plus and minus pictures to the two image buttons,
                // that can increase or decrease the difficulty level.
                addPlusAndMinus();

                initializeKeyComponents();
            }
            catch
            {
                GlobalApp.Alert(this, 0);
            }
        }
Esempio n. 5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            try
            {
                base.OnCreate(savedInstanceState);
                SetContentView(Resource.Layout.UserInput);

                saveBtn          = FindViewById <Button>(Resource.Id.saveBtn);
                menuBtn          = FindViewById <Button>(Resource.Id.menuBtn);
                enterNameTxt     = FindViewById <EditText>(Resource.Id.enterNameETxt);
                scoreTxtView     = FindViewById <TextView>(Resource.Id.scoreTxtView);
                timeTxtView      = FindViewById <TextView>(Resource.Id.timeTxtView);
                highScoreTxtView = FindViewById <TextView>(Resource.Id.highScoreTxtView);
                congratTxtView   = FindViewById <TextView>(Resource.Id.congratulationsTxtView);
                chkBoxName       = FindViewById <CheckBox>(Resource.Id.chkBoxPreviousName);
                // Event handlers:
                enterNameTxt.Click += EditTextClick;
                menuBtn.Click      += MenuButtonClick;
                chkBoxName.Click   += CheckBoxClick;
                saveBtn.Click      += SaveButtonClick;

                // Initializing data for the User input.
                enterNameTxt.Text = DEFAULTENTERNAMEHERE;

                string content = Intent.GetStringExtra(GlobalApp.getPlayersScoreVariable());


                // Why starting at index 1? Because the Name will come before the score data.
                string score = GlobalApp.splitString(content, 1, '-');
                string dif   = GlobalApp.splitString(content, 2, '-');
                string time  = GlobalApp.splitString(content, 3, '-');
                scoreTxtView.Text += " " + score;
                timeTxtView.Text  += " " + time;

                chkBoxName.Enabled = !GlobalApp.isNewPlayer();

                // We don't want the checkbox to be auto checked.
                if (chkBoxName.Enabled)
                {
                    chkBoxName.Checked = false;
                }

                checkForNewPositionToLocalAndOnline(score, time, dif);
            }
            catch
            {
                GlobalApp.Alert(this, 0);
            }
        }
Esempio n. 6
0
        // ----------------------------------------------------------------------------------------------------------------
        protected override void OnCreate(Bundle savedInstanceState)
        {
            try
            {
                base.OnCreate(savedInstanceState);
                SetContentView(Resource.Layout.Leaderboard);
                Background          = FindViewById <LinearLayout>(Resource.Id.BackgroundLinLay);
                LeaderBoard         = FindViewById <LinearLayout>(Resource.Id.LeaderBoardLinLay);
                LeaderBoardHeader   = FindViewById <LinearLayout>(Resource.Id.linearLayout1);
                LeaderBoardListView = FindViewById <ListView>(Resource.Id.LeaderBoardListView);
                middleLayout        = FindViewById <LinearLayout>(Resource.Id.MiddleLinLay);
                btnBack             = FindViewById <Button>(Resource.Id.btnGameSelect);
                localBtn            = FindViewById <Button>(Resource.Id.btnLocal);
                onlineBtn           = FindViewById <Button>(Resource.Id.btnOnline);

                var metrics = Resources.DisplayMetrics;
                middleLayout.LayoutParameters = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.MatchParent,
                    (int)(metrics.HeightPixels * 0.75)
                    );

                LeaderBoardListView.Adapter = new LeaderBoardRowAdapter(this, false);

                setBackgroundColorByClick(Color.DarkGray, Color.Gray, false);

                LeaderBoard.SetBackgroundColor(Color.Gray);
                LeaderBoardHeader.SetBackgroundColor(Color.LightGray);

                gameChoice = Intent.GetIntExtra(GlobalApp.getVariableChoiceName(), 0);

                game = GameInterface.getGameAt(gameChoice);

                if (game == null)
                {
                    throw new Exception();
                }

                Background.SetBackgroundResource(game.gMenuBackground);

                // Event handlers.
                btnBack.Click   += ButtonClickSelect;
                localBtn.Click  += ButtonLocalClick;
                onlineBtn.Click += ButtonOnlineClick;
            }
            catch
            {
                GlobalApp.Alert(this, 0);
            }
        }
Esempio n. 7
0
 // ----------------------------------------------------------------------------------------------------------------
 // Predefined method to the create to build the Activity Main.axml executes.
 protected override void OnCreate(Bundle bundle)
 {
     try
     {
         // Bind, and create all Views, and data for the Main.axml
         base.OnCreate(bundle);
         SetContentView(Resource.Layout.Main);
         lvGameList            = FindViewById <ListView>(Resource.Id.lvGameList);
         lvGameList.Adapter    = new MainRowAdapter(this);
         lvGameList.ItemClick += listViewItemClick;
     }
     catch
     {
         GlobalApp.Alert(this, 0);
     }
 }
Esempio n. 8
0
        // ----------------------------------------------------------------------------------------------------------------
        // Add the players score, and saves it into the current storage.
        protected void SaveButtonClick(Object sender, EventArgs args)
        {
            try
            {
                string content = Intent.GetStringExtra(GlobalApp.getPlayersScoreVariable());

                if (GlobalApp.isNewPlayer())
                {
                    if (String.Compare(enterNameTxt.Text, DEFAULTENTERNAMEHERE) == 0)
                    {
                        GlobalApp.setName(DEFAULTNAME);
                        content = DEFAULTNAME + content;
                    }
                    else
                    {
                        GlobalApp.setName(enterNameTxt.Text);
                        content = enterNameTxt.Text + content;
                    }
                }
                else
                {
                    if (String.Compare(enterNameTxt.Text, DEFAULTENTERNAMEHERE) == 0)
                    {
                        GlobalApp.setName(DEFAULTNAME);
                        content = DEFAULTNAME + content;
                    }
                    else
                    {
                        GlobalApp.setName(enterNameTxt.Text);
                        content = enterNameTxt.Text + content;
                    }
                }

                // Now we can add the new score into the local leaderboard.
                // Method: addNewScore will also determine if the score can be added into the Online leaderboard.
                LeaderBoardInterface.addNewScore(content);
            }
            catch
            {
                GlobalApp.Alert(this, 0);
            }
            finally
            {
                GlobalApp.BeginActivity(this, typeof(GameMenuActivity), GlobalApp.getVariableChoiceName(), Intent.GetIntExtra(GlobalApp.getVariableChoiceName(), 0));
            }
        }
Esempio n. 9
0
 protected override void OnCreate(Bundle savedInstanceState)
 {
     try
     {
         base.OnCreate(savedInstanceState);
         base.
         SetContentView(Resource.Layout.Start);
         appLogoImgView = FindViewById <ImageView>(Resource.Id.ApplicationLogoImgView);
         progress       = FindViewById <ProgressBar>(Resource.Id.startProgress);
         Bitmap appLogo = BitmapFactory.DecodeResource(Resources, Resource.Drawable.SCaRARCADE);
         appLogoImgView.SetImageBitmap(appLogo);
         delay = 3;      // Arbitrary number (3 seconds).
         CountDown();
     }
     catch
     {
         GlobalApp.Alert(this, 1);
     }
 }
Esempio n. 10
0
        // ----------------------------------------------------------------------------------------------------------------
        // Determines if the @param scoreStr, and timeStr is a players new high score.
        // All parameters must have been extracted from a players score data (Name-Diff-Score-Time).
        // @timeStr will be in the form of either HH:MM:SS or MM:SS
        public static bool newHighTimeScore(string scoreStr, string timeStr, string difStr)
        {
            int score   = Convert.ToInt32(scoreStr);
            int minutes = 0;
            int seconds = 0;

            // Counts the number of special characters in timeStr,
            // In this case we are counting the number of ":"
            // There will be two if timeStr is in the format of HH:MM:SS
            // Otherwise there will be only one MM:SS
            int count = GlobalApp.findNumberOfCharacters(":", timeStr);

            // What we are determining is if the timeStr has 2 ":";
            // if it does have 2 ":", the format of timeStr is HH:MM:SS
            if (count < 2)
            {
                // First part of the string
                minutes = Convert.ToInt32(GlobalApp.splitString(timeStr, 0, ':'));

                // Second part of the string
                seconds = Convert.ToInt32(GlobalApp.splitString(timeStr, 1, ':'));

                localPosition  = determinePosition(false, score, 0, minutes, seconds);
                onlinePosition = determinePosition(true, score, 0, minutes, seconds);
            }
            else
            {
                // First part of the string
                int hours = Convert.ToInt32(GlobalApp.splitString(timeStr, 0, ':'));

                // Second part of the string
                minutes = Convert.ToInt32(GlobalApp.splitString(timeStr, 1, ':'));

                // Third part of the string
                seconds = Convert.ToInt32(GlobalApp.splitString(timeStr, 2, ':'));

                localPosition  = determinePosition(false, score, hours, minutes, seconds);
                onlinePosition = determinePosition(true, score, hours, minutes, seconds);
            }
            return(localPosition <= MAXNUMBEROFLOCALSCORES || onlinePosition <= MAXNUMBEROFONLINESCORES);
        }
Esempio n. 11
0
 // ----------------------------------------------------------------------------------------------------------------
 // Initializes the data for the Leaderboard Local, and Online.
 // @param isOnline, must be either true, or false.
 private void initializeLeaderboardData(bool isOnline)
 {
     try
     {
         if (isOnline)
         {
             setBackgroundColorByClick(Color.DarkGray, Color.Gray, isOnline);
             if (LeaderBoardInterface.hasInternetConnection())
             {
                 // Delete the current Adpater
                 LeaderBoardListView.Adapter = null;
                 // And store a new one.
                 LeaderBoardListView.Adapter = new LeaderBoardRowAdapter(this, isOnline);
             }
             else
             {
                 // Delete the current Adpater
                 LeaderBoardListView.Adapter = null;
                 // And store a new one.
                 LeaderBoardListView.Adapter = new LeaderBoardRowAdapter(this);
             }
         }
         else
         {
             setBackgroundColorByClick(Color.DarkGray, Color.Gray, isOnline);
             // Delete the current Adpater
             LeaderBoardListView.Adapter = null;
             // And store a new one.
             LeaderBoardListView.Adapter = new LeaderBoardRowAdapter(this, isOnline);
         }
     }
     catch
     {
         GlobalApp.Alert(this, 0);
     }
 }
Esempio n. 12
0
 // ----------------------------------------------------------------------------------------------------------------
 // Event Handler: Will direct the player to the Main menu.
 public override void OnBackPressed()
 {
     // Begin the Main Activity
     GlobalApp.BeginActivity(this, typeof(MainActivity), "", 0);
 }
Esempio n. 13
0
 // ----------------------------------------------------------------------------------------------------------------
 protected void CheckBoxClick(Object sender, EventArgs args)
 {
     // Get the current name of the player.
     enterNameTxt.Text = GlobalApp.getName();
 }
Esempio n. 14
0
 // ----------------------------------------------------------------------------------------------------------------
 // Event Handler: Will direct the user to the Leaderboard.
 protected void ButtonClickLeaderboard(Object sender, EventArgs ev)
 {
     GlobalApp.BeginActivity(this, typeof(LeaderBoardActivity), GlobalApp.getVariableChoiceName(), gameChoice);
 }
Esempio n. 15
0
 // ----------------------------------------------------------------------------------------------------------------
 // Event handler: Determines which item was selected in the list of games
 // and moves to GameMenuActivity.
 private void listViewItemClick(Object sender, AdapterView.ItemClickEventArgs args)
 {
     GlobalApp.BeginActivity(this, typeof(GameMenuActivity), GlobalApp.getVariableChoiceName(), args.Position);
 }
Esempio n. 16
0
 // ----------------------------------------------------------------------------------------------------------------
 protected void MenuButtonClick(Object sender, EventArgs args)
 {
     GlobalApp.BeginActivity(this, typeof(GameMenuActivity), GlobalApp.getVariableChoiceName(), Intent.GetIntExtra(GlobalApp.getVariableChoiceName(), 0));
 }
Esempio n. 17
0
 // ----------------------------------------------------------------------------------------------------------------
 // Returns to the Game Menu Activity of the application.
 protected void ButtonClickSelect(Object sender, EventArgs args)
 {
     GlobalApp.BeginActivity(this, typeof(GameMenuActivity), GlobalApp.getVariableChoiceName(), gameChoice);
 }
Esempio n. 18
0
        // ----------------------------------------------------------------------------------------------------------------
        // Determines the position of the players score, by comparing the time it took to complete the game
        // @params score, hours, minutes, and seconds must be properly extracted from a string.
        private static int determinePosition(bool isOnline, int score, int hours, int minutes, int seconds)
        {
            int currentHours   = 0;
            int currentMinutes = 0;
            int currentSeconds = 0;
            int position       = 1;

            List <LeaderBoard> listLBd = PopulateLeaderBoardData(isOnline);

            for (int i = 0; i < listLBd.Count; i++)
            {
                if (hours == 0)
                {
                    // Extract the new comparable values from the strings stored in listLbd.
                    // We are extracting particular values separated by the special character ":"
                    currentMinutes = Convert.ToInt32(GlobalApp.splitString(listLBd[i].lbTime, 0, ':'));
                    currentSeconds = Convert.ToInt32(GlobalApp.splitString(listLBd[i].lbTime, 1, ':'));
                    if (minutes > currentMinutes)
                    {
                        position++;
                    }
                    else if (minutes == currentMinutes)
                    {
                        if (seconds > currentSeconds)
                        {
                            position++;
                        }
                    }
                }
                else
                {
                    // Extract the new comparable values from the strings stored in listLbd.
                    // We are extracting particular values separated by the special character ":"
                    currentHours   = Convert.ToInt32(GlobalApp.splitString(listLBd[i].lbTime, 0, ':'));
                    currentMinutes = Convert.ToInt32(GlobalApp.splitString(listLBd[i].lbTime, 1, ':'));
                    currentSeconds = Convert.ToInt32(GlobalApp.splitString(listLBd[i].lbTime, 2, ':'));
                    if (hours > currentHours)
                    {
                        position++;
                    }
                    else if (hours == currentHours)
                    {
                        if (minutes > currentMinutes)
                        {
                            position++;
                        }
                        else
                        {
                            if (minutes == currentMinutes)
                            {
                                if (seconds > currentSeconds)
                                {
                                    position++;
                                }
                            }
                        }
                    }
                }
            }
            return(position);
        }
Esempio n. 19
0
 // ----------------------------------------------------------------------------------------------------------------
 // Returns to the Main Activity of the application.
 protected void ButtonClickSelect(Object sender, EventArgs args)
 {
     // Begin the Main Activity
     GlobalApp.BeginActivity(this, typeof(MainActivity), "", 0);
 }
Esempio n. 20
0
 // ----------------------------------------------------------------------------------------------------------------
 // Event Handler: Will direct the player to the Main menu.
 public override void OnBackPressed()
 {
     GlobalApp.BeginActivity(this, typeof(GameMenuActivity), GlobalApp.getVariableChoiceName(), gameChoice);
 }
Esempio n. 21
0
 // ---------------------------------------------------------------------------------------------------------------
 // Begins the game selected from the Main menu.
 protected void ButtonClickStart(Object sender, EventArgs args)
 {
     // Begin the game Activity specifed by type
     GlobalApp.BeginActivity(this, game.gType, GlobalApp.getVariableDifficultyName(), difficulty, GlobalApp.getVariableChoiceName(), Intent.GetIntExtra(GlobalApp.getVariableChoiceName(), 0));
 }