Count the number of repetitions of each element in the list in LISP

Write a program in Lisp to enter a number n and create a list of length n of repeated elements. Count the number of repetitions of each element in the list. Display the count value of each element in character.

( Eg (1 2 1 1 3) should give the output “element 1: three times”).


(defun Num()
(print "Enter a Number:")
(setq a(read))
(loop for i from 0 to a collect(random 3)
)
)
NUM

(defun occurence()
(setf b(Num))
(format t "Elements are : ~S ~%" b)
(setq m(count 0 b))
(format t "Element : ~R ~R times ~%" 0 m)
(setq c(count 1 b))
(format t "Element : ~R ~R times ~%" 1 c)
(setq d(count 2 b))
(format t "Element : ~R ~R times ~%" 2 d)
(setq e(count 3 b))
(format t "Element : ~R ~R times ~%" 3 d)
)
OCCURENCE



Average, Factorial and Fibonacci using LISP


Average

(defun average(n1 n2)
           (setq avg (/  (+ n1 n2) 2))
)

Factorial

(defun factorial(n)
          (if(= n 0 ) 1
                 (* n (factorial(- n 1)))
          )
)


Fibonacci

(defun fibonacci()
         (format t "Enter the limit : ")
         (setf n(read))
         (format t "Fibonacci series : ")
         (format t "0 1")
         (setf a 0)
         (setf b 1)
         (do ((i 3(+ i 1))) ((> i n))
                (setf c (+ a b))
                (format t " ~d" c)
                (setf a b)
                (setf b c)
         )
)

Addition, subtraction, multiplication & division of two numbers using LISP

Write and execute the statements for the following in LISP:

Addition,  subtraction, multiplication & division of two numbers.


(setq no1(read))
12
12

(setq no2(read))
30
30

(+ no1 no2)
42

(- no2 no1)
18

(* no1 no2)
360

(/ no2 no1)
5/2


3 ways to speed up your old smartphone

As smartphones age, they tend to slow down and lag too much while performing the simplest of tasks. But worry not, you can make your old gadget operate faster, just follow these three tips:

Updates
Firmware updates take care of lags, bugs, and other issues that you may not be aware of. Such issues crop up with reasonable frequency, so updating regularly will ensure the best performance for your phone.

Memory issues
Low internal memory might be the reason behind any severe lag that your phone is experiencing. Move your media (pictures, MP3 files, videos, and so forth) to the external memory, usually an SD card. Some low-end and mid-range smartphones might already have low internal memories, in which case, moving your files to the SD card won't help that much.

Apps
The application store of your phone, regardless of which OS it uses, will have plenty of apps that can help boost your phone's performance. Task managers help you monitor and close unnecessary processes. This frees up some RAM memory, and so, the phone will run faster. A good antivirus application will scan your phone for any possible viruses and malwares, which can also slow down your phone.

Convert Service pack 2 to service pack 3

~ go to start---->Run--> type the word Regedit



~ Your windows Registry Editor will open,



~ Go to HKEY_LOCAL_MACHINE\SYSTEM\ CurrentControlSet\ Control\ Windows



~ Than please modify “CSDVersion” from “0×00000200” (SP2) to the Windows XP SP3 value of “0×00000300” and than reboot your system.



Now your Window has been upgraded to SP3 and you will be able to installed various advance softwares.

Factorial Of A Number Recursion Function

Write a program to find factorial of the given number.
Recursion: A function is called'recursive 'if a statement within the body of a function calls the same function. It
is also called'circular definition '. Recursion is thus a process of defining something in terms of itself.
Program: To calculate the factorial value using recursion.
#include

int fact(int n);
int main()
{
int x, i;

printf("En ter a value for x: \n");
scanf("%d" ,&x);

i = fact(x);

printf("\n Factorial of %d is %d", x, i);
return 0;
}
int fact(int n)
{
/* n=0 indicates a terminatin g condition */
if (n
return (1);
}
else
{
/* function calling itself */
return (n * fact(n - 1));
/*n*fact(n -1) is a recursive expression */
}
}
Output:
Enter a value for x:
4
Factorial of 4 is 24
Explanatio n:
fact(n) = n * fact(n-1)
If n=4
fact(4) = 4 * fact(3) there is a call to fact(3)
fact(3) = 3 * fact(2)
fact(2) = 2 * fact(1)
fact(1) = 1 * fact(0)
fact(0) = 1
fact(1) = 1 * 1 = 1
fact(2) = 2 * 1 = 2
fact(3) = 3 * 2 = 6
Thus fact(4) = 4 * 6 = 24
Terminatin g condition( n
infinite loop.

Simple Slider using JQuery Animation

Step 1 : Create a html file and add the following script tag in head section
             <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript">

Step 2 : add the following code to display the images
           
             <div id="wrapper">
<div id="slide">
<img src="7.JPG" width="200px" height="200px" />
<img src="8.JPG" width="200px" height="200px" />
<img src="9.JPG" width="200px" height="200px" />
<img src="11.JPG" width="200px" height="200px" />
<img src="12.JPG" width="200px" height="200px" />
</div>
   </div>

Step 3 : add the following code for next and previous button
            <div id="buttons">
<a href="javascript:void(0)" id="prev"><span style="text-decoration:none;"> < </span></a>
<a href="javascript:void(0)" id="next"><span style="text-decoration:none;"> > </span></a>
   </div>

Step 4: add the following css code
            *{
margin: 0 auto;
padding:0;
        }

#wrapper{
width:600px;
overflow:hidden;

}
#slide{
width:900px;
overflow:hidden;
height:210px;
position:relative;
}

#buttons{
position: relative;
width: 600px;
}


Step 5: add the following jquery to animate slide the images
            $(document).ready(function(){
               var timages = 5; <!-- timages = total number of images -->
var simages = 3; <1-- simages = number of images to show -->
var limages = timages-simages; <!-- limages = number of images remaining i.e. 5-3=2 -->
var cimages = 0; <!-- cimages = current images -->
$("#prev").click(function(){
cimages --;
if (cimages < 0)
{
cimages = 0
}
var posx = cimages* 200;
//showInputText();
$("#slide").animate({left:"-"+posx+"px"}, 500 )
});

$("#next").click(function(){
cimages ++;
if (cimages > limages)
{
cimages = limages
}
var posx = cimages* 200;
//showInputText();
$("#slide").animate({left:"-"+posx+"px"}, 500 )
})
 })



Your final code should look like this

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>

<title>Untitled Document</title>
<style>
*{
margin: 0 auto;
padding:0;
}

#wrapper{
width:600px;
overflow:hidden;

}
#slide{
width:900px;
overflow:hidden;
height:210px;
position:relative;
}

#buttons{
position: relative;
width: 600px;
}
</style>
<script>
$(document).ready(function(){
var timages = 5;
var simages = 3;
var limages = timages-simages;
var cimages = 0;
$("#prev").click(function(){
cimages --;
if (cimages < 0)
{
cimages = 0
}
var posx = cimages* 200;
//showInputText();
$("#slide").animate({left:"-"+posx+"px"}, 500 )
});

$("#next").click(function(){
cimages ++;
if (cimages > limages)
{
cimages = limages
}
var posx = cimages* 200;
//showInputText();
$("#slide").animate({left:"-"+posx+"px"}, 500 )
})
})

</script>
</head>

<body>
<div id="wrapper">
<div id="slide">
<img src="7.JPG" width="200px" height="200px" />
<img src="8.JPG" width="200px" height="200px" />
<img src="9.JPG" width="200px" height="200px" />
<img src="11.JPG" width="200px" height="200px" />
<img src="12.JPG" width="200px" height="200px" />
</div>
</div>
<div id="buttons">
<a href="javascript:void(0)" id="prev"><span style="text-decoration:none;"> < </span></a>
<a href="javascript:void(0)" id="next"><span style="text-decoration:none;"> > </span></a>
</div>
</body>
</html>


Speech Recognition: javax.speech.recognition

Hello World!


The following example shows a simple application that uses speech recognition. For this application we need to define a grammar of everything the user can say, and we need to write the Java software that performs the recognition task.
A grammar is provided by an application to a speech recognizer to define the words that a user can say, and the patterns in which those words can be spoken. In this example, we define a grammar that allows a user to say "Hello World" or a variant. The grammar is defined using the Java Speech Grammar Format. This format is documented in the Java Speech Grammar Format Specification.


Place this grammar into a file.


grammar javax.speech.helloworld;

public <sentence> = hello world | good morning |
                                      hello mighty computer;
This trivial grammar has a single public rule called "sentence". A rule defines what may be spoken by a user. A public rule is one that may be activated for recognition.

The following code shows how to create a recognizer, load the grammar, and then wait for the user to say something that matches the grammar. When it gets a match, it deallocates the engine and exits.


import javax.speech.*;
import javax.speech.recognition.*;
import java.io.FileReader;
import java.util.Locale;

public class HelloWorld extends ResultAdapter {
 static Recognizer rec;

 // Receives RESULT_ACCEPTED event: print it, clean up, exit
 public void resultAccepted(ResultEvent e) {
  Result r = (Result)(e.getSource());
  ResultToken tokens[] = r.getBestTokens();

  for (int i = 0; i < tokens.length; i++)
   System.out.print(tokens[i].getSpokenText() + " ");
  System.out.println();

  // Deallocate the recognizer and exit
  rec.deallocate();
  System.exit(0);
 }

 public static void main(String args[]) {
  try {
   // Create a recognizer that supports English.
   rec = Central.createRecognizer(
       new EngineModeDesc(Locale.ENGLISH));
 
   // Start up the recognizer
   rec.allocate();
 
   // Load the grammar from a file, and enable it
   FileReader reader = new FileReader(args[0]);
   RuleGrammar gram = rec.loadJSGF(reader);
   gram.setEnabled(true);

   // Add the listener to get results
   rec.addResultListener(new HelloWorld());

   // Commit the grammar
   rec.commitChanges();

   // Request focus and start listening
   rec.requestFocus();
   rec.resume();
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
}



This example illustrates the basic steps which all speech recognition applications must perform. Let's examine each step in detail.

Create: The Central class of javax.speech package is used to obtain a speech recognizer by calling the createRecognizer method. The EngineModeDesc argument provides the information needed to locate an appropriate recognizer. In this example we requested a recognizer that understands English (since the grammar is written for English).

Allocate: The allocate methods requests that the Recognizer allocate all necessary resources.

Load and enable grammars: The loadJSGF method reads in a JSGF document from a reader created for the file that contains the javax.speech.demo grammar. (Alternatively, the loadJSGF method can load a grammar from a URL.) Next, the grammar is enabled. Once the recognizer receives focus (see below), an enabled grammar is activated for recognition: that is, the recognizer compares incoming audio to the active grammars and listens for speech that matches those grammars.

Attach a ResultListener: The HelloWorld class extends the ResultAdapter class which is a trivial implementation of the ResultListener interface. An instance of the HelloWorld class is attached to the Recognizer to receive result events. These events indicate progress as the recognition of speech takes place. In this implementation, we process the RESULT_ACCEPTED event, which is provided when the recognizer completes recognition of input speech that matches an active grammar.

Commit changes: Any changes in grammars and the grammar enabled status needed to be committed to take effect (that includes creation of a new grammar).
Request focus and resume: For recognition of the grammar to occur, the recognizer must be in the RESUMED state and must have the speech focus. The requestFocus and resume methods achieve this.
Process result: Once the main method is completed, the application waits until the user speaks. When the user speaks something that matches the loaded grammar, the recognizer issues aRESULT_ACCEPTED event to the listener we attached to the recognizer. The source of this event is a Result object that contains information about what the recognizer heard. The getBestTokensmethod returns an array of ResultTokens, each of which represents a single spoken word. These words are printed.
Deallocate: Before exiting we call deallocate to free up the recognizer's resources.


Credits : www.ling.helsinki.fi

CSS3 Flip 3D Animation Cards HTML5

<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.flip3D{ width:240px; height:200px; margin:10px; float:left; }
.flip3D > .front{
position:absolute;
-webkit-transform: perspective( 600px ) rotateY( 0deg );
transform: perspective( 600px ) rotateY( 0deg );
background:#FC0; width:240px; height:200px; border-radius: 7px;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
transition: -webkit-transform .5s linear 0s;
transition: transform .5s linear 0s;
}
.flip3D > .back{
position:absolute;
-webkit-transform: perspective( 600px ) rotateY( 180deg );
transform: perspective( 600px ) rotateY( 180deg );
background: #80BFFF; width:240px; height:200px; border-radius: 7px;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
transition: -webkit-transform .5s linear 0s;
transition: transform .5s linear 0s;
}
.flip3D:hover > .front{
-webkit-transform: perspective( 600px ) rotateY( -180deg );
transform: perspective( 600px ) rotateY( -180deg );
}
.flip3D:hover > .back{
-webkit-transform: perspective( 600px ) rotateY( 0deg );
transform: perspective( 600px ) rotateY( 0deg );
}
</style>
</head>
<body>
<div class="flip3D">
  <div class="back">Box 1 - Back</div>
  <div class="front">Box 1 - Front</div>
</div>
<div class="flip3D">
  <div class="back">Box 2 - Back</div>
  <div class="front">Box 2 - Front</div>
</div>


<div class="flip3D">
  <div class="back">Box 3 - Back</div>
  <div class="front">Box 3 - Front</div>
</div>
</body>
</html>



credits www.developphp.com

Speech Recognition

Hello Friends here is a simple code to develop a speech recognition in android.


I would suggest that you create a blank project for this, get the basics, then think about merging VR into your existing applications. I’d also suggest that you copy the code below exactly as it appears, once you have that working you can begin to tweak it.
With your blank project setup, you should have an AndroidManifest file like the following.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.jameselsey"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:label="VoiceRecognitionDemo" android:icon="@drawable/icon"
            android:debuggable="true">
        <activity android:name=".VoiceRecognitionDemo"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

And have the following in res/layout/voice_recog.xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="4dip"
        android:text="Click the button and start speaking" />

    <Button android:id="@+id/speakButton"
        android:layout_width="fill_parent"
        android:onClick="speakButtonClicked"
        android:layout_height="wrap_content"
        android:text="Click Me!" />

    <ListView android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1" />

 </LinearLayout>

And finally, this in your res/layout/main.xml :


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="VoiceRecognition Demo!"
    />
</LinearLayout>


So thats your layout and configuration sorted. It will provide us with a button to start the voice recognition, and a list to present any words which the voice recognition service thought it heard. Lets now step through the actual activity and see how this works.

You should copy this into your activity :



package com.jameselsey;

import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.speech.RecognizerIntent;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import java.util.ArrayList;
import java.util.List;

/**
 * A very simple application to handle Voice Recognition intents
 * and display the results
 */
public class VoiceRecognitionDemo extends Activity
{

    private static final int REQUEST_CODE = 1234;
    private ListView wordsList;

    /**
     * Called with the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.voice_recog);

        Button speakButton = (Button) findViewById(R.id.speakButton);

        wordsList = (ListView) findViewById(R.id.list);

        // Disable button if no recognition service is present
        PackageManager pm = getPackageManager();
        List<ResolveInfo> activities = pm.queryIntentActivities(
                new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
        if (activities.size() == 0)
        {
            speakButton.setEnabled(false);
            speakButton.setText("Recognizer not present");
        }
    }

    /**
     * Handle the action of the button being clicked
     */
    public void speakButtonClicked(View v)
    {
        startVoiceRecognitionActivity();
    }

    /**
     * Fire an intent to start the voice recognition activity.
     */
    private void startVoiceRecognitionActivity()
    {
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Voice recognition Demo...");
        startActivityForResult(intent, REQUEST_CODE);
    }

    /**
     * Handle the results from the voice recognition activity.
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        if (requestCode == REQUEST_CODE && resultCode == RESULT_OK)
        {
           
            ArrayList<String> matches = data.getStringArrayListExtra(
                    RecognizerIntent.EXTRA_RESULTS);
            wordsList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
                    matches));
        }
        super.onActivityResult(requestCode, resultCode, data);
    }
}



Breakdown of what the activity does :

Declares a request code, this is basically a checksum that we use to confirm the response when we call out to the voice recognition engine, this value could be anything you want. We also declare a ListView which will hold any words the recognition engine thought it heard.

The onCreate method does the usual initialisation when the activity is first created. This method also queries the packageManager to check if there are any packages installed that can handle intents for ACTION_RECOGNIZE_SPEECH. The reason we do this is to check we have a package installed that can do the translation, and if not we will disable the button.



The speakButtonClicked is bound to the button, so this method is invoked when the button is clicked.



The startVoiceRecognitionActivity invokes an activity that can handle the voice recognition, setting the language mode to free form (as opposed to web form)

The onActivityResult is the callback from the above invocation, it first checks to see that the request code matches the one that was passed in, and ensures that the result is OK and not an error.

Next, the results are pulled out of the intent and set into the ListView to be displayed on the screen.



Notes on debugging :

You won’t have a great deal of luck running this on the emulator, there may be ways of using a PC microphone to direct audio input into the emulator, but that doesn’t sound like a trivial task. Your best bet is to generate the APK and transfer it over to your device



If you experience any crashing errors (I did), then connect your device via USB, enable debugging, and then run the following command from a console window

1
<android-home>/platform-tools/adb -d logcat
What this does, is invoke the android device bridge, the -d switch specifies to run this against the physical device, and the logcat tells the ADB to print out any device logging to the console.

This means anything you do on the device will be logged into your console window, it helped me find a few null pointer issues.



Thats quite a simple activity.  and if you have any comments please let me know. You may have mixed results with what the recognition thinks you have said, I’ve had some odd surprises, let me know!

Happy coding!

Snakes N Ladders Game Java

The Code Below Shows How To Develop SnakesNLadder Game

Step1 : Create a directory to store your snakesnladder image

Step2 : Create a java file and place a main JPanel. In This JPanel Place SnakenLadder Image.

Step 3 : Now place a new JLayeredPane. JLayeredPane Helps you to place panel above a panel. This panel will be a player that will move when the dice is played.

Step 4 : Take maximum width and maximum height of the main panel. Use maximum width as maximum X valu and maximum height as Maximum Y value.Initially  keep the players  position at maximum height and minimum width. Eg X=450 Y=450 then player.x = 25 and player.y = 425

Step 5 : Make a button that gives the dice value. Use this value to move the player. Eg if dice gives value as 6 then add 25 to player.x value till it reaches maximum X value.

Step 6 : If player.x reaches the Maximum X value, reduce the player.y value(eg if player.x = 425 then player.y = 400) and start reducing the player.x value till reaches to the minimum X value
Step 7 : Repeat this procedure till the player.x and player.y value reaches to the 100 block

Note : Even thought the code has the login snake bite and climbing ladder still you should use some logic for snake bite and ladder climbing to improve your logics


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.Timer;
import java.io.*;

public class SnakeLadder extends JFrame implements ActionListener
{
JPanel jp,southPanel,jp2,jp3,northPanel,smiley;
JLayeredPane jp1;
JLabel l1,l2,l3,l4,move,position;
private Timer timer,timer1;
private int delay = 50,delay1 = 1000;
int i=1,j=1,counter=1, x = 10, y = 370, swt = 1, score = 500, moves = 0,a=10,b=370,cur_pos=1,cur_pos1=1;
JButton btnStart,btnStop,btnPlay,btnUndo;
public SnakeLadder()
{
jp = (JPanel)getContentPane();
jp.setLayout(new BorderLayout());
southPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
northPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
jp1 = new JLayeredPane();
jp2 = new JPanel(new FlowLayout(FlowLayout.CENTER));
jp3 = new JPanel(new FlowLayout(FlowLayout.CENTER));
smiley = new JPanel(new FlowLayout(FlowLayout.CENTER));
jp3.setBackground(Color.BLUE);
smiley.setBounds(-10,-10,15,20);
jp3.setBounds(10,370,20,20);
jp2.setBounds(0,0,400,400);
l1 = new JLabel("Score = 500");
l2 = new JLabel("Ladders");
l3 = new JLabel("Snakes");
l4 = new JLabel("1");
position = new JLabel("Position = 1");
move = new JLabel("Moves = 0");
btnStart = new JButton("Start");
btnStop = new JButton("Stop");
btnPlay = new JButton("New Game");
btnUndo = new JButton("Undo");
timer = new Timer(delay,new ActionListener(){
public void actionPerformed(ActionEvent ae)
{
if(i > 0)
                {
                    if(i != 7)
{
counter = i;
                    l4.setText("" + counter);
i++;
}
else
{
i = 1;
}
                }
}
});

timer1 = new Timer(delay1,new ActionListener(){
public void actionPerformed(ActionEvent ae)
{
//jp3.setBounds(x,y,20,20);
timer1.stop();
}
});
jp.add(jp1,BorderLayout.CENTER);
jp2.setOpaque(true);
JLabel background=new JLabel(new ImageIcon("Snakes-Ladders.jpg"));
JLabel background1=new JLabel(new ImageIcon("smileyevil.png"));
jp2.add(background);
smiley.add(background1);
jp1.add(jp2, new Integer(0),0);
jp1.add(jp3, new Integer(1),0);
jp1.add(smiley, new Integer(2),0);
//smiley.setVisible(false);
jp.add(northPanel,"North");
jp.add(l2,"East");
jp.add(l3,"West");
jp.add(southPanel,"South");
southPanel.add(btnStart);
southPanel.add(btnStop);
southPanel.add(btnPlay);
southPanel.add(btnUndo);
southPanel.add(l4);
northPanel.add(l1);
northPanel.add(move);
northPanel.add(position);
btnStart.addActionListener(this);
btnStop.addActionListener(this);
btnPlay.addActionListener(this);
btnUndo.addActionListener(this);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}

public void actionPerformed(ActionEvent ae)
{
if(ae.getSource() == btnUndo)
{
x = a;
y = b;
moves++;
jp3.setBounds(x,y,20,20);
score = score - 5;
if(y == 330 || y == 250 || y == 170 || y == 90 || y == 10)
{
swt = 2;
}
else //if(x == 370 || x == 290 || x == 210 || x == 130 || x == 80)
{
swt = 1;
}
System.out.println("X = " + x + " Y = " + y);
}
if(ae.getSource() == btnPlay)
{
        timer.stop();
btnStop.setEnabled(true);
btnStart.setEnabled(true);
i=1;j=1;counter=1; x = 10; y = 370; swt = 1; score = 500; moves = 0;a=10;b=370;cur_pos=1;
jp3.setBounds(x,y,20,20);
l1.setText("Score = 500");
l4.setText("1");
position.setText("Postion = 1");
move.setText("Moves = 0");
}
if(ae.getSource() == btnStart)
{
smiley.setVisible(false);
        timer.start();
btnStart.setEnabled(false);
btnStop.setEnabled(true);
score= score - 5;
l1.setText("Score = " + score);
}
if(ae.getSource() == btnStop)
{
        timer.stop();
System.out.println("Counter = " + counter);
btnStart.setEnabled(true);
btnStop.setEnabled(false);
moves++;
a = x;
b = y;
if(x == 10 && y == 370 && counter != 6)
{
counter = 1;
}
if(x == 10 && y == 370)
{
counter--;
}
if(x == 210 && y == 10 && counter > 5)
{}
else if(x == 170 && y == 10 && counter > 4)
{}
else if(x == 130 && y == 10 && counter > 3)
{}
else if(x == 90 && y == 10 && counter > 2)
{}
else if(x == 50 && y == 10 && counter > 1)
{}
else
{
while(j <= counter)
{
if(swt == 1)
{
if(x == 370)
{
if(counter == 1)
{
y = y - 40;
swt = 2;
}
else
{
x = 370;
y = y - 40;
swt = 2;
}
}
else
{
x = x + 40;
}
j++;
}
if(swt == 2)
{

if(x == 10)
{
if(counter == 1)
{
y = y - 40;
swt = 1;
}
else
{
x = 10;
y = y - 40;
swt = 1;
}
}
else
{
x = x - 40;
}
j++;
}
}
j = 1;
timer1.start();
jp3.setBounds(x,y,20,20);
}

move.setText("Moves = " + moves);

// LADDERS

if(x == 130 && y == 370)
{
x = 250;
y = 330;
jp3.setBounds(x,y,20,20);
swt = 2;
}
if(x == 330 && y == 370)
{
x = 370;
y = 250;
jp3.setBounds(x,y,20,20);
swt = 2;
}
if(x == 50 && y == 330)
{
x = 90;
y = 250;
jp3.setBounds(x,y,20,20);
swt = 2;
}
if(x == 10 && y == 290)
{
x = 50;
y = 210;
jp3.setBounds(x,y,20,20);
swt = 1;
}
if(x == 290 && y == 290)
{
x = 130;
y = 50;
jp3.setBounds(x,y,20,20);
swt = 1;
}
if(x == 370 && y == 170)
{
x = 250;
y = 130;
jp3.setBounds(x,y,20,20);
swt = 2;
}
if(x == 370 && y == 90)
{
x = 370;
y = 10;
jp3.setBounds(x,y,20,20);
swt = 2;
}
if(x == 10 && y == 90)
{
x = 10;
y = 10;
jp3.setBounds(x,y,20,20);
//swt = 2;
}
// SNAKES
if(x == 130 && y == 330)
{
smiley.setVisible(true);
smiley.setBounds(x,y,15,20);
x = 250;
y = 370;
jp3.setBounds(x,y,20,20);
swt = 1;
}
if(x == 250 && y == 170)
{
smiley.setVisible(true);
smiley.setBounds(x,y,15,20);
x = 250;
y = 250;
jp3.setBounds(x,y,20,20);
swt = 2;
}
if(x == 50 && y == 130)
{
smiley.setVisible(true);
smiley.setBounds(x,y,15,20);
x = 50;
y = 330;
jp3.setBounds(x,y,20,20);
swt = 2;
}
if(x == 130 && y == 130)
{
smiley.setVisible(true);
smiley.setBounds(x,y,15,20);
x = 10;
y = 170;
jp3.setBounds(x,y,20,20);
swt = 2;
}
if(x == 250 && y == 50)
{
smiley.setVisible(true);
smiley.setBounds(x,y,15,20);
x = 130;
y = 290;
jp3.setBounds(x,y,20,20);
swt = 1;
}
if(x == 290 && y == 10)
{
smiley.setVisible(true);
smiley.setBounds(x,y,15,20);
x = 290;
y = 90;
jp3.setBounds(x,y,20,20);
swt = 2;
}
if(x == 210 && y == 10)
{
smiley.setVisible(true);
smiley.setBounds(x,y,15,20);
x = 210;
y = 90;
jp3.setBounds(x,y,20,20);
swt = 2;
}
if(x == 90 && y == 10)
{
smiley.setVisible(true);
smiley.setBounds(x,y,15,20);
x = 50;
y = 90;
jp3.setBounds(x,y,20,20);
swt = 2;
}
System.out.println("X = " + x + " Y = " + y);

// Position

if(y == 370)
{
cur_pos = (x - 10)/40;
cur_pos = cur_pos + 1;
position.setText("Position = " + cur_pos);

}
if(y == 330)
{
cur_pos = (x - 10)/40;
cur_pos = 10 - cur_pos + 10;
position.setText("Position = " + cur_pos);

}
if(y == 290)
{
if(x == 10)
{
cur_pos = (x - 10)/40;
cur_pos = cur_pos + 1 + 20;
position.setText("Position = " + cur_pos);
}
else
{
cur_pos = (x - 10)/40;
cur_pos = cur_pos + 21;
position.setText("Position = " + cur_pos);
}

}
if(y == 250)
{
cur_pos = (x - 10)/40;
cur_pos = 10 - cur_pos + 30;
position.setText("Position = " + cur_pos);

}
if(y == 210)
{
if(x == 10)
{
cur_pos = (x - 10)/40;
cur_pos = cur_pos + 1 + 40;
position.setText("Position = " + cur_pos);
}
else
{
cur_pos = (x - 10)/40;
cur_pos = cur_pos + 41;
position.setText("Position = " + cur_pos);
}

}
if(y == 170)
{
cur_pos = (x - 10)/40;
cur_pos = 10 - cur_pos + 50;
position.setText("Position = " + cur_pos);

}
if(y == 130)
{
if(x == 10)
{
cur_pos = (x - 10)/40;
cur_pos = cur_pos + 1 + 60;
position.setText("Position = " + cur_pos);
}
else
{
cur_pos = (x - 10)/40;
cur_pos = cur_pos + 61;
position.setText("Position = " + cur_pos);
}

}
if(y == 90)
{
cur_pos = (x - 10)/40;
cur_pos = 10 - cur_pos + 70;
position.setText("Position = " + cur_pos);

}
if(y == 50)
{
if(x == 10)
{
cur_pos = (x - 10)/40;
cur_pos = cur_pos + 1 + 80;
position.setText("Position = " + cur_pos);
}
else
{
cur_pos = (x - 10)/40;
cur_pos = cur_pos + 81;
position.setText("Position = " + cur_pos);
}

}
if(y == 10)
{
cur_pos = (x - 10)/40;
cur_pos = 10 - cur_pos + 90;
position.setText("Position = " + cur_pos);

}
if(score == 0)
{
JOptionPane.showMessageDialog(this,"Game Over. Your Score is " + score);
int ans = JOptionPane.showConfirmDialog(this,"New Game","Game",JOptionPane.YES_NO_OPTION);
if(ans == JOptionPane.YES_OPTION)
{
        timer.stop();
btnStop.setEnabled(true);
btnStart.setEnabled(true);
i=1;j=1;counter=1; x = 10; y = 370; swt = 1; score = 500; moves = 0;a=10;b=370;
jp3.setBounds(x,y,20,20);
l1.setText("Score = 500");
l4.setText("1");
move.setText("Moves = 0");
position.setText("Position = 1");
}
else if(ans ==JOptionPane.NO_OPTION)
{
System.exit(0);
}
}
if(x == 10 && y == 10)
{
JOptionPane.showMessageDialog(this,"You Won. Your Score Is " + score);
int ans = JOptionPane.showConfirmDialog(this,"New Game","Game",JOptionPane.YES_NO_OPTION);
if(ans == JOptionPane.YES_OPTION)
{
        timer.stop();
btnStop.setEnabled(true);
btnStart.setEnabled(true);
i=1;j=1;counter=1; x = 10; y = 370; swt = 1; score = 500; moves = 0;a=10;b=370;
jp3.setBounds(x,y,20,20);
l1.setText("Score = 500");
l4.setText("1");
move.setText("Moves = 0");
position.setText("Position = 1");
}
else if(ans ==JOptionPane.NO_OPTION)
{
System.exit(0);
}
}
}
}

public static void main(String[] args)
{
SnakeLadder sl = new SnakeLadder();
sl.setSize(500,500);
sl.setVisible(true);
sl.setResizable(false);
}
}