EU Code Week 2020 - Day Nine - Play Your Own Game
About this lesson

Today we'll apply some of our coding skills to a game of rock, paper, scissors.
The brilliant thing about today's lesson is that, if we mess up, we can always reset the page or download a new copy of the Rock, Paper, Scissors playground. What will your game look like?
Video
Recorded Friday, October 16th, 2020:
Recorded Friday, October 23rd, 2020:
Unplugged Activity
Rock, Paper, Scissors - play your own game
You will need:- A4 Paper to record the score
- Pen or pencil
Activity:
We will play the 'Rock, Paper, Scissors' game. We will play in pairs, to see who will be the champion. You will record the players names and the score. We will look back at the week, to name the steps of the algorithm, the loops and the variables.Extend
More Depth: Complete the Add Hidden Actions and Add Opponents pages to build a more complete game. Think about how people are going to play this game. Test out your additions to see if it makes the game more compelling. Hand your game to someone else if you are able. Did they enjoy your twist(s) on the game?
Beyond Games: "What? Beyond games? What are you talking about?" I can hear you say. But maybe what you want to build is an app that uses the camera on your iPad. Or in which you can decorate photos and other images?
Download the Lights, Camera, Code playground from More Playgrounds and see if you can build a working camera app. If you already did that on day five, try out one of the next playgrounds in that series: Assemble Your Camera or Flashy Photos!
Even More Advanced: What if games are your thing, but you want to build a game using some of the other sensors on the iPad, like the microphone, or the light sensor in the camera? Grab the Sensor Arcade playground from the Challenges section of More Playgrounds and give it a whirl! This is an intermediate playground, so it's a big step up, so don't be discouraged if some of the code is utterly foreign-looking. Experiment with it. And if you get stuck, you can always reset the page and get it back to its original state!
Beyond Games: "What? Beyond games? What are you talking about?" I can hear you say. But maybe what you want to build is an app that uses the camera on your iPad. Or in which you can decorate photos and other images?
Download the Lights, Camera, Code playground from More Playgrounds and see if you can build a working camera app. If you already did that on day five, try out one of the next playgrounds in that series: Assemble Your Camera or Flashy Photos!
Even More Advanced: What if games are your thing, but you want to build a game using some of the other sensors on the iPad, like the microphone, or the light sensor in the camera? Grab the Sensor Arcade playground from the Challenges section of More Playgrounds and give it a whirl! This is an intermediate playground, so it's a big step up, so don't be discouraged if some of the code is utterly foreign-looking. Experiment with it. And if you get stuck, you can always reset the page and get it back to its original state!
Code in this session:
Copy
Personalize the Game
let game = Game()
// To modify your setup code, edit setup(game:) in the SharedCode file.
setup(game: game)
// Example: changes the game prize to "🐶".
// To preserve this code in your game, cut and paste this line
// into setup(game:) in SharedCode.swift.
game.prize = "🐶"
game.play()
Copy
Solution
let game = Game()
func setupExample(game: Game) {
// Actions for the game.
let rock = game.addAction("✊")
let paper = game.addAction("🖐")
let scissors = game.addAction("✌")
let hardRock = game.addAction("🤘")
let doublePaper = game.addAction("🙌")
let doubleScissors = game.addAction("🖖")
// Rules for the actions.
rock.beats([doubleScissors, scissors])
doubleScissors.beats([scissors, doublePaper, paper])
scissors.beats([doublePaper, paper])
doublePaper.beats([paper, hardRock, rock])
paper.beats([hardRock, rock])
hardRock.beats([rock, doubleScissors, scissors])
// 'shark' hidden action that loses to all other actions.
let shark = game.addHiddenAction("🦈")
for action in game.actions {
action.beats(shark)
}
// 'peach' hidden action that beats all other actions.
let peach = game.addHiddenAction("🍑")
peach.beats(game.actions)
// Opponents for the game.
game.addOpponent("🕷",
color: #colorLiteral(red: 0.556862771511078,
green: 0.352941185235977,
blue: 0.968627452850342, alpha: 1.0))
game.addOpponent("🐞",
color: #colorLiteral(red: 0.941176474094391,
green: 0.498039215803146,
blue: 0.352941185235977, alpha: 1.0))
game.addOpponent("🦗",
color: #colorLiteral(red: 0.584313750267029,
green: 0.823529422283173,
blue: 0.419607847929001, alpha: 1.0))
game.addOpponent("🐛",
color: #colorLiteral(red: 0.239215686917305,
green: 0.674509823322296,
blue: 0.968627452850342, alpha: 1.0))
// Configurations for the game.
game.roundsToWin = 5
game.prize = "🚢"
// Colors for the game.
game.myColor = #colorLiteral(red: 0.960784316062927,
green: 0.705882370471954,
blue: 0.200000002980232, alpha: 1.0)
game.outerRingColor = #colorLiteral(red: 0.10196078568697,
green: 0.278431385755539,
blue: 0.400000005960464, alpha: 1.0)
game.innerCircleColor = #colorLiteral(red: 1,
green: 1,
blue: 1, alpha: 1)
game.mainButtonColor = #colorLiteral(red: 0.952941179275513,
green: 0.686274528503418,
blue: 0.133333340287209, alpha: 1.0)
game.changeActionButtonsColor = #colorLiteral(red: 0.10196078568697,
green: 0.278431385755539,
blue: 0.400000005960464, alpha: 1.0)
game.backgroundColors = [
#colorLiteral(red: 0.474509805440903,
green: 0.839215695858002,
blue: 0.976470589637756, alpha: 1.0),
#colorLiteral(red: 0.976470589637756,
green: 0.850980401039124,
blue: 0.549019634723663, alpha: 1.0)
]
}
setupExample(game: game)
game.play()