From 04ef2d06c2b82baeec8a0ab62636375d6e771122 Mon Sep 17 00:00:00 2001 From: Scorpion Date: Mon, 4 Mar 2013 15:05:30 +0900 Subject: [PATCH 1/3] Add save data of balance --- AndroidManifest.xml | 2 +- src/com/as/slotmachine/MainActivity.java | 56 ++++++++++++++++++------ src/com/as/slotmachine/Music.java | 4 +- 3 files changed, 47 insertions(+), 15 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index c54c2c7..d14a0c3 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,7 +1,7 @@ + android:versionName="1.4" android:installLocation="auto"> Date: Sun, 29 Dec 2013 15:08:49 +0200 Subject: [PATCH 2/3] Cosmetic changes. Source code formatting was done. Some project files were changed. --- .classpath | 9 + .gitignore | 2 - .project | 44 +++ AndroidManifest.xml | 2 +- gen/.gitignore | 1 + gen/com/as/slotmachine/BuildConfig.java | 2 +- project.properties | 2 +- res/values/strings.xml | 26 +- src/com/as/slotmachine/MainActivity.java | 480 +++++++++++++---------- src/com/as/slotmachine/Music.java | 37 -- 10 files changed, 353 insertions(+), 252 deletions(-) create mode 100644 .classpath create mode 100644 .project create mode 100644 gen/.gitignore delete mode 100644 src/com/as/slotmachine/Music.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..0461652 --- /dev/null +++ b/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.gitignore b/.gitignore index 5ebd21a..c184c0a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ ################# *.pydevproject -.project .metadata bin/ tmp/ @@ -12,7 +11,6 @@ tmp/ *.swp *~.nib local.properties -.classpath .settings/ .loadpath diff --git a/.project b/.project new file mode 100644 index 0000000..fb968db --- /dev/null +++ b/.project @@ -0,0 +1,44 @@ + + + Dark Scorpion Slot + + + + + + com.android.ide.eclipse.adt.ResourceManagerBuilder + + + + + com.android.ide.eclipse.adt.PreCompilerBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + com.android.ide.eclipse.adt.ApkBuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + com.android.ide.eclipse.adt.AndroidNature + org.eclipse.jdt.core.javanature + org.eclipse.pde.PluginNature + + diff --git a/AndroidManifest.xml b/AndroidManifest.xml index d14a0c3..bc8f3ee 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -5,7 +5,7 @@ + android:targetSdkVersion="19" /> - - Игровой Автомат - Фруктовый автомат - Descript - #1088F1 - Ставка - Запустить автомат - Баланс: - Получить деньги - + - - - + + + Игровой Автомат + Фруктовый автомат + Descript + #1088F1 + Ставка + Запустить автомат + Баланс: + Получить деньги + + + - + \ No newline at end of file diff --git a/src/com/as/slotmachine/MainActivity.java b/src/com/as/slotmachine/MainActivity.java index 11d4f46..d7ea716 100644 --- a/src/com/as/slotmachine/MainActivity.java +++ b/src/com/as/slotmachine/MainActivity.java @@ -1,9 +1,15 @@ package com.as.slotmachine; -// + +/* + * . + */ import java.util.Random; + +import android.media.MediaPlayer; import android.os.Bundle; import android.app.Activity; import android.app.AlertDialog; +import android.content.Context; import android.content.DialogInterface; import android.content.SharedPreferences; import android.content.DialogInterface.OnClickListener; @@ -19,212 +25,292 @@ 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(); +/** + * + * @author + */ +public class MainActivity extends Activity { + /** + * + * @author + */ + private static class Music { + private static MediaPlayer mp = null; + + private static MediaPlayer sp = null; + + public static void play(Context context, int resource) { + stop(context); + mp = MediaPlayer.create(context, resource); + mp.setLooping(true); + mp.start(); + } + + public static void sound(Context context, int resource) { + sp = MediaPlayer.create(context, resource); + sp.start(); + } + + public static void stop(Context context) { + if (mp != null) { + mp.stop(); + mp.release(); + mp = null; + } + } + } + + private final static int STANDARD_BET = 5; + + private final static int MAXIMAL_BET = 1000; + + private final static Random PRNG = new Random(); + int bet = 5; + int balance; - int imageIdSize,i; + + int imageIdSize, i; + int FruitCount = 3; + SharedPreferences sPref; + TextView tvBet, tvBalance; - Button btnBetUp,btnBetDown,btnStart; - // - 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); - LoadBalance(); - } - // - public void btnBetUp_Click(View v) - { - if(bet+StandartBet < 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() - { - int prize; - Animation ScaleAnim; - int randBuffer[] = new int [FruitCount]; - ImageView [] ivFruit = { - (ImageView)findViewById(R.id.imageView1), - (ImageView)findViewById(R.id.imageView2), - (ImageView)findViewById(R.id.imageView3) - }; - // . - for(i=0;i 0) { + bet -= STANDARD_BET; + tvBet.setText("$" + bet); + } else { + ShowMessage(" "); + } + } + + /** + * . + * + * @param v + */ + 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() { + int prize; + + Animation ScaleAnim; + + int randBuffer[] = new int[FruitCount]; + + ImageView[] ivFruit = { (ImageView) findViewById(R.id.imageView1), + (ImageView) findViewById(R.id.imageView2), + (ImageView) findViewById(R.id.imageView3) }; + + /* + * . + */ + for (i = 0; i < FruitCount; i++) { + randBuffer[i] = PRNG.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); } - }).create().show(); } - - - public void SaveBalance(int balance) - { - sPref = getSharedPreferences("FruitMachin_data",MODE_PRIVATE); + + /** + * . + * + * @param imageNum + * + * @return + */ + 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; + } + + /** + * . + * + * @param s + */ + public void ShowMessage(String s) { + Toast toast1 = Toast.makeText(getApplicationContext(), s, + Toast.LENGTH_SHORT); + toast1.setGravity(Gravity.CENTER, 0, 0); + toast1.show(); + } + + /** + * . + * + * @param money + */ + 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(); + SaveBalance(balance); + Music.stop(this); + } + + /** + * . + */ + @Override + public void onBackPressed() { + new AlertDialog.Builder(this).setTitle(" ") + .setMessage(" ?") + .setNegativeButton("", null) + .setPositiveButton("", new OnClickListener() { + public void onClick(DialogInterface arg0, int arg1) { + /* + * Activity. + */ + finish(); + } + }).create().show(); + } + + /** + * + * @param balance + */ + public void SaveBalance(int balance) { + sPref = getSharedPreferences("FruitMachin_data", MODE_PRIVATE); Editor ed = sPref.edit(); ed.putInt("Balance", balance); ed.commit(); } - - public void LoadBalance() - { - sPref = getSharedPreferences("FruitMachin_data",MODE_PRIVATE); - balance = sPref.getInt("Balance", 150); - tvBalance.setText("$"+balance); - - } - - - @Override - public boolean onOptionsItemSelected(MenuItem item) - { - // - switch (item.getItemId()) - { - case R.id.menu_AddMoney: - AddMoney(500); - return true; - default: - return super.onOptionsItemSelected(item); - } - } + + /** + * + */ + public void LoadBalance() { + sPref = getSharedPreferences("FruitMachin_data", MODE_PRIVATE); + balance = sPref.getInt("Balance", 150); + tvBalance.setText("$" + balance); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + /* + * . + */ + switch (item.getItemId()) { + case R.id.menu_AddMoney: + AddMoney(500); + return true; + default: + return super.onOptionsItemSelected(item); + } + } } diff --git a/src/com/as/slotmachine/Music.java b/src/com/as/slotmachine/Music.java deleted file mode 100644 index 36376b0..0000000 --- a/src/com/as/slotmachine/Music.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.as.slotmachine; - -import android.content.Context; -import android.media.MediaPlayer; - -public class Music -{ - private static MediaPlayer mp = null; - private static MediaPlayer sp = null; - - public static void play(Context context, int resource) - { - stop(context); - mp = MediaPlayer.create(context, resource); - mp.setLooping(true); - mp.start(); - } - - public static void sound (Context context, int resource) - { - //int soundID = sp.load(context, resource,1); - //sp.play(soundID, 1, 0, 1, 0, 1f); - sp = MediaPlayer.create(context, resource); - sp.start(); - } - - - public static void stop(Context context) - { - if (mp != null) - { - mp.stop(); - mp.release(); - mp = null; - } - } -} From c1b1edd903b1be1bf4cd35dd420272695c400458 Mon Sep 17 00:00:00 2001 From: Todor Balabanov Date: Sun, 29 Dec 2013 15:10:21 +0200 Subject: [PATCH 3/3] Gen files are not needed. --- gen/.gitignore | 1 - gen/com/as/slotmachine/BuildConfig.java | 6 -- gen/com/as/slotmachine/R.java | 83 ------------------------- 3 files changed, 90 deletions(-) delete mode 100644 gen/.gitignore delete mode 100644 gen/com/as/slotmachine/BuildConfig.java delete mode 100644 gen/com/as/slotmachine/R.java diff --git a/gen/.gitignore b/gen/.gitignore deleted file mode 100644 index 43e58b9..0000000 --- a/gen/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/com diff --git a/gen/com/as/slotmachine/BuildConfig.java b/gen/com/as/slotmachine/BuildConfig.java deleted file mode 100644 index 176b1b8..0000000 --- a/gen/com/as/slotmachine/BuildConfig.java +++ /dev/null @@ -1,6 +0,0 @@ -/** Automatically generated file. DO NOT MODIFY */ -package com.as.slotmachine; - -public final class BuildConfig { - public final static boolean DEBUG = true; -} \ No newline at end of file diff --git a/gen/com/as/slotmachine/R.java b/gen/com/as/slotmachine/R.java deleted file mode 100644 index e0411c7..0000000 --- a/gen/com/as/slotmachine/R.java +++ /dev/null @@ -1,83 +0,0 @@ -/* AUTO-GENERATED FILE. DO NOT MODIFY. - * - * This class was automatically generated by the - * aapt tool from the resource data it found. It - * should not be modified by hand. - */ - -package com.as.slotmachine; - -public final class R { - public static final class anim { - public static final int scale_anim=0x7f040000; - } - public static final class attr { - } - public static final class color { - public static final int bgrColor=0x7f070006; - public static final int button_focused_color_end=0x7f070001; - public static final int button_focused_color_start=0x7f070000; - public static final int button_normal_color_end=0x7f070003; - public static final int button_normal_color_start=0x7f070002; - public static final int button_pressed_color_end=0x7f070005; - public static final int button_pressed_color_start=0x7f070004; - } - public static final class drawable { - public static final int coin_balance=0x7f020000; - public static final int fruit00=0x7f020001; - public static final int fruit01=0x7f020002; - public static final int fruit02=0x7f020003; - public static final int fruit03=0x7f020004; - public static final int fruit04=0x7f020005; - public static final int fruit05=0x7f020006; - public static final int fruit06=0x7f020007; - public static final int fruit07=0x7f020008; - public static final int ic_action_search=0x7f020009; - public static final int ic_launcher=0x7f02000a; - public static final int newbtn=0x7f02000b; - public static final int newbtn_focused=0x7f02000c; - public static final int newbtn_normal=0x7f02000d; - public static final int newbtn_pressed=0x7f02000e; - } - public static final class id { - public static final int btnBetDown=0x7f0a0005; - public static final int btnBetUp=0x7f0a0007; - public static final int buttonStart=0x7f0a0009; - public static final int imageView1=0x7f0a0001; - public static final int imageView2=0x7f0a0002; - public static final int imageView3=0x7f0a0003; - public static final int imageView4=0x7f0a000b; - public static final int linearLayout1=0x7f0a0000; - public static final int menu_AddMoney=0x7f0a000d; - public static final int tableRow1=0x7f0a0004; - public static final int tableRow2=0x7f0a0008; - public static final int tableRow3=0x7f0a000a; - public static final int textViewBalance=0x7f0a000c; - public static final int textViewBet=0x7f0a0006; - } - public static final class layout { - public static final int activity_main=0x7f030000; - } - public static final class menu { - public static final int activity_main=0x7f090000; - } - public static final class raw { - public static final int main=0x7f050000; - public static final int slotcoin=0x7f050001; - } - public static final class string { - public static final int ImageDescription=0x7f080002; - public static final int Menu_AddMoney=0x7f080006; - public static final int app_name=0x7f080000; - public static final int betDown=0x7f080008; - public static final int betUp=0x7f080007; - public static final int btnBet=0x7f080003; - public static final int btnStart=0x7f080004; - public static final int title_activity_main=0x7f080001; - public static final int wordBalance=0x7f080005; - } - public static final class style { - public static final int AppTheme=0x7f060001; - public static final int ButtonTheme=0x7f060000; - } -}