Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 Conditionals Coding with Playing Cards

2 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

3 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 }

4 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

5 Card properties Card PropertiesVariables card.colourblack, red card.suitdiamonds, hearts, clubs, spades card.valueA=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)

6 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.

7 Writing code for another game Write 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 }

8 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


Download ppt "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."

Similar presentations


Ads by Google