Friday, April 24, 2009

Java Desktop Fortune teller

This is a simple java desktop application that "predicts" your fortune. It makes use of a getfortune method to display predefined fortune texts in a label. The getFortune method uses the random function from the "import java.lang.Math.*" package to choose the fortune to display.

fortune teller
public String getFortune() {
String prediction[]={"You will die a horrible death at 3:00 PM","You will win a lottery today","You will slip and fall today","Beware of red Vehicles","You will get a promotion today","You will become king one day","You will win the Nobel prize next year","You will win every contest you enter today","Your boss will go on leave for the next week","You will buy a car soon","You will become God"};
int forval=(int)Math.round(Math.random()*10);
return prediction[forval];
}

The different fortunes are stored in an array of strings and the value obtained from the random function is used as the array index. The value from random is between 0 and 1, and is multiplied by 10 to get the final value. Hence, the array will not go out of bound.

Thursday, April 23, 2009

Crayon Physics - error - limit on number of drawings

After writing a kind of tutorial on wining the seven different crayon physics puzzles or levels (crayon puzzles) in the demo mode, the game showed few limits, not by itself by the physics engine on which it runs. The error says "You Broke my Game! There's too many objects on the screen . The physics engine can't keep up with it. Unfortunately you will have to restart the level :("

crayon physics errorThe worst thing about this error is it pops up just when you are able to solve :) the puzzle.

The different levels of the demo are:

  1. Tutorial
  2. The 2 towers
  3. Tee Ters
  4. Lots of Space
  5. Log
  6. Sky Captain
  7. Nasty
The background music of the game is pretty melodious and not interfering. The final word is Crayon physics proves beyond doubt tat its an awesomely cool game :)

Wednesday, April 22, 2009

Crayon Physics - Nasty

The Nasty level in crayon physics has two stars to collect. Although its possible to collect both stars in a single go, this method shows collecting each of the stars in separate goes.

To collect the first star, first block the ball at the top. and create structures as in image below.
Nasty crayon Physics
Delete the blocking box to collect the first start. The ball falls down and comes for second go. Block the ball and build the next set of structures as in below image.

Nasty Crayon second starDraw both structures together along with guarding wall at the left bottom corner to collect both stars in a single go.

Crayon Physics - Sky Captain

Sky captain can be solved similar to TEE TERS by balancing the see saws and then setting the ball rolling. But make sure the right side is having some weight to counteract the weight of the square tat gets the ball rolling.

The seesaws can be balanced using a single beam or two separate beams. But make sure to use long beams to get them balanced.

Crayon Physics - Log

The Log can be solved very easily by removing the log and then setting the ball roll. However, can anybody solve it without making the log fall? The acclaimed tunneling effect from quantum physics is required for this :) Any quantum physicists out there? can u do it?

Anyway for the rest of us the easy solution is given below. First get the log out of the way by dropping beams on top of it. Then just get the ball rolling to collect the star.

crayon physics log
If any of you quantum physicists can do the tunneling effect without making the log fall, do let me know how u did it.

Crayon Physics - Lots Of Space

Lots of space seemed a bit difficult to solve to begin with as it required the drawing of boxes of exact sizes so tat the weight got balanced. If you draw a box tats too small or too big, they will both go tumbling down. The challenge is to fill the space and make the ball roll.
crayon physics lots of spaceDraw the leftmost vertical box first and make it stand properly. Next draw the slant pole so tat it gets balanced by the vertical box. Once the the two boxes get balanced, draw a third box to get the ball rolling.

A much easier way is to draw multiple boxes to make the levels nearly equal, and drawing a pole connecting the two. Then once the ball comes near the piled up boxes, delete them quickly so tat the ball falls on top of the star.

The way2 to solve lots of space teaches cantilever concept.
crayon physics lot of space cantileverSo lot of physics learning going on with the crayon.

Crayon Physics - tee ters

The third puzzle called the Teeters or TEE TERS can be solved by drawing a single bar that balances and equalises the two see saws and drawing another box to get the ball rolling.


This seems to be the simplest solution. So should we try to solve the puzzle by drawing the least number of stuffs? is tat the aim of the game? well tat would make the game boring and does not make the full use of the artistic power of Crayon Physics.