Check out this link for detailed information and source code.
https://svn.cc.jyu.fi/srv/svn/ohj1-pelit/2014k/vaakakva/