Skip to content

Instantly share code, notes, and snippets.

@ssaurel
Created June 15, 2018 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssaurel/f20730f9f4951387dfd976a07dd6df06 to your computer and use it in GitHub Desktop.
Save ssaurel/f20730f9f4951387dfd976a07dd6df06 to your computer and use it in GitHub Desktop.
Main Activity Java Code for the Roulette Game on the SSaurel's Channel
package com.ssaurel.roulettegame;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.Random;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class MainActivity extends AppCompatActivity {
// sectors of our wheel (look at the image to see the sectors)
private static final String[] sectors = { "32 red", "15 black",
"19 red", "4 black", "21 red", "2 black", "25 red", "17 black", "34 red",
"6 black", "27 red","13 black", "36 red", "11 black", "30 red", "8 black",
"23 red", "10 black", "5 red", "24 black", "16 red", "33 black",
"1 red", "20 black", "14 red", "31 black", "9 red", "22 black",
"18 red", "29 black", "7 red", "28 black", "12 red", "35 black",
"3 red", "26 black", "zero"
};
@BindView(R.id.spinBtn)
Button spinBtn;
@BindView(R.id.resultTv)
TextView resultTv;
@BindView(R.id.wheel)
ImageView wheel;
// We create a Random instance to make our wheel spin randomly
private static final Random RANDOM = new Random();
private int degree = 0, degreeOld = 0;
// We have 37 sectors on the wheel, we divide 360 by this value to have angle for each sector
// we divide by 2 to have a half sector
private static final float HALF_SECTOR = 360f / 37f / 2f;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment