Android Game Programming For Dummies by Derek James
Author:Derek James
Language: eng
Format: epub, pdf
Publisher: Wiley Publishing
Published: 2012-11-27T16:00:00+00:00
Figure 6-6: The game screen displays the discard pile.
Taking Your Turn
After you display the vital game elements displayed on the play screen (both scores, both hands, the draw pile, and the discard pile), you can move on to handling the game logic, such as determining who plays first and how to alternate turns.
Handling turns
To handle turns, you
Add a boolean variable to GameView that keeps track of the player’s turn.
Enable or disable certain logic based on the value of that boolean.
Add the following declaration to your other variable declarations:
private boolean myTurn;
Then, in the constructor, add this line:
myTurn = new Random().nextBoolean();
This value randomly decides who goes first — the computer opponent or the player. You toggle this value every time either player makes a valid play.
The next couple of sections show you how to
Enable players to draw and pick up cards to make valid plays.
Enable the computer opponent to make valid plays.
Crazy Eights has only two valid plays:
Play a card that matches either the suit or rank of the card on top of the discard pile (or an eight).
Draw a card.
Before you move on, make a simple computer opponent that returns legal moves. Later in this chapter, I show you how to make the opponent more sophisticated.
Because you need to get both the rank and suit from a card to evaluate valid plays, you need to modify the Card class. Modify its code to look like Listing 6-11.
Download
Android Game Programming For Dummies by Derek James.pdf
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Deep Learning with Python by François Chollet(12563)
Hello! Python by Anthony Briggs(9911)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9794)
The Mikado Method by Ola Ellnestam Daniel Brolund(9775)
Dependency Injection in .NET by Mark Seemann(9335)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8292)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7758)
Grails in Action by Glen Smith Peter Ledbrook(7693)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7557)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(7016)
Microservices with Go by Alexander Shuiskov(6782)
Practical Design Patterns for Java Developers by Miroslav Wengner(6692)
Test Automation Engineering Handbook by Manikandan Sambamurthy(6635)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6409)
Angular Projects - Third Edition by Aristeidis Bampakos(6043)
The Art of Crafting User Stories by The Art of Crafting User Stories(5572)
NetSuite for Consultants - Second Edition by Peter Ries(5507)
Demystifying Cryptography with OpenSSL 3.0 by Alexei Khlebnikov(5309)
Kotlin in Action by Dmitry Jemerov(5061)
