コード例 #1
0
ファイル: HighScoresActivity.cs プロジェクト: namftl/Whackem
        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);
            };
        }
コード例 #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            RequestWindowFeature(WindowFeatures.NoTitle);
            SetContentView(Resource.Layout.Tutorial);

            PageController pageController = new PageController(this);
            Button         forward        = FindViewById <Button>(Resource.Id.forwardButton);
            Button         back           = FindViewById <Button>(Resource.Id.backButton);
            Button         menuButton     = FindViewById <Button>(Resource.Id.MenuButton);
            LinearLayout   linearLayout   = FindViewById <LinearLayout>(Resource.Id.tutorialLayout);
            int            UserId         = Intent.Extras.GetInt(Common.USERID);
            int            pagecounter    = 1;
            int            tutorialPageId = 0;

            //the forward button will allow to go forward thru the presentation and will be disabled on the last page
            forward.Click += (sender, e) =>
            {
                if ((pagecounter >= 1) && (pagecounter < 9))
                {
                    switch (pagecounter)
                    {
                    case 1:
                        pagecounter++;
                        back.Clickable = true;
                        tutorialPageId = Resource.Drawable.tutorial2;
                        break;

                    case 2:
                        pagecounter++;
                        tutorialPageId = Resource.Drawable.tutorial3;
                        break;

                    case 3:
                        pagecounter++;
                        tutorialPageId = Resource.Drawable.tutorial4;
                        break;

                    case 4:
                        pagecounter++;
                        tutorialPageId = Resource.Drawable.tutorial5;
                        break;

                    case 5:
                        pagecounter++;
                        tutorialPageId = Resource.Drawable.tutorial6;
                        break;

                    case 6:
                        pagecounter++;
                        tutorialPageId = Resource.Drawable.tutorial7;
                        break;

                    case 7:
                        pagecounter++;
                        tutorialPageId = Resource.Drawable.tutorial8;
                        break;

                    case 8:
                        pagecounter++;
                        tutorialPageId = Resource.Drawable.tutorial9;
                        break;

                    case 9:
                        pagecounter = 10;
                        break;
                    }
                    ChangeViewBgImg(linearLayout, tutorialPageId);
                }
            };
            //the back button will allow to go back thru the presentation and will be disabled on the first page
            back.Click += (sender, e) =>
            {
                if ((pagecounter > 1) && (pagecounter <= 9))
                {
                    switch (pagecounter)
                    {
                    case 1:
                        pagecounter = 0;
                        break;

                    case 2:
                        pagecounter--;
                        tutorialPageId = Resource.Drawable.tutorial1;
                        break;

                    case 3:
                        pagecounter--;
                        tutorialPageId = Resource.Drawable.tutorial2;
                        break;

                    case 4:
                        pagecounter--;
                        tutorialPageId = Resource.Drawable.tutorial3;
                        break;

                    case 5:
                        pagecounter--;
                        tutorialPageId = Resource.Drawable.tutorial4;
                        break;

                    case 6:
                        pagecounter--;
                        tutorialPageId = Resource.Drawable.tutorial5;
                        break;

                    case 7:
                        pagecounter--;
                        tutorialPageId = Resource.Drawable.tutorial6;
                        break;

                    case 8:
                        pagecounter--;
                        tutorialPageId = Resource.Drawable.tutorial7;
                        break;

                    case 9:
                        pagecounter--;
                        tutorialPageId = Resource.Drawable.tutorial8;
                        break;
                    }
                    ChangeViewBgImg(linearLayout, tutorialPageId);
                }
            };

            //move through to the game if presentation is on last page
            linearLayout.Click += (sender, e) =>
            {
                if (pagecounter == 9)
                {
                    pageController.GotoPage(typeof(GameActivity), UserId, "UserId");
                }
            };

            menuButton.Click += (sender, e) =>
            {
                pageController.GotoPage(typeof(MenuActivity), UserId, "UserId");
            };
        }
コード例 #3
0
ファイル: NewPlayerActivity.cs プロジェクト: namftl/Whackem
        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);
            };
        }
コード例 #4
0
ファイル: GameActivity.cs プロジェクト: namfat/try3
        /// <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);
            };
        }