#100DaysOfCode in Python Transcripts
Chapter: Days 97-99: Building JSON APIs
Lecture: Implementing the game (client-side)

Login or purchase this course to watch this video and the rest of the course contents.
0:00 You saw us write the game,
0:01 interaction of the game loop previously.
0:04 We've consumed a bunch of API's with Uplink already.
0:07 So let me just drop in some code here that is going to
0:11 be basically, the same thing but using the service,
0:15 just for the sake of time.
0:18 So what do we got?
0:19 We're going to print out the top scores,
0:20 and we're going to call top_scores and then we'll loop
0:22 over them, and remember everything that comes back is a
0:24 dictionary so we've got to get the values and then
0:28 this is a nested dictionary,
0:29 so we've got to get the name from the player that we got,
0:31 and so on.
0:32 So we're going to print out the top scores,
0:35 we're going to create a new game that's going to return
0:37 that dictionary which we're going to get the game id.
0:39 We could do some work to make this much easier to consume,
0:41 but just keep it focused on more the server side.
0:44 Kind of just roll with what we got.
0:46 Give us all the rolls, get us the player list.
0:48 Suppose we want to be the player Charles.
0:52 And then we're just going to say while the game is not over,
0:54 we're just going to go through and play a round,
0:55 pass the game id,
0:57 the user being Charles, and the roll which we're randomly
1:00 choosing from the various options we got from the server.
1:05 Right up there.
1:06 Okay, so we're just going to go run and do that, and when
1:08 it's over we're going to get the game status,
1:10 and print the outcome which the game status has the winner.
1:13 Oh, okay, so let's run this.
1:16 By the way, it doesn't ask us what we want to do.
1:19 It just randomly chooses rolls for Charles,
1:21 and makes him play those.
1:22 But it could just as well, this could be an input or
1:25 some other type of UI.
1:29 Oh, Charles is not found.
1:33 Yeah, I guess we got to create Charles.
1:34 Let's go ahead and just create him this way,
1:35 it's probably the easiest way.
1:43 All right, try again.
1:45 Boom, look at that.
1:48 Top scores, Michael scored 1, Charles scored 0,
1:51 so Charles threw rock, computer threw scissors,
1:54 that resulted in a win for the player which is Charles.
1:57 We got a tree and a sponge, win.
2:00 Lightning does not beat the devil,
2:02 water does not beat humans,
2:03 but finally the end, humans beat scissors and that takes it.
2:07 The game is over and Charles is the winner.
2:10 Let's run it again.
2:11 At the top you see now Charles and Michael have 1.
2:13 One score each in the top score, in the leaderboard there.
2:17 Come down here, game is over, the computer won.
2:20 Let's try again.
2:21 Leaderboard should now be 1, 1, 1.
2:24 How come Charles winner, is the winner.
2:26 So if we run it this time,
2:27 Charles now has the global high score.
2:32 Pretty amazing.
2:33 It might feel like we're kind of playing the same game,
2:35 but this is totally different, right?
2:36 We could put this on a phone app,
2:38 we could distribute this around the world.
2:40 And if we were hosting that website somewhere
2:42 like Heroku, or Digital Ocean, or Linode,
2:45 or something like that.
2:46 Put it out there, and this would be shared for the world.
2:49 Pretty cool.
2:50 Hopefully this has inspired you to see what you could build.
2:55 I know it's not the super simplest demo,
2:57 but it's pretty realistic, and it does cover a lot of
3:00 interesting use cases, and it really opens another world
3:04 for you guys to build cool applications that are
3:07 data driven remotely.