1 00:00:00,781 --> 00:00:01,564 Welcome back, 2 00:00:01,564 --> 00:00:05,730 congrats on finishing the final step in developing our foreign arrow game. 3 00:00:05,730 --> 00:00:09,703 We are done, let us go over the solution for the last assignment. 4 00:00:09,703 --> 00:00:12,976 First, you were tasked with adding a method to the player class 5 00:00:12,976 --> 00:00:14,411 called checkTokens(). 6 00:00:14,411 --> 00:00:18,813 This methods job is to tell us if a player has any unused tokens left. 7 00:00:18,813 --> 00:00:21,280 If they've used all their tokens, they can't play anymore. 8 00:00:22,350 --> 00:00:24,572 We used another ternary expression here. 9 00:00:24,572 --> 00:00:28,555 If the length of the unusedTokens array == 0, 10 00:00:28,555 --> 00:00:33,131 then we return false, if it's not 0, we return true. 11 00:00:33,131 --> 00:00:39,787 Okay, let's move to game.js to review the final method updateGameState(). 12 00:00:39,787 --> 00:00:45,392 The updateGameState() method receives two arguments, token and target. 13 00:00:45,392 --> 00:00:50,236 Token is the token object that was most recently dropped by a player and 14 00:00:50,236 --> 00:00:54,190 target is the space object that that token now occupies. 15 00:00:55,330 --> 00:00:59,337 Your first step inside the updateGameState method was to associate 16 00:00:59,337 --> 00:01:01,593 the space object with a droped token. 17 00:01:01,593 --> 00:01:05,742 This is done using the mark method you wrote earlier in this stage. 18 00:01:05,742 --> 00:01:11,402 We call the mark method on the target space and pass in the dropped token. 19 00:01:11,402 --> 00:01:12,468 As you recall, 20 00:01:12,468 --> 00:01:17,648 this will set the target spaces token property to the droped token object. 21 00:01:17,648 --> 00:01:21,731 The next step is to check if the last move was a winning move. 22 00:01:21,731 --> 00:01:24,881 This is done with a simple if else statement. 23 00:01:24,881 --> 00:01:28,704 If it was a winning move, we pass a message to the gameOver method and 24 00:01:28,704 --> 00:01:29,452 that's it. 25 00:01:29,452 --> 00:01:34,269 If it wasn't, we have some other steps to take that logic is all handled 26 00:01:34,269 --> 00:01:37,260 in the first part of this if else statement. 27 00:01:37,260 --> 00:01:39,216 First we switchPlayers(), 28 00:01:39,216 --> 00:01:43,962 that's simply a call to the switchPlayers() method you wrote earlier. 29 00:01:43,962 --> 00:01:49,891 Then we use another if else to check that the newly activePlayer still has tokens. 30 00:01:49,891 --> 00:01:53,876 If they don't have tokens available, then they can't complete their turn and 31 00:01:53,876 --> 00:01:54,773 the game is over. 32 00:01:54,773 --> 00:01:59,329 If they do have tokens left, then we need to render a new HTML Token for 33 00:01:59,329 --> 00:02:04,610 them using the drawHTMLToken() method you wrote much earlier in the course. 34 00:02:05,720 --> 00:02:09,882 After that, we set the game state back to ready and voila. 35 00:02:09,882 --> 00:02:12,722 That's a wrap on four in a row. 36 00:02:12,722 --> 00:02:15,790 Come watch me and a fellow teacher play the game in the next video.