veloek / cnake Goto Github PK
View Code? Open in Web Editor NEWSimple snake clone for terminals without the use of any 3rd party libraries
License: GNU General Public License v3.0
Simple snake clone for terminals without the use of any 3rd party libraries
License: GNU General Public License v3.0
They might appear different. We can get by with regular ascii characters.
If game->points > highscore
then update highscore right away rather than waiting for game over to do it. I think this makes more sense.
Not all terminals support hiding the cursor, so better to make use of it.
An improvement over clearing all parts before redrawing.
The game doesn't accept input until the countdown is done. It should just quit immediately when q/esc is pressed.
Should also affect the score bump when eating candy.
Store highscore to make it persistent between runs.
Should listen for updates in case some other instance of the game is using the same highscore store.
At least one for drawing and one for gameplay.
Look into the possibilities for listening for cursor movement instead of reading characters from stdin.
Avoid dynamic allocation throughout the game (and possible failure) by allocating everything ever need up front.
Highscore should be persisted between runs.
Could also consider writing to file.
Should probably be a cli option in case the terminal/font doesn't support it.
The app should have the version printed out in the status bar.
The version should be derived from git tags, i.e. git describe --tags
.
Print score somewhere in the screen, perhaps in some kind of status bar at the bottom with potentially more information like speed, time playes, credits, etc.
The rand_int
function in game.c generates numbers in range [min, (min+max))
, which is not in line with the documenting comment that describes the range as [min, max)
.
This manifests itself only when min != 0
. This happens in create_candy()
when finding a free spot.
This test program verifies the bug (unless you are (un)lucky):
#if 0
cc $0
./a.out
rm -f a.out
exit 0
#endif
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
static inline int
rand_bug(int min, int max)
{
double r = (double)rand() / (double)RAND_MAX;
return (int)(r * max) + min;
}
// Verify that the input is bugged
static inline int
verify(int n, int min, int max)
{
return (n < min || n >= max);
}
int
main(int num_args, char *args[])
{
// Try 10000 times to see if we can get a out of range resultqq
for(int i=0; i<10000; ++i)
{
if(verify(rand_bug(10, 11), 10, 11))
{
puts("rand_bug is bugged");
break;
}
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.