Card Games - Controlling cards

Step 1
Create a new file to read input
Temp1544739008 Temp1544739081
Step 2
Add input variables
Temp1544739401

mouseDown - will keep track of whether or not the mouse is pressed

onClick - will change to true for a very small amount of time after the mouse is clicked

Step 3
Add functions to read mouse Input
Temp1544739508
Challenge
Step 4
Control the value of mouseDown with these functions
Temp1544739682
Step 5
Set onClick to true when the mouse is pressed
Temp1544739864
Step 6
Add a delayed function
Temp1544740001

setTimeout runs a function after a delay. In this case we choose 50 milliseconds

Step 7
Set onClick back to false
Temp1544740101
Step 8
Load Input into your main page
Temp1544740267
Step 9
Add a mouseOver method to the Card class
Temp1544740429
Step 10
Check the position of the mouse against the position of the card
Temp1544740789
Step 11
Return true or false
Temp1544740943
Step 12
Use mouseOver to zoom in on cards
Temp1544741199
Check Your Work
Step 13
Bigger Cards!
Temp1544741246
Step 14
Add a move method to our Card
Temp1544741393
Step 15
Check if the card has been clicked
Temp1544741707
Step 16
Create a variable to control whether or not the card should be moving
Temp1544741853
Step 17
Control when it should stop moving
Temp1544741990
Step 18
Move the card
Temp1544742178
Step 19
Add an update function
Temp1544742286

update will both move and draw the card

Step 20
In Index update our cards

Change from just drawing our cards to updating them

Temp1544742417
Step 21
Add this line to prevent grabbing more than one card at once!
Temp1544743340
Check Your Work
Step 22
Moving Cards!
Temp1544742544
Step 23
Add a method to draw the deck of cards
Temp1545949142
Step 24
Only draw the deck if it has cards remaining
Temp1545949298
Step 25
Choose colors and draw the deck
Temp1545949706
Step 26
Make the deck draw in the Index file
Temp1545949820
Check Your Work
Step 27
Your deck should now display!
Temp1545950102
Step 28
Add a method to draw cards from our deck
Temp1545950260
Step 29
Exit the method if there are no cards to draw!
Temp1545950426
Step 30
Add the next card in the deck to our hand and remove it from the deck
Temp1545951009

return true - exits the function with the value of true. this enables us to check whether or not drawing a card was successful

Step 31
Inside the draw method check if the deck is clicked
Temp1545951429
Step 32
Draw a card when the deck is clicked
Temp1545951674
Check Your Work
Step 33
Play a test game!
Temp1545951772
Card Games - Controlling cards Info

Account

MVCode Clubs

Created By

Missing tiny jake wheaton

Course:

Card Games

Access Level

premium

For Teachers and Schools

Teach coding to your students with MVCode Teach

MVCode offers an integrated product designed to teach coding to students.

Learn more about MVCode Teach