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); }; }
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); }; }
/// <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); }; }