Search This Blog

Thursday, September 6, 2012

Cows and Bulls : back to JavaScript

No ROR today. My aim for the day was to develop cows and bulls game. Sadly many friends of mine didn't know about the game! Its a very popular time pass game in school.

http://en.wikipedia.org/wiki/Bulls_and_cows

check this link to know the rules of the game :)

What i did is basically a word game. The word to be guessed correctly can be a 3 or 4 or 5 letter word . User's can adjust word length.
So the major problem here is , the words chosen by computer and words given by users as guess should be all proper English words.
To solve this problem,

  • i downloaded a text file containing all dictionary words
  • made a new file containing words of length only from 3 to 6 using grep command
  • from inside the webpage sent a xmlhttp request (AJAX request) to the local file
  • fetched the words and loaded them into array
  • used this array to check if the word entered by user is a proper english word
The solution worked perfectly on Firefox. Chrome didn't allow AJAX request to be sent to some local file. Seems like they are strict with security issues associated with accessing resources in local system.
I have to find some workaround for making the game work in Chrome.

To add more spice to the game, i implemented a scratch pad kind of thing ( using tables) which has all 26 English alphabets. Users can mark them red/green so that they can easily track what alphabets are rejected(red) and what alphabets are present(green).

It looked like a small application when i started coding. But it took one full day to fix all bugs and make it work smoothly in a user friendly way.Wrote the game from scratch using pure JS and html.
I shall share the code with you soon.
See you in next post with more interesting applications :)

No comments:

Post a Comment