In this video, Doug Winnie walks through how to use the Random class to create a die in our game, and then create a message to display when the die is rolled.
- [Instructor] Now that we have…a random number generator, we can create one…of the dice in our game.…Make sure you have the MainActivity.java…file open in the project.…We will remove the lines we created…in the rollDice method from the last lesson…since we won't need these to create our die.…We need to create a new integer…to hold the value of our die.…This will need to be a field…that is scoped to the entire project.…So we need to create that at the top.…We can call it die1.…
Then in our rollDice method we can use…our random number generator to create…the value for the die.…Start with the comment Roll dice.…And we'll set die1 to be equal to…a random number generator nextInt six, and we'll add one.…And then we can build the string…we want to put in the roll result text view.…We'll add a comment, build message with the result.…String message M-S-G, equals you rolled a plus die1.…
And then set the text of the roll result…text view to the new message.…Comment update the app to display the result message.…Then we'll access rollResult.…
- Installing Android Studio
- Coding in Java and XML
- Getting a head start with starter templates
- Working with emulators
- Creating a project, variable, and toast
- Connecting XML widgets to code
- Adding images
- Adding game logic with conditional statements and operators
- Changing the data or design
Skill Level Beginner
1. Android Basics
Test your setup2m 56s
3. The Major Parts
4. Make an App
5. Tinkering with Your App
Next steps1m 4s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.