Esempio n. 1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            RequestWindowFeature(WindowFeatures.NoTitle);
            SetContentView(Resource.Layout.MenuScr);

            TextView               HelloUser          = FindViewById <TextView>(Resource.Id.HelloUser);
            Button                 StartGameButton    = FindViewById <Button>(Resource.Id.StartGameButton);
            Button                 SwitchUserButton   = FindViewById <Button>(Resource.Id.switchUserButton);
            Button                 TutorialButton     = FindViewById <Button>(Resource.Id.tutorialButton);
            Button                 playersButton      = FindViewById <Button>(Resource.Id.playersButton);
            Button                 highScoresButton   = FindViewById <Button>(Resource.Id.highScoresButton);
            PageController         pageController     = new PageController(this.BaseContext);
            UserDatabaseController databaseController = new UserDatabaseController();

            //display username
            int  UserId = Intent.Extras.GetInt(Common.USERID);
            User user   = databaseController.GetUser(UserId);

            HelloUser.Text = "Hello " + user.UserName;
            //display "players" button if user is an admin
            if (user.IsAdmin)
            {
                playersButton.Visibility = ViewStates.Visible;
                playersButton.Enabled    = true;
            }

            StartGameButton.Click += (sender, e) =>
            {
                pageController.GotoPage(typeof(GameActivity), UserId, Common.USERID);
            };

            TutorialButton.Click += (sender, e) =>
            {
                pageController.GotoPage(typeof(TutorialActivity), UserId, Common.USERID);
            };

            SwitchUserButton.Click += (sender, e) =>
            {
                pageController.GotoPage(typeof(LoginActivity));
            };

            highScoresButton.Click += (sender, e) =>
            {
                pageController.GotoPage(typeof(HighScoresActivity), UserId, Common.USERID);
            };

            playersButton.Click += (sender, e) =>
            {
                pageController.GotoPage(typeof(UsersActivity), UserId, Common.USERID);
            };
        }
Esempio n. 2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            RequestWindowFeature(WindowFeatures.NoTitle);
            SetContentView(Resource.Layout.TitleScr);
            PageController         pageController     = new PageController(this);
            LinearLayout           linearLayout       = FindViewById <LinearLayout>(Resource.Id.TitleLayout);
            UserDatabaseController databaseController = new UserDatabaseController();
            User lastUser = databaseController.GetLastUser();

            linearLayout.Click += (sender, e) =>
            {
                if (lastUser != null)
                {
                    pageController.GotoPage(typeof(MenuActivity), lastUser.Id, Common.USERID);
                }
                else
                {
                    pageController.GotoPage(typeof(LoginActivity));
                }
            };
        }
Esempio n. 3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            RequestWindowFeature(WindowFeatures.NoTitle);
            SetContentView(Resource.Layout.Login);

            Button   LoginButton     = FindViewById <Button>(Resource.Id.LoginButton);
            Button   newPlayerButton = FindViewById <Button>(Resource.Id.NewPlayerButton);
            EditText userName        = FindViewById <EditText>(Resource.Id.userName);
            EditText password        = FindViewById <EditText>(Resource.Id.password);
            TextView userErr         = FindViewById <TextView>(Resource.Id.userErr);
            UserDatabaseController databaseController = new UserDatabaseController();
            PageController         pageController     = new PageController(this.BaseContext);

            LoginButton.Click += (sender, e) =>
            {
                pageController.CloseKeyboard(userName);
                pageController.CloseKeyboard(password);
                //search the db for the user
                int reply = databaseController.checkUserPassword(userName.Text, password.Text);
                if ((reply == (int)UserDatabaseController.UserCheckErr.USERNAME_ERR) ||
                    (reply == (int)UserDatabaseController.UserCheckErr.PASSWORD_ERR)) //user accepted
                {
                    userErr.Text = ((UserDatabaseController.UserCheckErr)reply).ToString();
                    userErr.SetTextColor(Android.Graphics.Color.Red);
                }
                else
                {
                    pageController.GotoPage(typeof(MenuActivity), reply, Common.USERID);
                }
            };
            newPlayerButton.Click += (sender, e) =>
            {
                pageController.GotoPage(typeof(NewPlayerActivity));
            };
        }
Esempio n. 4
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            RequestWindowFeature(WindowFeatures.NoTitle);
            SetContentView(Resource.Layout.TopScores);
            UserDatabaseController databaseController = new UserDatabaseController();
            PageController         pageController     = new PageController(this);
            int         UserId          = Intent.Extras.GetInt(Common.USERID);
            Button      menuButton      = FindViewById <Button>(Resource.Id.menuButton);
            TableLayout highScoresTable = FindViewById <TableLayout>(Resource.Id.highScoresTable);
            int         tableLength     = highScoresTable.ChildCount - 1;

            Game[]      bestGames = new Game[tableLength];
            List <Game> allGames  = databaseController.GetGames();

            fillTable();

            /// <summary>
            /// Fills the table with top5 games by locating and removing the best games one by one from a local
            /// list containing all the games.
            /// </summary>
            void fillTable()
            {
                TextView Name;
                TextView HighScore;
                TableRow tableRow;

                for (int i = 0; i < tableLength; i++)
                {
                    Game bestGame = findBestGame();
                    if (bestGame.FinalScore == 0)
                    {
                        break;
                    }
                    allGames.Remove(bestGame);
                    User user = databaseController.GetUser(bestGame.UserId);
                    tableRow  = (TableRow)highScoresTable.GetChildAt(i + 1);
                    Name      = (TextView)(tableRow.GetChildAt(1));
                    Name.Text = user.UserName;
                    Name.SetTextColor(Android.Graphics.Color.Black);
                    HighScore      = (TextView)(tableRow.GetChildAt(2));
                    HighScore.Text = bestGame.FinalScore.ToString();
                    HighScore.SetTextColor(Android.Graphics.Color.Black);
                }
            }

            /// <summary>
            /// Finds the best game.
            /// </summary>
            /// <returns>The best game.</returns>
            Game findBestGame()
            {
                Game bestGame = new Game();

                foreach (Game game in allGames)
                {
                    if (game.FinalScore > bestGame.FinalScore)
                    {
                        bestGame = game;
                    }
                }
                return(bestGame);
            }

            menuButton.Click += (sender, e) =>
            {
                pageController.GotoPage(typeof(MenuActivity), UserId, Common.USERID);
            };
        }
Esempio n. 5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            RequestWindowFeature(WindowFeatures.NoTitle);
            SetContentView(Resource.Layout.NewPlayer);

            //
            databaseController = new UserDatabaseController();
            EditText       userNameInput       = FindViewById <EditText>(Resource.Id.newUserName);
            EditText       userPassword        = FindViewById <EditText>(Resource.Id.userPassword);
            Button         checkUserNameButton = FindViewById <Button>(Resource.Id.checkUserNameButton);
            Button         toMenuButton        = FindViewById <Button>(Resource.Id.toMenuButton);
            Button         registerButton      = FindViewById <Button>(Resource.Id.registerButton);
            Button         beginButton         = FindViewById <Button>(Resource.Id.beginButton);
            TextView       illegalUserName     = FindViewById <TextView>(Resource.Id.illegalUsername);
            CheckBox       adminBox            = FindViewById <CheckBox>(Resource.Id.adminBox);
            EditText       adminPassword       = FindViewById <EditText>(Resource.Id.adminPassword);
            PageController pageController      = new PageController(this.BaseContext);
            bool           isAdmin             = false;
            int            newUserId           = 0;

            //check if username is legal and unique
            checkUserNameButton.Click += (sender, e) =>
            {
                pageController.CloseKeyboard(userNameInput);
                if (databaseController.checkUsername(userNameInput.Text))
                {
                    illegalUserName.Text = "Name exists - try a different one";
                    illegalUserName.SetTextColor(Android.Graphics.Color.Red);
                }
                else if ((userNameInput.Length() > MAX_USERNAME_LENGTH) || (userNameInput.Length() < MIN_USERNAME_LENGTH))
                {
                    illegalUserName.Text = string.Format("Name must be between {0}-{1} characters", MIN_USERNAME_LENGTH, MAX_USERNAME_LENGTH);
                    illegalUserName.SetTextColor(Android.Graphics.Color.Red);
                }
                else
                {
                    illegalUserName.Text = "GOOD!";
                    illegalUserName.SetTextColor(Android.Graphics.Color.Green);
                    userPassword.Enabled = true;
                }
            };

            //opens the admin password dialog if the admin checkbox is clicked
            adminBox.Click += (sender, e) =>
            {
                if (adminBox.Checked)
                {
                    adminPassword.Visibility = ViewStates.Visible;
                }
                else
                {
                    adminPassword.Visibility = ViewStates.Invisible;
                }
            };

            //try to insert a new player and informs of the outcome
            registerButton.Click += (sender, e) =>
            {
                pageController.CloseKeyboard(userPassword);
                if ((!adminBox.Checked) ||
                    (adminPassword.Text == ADMIN_PASSWORD))
                {
                    isAdmin = adminBox.Checked;
                    if ((userPassword.Length() > MAX_PASSWORD_LENGTH) || (userPassword.Length() < MIN_PASSWORD_LENGTH))
                    {
                        illegalUserName.Text = string.Format("Password must be between {0}-{1} characters", MIN_PASSWORD_LENGTH, MAX_PASSWORD_LENGTH);
                        illegalUserName.SetTextColor(Android.Graphics.Color.Red);
                    }
                    else
                    {
                        newUserId = databaseController.saveUser(userNameInput.Text, userPassword.Text, isAdmin);
                        if (newUserId != 0)
                        {
                            beginButton.Enabled = true;
                        }
                        else
                        {
                            illegalUserName.Text = "registration failed";
                            illegalUserName.SetTextColor(Android.Graphics.Color.Red);
                        }
                    }
                }
                else
                {
                    illegalUserName.Text = "admin password error";
                    illegalUserName.SetTextColor(Android.Graphics.Color.Red);
                }
            };

            beginButton.Click += (sender, e) =>
            {
                pageController.GotoPage(typeof(MenuActivity), newUserId, Common.USERID);
            };

            toMenuButton.Click += (sender, e) =>
            {
                Intent intent = new Intent(this, typeof(LoginActivity));
                StartActivity(intent);
            };
        }
Esempio n. 6
0
        /// <summary>
        /// Ons the create.
        /// </summary>
        /// <param name="savedInstanceState">Saved instance state.</param>
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            RequestWindowFeature(WindowFeatures.NoTitle);
            SetContentView(Resource.Layout.Game);

            //getting elements from layout
            TextView     currHighScore = FindViewById <TextView>(Resource.Id.scoreText13);
            LinearLayout GameLayout    = FindViewById <LinearLayout>(Resource.Id.GameLayout);
            Button       pauseButton   = FindViewById <Button>(Resource.Id.pauseButton11);
            Button       menuButton    = FindViewById <Button>(Resource.Id.menuButton);

            CountdownButton = FindViewById <TextView>(Resource.Id.countdownText22);
            TimerText       = FindViewById <TextView>(Resource.Id.timerText);
            ScoreTest       = FindViewById <TextView>(Resource.Id.scoreText2);
            GameProgressBar = FindViewById <ProgressBar>(Resource.Id.gameProgressBar);
            AllButtons      = GetButtonList(Resource.Id.button1, Resource.Id.button2, Resource.Id.button3,
                                            Resource.Id.button4, Resource.Id.button5, Resource.Id.button6);
            //initing params
            PageCtrl   = new PageController(this);
            WaitingMin = MIN_EASY_MILI;
            WaitingMax = MAX_EASY_MILI;
            UserId     = Intent.Extras.GetInt(Common.USERID);
            UserDatabaseController databaseController = new UserDatabaseController();
            User currUser = databaseController.GetUser(UserId);

            InitGameButtons(AllButtons);
            bool gameOver = false;
            bool isPaused = false;

            Countdown = COUNTDOWN_TIME;
            double timerInterval = 1;

            GameTimer          = new System.Timers.Timer(timerInterval * MILI);
            GameTimer.Elapsed += GameTimerEvent;
            GameSecondsLeft    = GAME_TIME;

            RunOnUiThread(() => MoleSuccess         = Resource.Drawable.coolMoleOrange);
            RunOnUiThread(() => MolePic             = Resource.Drawable.coolMoleGreen);
            RunOnUiThread(() => PauseButtonPic      = Resource.Drawable.pauseButton);
            RunOnUiThread(() => PlayButtonPic       = Resource.Drawable.playButton);
            RunOnUiThread(() => currHighScore.Text  = "HighScore:" + currUser.HighScore.ToString());
            RunOnUiThread(() => CountDownGoPic      = Resource.Drawable.countDownGo);
            RunOnUiThread(() => CountDown1Pic       = Resource.Drawable.countDown1);
            RunOnUiThread(() => CountDown2Pic       = Resource.Drawable.countDown2);
            RunOnUiThread(() => CountDown3Pic       = Resource.Drawable.countDown3);
            RunOnUiThread(() => GameOverPic         = Resource.Drawable.gameOver);
            RunOnUiThread(() => GameProgressBar.Max = GAME_TIME);
            RunOnUiThread(() => GameProgressBar.SetProgress(GAME_TIME, true));
            RunOnUiThread(() => GameTimer.Enabled = true);
            RunOnUiThread(() => ScoreTest.Text    = Score.ToString());

            //the event for text changed is used for monitoring time left
            TimerText.TextChanged += (sender, e) =>
            {
                if (GameSecondsLeft == 0)
                {
                    GameTimer.Stop();
                    ChangeViewBgImg(CountdownButton, GameOverPic);
                    RunOnUiThread(() => CountdownButton.Visibility = ViewStates.Visible);
                    gameOver = true;
                }
            };

            GameLayout.Click += (sender, e) =>
            {
                if (gameOver)
                {
                    List <KeyValuePair <string, int> > postGameArgs = new List <KeyValuePair <string, int> >
                    {
                        new KeyValuePair <string, int>(Common.SCORE, Score),
                        new KeyValuePair <string, int>(Common.USERID, UserId)
                    };
                    databaseController.InsertGame(UserId, Score);
                    PageCtrl.GotoPage(typeof(PostGameActivity), postGameArgs);
                }
            };

            pauseButton.Click += (sender, e) =>
            {
                if (isPaused)
                {
                    RunOnUiThread(() => menuButton.Visibility = ViewStates.Invisible);
                    GameTimer.Start();
                    ChangeViewBgImg(pauseButton, PauseButtonPic);
                    isPaused = false;
                }
                else
                {
                    RunOnUiThread(() => menuButton.Visibility = ViewStates.Visible);
                    GameTimer.Stop();
                    ChangeViewBgImg(pauseButton, PlayButtonPic);
                    isPaused = true;
                }
            };

            menuButton.Click += (sender, e) =>
            {
                PageCtrl.GotoPage(typeof(MenuActivity), UserId, Common.USERID);
            };
        }