Full Stack Web Development Internship Program
- 29k Enrolled Learners
- Weekend/Weekday
- Live Class
We hope you had fun building the Drawing Brush Android application using Edureka’s tutorial last week! So, you want to create Android games now, don’t you? Very well, here’s a tutorial that would help you create Android games (Blackjack, to be specific). Since, the demand for Android Certifed Developers is on a meteoric rise, developing an Android game should be a nice and fun way to start with Android development.
To create Android games, you must understand how they run. This video would help you understand how my Blackjack application runs:
Here are the skills that you need to create Android games:
i) Eclipse IDE: If you don’t have Eclipse yet, download this free guide to help you set it up.
iii) Sound clips like – click sounds, card shuffling sounds, clips to play when you win and lose.
Here’s a screenshot of the sound clips I used. :)
Okay, now that you have everything that you’ll require for creating a basic Black Jack game, let’s begin!
Before making any application a programmer needs to understand what he wants to build. So,
For those of you who are in a hurry to dive in and create Android games, here’s a quick overview:
Example:
Case 1: (A, 7) has the hand value of 18
Case 2: (A, 7, 8) has the hand value of 16.
In Case 1, the value of Ace is ’11’, whereas it is ‘1’ in Case 2.
ii) Cards ‘2’ through ‘9’: The cards 2 through 9 are marked at their face value.
iii) 10, Jack, Queen, and King are all valued at ‘10’.
The value of a hand is simply the sum of the point counts of each card in hand. For instance, a hand containing (5, 7, and 8) has the value of 20.
Great, you already know the layman part of it pretty well. Not too shabby, eh!
Let’s get technical now, shall we!
Now that you’ll (hopefully) create Android games all the time, you need to get the logic right. Therefore, the most important (though frustrating) step is writing the Algorithm. Believe me; I had a really hard time creating the algorithm initially. Don’t get frustrated if it seems a little tricky in the beginning. It gets better, when you get the hang of it.
I wrote some basic steps of the algorithm while coding. I hope this would make the task a little easier for you.
Here you would:
Below is a screenshot of my application’s User Interface.
All the game enthusiasts here would agree that this part typically defines the quality of any game.
The key to creating great Android games is to keep the logic simple: Computer will keep drawing cards until its score is less than 17 or less than ‘or’ equal to the user’s score.
Tighten your seat belts because this will be a rough ride! :)
Logic for Drawing Cards:
1) Random class of Java: Cards in the game are drawn at random. For that I used the random class of Java.
2) Binding cards with numbers: This random Class of Java works on numbers so we would need to bind the images of cards with numbers. For instance:
0 – Ace of Clubs
1 – King of Clubs
2 – Queen of Clubs
3 – Jack of Clubs
4 – 10 of Clubs, and so on.
You’ll end up with 52 card images bound to 52 numbers.
This is what I used. It is not necessary for you to bind the images in this exact order. You can always use your own logic.
Random _random = new Random();
_random.nextInt(52); will give you a random number between 0 and 51.
3) Running the logic: Show the user the image related to this number. For instance, (according to the sequence that I used) if the random number is 2, the user gets a Queen of Clubs.
4) Create a list of all the numbers: Create a list for all the numbers to make sure no card comes twice. (All your effort would be futile if the user gets the same card twice).
1. Separate module for scoring: For scoring you need a separate module which will return you a number between 1 and 11 based on the card you get by the _random.nextInt(52);
Example: If the card was Queen – return a number 10
2. Create a separate list to store these scores.
I used two different arrays to store scores:
// Dealer and Player Score Count
int[] _dealerScoreCount = new int[] { 0, 0, 0, 0, 0 };
int[] _playerScoreCount = new int[] { 0, 0, 0, 0, 0 };
After one complete hand:
To keep it from getting complex:
Remember I had advised you guys earlier to make smaller modules. You’ll feel the move’s benefits now.
So, do you guys feel comfortable enough to create Android games on your own now? If you have the slightest doubt, sign up for our free class here!
If you want us to send you more Android programming tips in email, sign up here for Free. Stay tuned for more on How to create Android games! :)
Happy Learning!
You may also like these related posts:
Hey! I was wondering if you could post a folder somewhere (dropbox, etc.) with all the card pictures? Building a blackjack game and cant find any set of card pictures
Where can I get those images and sound clips?
I need this android blackjack project with source code. I like this. pls mail to me gunaflower@gmail.com.
Generally I do not understand article upon weblogs, however i want to express that the following write-up quite obligated us to see in addition to do so! A person’s writing flavour have been shocked my family. Thank you, very good write-up.
Hello to all, how is all, I think every one is getting more from
this site, and your views are nice in support of new people.
Thanks for your wonderful feedback! We are happy we could help you take your interest further.
Smart tinhnkig – a clever way of looking at it.
My brother recommended I might like this website. He was entirely right. This post actually made my day. You can not imagine just how much time I had spent for this info! Thanks!|
definitely try….