1
00:00:00,640 --> 00:00:04,930
In this lesson, we're going to go through the solution to part one of building rock, paper, scissors.

2
00:00:05,200 --> 00:00:10,870
Remember, the first task is to see if the user wants to play and we can pick up the user's answer using

3
00:00:10,870 --> 00:00:12,120
scanned next line.

4
00:00:12,520 --> 00:00:15,880
So we'll set a variable already is equal to scan.

5
00:00:16,059 --> 00:00:16,860
Next line.

6
00:00:18,060 --> 00:00:19,110
And that's really it.

7
00:00:20,430 --> 00:00:24,930
I'm going to run my coat after each task because it's a good habit to keep testing your coat.

8
00:00:31,240 --> 00:00:36,400
And it looks like the OP starts by asking the user if they want to play, to which we reply yes.

9
00:00:37,830 --> 00:00:38,940
So far, so good.

10
00:00:39,180 --> 00:00:44,040
Now, test tube was to set up the game, and so if the user enters, yes, we can start by setting up

11
00:00:44,040 --> 00:00:49,260
the game, that is, if the answer is stored inside the ready variable.

12
00:00:50,730 --> 00:00:52,020
Equals, yes.

13
00:00:59,070 --> 00:01:00,990
We're going to print a new line.

14
00:01:06,640 --> 00:01:10,570
Great, then we'll print rock, paper, scissors shoots.

15
00:01:22,470 --> 00:01:23,910
Otherwise else.

16
00:01:27,530 --> 00:01:29,990
We'll print Dan's some other time.

17
00:01:44,260 --> 00:01:49,900
Now the game starts after rock, paper, scissors, shoot, so here the user needs to choose between

18
00:01:49,900 --> 00:01:55,660
a rock, paper, scissors, and we can easily pick up the user's choice with scanned next line.

19
00:01:58,000 --> 00:02:02,290
And that's all task to I can now safely delete it because we're done.

20
00:02:09,460 --> 00:02:14,080
And all of these tasks are going to be done inside the if statement, so I'm going to move them here.

21
00:02:24,120 --> 00:02:26,250
OK, I'm going to run a test case.

22
00:02:31,080 --> 00:02:32,730
Where the user says yes.

23
00:02:33,950 --> 00:02:36,860
I'll choose rock and good this worked out.

24
00:02:37,440 --> 00:02:40,370
Now I'm going to run a test case where the user says anything else.

25
00:02:42,530 --> 00:02:44,330
And it prints Darren some other time.

26
00:02:45,310 --> 00:02:48,220
The app is coming together so we can move on to task three.

27
00:02:50,180 --> 00:02:54,950
The next step is to write a function, it's going to let the computer pick randomly between rock, paper,

28
00:02:54,950 --> 00:03:00,620
scissors, if you look at the instructions, it returns a string and takes no parameters.

29
00:03:01,040 --> 00:03:03,980
So we'll say public static string.

30
00:03:07,720 --> 00:03:14,230
The function is called computer choice, and inside the function, the first instruction is to pick

31
00:03:14,230 --> 00:03:16,240
a random number between zero and two.

32
00:03:16,900 --> 00:03:21,820
The first, I can use math at random to get a random decimal from zero to less than one.

33
00:03:26,880 --> 00:03:33,120
And we can multiply the result by three to scale the range from zero to less than three, essentially

34
00:03:33,120 --> 00:03:34,430
from zero to less than two.

35
00:03:35,220 --> 00:03:39,570
So we'll make a comment that says it returns a number between zero and less than three.

36
00:03:42,470 --> 00:03:46,510
We can convert this number to an integer by typecasting the double tint.

37
00:03:55,640 --> 00:04:00,890
This is going to cut off all the decibels and so the integer variable is going to carry any hole number

38
00:04:01,100 --> 00:04:02,750
between zero and less than three.

39
00:04:03,560 --> 00:04:05,540
In other words, from zero to two.

40
00:04:07,840 --> 00:04:13,690
And so the next step is to compare the random integer value against three cases, so we'll make a switch

41
00:04:13,690 --> 00:04:16,420
statement that compares the random integer.

42
00:04:20,269 --> 00:04:24,020
Against the three possible integers that it could be zero.

43
00:04:28,180 --> 00:04:28,990
In case, Tim.

44
00:04:30,070 --> 00:04:33,610
If it matches case zero, return the string rock.

45
00:04:36,000 --> 00:04:37,860
Return paper for case one.

46
00:04:44,940 --> 00:04:46,650
And scissors for case to.

47
00:04:50,960 --> 00:04:53,870
And as always, we need to add a default case.

48
00:04:56,310 --> 00:05:00,810
We're in we're just going to return an empty string because it's impossible for the injured to be any

49
00:05:00,810 --> 00:05:02,490
number other than zero one or two.

50
00:05:02,670 --> 00:05:05,070
So I don't expect default to ever run.

51
00:05:05,550 --> 00:05:10,680
But we need to put it anyway because the function expects a return value no matter what.

52
00:05:12,410 --> 00:05:14,330
OK, that's all we need for our function.

53
00:05:24,040 --> 00:05:25,930
I can now call the function from Main.

54
00:05:33,510 --> 00:05:38,490
And this function call is going to return a random string that can be rock, paper, scissors, and

55
00:05:38,490 --> 00:05:42,240
we're going to store that value in a variable called computer choice.

56
00:05:43,390 --> 00:05:49,420
OK, finally, we can test our code by putting in two temporary print statements, I'm going to print

57
00:05:49,870 --> 00:05:52,810
first, I'll insert a new line of space for aesthetic purposes.

58
00:05:53,170 --> 00:06:00,550
Then I'll say you chose Colon and I'll put a tab of space between the string and the value that you

59
00:06:00,550 --> 00:06:01,300
chose.

60
00:06:05,980 --> 00:06:07,270
I'll do another print.

61
00:06:09,860 --> 00:06:11,720
We're all say the computer chose.

62
00:06:13,330 --> 00:06:19,480
Colin and I'll put a tab of space between this string and the random value returned by the computer.

63
00:06:24,500 --> 00:06:26,570
OK, we can perform a final test.

64
00:06:37,360 --> 00:06:42,730
And that prince, my choice, as well as the computer's choice, I'm going to keep running my code and

65
00:06:42,730 --> 00:06:48,310
as I'm doing that, the computer keeps picking random choices, which is what you'd expect from a game

66
00:06:48,310 --> 00:06:49,790
of rock, paper, scissors.

67
00:06:50,710 --> 00:06:54,940
OK, so the next step is to compare your choice against the computer's choice and then you're going

68
00:06:54,940 --> 00:06:57,230
to write code that determines the winner of the game.

69
00:06:57,640 --> 00:06:58,780
See you in part two.

