conditionals coding with playing cards. card game – teacher v students the rules of the game are:...
TRANSCRIPT
Conditionals
Coding with Playing Cards
Card game – Teacher v Students
The rules of the game are:
If I draw a black card, I get a point
Else, you get a point
Card game – Teacher v Students
The rules of the game are:
If I draw a black card, I get a point
Else, you get a point
if (card.colour) == black) {teacher.points +=1;}else {student.points +=1}
What is this game?Work together to understand what the rules of this next game are.Then split into two teams and each team takes it in turns to draw a card from the pack, until each team has drawn 15 cards. The rules are:if (card.colour) == black) {team.points +=1; }
if (card.suit) == clubs) {team.points +=2;}
}else {otherteam.points +=1}
Pseudo code:
If a card is black the playing team gets 1 point
If the card is a club they get 2 points
Else the other team gets a point
Card properties
Card Properties Variablescard.colour black, redcard.suit diamonds, hearts, clubs, spades
card.value A=1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 10, J=11, Q=12, K=13
Attributing points - some examples
+=1 -=2+=timesTwo (to double the current score)
Writing code for another game
Write the code for the following game:1. The team drawing the card gets a point for
every red card, 2. except if drawing a red ace, when they will
double their current points score, 3. else the other team gets a point.
Writing code for another gameWrite the code for a game where the team drawing the card gets a point for every red card, except if drawing a red ace, when they will double their current points score, else the other team gets a point.
if (card.colour) == red) {team.points +=1;
if (card.value) == ace) {team.points +=timesTwo;}
}else {otherteam.points +=1}
Code your own card game
Can you make up a game and write the code for the game rules where:• odds and even numbered cards are treated
differently?• the points scored relate to the face value of
the card?• there are special events – eg wiping out all
points, instant win, triple points