Final thoughts Payday loan Top Advantages of our payday loans

Programming fun for children with Neko and Turtle in Windows

Python : A fun filled language for both beginners and experienced programmers. But some of us may not cared the fact that it is good for children also.. to start learning programming. As python is a heavily ported language (It runs in huge servers as well as on handheld gaming devices like gp2x too), it doesn’t matter where you are … you can be in Gnu/Linux (highly preferred and for the smart kids) or in Windows platform (only for the not so cool kids)

In Gnu/Linux, Python almost ‘pre loaded’. So you just need to care about the Tkinter module. In Windows , we need to install Python first to do something for for our kids. Just download Python 2.5.2 installer from http://www.python.org/ftp/python/2.5.2/python-2.5.2.msi and click to install it on your machine. Don’t forget to select the Tkinter during installation. Preferably you should modify the Environment Variable Path to include the Python : (C:Python25) will be the default path.

The default package that is present in the Python installation for Kids is Turtle. It is easy to play with Turtle in Python.
The kids can move the lines and draw things in the computer by typing very simple commands in the python interpreter. It is as easy as

import turtle
turtle.begin_fill()
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
This will give the kids an interesting way to see animation of what they are doing in real time and they will get an idea of what programs are suppossed to do.Its output looks like

The best way for the kid to learn programming is by playing with Neko (Cat in Japanese). Just like the Tom and Jerry Show, there is a rat in PyNeko which is an opponent for our Neko. If we program neko, he can jump to places and then eat that cat :) … Must be very funny for the kids….

To start doing something with Neko, we need to download neko.py and nekomaps.py from http://gnuvision.com/pyneko/. ” Adventures with Neko !” is a fun filled programming book by Mr. Pramode CE, a veteran Programmer/Teacher/Philosopher who lives in Thrissur. It is available at http://gnuvision.com/books/pybook/.

Now lets move on with Neko. Create a directory C:Python and download neko.py and nekomaps.py to that directory. Start cmd and cd to C:Python. Now we can start playing with Neko.

Neko can be invoked in Windows by

from neko import *
right() #moves the cat to 1 step right
left() # moves the cat to 1 step left
up() # moves it upwards
down() # moves it downwards..

It is really a funny experience. Read the Adventures with Neko for more fun filled adventures. A sneak peak of Neko :

Try it for your kid, it will be worth the effort, no matter what the OS you choose for it.

Readmore

Play with Configuration files using Python

Today, the main purpose of most of the administrator GUI utilities is to modify the respective configuration files. The most reliable way to modify the configuration file  is to  use  editors like vi or emacs and modify it by hand.
Python provides a better and easy way to play with our configuration files… by using the configobj module. So we can create our own administrative utilities using python (either standalone apps or cgi applications)

http://sourceforge.net/projects/configobj

The configobj module is fully utf-8 encoding compatible. So it doesn’t matter whether your configuration is in English or say for example in Hindi.

Many projects like Bazaar, Turbogears etc are using this module for reading and modifying the configuration files.To modify a config file is as easy as…

from configobj import ConfigObj
config = ConfigObj()
config.filename = filename
#
config['keyword1'] = value1
config['keyword2'] = value2
config.write()

done….. :) , it is that easy….

Refer these links for further information…

http://www.voidspace.org.uk/python/configobj.html#introduction
http://www.linuxjournal.com/article/3616

My idea is to create some customised gui (in Tkinter for portability) for my favourite tools like subversion for administration (in the future , of course)

Readmore

Create and manipulate SQLite databases using Python

SQLite is a small,embedable relational database management System which is almost ACID compliant. It is 
heavily used in the Free/Open source world and by people like Apple. It is deployed in Firefox, Mac OS X, Skype, IPhone 
and Symbian phones. So when you use your Nokia phone (a symbian based phone), remember that you are a sqlite user. With a size less than 500k, it is one of the small but beautiful softwares which is platform independent.

Now let’s play with sqlite3 in Linux..

To create a sqlite database (here test.db), run the sqlite3 command in terminal.

sqlite3 test.db “create table t1(t1key INTEGER PRIMARY KEY, data TEXT, num double, timeEnter Date);”

now we have the test.db database in the present working directory.

To see the table details in a given database, execute this command.

sqlite3 test.db “.table”
t1

Now let’s populate the database..
sqlite3 test.db “insert into t1(data,num) values(‘this is a sample data’,3);”

Ok, now let’s use python’s sqlite bindings to manipulate the database and the data in it..

>>> import sqlite
>>> con = sqlite.connect(‘test.db’)
>>> cur = con.cursor()
>>> cur.execute(‘insert into t1(data,num) values(“this is again a test”,1)’)
>>> cur.commit()
>>> cur.execute(‘SELECT * from t1′)
>>> print cur.fetchall()
[(1, 'this is a sample data', 3.0, None), (2, 'this is again a test', 1.0, None)]

>> cur.execute(‘select * from t1 where num=3′)
>>result=cur.fetchall()[0]
>>print result
(1, ‘this is a sample data’, 3.0, None)
>> print result[1]
this is a sample data

Well, if you think it is not enough to use sqlite in your project, refer this SQLite tutorial : http://souptonuts.sourceforge.net/readme_sqlite_tutorial.html

Readmore

My pretty “Cafe Babe”….

Today I have decided to analyse the class files of my “Chicken Warrior” program.  Instead of .java files, I chose the .class files and viewed it using the PSPad Hex editor…  I found something extra ordinary in the class file (may be , I am looking into the .class file using the hex editor for the first time…  What I saw in
the .class file was this..

The CAFEBABE !!! in a class.. What a sexy class.. A quick google search directed me to this site..  http://www.artima.com/insidejvm/whyCAFEBABE.html

CAFEBABE is the magic number for the .class files in Java. And the magic number is a constant used to identify a file format or protocol in the hacker’s language..

Well, can’t resist java now, anyway there is a Babe in every java class.. Kiss

Readmore

ChickenWarrior : An epic game development in JavaME using Gnu/Linux and NetBeans Mobility Pack

Today, I am releasing the beta version of my new game, ChickenWarrior. This game is  in J2ME, intented for the Mobile Phone users. I have tested this game in Motorolla MotoRokr, Sony Ericsson K700i and Sony Ericsson K300i and it works fairly well Cool

The theme of this game is a chicken desperate to save it’s eggs falling from the sky at night.  Ten eggs will fall from the Sky and the chicken will have to save it .

The NetBeans IDE 6.0 with Mobility pack was used to create this game. The Game Designing part of Mobility pack helps us to easily create the Sprite objects , TiledLayer objects and other game objects  which is very complex to code otherwise.

For game play, we can use the left and right keys to move the chicken left and right. The up key will terminate the game if we wish to terminate the game in the middle.

Source Code :
1) ChickenWarrior.java

/**
  *  @author Maxin B. John <maxinbjohn@gmail.com>
  *
  */

package com;

import java.io.IOException;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;

/**
 * @author maxin.john
 */
public class ChickenWarrior extends MIDlet implements CommandListener {

    private boolean midletPaused = false;
    private Player player ;
    private Display d;
    //<editor-fold defaultstate=”collapsed” desc=” Generated Fields “>//GEN-BEGIN:|fields|0|
    private Command exitCommand;
    private Command playCommand;
    private Form form;
    private StringItem stringItem;
    //</editor-fold>//GEN-END:|fields|0|

    /**
     * The HelloMIDlet constructor.
     */
    public ChickenWarrior() {
     
    }

    //<editor-fold defaultstate=”collapsed” desc=” Generated Methods “>//GEN-BEGIN:|methods|0|
    //</editor-fold>//GEN-END:|methods|0|

    //<editor-fold defaultstate=”collapsed” desc=” Generated Method: initialize “>//GEN-BEGIN:|0-initialize|0|0-preInitialize
    /**
     * Initilizes the application.
     * It is called only once when the MIDlet is started. The method is called before the <code>startMIDlet</code> method.
     */
    private void initialize() {//GEN-END:|0-initialize|0|0-preInitialize
        // write pre-initialize user code here
//GEN-LINE:|0-initialize|1|0-postInitialize
        // write post-initialize user code here
    }//GEN-BEGIN:|0-initialize|2|
    //</editor-fold>//GEN-END:|0-initialize|2|

    //<editor-fold defaultstate=”collapsed” desc=” Generated Method: startMIDlet “>//GEN-BEGIN:|3-startMIDlet|0|3-preAction
    /**
     * Performs an action assigned to the Mobile Device – MIDlet Started point.
     */
    public void startMIDlet() {
       
        switchDisplayable(null, getForm());
       // show();
    }
   
    void show() {
       
        System.out.println(“Midlet running \n”);
        MyGameCanvas dgn = new MyGameCanvas();
        dgn.mid= this;
        new Thread(dgn).start();
        d = Display.getDisplay(this);
        d.setCurrent(dgn);

    }
   
    //<editor-fold defaultstate=”collapsed” desc=” Generated Method: resumeMIDlet “>//GEN-BEGIN:|4-resumeMIDlet|0|4-preAction
    /**
     * Performs an action assigned to the Mobile Device – MIDlet Resumed point.
     */
    public void resumeMIDlet() {
      
    }

    //<editor-fold defaultstate=”collapsed” desc=” Generated Method: switchDisplayable “>//GEN-BEGIN:|5-switchDisplayable|0|5-preSwitch
    /**
     * Switches a current displayable in a display. The <code>display</code> instance is taken from <code>getDisplay</code> method. This method is used by all actions in the design for switching displayable.
     * @param alert the Alert which is temporarily set to the display; if <code>null</code>, then <code>nextDisplayable</code> is set immediately
     * @param nextDisplayable the Displayable to be set
     */
    public void switchDisplayable(Alert alert, Displayable nextDisplayable) {//GEN-END:|5-switchDisplayable|0|5-preSwitch
        // write pre-switch user code here
        Display display = getDisplay();//GEN-BEGIN:|5-switchDisplayable|1|5-postSwitch
        if (alert == null) {
            display.setCurrent(nextDisplayable);
        } else {
            display.setCurrent(alert, nextDisplayable);
        }//GEN-END:|5-switchDisplayable|1|5-postSwitch
        // write post-switch user code here
    }

    //<editor-fold defaultstate=”collapsed” desc=” Generated Method: commandAction for Displayables “>//GEN-BEGIN:|7-commandAction|0|7-preCommandAction
    /**
     * Called by a system to indicated that a command has been invoked on a particular displayable.
     * @param command the Command that was invoked
     * @param displayable the Displayable where the command was invoked
     */
    public void commandAction(Command command, Displayable displayable) {//GEN-END:|7-commandAction|0|7-preCommandAction
        // write pre-action user code here
        if (displayable == form) {//GEN-BEGIN:|7-commandAction|1|19-preAction
            if (command == exitCommand) {//GEN-END:|7-commandAction|1|19-preAction
                // write pre-action user code here
                exitMIDlet();//GEN-LINE:|7-commandAction|2|19-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|3|7-postCommandAction
            if (command == playCommand) {//GEN-END:|7-commandAction|1|19-preAction
                // write pre-action user code here
                show();//GEN-LINE:|7-commandAction|2|19-postAction
                // write post-action user code here
            }//GE
        }//GEN-END:|7-commandAction|3|7-postCommandAction
        // write post-action user code here
    }//GEN-BEGIN:|7-commandAction|4|
    //</editor-fold>//GEN-END:|7-commandAction|4|

    //<editor-fold defaultstate=”collapsed” desc=” Generated Getter: exitCommand “>//GEN-BEGIN:|18-getter|0|18-preInit
    /**
     * Returns an initiliazed instance of exitCommand component.
     * @return the initialized component instance
     */
    public Command getExitCommand() {
        if (exitCommand == null) {//GEN-END:|18-getter|0|18-preInit
            // write pre-init user code here
            exitCommand = new Command(“Exit”, Command.EXIT, 0);//GEN-LINE:|18-getter|1|18-postInit
            // write post-init user code here
        }//GEN-BEGIN:|18-getter|2|
        return exitCommand;
    }
   
   
    public Command getPlayCommand() {
        if (playCommand == null) {//GEN-END:|18-getter|0|18-preInit
            // write pre-init user code here
            playCommand = new Command(“Play”, Command.OK, 0);//GEN-LINE:|18-getter|1|18-postInit
            // write post-init user code here
        }//GEN-BEGIN:|18-getter|2|
        return playCommand;
    }
   
    //</editor-fold>//GEN-END:|18-getter|2|

    //<editor-fold defaultstate=”collapsed” desc=” Generated Getter: form “>//GEN-BEGIN:|14-getter|0|14-preInit
    /**
     * Returns an initiliazed instance of form component.
     * @return the initialized component instance
     */
    public Form getForm() {
        if (form == null) {//GEN-END:|14-getter|0|14-preInit
            // write pre-init user code here
            form = new Form(“       Save the Eggs! “, new Item[] { getStringItem() });//GEN-BEGIN:|14-getter|1|14-postInit
            form.addCommand(getExitCommand());
            form.addCommand(getPlayCommand());
            form.setCommandListener(this);//GEN-END:|14-getter|1|14-postInit
            // write post-init user code here
        }//GEN-BEGIN:|14-getter|2|
        return form;
    }
    //</editor-fold>//GEN-END:|14-getter|2|

    //<editor-fold defaultstate=”collapsed” desc=” Generated Getter: stringItem “>//GEN-BEGIN:|16-getter|0|16-preInit
    /**
     * Returns an initiliazed instance of stringItem component.
     * @return the initialized component instance
     */
    public StringItem getStringItem() {
        if (stringItem == null) {//GEN-END:|16-getter|0|16-preInit
            // write pre-init user code here
            stringItem = new StringItem(“A Chicken Desperate to save it’s eggs..”, “”);//GEN-LINE:|16-getter|1|16-postInit
            // write post-init user code here
        }//GEN-BEGIN:|16-getter|2|
        return stringItem;
    }
   
    /**
     * Returns a display instance.
     * @return the display instance.
     */
    public Display getDisplay () {
        return Display.getDisplay(this);
    }

    /**
     * Exits MIDlet.
     */
    public void exitMIDlet() {
        switchDisplayable (null, null);
        destroyApp(true);
        notifyDestroyed();
    }

    /**
     * Called when MIDlet is started.
     * Checks whether the MIDlet have been already started and initialize/starts or resumes the MIDlet.
     */
    public void startApp() {
        if (midletPaused) {
            resumeMIDlet ();
        } else {
            initialize ();
           // startMIDlet ();
           try{
           player = Manager.createPlayer(getClass().getResourceAsStream(“/Arcade.mid”), “audio/midi”);
           player.setLoopCount(-1);
           player.start();
           }catch(MediaException me)
    {
    }catch(java.io.IOException e)
    {
   
         }
         System.out.println(“Before start midlet\n”);
         startMIDlet ();
        }
        midletPaused = false;
    }

    /**
     * Called when MIDlet is paused.
     */
    public void pauseApp() {
        midletPaused = true;
         try{
        player.stop();
    }catch (MediaException me){
    }
       
    }

    /**
     * Called to signal the MIDlet to terminate.
     * @param unconditional if true, then the MIDlet has to be unconditionally terminated and all resources has to be released.
     */
    public void destroyApp(boolean unconditional) {
        try{
        player.stop();
    }catch (MediaException me){
    }
    }
    }

############################################################

2) MyGameCanvas.java

/**
  *  @author Maxin B. John <maxinbjohn@gmail.com>
  *
  */

package com;

import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.lcdui.game.LayerManager;
import javax.microedition.lcdui.game.Sprite;
import javax.microedition.midlet.*;

/**
 *
 * @author Maxin B. John <maxinbjohn@gmail.com>
 *
 */
public class MyGameCanvas  extends GameCanvas implements Runnable{
     private static final int SPEED = 5;
     private LayerManager lm;
     //private byte lastDirection = -1;
     private SpriteAnimationTask spriteEggAnimator;
     private SpriteAnimationTask spriteChickenAnimator;
     private EggFall EggRandomMovement;
     private boolean interrupted;
     private Timer timer;
     private MyGameDesign gameDesign;
     private int eggNumber;
     private Sprite Egg;
     private Sprite Chicken;
     public MIDlet mid;
     public int canvasHeight;
     public int canvasWidth;
    
    
     public MyGameCanvas(){
            super(true);
            this.eggNumber=0;
            this.setFullScreenMode(true);
            this.init();
        }
    
    public void stop() {
        this.interrupted = true;
    }
     private void init()  {
         try{
         System.out.println(“In init \n”);
         this.timer = new Timer();
         this.gameDesign= new MyGameDesign();
         this.Egg = gameDesign.getEgg();
         this.Chicken = gameDesign.getMyChicken();
         this.Egg.defineReferencePixel(8, 8);
         this.Chicken.defineReferencePixel(8, 8);
         this.canvasHeight= this.getHeight();
         this.canvasWidth = this.getWidth();
         this.spriteEggAnimator = new SpriteAnimationTask(this.Egg, false);
         this.spriteChickenAnimator = new SpriteAnimationTask(this.Chicken, false);
         this.timer.scheduleAtFixedRate(this.spriteEggAnimator, 0, gameDesign.Eggseq001Delay);
         this.timer.scheduleAtFixedRate(this.spriteChickenAnimator, 0, gameDesign.MyChickenseq001Delay);
         this.lm = new LayerManager();
         gameDesign.updateLayerManagerForMySky(lm);
         this.EggRandomMovement = new EggFall(this, Egg);
     
         this.EggRandomMovement.setSequences(
            gameDesign.MyChickenseq001, Sprite.TRANS_NONE,
            gameDesign.MyChickenseq001, Sprite.TRANS_NONE,
            gameDesign.MyChickenseq001, Sprite.TRANS_NONE,
            gameDesign.MyChickenseq001, Sprite.TRANS_NONE
            );
      
        (new Thread(EggRandomMovement)).start();
         }catch (IOException io){}
         }
    
     public boolean setEggNo(){
         this.eggNumber+=1;
         return true;
     }
    
     public int getEggNo(){
         return this.eggNumber;
       }

      /**
     * Check if sprite collides with the Chicken object
     *
     * @param sprite the sprite checked for collision with other layers
     * @return true is sprite does collide, false otherwise
     */
    public boolean spriteCollides(Sprite sprite) {
     return sprite.collidesWith(this.Chicken, true);
       }
    
     public void run(){
           System.out.println(“Inside the run \n”);
           Graphics g = getGraphics();
           while (!this.interrupted) {
            //check for user input
            int keyState = getKeyStates();
            if ((keyState & LEFT_PRESSED) != 0) {
                this.Chicken.setFrameSequence(gameDesign.MyChickenseq001);
                this.Chicken.setTransform(Sprite.TRANS_MIRROR);
                this.spriteChickenAnimator.backward();
                this.Chicken.move(-SPEED, 0);
                System.out.println(“Left key pressed \n”);
              
            }
            if ((keyState & RIGHT_PRESSED) != 0) {
                this.Chicken.setFrameSequence(gameDesign.MyChickenseq001);
                this.Chicken.setTransform(Sprite.TRANS_MIRROR);
                this.Chicken.move(SPEED, 0);
                System.out.println(“Right key pressed \n”);
               
           
            }
            if ((keyState & UP_PRESSED) != 0) {
                this.Chicken.setFrameSequence(gameDesign.MyChickenseq001);
                this.Chicken.setTransform(Sprite.TRANS_MIRROR);
                System.gc();
                try{
                   this.mid.notifyDestroyed();
                  }catch(Exception ex){
                
              }
            } 
                       
            this.Chicken.setFrameSequence(gameDesign.MyChickenseq001);
            this.spriteChickenAnimator.setMoving(true);
            this.lm.paint(g, 0, 0);
            flushGraphics(0, 0, this.getWidth(), this.getHeight());
             try {
                Thread.sleep(200);
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
         }
     }
    
/**
     * Animates a sprite.
     */
  private class SpriteAnimationTask extends TimerTask {

        private boolean moving = false;
        private boolean forward = true;
        private Sprite sprite;

        public SpriteAnimationTask(Sprite sprite, boolean forward) {
            this.sprite = sprite;
            this.forward = forward;
        }

        public void run() {
            if (!this.moving) {
                return;
            }
           
            if (this.forward) {
                this.sprite.nextFrame();
            } else {
                this.sprite.prevFrame();
            }
        }

        public void forward() {
            this.forward = true;
            this.moving = true;
        }

        public void backward() {
            this.forward = false;
            this.moving = true;
        }

        public void setMoving(boolean isMoving) {
            this.moving = isMoving;
        }
    }
}

##############################################################

3) EggFall.java

package com;

/**
 *  @author Maxin B. John <maxinbjohn@gmail.com>
 */

import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.lcdui.game.Sprite;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import java.util.Random;

public class EggFall implements Runnable,CommandListener{

    private static final int SPEED = 3;
    private MyGameCanvas canvas;
    private Sprite sprite;
   
    private byte previousDirection = GameCanvas.DOWN;
    private byte direction = GameCanvas.DOWN;
    private boolean interrupted;
    private int[] downSeq;
    private int downTrans;
    private int[] upSeq;
    private int upTrans;
    private int[] leftSeq;
    private int leftTrans;
    private int[] rightSeq;
    private int rightTrans;
    private int finalScore=0;
    private Command exitCommand;
    private Form form;
    private StringItem stringItem;
    private Display dsp;
   
 
    public EggFall(MyGameCanvas canvas, Sprite sprite) {
        this.canvas = canvas;
        this.sprite = sprite;
    }
  
    /////////////////////////////////////////////////////////
    public void commandAction(Command command, Displayable displayable){
        
   if (command == exitCommand) {
             exitMIDlet();
             System.out.println(“Exit Command \n”); 
            }
   
      }
   
    public Command getExitCommand() {
      
        if (exitCommand == null) {
           exitCommand = new Command(“Exit”, Command.EXIT, 0);
           }
        return exitCommand;
    }
   

      public void exitMIDlet() {
            this.canvas.mid.notifyDestroyed();
    
    }
     
    

     
     /////////////////////////////////////////////////////////
    public void setSequences(int[] downSeq, int downTrans, int[] upSeq, int upTrans, int[] leftSeq, int leftTrans, int[] rightSeq, int rightTrans) {
        this.downSeq = downSeq;
        this.downTrans = downTrans;
        this.upSeq = upSeq;
        this.upTrans = upTrans;
        this.leftSeq = leftSeq;
        this.leftTrans = leftTrans;
        this.rightSeq = rightSeq;
        this.rightTrans = rightTrans;
    }

    public void stop() {
        this.interrupted = true;
    }
   
   public int getRandomNumber(){
        int intervalMin = 10;
        int intervalMax = 100;
        int halfInterval = (intervalMin – intervalMax) / 2;
        int integerDisc = Integer.MAX_VALUE / halfInterval;
        Random r = new Random(System.currentTimeMillis());
        int randomNumber = r.nextInt();
        randomNumber = randomNumber / integerDisc;
        randomNumber = randomNumber + halfInterval;
        randomNumber = randomNumber <0 ? -1*randomNumber: randomNumber;
       
        return randomNumber;
    }
   
    public void run() {
        while (!this.interrupted) {
            if (this.direction == GameCanvas.DOWN) {
                if (this.previousDirection != this.direction) {
                    this.sprite.setFrameSequence(this.downSeq);
                    this.sprite.setTransform(this.downTrans);
                    this.previousDirection = this.direction;
                }
                this.sprite.move(0, SPEED);
                if(this.sprite.getY()> this.canvas.canvasHeight && this.sprite.isVisible()){
                    System.out.println(“This egg got broken .. you loose one egg\n”);
                    this.sprite.setVisible(false);
                    if (this.canvas.getEggNo() >= 10){
                        System.out.println(“Game over You scored ..\n”+ this.finalScore);
                        this.canvas.stop();
                        this.stop();
                        this.canvas.setFullScreenMode(false);
                        this.canvas.setCommandListener(this);
                        this.canvas.addCommand(this.getExitCommand());
                       
                     }
                    else{
                        this.canvas.setEggNo();
                        this.sprite.setPosition(this.getRandomNumber(), 0);
                        this.sprite.setVisible(true);
                         System.out.println(this.canvas.getEggNo());
                    }
                    }
               
                if (this.canvas.spriteCollides(this.sprite)) {
                    this.sprite.setVisible(false);
                    this.finalScore += 1;
                    System.out.println(“You secured your egg!scored”+this.finalScore+”\n”);
                   
                     if (this.canvas.getEggNo() >= 10){
                        System.out.println(“Game over \n”+ this.finalScore);
                        this.canvas.stop();
                        this.stop();
                        this.canvas.setFullScreenMode(false);
                        this.canvas.setCommandListener(this);
                        this.canvas.addCommand(this.getExitCommand());
                    }
                    else{
                        this.canvas.setEggNo();
                        this.sprite.setPosition(this.getRandomNumber(), 0);
                        this.sprite.setVisible(true);
                         System.out.println(this.canvas.getEggNo());
                    }
                    continue;
                }
             }
            try {
                Thread.sleep(200);
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
        }
    }
}

########################################################

4) MyGameDesign.java

/**
  * Maxin B. John <maxinbjohn@gmail.com>
  */

package com;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import java.io.IOException;
import java.util.Random;

/**
 * @author maxin.john
 */
public class MyGameDesign {

    //<editor-fold defaultstate=”collapsed” desc=” Generated Fields “>                     
    private Image eggs;
    private Sprite MyEgg;
    public int MyEggseq001Delay = 200;
    public int[] MyEggseq001 = {68, 68, 68, 67, 67};
    private TiledLayer MyLayer;
    private Sprite Chicken;
    public int Chickenseq001Delay = 100;
    public int[] Chickenseq001 = {84, 85, 86, 87, 84};
    private Image chickens;
    private TiledLayer ChicLayer;
    private Sprite Egg;
    public int Eggseq001Delay = 200;
    public int[] Eggseq001 = {69, 69, 69, 69, 69};
    private Sprite MyChicken;
    public int MyChickenseq001Delay = 200;
    public int[] MyChickenseq001 = {0, 0, 5, 16, 21};
    //</editor-fold>                   
   /* public int canvasHeight=100;
    public int canvasWidth;*/
    //<editor-fold defaultstate=”collapsed” desc=” Generated Methods “>                      
    //</editor-fold>                    

    

                     
    
    public void updateLayerManagerForMySky(LayerManager lm) throws java.io.IOException {                                             
        // write pre-update user code here
        int intervalMin = 10;
        int intervalMax = 100;
        int halfInterval = (intervalMin – intervalMax) / 2;
        int integerDisc = Integer.MAX_VALUE / halfInterval;
        Random r = new Random(System.currentTimeMillis());
        int randomNumber = r.nextInt();
        randomNumber = randomNumber / integerDisc;
        randomNumber = randomNumber + halfInterval;
        randomNumber = randomNumber <0 ? -1*randomNumber: randomNumber;
        getEgg().setPosition(randomNumber, 0);
        getMyChicken().setPosition(10,100);
        getMyChicken().setVisible(true);
        getEgg().setVisible(true);
        lm.append(getEgg());
        lm.append(getMyChicken());
        getChicLayer().setPosition(0, 0);
        getChicLayer().setVisible(true);
        lm.append(getChicLayer());
                                              
        // write post-update user code here
    }                                   
                                 
 

    public Image getChickens() throws java.io.IOException {                                
        if (chickens == null) {                              
            // write pre-init user code here
            chickens = Image.createImage(“/chickens.png”);                                 
        }                               
        // write post-init user code here
        return this.chickens;                       
    }
                     

    public TiledLayer getChicLayer() throws java.io.IOException {                                
        if (ChicLayer == null) {                              
            // write pre-init user code here
            ChicLayer = new TiledLayer(20, 20, getChickens(), 16, 16);                                
            int[][] tiles = {
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 52 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 52 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 52 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 52 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 52 },
                { 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52 }
            };                              
            // write mid-init user code here
            for (int row = 0; row < 20; row++) {                                 
                for (int col = 0; col < 20; col++) {
                    ChicLayer.setCell(col, row, tiles[row][col]);
                }
            }
        }                               
        // write post-init user code here
        return ChicLayer;                       
    }
                     

    public Sprite getEgg() throws java.io.IOException {                                  
        if (Egg == null) {                                
            // write pre-init user code here
            Egg = new Sprite(getChickens(), 16, 16);                                   
            Egg.setFrameSequence(Eggseq001);                                 
            // write post-init user code here
        }                        
        return Egg;
    }
                      

    public Sprite getMyChicken() throws java.io.IOException {                                  
        if (MyChicken == null) {                                
            // write pre-init user code here
            MyChicken = new Sprite(getChickens(), 16, 16);                                   
            MyChicken.setFrameSequence(MyChickenseq001);                                 
            // write post-init user code here
        }                        
        return MyChicken;
    }
                      

}

#############################################################

The resources used in this project, chickens.png


The complete sourcecode along with ChickenWarrior.jad and ChickenWarrior.jar can be downloaded from
http://pysportslive.googlecode.com/files/ChickenWarrior.zip

Wow…. Now I got my own game in My mobile.. So from now on , I can play my games when I get bored… :)

Readmore

Bluejacking in Linux

It’s 6.30 in the afternoon. You are walking out of the Forum in Bengaluru ( New name of Bangalore).  Suddenly your  bluetooth enabled  phone  cries with a strange tone…  You takes it out of your pocket and finds that it’s just vcard sent by some other anonymous bluetooth device.. You opens the vcard and it says..
 ”You have been bluejacked !”…  and now your blood turns cold…

Relax.. real bluejacking wont’ do anything to your phone.. It is just another prank.. to pump up some adrenaline to your blood stream.

Bluejacking is the sending of unsolicited messages over Bluetooth to Bluetooth-enabled devices such as mobile phones, PDAsby sending a vCard which typically contains a message in the name field  to another bluetooth enabled device via the Obex protocol.

The http://www.bluejackq.com/ has some interesting information regarding bluejacking.

We can do Bluejacking in Linux using ussp-push ,  an OBEX object pusher for Linux, using the BlueZ BlueTooth stack. If you have the bluetooth dongle in your machine(Laptop), you can bluejack your friends (certainly don’t do it on strangers, as it may hurt their feelings..).

Download ussp-push from http://freshmeat.net/projects/ussp-push/ and compile it. It depends on the Bluez library, openobex library and usblib libraries. Make sure you satisfy all these dependencies. For that , install the bluez-devel, openobex-devel and libusb-devel packages.

After compiling it, run it as

./ussp-push $MAC@$OCHAN $FILENAME $FILENAME
here MAC is the address of the bluetooth device obtained by the

hcitool scan

and OCHAN can be 1, but if it is not given, the ussp-push uses the sdp protocol to find the supported channel on the device.FILENAME is the name of the file to be sent to the remote phone.

Well, if you really want to see the wild side of ussp-push, see this shell program. http://archives.neohapsis.com/archives/fulldisclosure/2007-01/att-0435/obex_dos.sh

It successfully performed a DOS attack on my friend Jibin’s phone (done with his consent, just to check whether it works on a Sony Ericsson K700i)

Readmore