Compile the snake in the browser
Seen linux on a PC emulator written in javascript?
If not, here's a little post about him .
And here he is .
This emulator is a good way to get to know the linux console.
If you have or had Ubuntu (which is also linux), it had a user interface, as in Windows, programs and games are installed using the package manager.
Well, what can be done here?
One of the application actions that can be performed on linux is to compile programs from source.
If you ever wrote a program, you used an IDE like Visual Studio or CodeBlocks, but in this case, obviously, there is no IDE.
But you can compile the code from the console using the gcc program, which is very handy in the system image.
All you need to do is write in the console: gcc hello.c and press [ENTER]
Here hello.c is the name of the file, or rather the path to it, but now we only write the name, since hello.c is in the current folder.
Yes, in the console we have the current folder, its path is written to the left of # or $
( # means we are working as root with unlimited rights; $ - as a regular user).
We move through the folders using cd% folder name% or cd .. to move up the folder higher in the hierarchy, as well as lsto list the files and folders in the current folder:

Well, we ordered gcc hello.c and wait:
(hello.c was put in advance by the author in the system image for testing)

I waited a minute or two, but the program still compiled .
gcc created the a.out file (the default name), this is a ready-made binary, so let's run:
If you just write the name of the program, the command line interpreter will say that it didn’t find such a file,
because in this case it searches not in the current folder, but in / usr / bin, for example, and in other places where programs like cd, ls, gcc are.
Therefore, we write ./a.out : ( ./ - means the current folder)

We see Hello, World on the screen, so everything works. But a whole minute at helloworld it's a long time! Could it be faster?
There is a simple solution: instead of using the gcc compiler, using tcc is the same, but instead of gcc hello.c you need to write tcc hello.c
Let's try to compile something more complicated!
True, we can only run the console application, so take the source code for the console snake nsnake .
The archive contains the src folder, it contains exactly what we need.
But the question is: how can we transfer these files to our emulator?
There is an answer to this question in the emulator FAQ:
You need to use the clipboard - the area for inserting text to the right and the command (program) cat <and> is the redirection of input and output streams for the cat command, respectively: cat </ dev / clipboard> main.c You
also need to create a folder for the game and a folder src (with the mkdir src command ), into which we copy the sources.
As a result, this process looks like this:

Using the up / down arrows, you can navigate through the history of the entered commands. So, in order not to enter a command each time, you can show the previous one using the up arrow and edit.
The sources are in place, now they need to be compiled, and then we will play.
But not everything is so simple, an attempt to compile any of the files will result in an error:

The fact is that compiling an entire project is sometimes very complicated and time-consuming, you need to add options to the compiler and linker to compile the files separately, and then collect the object files together, use external libraries, and the program still contains documentation and more ...
so that you they didn’t think about it when you assemble the program from the sources, the Makefile is written - it just says what to compile and so on.
In short, you need to copy it to the game folder on the emulator.
Also, you need to create the bin, obj, and doc folders, as in the folder with the game that you have on your computer.
Type make , a program that processes the Makefile and compiles everything according to it.

In general, I was tired of waiting and I pressed CTRL + C to complete the process. Why so long?
Because the Makefile says that we need to compile with gcc, but we don’t need this, we want it faster using tcc.
So we find such a line in the Makefile and replace gcc with tcc:

Delete the old Makefile, copy the new one and make again :
UPD: A simpler version from ZyXI : make CC = tcc

Much faster. Wow! it is written that you can already play!
Please note that only those files that were not compiled last time by gcc were compiled.
Because the files were compiled separately, and for each C-file its own .OBJ file was created in the obj folder, and then they were assembled into an
executable file in the bin folder.
Run ( bin / nsnake), the screen is cleared and ...

How is it! We saw that the files were displayed in different colors!
Well, let's play a snake and no flowers.
In the source code of the snake there is some line that displays an error message on the screen and, most importantly, interrupts the program.
If you delete it, the game may crash, as the function that controls the color of the terminal symbols will drop.
Or maybe it will just work somehow.
The code is in the engine.c file on line 243:

We write two slashes in front of each of the two lines - now the code is inactive, in other words, commented out.
Re-create engine.c and rebuild the program:

Now the snake starts and we see the game menu. Hurrah!

There is a problem with choosing the level of complexity and the presence of edges. Firstly, due to the fact that there are no colors, and the active item is highlighted in a different color. They are also selected by arrows, and arrows do not work in the game.
You can play using WASD.

PS: for the full installation of the game you need to copy the documentation and run make install , but there will be problems.
This possibility has not yet been considered: if there is already an executable file of the game, it can be transferred to the emulator using uuencode and uudecode (this is also written in the FAQ ).
UPD: the TERM = xterm command solves the problem of lack of colors, and
TERM = linux makes the arrows working as heaps - you can choose the level of complexity and the presence of edges.
Thanks kekekeks for the tip.
(however, a strange glitch appears - the right border is smeared on the elements on the left - see the screenshot in the comments)
If not, here's a little post about him .
And here he is .
This emulator is a good way to get to know the linux console.
If you have or had Ubuntu (which is also linux), it had a user interface, as in Windows, programs and games are installed using the package manager.
Well, what can be done here?
One of the application actions that can be performed on linux is to compile programs from source.
If you ever wrote a program, you used an IDE like Visual Studio or CodeBlocks, but in this case, obviously, there is no IDE.
But you can compile the code from the console using the gcc program, which is very handy in the system image.
All you need to do is write in the console: gcc hello.c and press [ENTER]
Here hello.c is the name of the file, or rather the path to it, but now we only write the name, since hello.c is in the current folder.
Yes, in the console we have the current folder, its path is written to the left of # or $
( # means we are working as root with unlimited rights; $ - as a regular user).
We move through the folders using cd% folder name% or cd .. to move up the folder higher in the hierarchy, as well as lsto list the files and folders in the current folder:

Well, we ordered gcc hello.c and wait:
(hello.c was put in advance by the author in the system image for testing)

I waited a minute or two, but the program still compiled .
gcc created the a.out file (the default name), this is a ready-made binary, so let's run:
If you just write the name of the program, the command line interpreter will say that it didn’t find such a file,
because in this case it searches not in the current folder, but in / usr / bin, for example, and in other places where programs like cd, ls, gcc are.
Therefore, we write ./a.out : ( ./ - means the current folder)

We see Hello, World on the screen, so everything works. But a whole minute at helloworld it's a long time! Could it be faster?
There is a simple solution: instead of using the gcc compiler, using tcc is the same, but instead of gcc hello.c you need to write tcc hello.c
Let's try to compile something more complicated!
True, we can only run the console application, so take the source code for the console snake nsnake .
The archive contains the src folder, it contains exactly what we need.
But the question is: how can we transfer these files to our emulator?
There is an answer to this question in the emulator FAQ:
You need to use the clipboard - the area for inserting text to the right and the command (program) cat <and> is the redirection of input and output streams for the cat command, respectively: cat </ dev / clipboard> main.c You
also need to create a folder for the game and a folder src (with the mkdir src command ), into which we copy the sources.
As a result, this process looks like this:

Using the up / down arrows, you can navigate through the history of the entered commands. So, in order not to enter a command each time, you can show the previous one using the up arrow and edit.
The sources are in place, now they need to be compiled, and then we will play.
But not everything is so simple, an attempt to compile any of the files will result in an error:

The fact is that compiling an entire project is sometimes very complicated and time-consuming, you need to add options to the compiler and linker to compile the files separately, and then collect the object files together, use external libraries, and the program still contains documentation and more ...
so that you they didn’t think about it when you assemble the program from the sources, the Makefile is written - it just says what to compile and so on.
In short, you need to copy it to the game folder on the emulator.
Also, you need to create the bin, obj, and doc folders, as in the folder with the game that you have on your computer.
Type make , a program that processes the Makefile and compiles everything according to it.

In general, I was tired of waiting and I pressed CTRL + C to complete the process. Why so long?
Because the Makefile says that we need to compile with gcc, but we don’t need this, we want it faster using tcc.
So we find such a line in the Makefile and replace gcc with tcc:

Delete the old Makefile, copy the new one and make again :
UPD: A simpler version from ZyXI : make CC = tcc

Much faster. Wow! it is written that you can already play!
Please note that only those files that were not compiled last time by gcc were compiled.
Because the files were compiled separately, and for each C-file its own .OBJ file was created in the obj folder, and then they were assembled into an
executable file in the bin folder.
Run ( bin / nsnake), the screen is cleared and ...

How is it! We saw that the files were displayed in different colors!
Well, let's play a snake and no flowers.
In the source code of the snake there is some line that displays an error message on the screen and, most importantly, interrupts the program.
If you delete it, the game may crash, as the function that controls the color of the terminal symbols will drop.
Or maybe it will just work somehow.
The code is in the engine.c file on line 243:

We write two slashes in front of each of the two lines - now the code is inactive, in other words, commented out.
Re-create engine.c and rebuild the program:

Now the snake starts and we see the game menu. Hurrah!

There is a problem with choosing the level of complexity and the presence of edges. Firstly, due to the fact that there are no colors, and the active item is highlighted in a different color. They are also selected by arrows, and arrows do not work in the game.
You can play using WASD.

PS: for the full installation of the game you need to copy the documentation and run make install , but there will be problems.
This possibility has not yet been considered: if there is already an executable file of the game, it can be transferred to the emulator using uuencode and uudecode (this is also written in the FAQ ).
UPD: the TERM = xterm command solves the problem of lack of colors, and
TERM = linux makes the arrows working as heaps - you can choose the level of complexity and the presence of edges.
Thanks kekekeks for the tip.
(however, a strange glitch appears - the right border is smeared on the elements on the left - see the screenshot in the comments)