The classic snake game

Snake Game in C

The classic snake game that a lot of us were addicted to playing on our cellphones, made for DOS using C/C++ language with Borland’s Turbo C & graphics.h library

The project started as a hobby project to explore my C/C++ skills and I along with my friends used it as my project for the Computer Graphics course at my university

Originally posted on TechBirbal on Wed, Feb 20, 2008 by me, under my alias ju_s_t4u. Unfortunately, this great site was discontinued by its owner, hence only archived links available

You may need to install DosBox to compile and/or play the game.


This is the classic version of the most popular mobile and computer game named “SNAKE”. The main objective of this game is to feed an increasing length of a snake with food particles which are found at random positions, picking up bonus mongooses that occur at regular intervals.

Classic Snake Game

The game starts with selecting one of the three difficulty levels followed by a screen which asks the user to select whether he wishes to play a bounded game or an unbounded game. These concepts are discussed later in the synopsis.

Features Of the Game

  • A very user-friendly game
  • Simple and easy game to understand
  • Explanations provided in the game as and when required
  • 3 different difficulty modes
  • 2 different gaming arenas
  • 3 Chances for each user
  • Presence of bonuses in the game to increase scores
  • Presentations of score card in a precise tabular form


The “snake game” is a game made in C++ language. This is a game which is quite easy to play. The game is a classic representation of the snake game which appears as an inbuilt game feature in most of the leading mobile handsets like Nokia.

The “snake game” is one of the simplest game concepts ever, and just like Tetris it’s very addictive. There are a lot of variations of this game written in Flash, a relatively easy game to code, with an ability that when keys are pressed in rapid succession they are all registered. This is necessary if you want to have full control of the snake at all times.

Your goal is to move the snake and eat as many “food” blocks as possible. There is only one food block at any given time. When the food is eaten, the snake grows in length. If you hit the snake itself the game is over.

Depending on the mode selection, the game modifies itself and hence gives the user choices as he is free to select the difficulty level, the game arena that he can select a bounded or an unbounded region.

Each user gets 3 chances. After the snake consumes a food particle, the score increases. After picking up 15 food particles, a bonus mongoose appears. This Bonus is present only for a limited time. Once the user picks up a bonus, his points increase by 5.

If the user wishes to quit the game anytime, He or she can press the ‘X’ key on the keyboard. This would directly exit the game.

Different modes used in the game

  • Easy mode: Here the box size in which the snake is allowed to move around freely is larger in size as compared to the other two modes. Hence, the user finds it a lot easier to control the snake. Chances for the snake to die are quite less
  • Medium mode: Here the box size in which the snake is allowed to move around freely is larger in size as compared to the hard mode and smaller than in easy mode. Chances for the snake to die are moderate
  • Hard mode: Here the box size in which the snake is allowed to move around freely is smallest. Chances for the snake to die are highest

Different Gaming Arena

  • Unbounded mode: Here, during the process of travelling, if the snake hits the boundary wall, it does not die, instead it comes out from the opposite wall as though there is a continuation in the movement.
  • Bounded mode: Here, during the process of travelling, if the snake hits the boundary wall, the snake dies, and this is counted as a loss of life. This is a tougher mode as compared to the unbounded mode.

Fork it on github
0 forks.
0 open issues.
Recent commits: – for bulk TIN & CST status check

A trader/entity in India pays value added tax (VAT) while buying goods and services and also collects VAT while selling to the next entity in the supply chain.

Say, the trader bought some goods worth Rs. 10 and if the VAT rate is 10% he would then pay Rs. 11 to the seller including Rs. 1 as VAT. Now the trader sells the goods to another entity for say Rs. 15, he also collects Rs. 1.5 from the buyer in this transaction. Overall the trader paid Rs.1 and collected Rs.1.5 towards VAT. At the end of the day this trader now owes Rs. 0.5 to the government between these two transactions amongst the three entities.

A trader of a decent magnitude would probably have several thousands of transactions a year across hundreds of buyers and sellers. The trader has to periodically (monthly/quarterly/annually) pay the net VAT he owes to the government. At this time he also needs to justify how the net VAT has been reached at. And this is done by a simple balance sheet (J1/J2) stating how much VAT he paid and to whom and how much he collected and from whom. The buyers and sellers are referred to by a unique number called taxpayer identification number or TIN. The government now knows from you, how much VAT you collected, at the same time it also knows from all your sellers how much VAT they collected from you when they submit their accounts.

Mathematically, the sum of all the VAT collected from you from all the sellers would be same as sum of all the VAT you paid to all of them. If either the trader fails to collect the correct TIN of the one of seller or one of the seller fails to provide your correct TIN, this would quickly raise a mismatch and a possible enquiry from the government asking for an explanation to either of the entities.

It’s the traders responsibility to gather and verify the TINs of various entities it transacts with, he may obtain it verbally, through email, sms and any medium he prefers. Obviously this can lead to mistakes. Thankfully the government (of Maharashtra in this instance) has provided a portal to verify and validate TINs @ Before submitting their accounts to the government, the trader, or his accountant, has to validate all the TINs in their records. An average 200-300 TINs may be fairly the size for each trader. An accountant may have 20 such clients and hence has to validate thousands of TINs. The portal in it’s current form allows validating on TIN at a time only.

Given the above pretext and the importance of having correct TINs and at the same time validating hundreds or thousands of TINs at once let me to create This came as a request from one of my close relatives who is a Chartered Accountant. I have not hacked the government’s TIN database or gained any access to the same maliciously. The tool provides a bulk input interface to the existing portal of the government and validates one TIN at a time behind the scene like a person would do.

GitHub Embed test page

Test page for

GitHub Links



16 repositories, 0 followers.

Highcharts Tips – Accessing chart object from container id

Given the following container for Highcharts, how do you access the appropriate chart object from the container’s id?

Let’s see how we can get a handle of the chart object to display the title

Highcharts 3.0.1+

Highcharts 3.0.1 has made it fairly straightforward like most jQuery plugins

Highcharts 2.3.4+

For Highcharts 2.3.4+ the array Highcharts.charts could be used in conjunction with the data-highcharts-chart attribute to get the position of the chart in the array


An array containing the current chart objects in the page. A chart’s position in the array is preserved throughout the page’s lifetime. When a chart is destroyed, the array item becomes undefined.

If you have only a single chart on your page, you can smartly predict the index to be 0 and skip the first step

All Versions

For versions before 2.3.4 you would need to track/manage the object yourself. We could use a map/object to store the charts by Id

If you have only a single chart on the page, you could simplify to just a  window.chart  object


Understanding Highcharts – Regular/Discrete Series Data

This is a part of the Understanding Highcharts – Series Data blog series

Let us first define what we mean by discrete or regular to set the context on this blog

  1. The x-axis (independent axis) is numerical
  2. The x-axis can be extended infinitely on either side, but sometimes can be bound by a mix & max
  3. Discrete: The x value of a points can’t be any number, but a certain (yet infinitely large) subset of the number system
  4. Regular: The difference between the x-values of any two given points is always an integral multiple of a fixed interval

Mathematically, all the x values can be formulated as follows

x = reference_x + N * fixed_interval

is the x value of a pre-defined reference point in the series, this can be the first point, last point or any other point in the series. N is an integer, can be positive or negative.
is a fixed float. The values of
are static across all the points and only the N value varies from point to point. Integers & Natural numbers are classic examples of such series with
Theoretically, for any series if we were to reduce the
to a very small number, we would always be able fit all data points into the above formula. But in most cases we would not have y-values for all corresponding
values for such small
Let’s say we are driving a car and wish to track the fuel consumption & time taken along our journey. For this experiment, we may choose a fixed interval after which we take a reading, let’s take a reading after every 50 kilometers. Initially, my odometer reads 10000 km and fuel tank is 90%. At the end of the journey I have the following readings

Odometer (km) Fuel Consumed (ltr.) Time Taken (mins.)
10050 7.2 110
10100 7.76 120
10150 8.96 115
10200 3.92 89
10250 7.76 122.6
10300 8.4 117

It can be easily inferred that
fixed_interval = 50 & reference_x = 10000
In fact the
could have been any x value in the series, just that the value of
for points before it would be negative if we were to choose any point other than the start point. More importantly, Highcharts makes life easy if we choose the first point as reference, we will see how to do it next. Generally, although not always, there would be not more than one y value corresponding to each value of x.

Regular/Discrete Series Data in Highcharts

It is easy to notice the pattern of the x values in such series. Given the first point and the interval, the Nth x-value can be calculated & Highcharts offers doing this calculation for you! The series options of Highcharts has following two special properties

If no x values are given for the points in a series, pointStart defines on what value to start. On a datetime X axis, the number will be given as milliseconds since 1970-01-01, for exampleDate.UTC(2011, 0, 1). Defaults to 0.


If no x values are given for the points in a series, pointInterval defines the interval of the x values in milliseconds. For example, if a series contains one value each day, set pointInterval to 24 * 3600 * 1000. Defaults to 1

If the above two properties are set in the series options, we can simply skip the x-values in the data and just provide the y values and let Highcharts take care of the rest.

1) A list of numerical values. In this case, the numerical values will be interpreted as y values, and x values will be automatically calculated, either starting at 0 and incrementing by 1, or from pointStart and pointInterval given in the plotOptions. This option is not available for series types with more than one value per point, like area range or OHLC.

data: [0, 5, 3, 5]

Let us see how to handle the above example in Highcharts


In this approach we are forced to put one and only one value for each possible x value. Since Highcharts calculates the x values by itself, we have very limited control over it.

Say, we did not have valid data for one of the x values? Or one of the x-values is itself not valid? Had we specified the x-values ourselves, we could easily skip the particular data point. We do have an option to mark the y-value as
for missing points, but this will break the chart and may be undesired. If we just wish to skip the point but not break the chart, we would need to use the [x,y] approach.

If we wanted to something more special, e.g. have multiple Y values for a given X, we may have to choose to treat the data as irregular and provide explicit x values for all points.

Read More @ Understanding Highcharts – Series Data blog series

Reference Links

Understanding Highcharts – Series Data

Getting back to basics, let us have a look at the the most fundamental aspect of a chart, the data. Diving deeper into the option of Highcharts.

This is a series of posts dealing with the following topics

Some of the topics are tentative, leave feedback if you want something more covered

Understanding Highcharts – Categorized Series Data

This is a part of the Understanding Highcharts – Series Data blog series

Categories are a bunch of strings that sit on your independent (generally x) axis. Say, for plotting average temperature by country, the country names on the x-axis are categories. This is the simplest form of data, the points & x-axis labels are equally spaced horizontally.

Highcharts supports defining this kind of data in the following two ways

Method I – Using xAxis.categories

Defining the categories at once while defining the x-axis using the xAxis.categories option, and defining only the y values for each series

Method II – Using {name,y} point format

If you are like me, you may not find the above approach very natural. The approach asked us to define all x-values (categories) first and then the y-values as another array, I prefer defining my points as (x,y) or something similar. Well, now we can do just that with Highcharts 3.0, which supports defining categories at the time of defining your data. The now also takes an array of objects, with two properties viz. name and y. The name acts as the category. Additionally we need to instruct Highcharts to use the xAxis as a category axis as follows.

Basic observation tells that the first method allows defining categories only once, hence if there are multiple series having same set of categories the first comes handy and prevents repetition & duplication. I would also use the first form if the set of categories were to be static, this would allow me to easily elevate the categories in a default option object. The second approach is more suited, in my opinion, for situations where the data and the categories are generated programmatically.

Read more @ Understanding Highcharts – Series Data blog series

Reference Links