WEBVTT

00:00.870 --> 00:07.790
Even using SEO and for all our output needs up until this point.

00:08.340 --> 00:13.200
However see out isn't really well-suited to games.

00:13.230 --> 00:19.010
For example we couldn't draw you the very right most of the screen very easily.

00:19.080 --> 00:23.980
You have to draw a lot of whitespace first and then draw what you wanted.

00:24.570 --> 00:29.910
So instead of using See outs and want to use a different way of drawing that's more flexible and more

00:29.910 --> 00:32.680
well-suited to games.

00:33.420 --> 00:38.510
We just installed the curses library last time and that's what we're going to be using.

00:38.850 --> 00:49.820
So curses allows us more flexibility on how we draw out our output and also how we get input as well.

00:50.040 --> 00:54.960
It keeps with the ASCII character aesthetic that we're used to.

01:00.160 --> 01:10.820
But allows us to draw the tax at any point the SCREATON you can think of it as having the screen be

01:10.820 --> 01:17.410
a two dimensional array and we can place characters at any location.

01:17.750 --> 01:22.920
In addition Pearse's allows more flexibility with her input.

01:22.950 --> 01:29.450
You noticed that scene will block the program from running the next instruction until the user input

01:29.450 --> 01:31.830
something and presses enter.

01:31.850 --> 01:41.390
This is limits the gains we can make to only turn based games like we've been doing but with curses

01:41.390 --> 01:46.150
we can make it so we don't lock put in.

01:46.460 --> 01:50.560
Instead we can pool periodically free.

01:50.760 --> 01:54.120
Now be able to make interactive games.

01:54.150 --> 01:59.580
So let me show you just a simple hello world example using curses.

01:59.790 --> 02:08.190
So we've already set up our project so if you haven't done that yet watch the last lecture.

02:08.330 --> 02:15.180
And also for myself set up the run configurations for Mac again for Windows users.

02:15.180 --> 02:18.180
You often do the external tools method that I showed

02:20.690 --> 02:25.140
so her saying we need to do is teach cursive.

02:25.160 --> 02:39.570
So you are using init our screen and that's the very first thing this initializes the terminal in curses

02:39.570 --> 02:45.090
mode to do anything uncurse is really cool this first.

02:45.120 --> 02:49.200
Now we can kind of really start using it.

02:49.240 --> 02:56.420
Next thing I want to do is say print W and say hello

02:59.170 --> 03:00.240
or old

03:03.110 --> 03:09.790
so so so this will actually print to the curses window.

03:10.730 --> 03:17.850
And the next thing you do is Refresh Refresh method.

03:20.300 --> 03:27.380
When we print using the print w the data is actually written to like a hidden window which hasn't been

03:27.530 --> 03:28.750
played yet.

03:28.790 --> 03:35.360
So in order to show what we printed we must call the refreshment.

03:35.580 --> 03:36.870
OK.

03:37.110 --> 03:42.280
Just remember if you know if you don't see something show up that you printed.

03:42.280 --> 03:51.500
You have to call refresh a in wanted to call this next function.

03:52.030 --> 03:54.980
Character get c h.

03:55.480 --> 04:01.410
And this really just will for us get one character from the user.

04:01.510 --> 04:07.240
OK this is really just to help us pause so doesn't kind of quit right away.

04:08.260 --> 04:13.620
We'll be using and explaining and get character a bit later too.

04:13.840 --> 04:19.630
So the last thing I need to do is call and win.

04:20.090 --> 04:30.890
And so this cleans up everything that in its green did for hey we must always call and win last.

04:30.910 --> 04:38.920
Every time we use curses it will restore our terminal console to its original state.

04:38.920 --> 04:43.510
Otherwise we may see some weird problems with our terminal.

04:43.570 --> 04:49.070
So let's run this means we yet.

04:49.450 --> 04:50.110
There you go.

04:50.170 --> 04:51.090
Hello world.

04:51.190 --> 04:59.980
And cursor see no text that we drew so far it's nothing exciting.

04:59.980 --> 05:07.360
We could have done this out before but in the next lecture I want to really start diving deep and show

05:07.360 --> 05:12.380
you why we're using curses instead of standard input and output.
