package com.as.slotmachine;
// 
import java.util.Random;

import android.os.Bundle;
import android.app.Activity;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity 
{
	final static int StandartBet = 5;
	final static int MaximalBet = 1000;
	Random rndNum = new Random();
	int bet=5;
	int balance=100;
	int imageIDSize,i,n=3;
	Button btnBetUp,btnBetDown,btnStart;
	TextView tvBet, tvBalance;
	//ImageView [] ivFruit = null;
	//   
	private int [] imageId = {
			R.drawable.fruit00, // 
			R.drawable.fruit01,
			R.drawable.fruit02,
			R.drawable.fruit03,
			R.drawable.fruit04,
			R.drawable.fruit05,
			R.drawable.fruit06,
			R.drawable.fruit07
			};
	
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // UI   
        imageIDSize = imageId.length;
        btnBetUp = (Button)findViewById(R.id.btnBetUp);
        btnBetDown = (Button)findViewById(R.id.btnBetDown);
        btnStart = (Button)findViewById(R.id.buttonStart);
        tvBet = (TextView)findViewById(R.id.textViewBet);
        tvBalance = (TextView)findViewById(R.id.textViewBalance);
    }
    //    
    public void btnBetUp_Click(View v)
    {
    	if(bet<MaximalBet) //   
    	{
    		bet+=StandartBet;
    		tvBet.setText("$"+bet);
    	}
    	else ShowMessage("   ");
    }
    //    
    public void btnBetDown_Click(View v)
    {	
    	if(bet-StandartBet>0) //   
		{
			bet-=StandartBet;
			tvBet.setText("$"+bet);
		}
    	else ShowMessage("   ");
    }
    //    
    public void btnStart_Click(View v)
    {
    	if (balance-bet >=0 )//    
    	{
    		balance-=bet;
    		tvBalance.setText("$"+balance);
    		StartGame();
    	}
    		else 
    		{
    			ShowMessage("   !");
    			bet=5;
        		tvBet.setText("$"+bet);
    		}
    	
    }
    //     
    public void StartGame()
    {
    	Animation ScaleAnim;
    	int prize;
    	int randBuffer[] = new int [n];
    	ImageView [] ivFruit = {
    			(ImageView)findViewById(R.id.imageView1),
				(ImageView)findViewById(R.id.imageView2),
				(ImageView)findViewById(R.id.imageView3)
				};
    	//        .
    	for(i=0;i<n;i++)
    	{
    		randBuffer[i] = rndNum.nextInt(imageIDSize);
        	ivFruit[i].setImageResource(imageId[randBuffer[i]]);
        	// 
        	ScaleAnim = AnimationUtils.loadAnimation(this, R.anim.scale_anim);
        	ivFruit[i].startAnimation(ScaleAnim);
    	}
    	//         
    	prize=CheckPrize(randBuffer)*bet;
    	if (prize != 0) 
    	{
    		Music.sound(this, R.raw.slotcoin);
    		ShowMessage(" : $"+prize);
    		AddMoney(prize);
    	}
    }
    //  
    public int CheckPrize (int imageNum[])
    {
    	if (imageNum[0]==imageNum[1] && imageNum[1]==imageNum[2]) return imageNum[1]*2;
    	if (imageNum[0]==imageNum[1] || imageNum[1]==imageNum[2]) return imageNum[1];
    	if (imageNum[0]==imageNum[2]) return imageNum[0];
    	return 0;
    }
    //    
    public void ShowMessage(String s)
    {
    Toast toast1 = Toast.makeText(getApplicationContext(), 
			   s, Toast.LENGTH_SHORT);
	toast1.setGravity(Gravity.CENTER, 0, 0);
	toast1.show();
    }
    
    // 
    public void AddMoney(int money)
    {
    	balance+=money;
        tvBalance.setText("$"+balance); 
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) 
    {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    //       
    @Override
    protected void onResume() 
    {
       super.onResume();
       Music.play(this, R.raw.main);
    }
    //     
    @Override
    protected void onPause() 
    {
       super.onPause();
       Music.stop(this);
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
    	//     
        switch (item.getItemId()) 
    	{
        case R.id.menu_AddMoney:
            AddMoney(250);
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }
    }
}

@@ -102,24 +102,152 @@
 p.Activity;%0A
+import android.app.AlertDialog;%0Aimport android.content.DialogInterface;%0Aimport android.content.DialogInterface.OnClickListener;%0A
 import andro
@@ -830,40 +830,8 @@
 ce;%0A
-%09//ImageView %5B%5D ivFruit = null;%0A
 %09// 
@@ -4093,32 +4093,361 @@
 op(this);%0A    %7D%0A
+%09%0A%09%0A%09//    %0A%09@Override%0A%09public void onBackPressed() %0A%09%7B%0A%09%09new AlertDialog.Builder(this)%0A%09%09.setTitle(%22  %22)%0A%09%09.setMessage(%22   ?%22)%0A%09%09.setNegativeButton(%22%22, null)%0A%09%09.setPositiveButton(%22%22, new OnClickListener() %0A%09%09%7B%0A%09%09public void onClick(DialogInterface arg0, int arg1) %0A%09%09%7B%0A%09%09%09finish(); //    Activity%0A%09%09%7D%0A%09%09%7D).create().show();%0A%09%7D%0A%09%0A
     %0A    @Overri
@@ -4624,10 +4624,10 @@
 ney(
-2
 5
+0
 0);%0A

Add exit dialog