Created
January 30, 2018 21:14
-
-
Save AhmedOmarDarwish/daddc18a16d27fca5dbaea0b590ebf07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.andriod.bowlinggame; | |
import android.annotation.SuppressLint; | |
import android.annotation.TargetApi; | |
import android.media.MediaPlayer; | |
import android.net.Uri; | |
import android.os.Build; | |
import android.support.annotation.RequiresApi; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.ImageView; | |
import android.widget.TextView; | |
import com.google.android.gms.appindexing.Action; | |
import com.google.android.gms.appindexing.AppIndex; | |
import com.google.android.gms.appindexing.Thing; | |
import com.google.android.gms.common.api.GoogleApiClient; | |
public class MainActivity extends AppCompatActivity { | |
/** | |
* ATTENTION: This was auto-generated to implement the App Indexing API. | |
* See https://g.co/AppIndexing/AndroidStudio for more information. | |
*/ | |
private GoogleApiClient client; | |
@TargetApi(Build.VERSION_CODES.LOLLIPOP) | |
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN) | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
// ATTENTION: This was auto-generated to implement the App Indexing API. | |
// See https://g.co/AppIndexing/AndroidStudio for more information. | |
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); | |
MediaPlayer Mp = MediaPlayer.create(this,R.raw.cheering); | |
} | |
int scoreplayer1; | |
int scoreplayer2; | |
int Counter1=0; | |
int Counter2=0; | |
public void ballblack(View v) { | |
if (Counter1 <= 10&& Counter1>=0) { | |
Counter1 = Counter1 + 1;} | |
Round(v); | |
int pins1 = (int) (Math.random() * ((10 - 0) + 1) + 0); | |
scoreplayer1 = scoreplayer1 + pins1; | |
displayScorePlayer1(scoreplayer1); | |
FallPins1(pins1); | |
findViewById(R.id.blackball).setEnabled(false); | |
findViewById(R.id.redball).setEnabled(true); | |
Winner(v); | |
} | |
public void ballred(View v) { | |
if (Counter2 < 10 && Counter2>=0) { | |
Counter2 = Counter2 + 1;} | |
Round(v); | |
int pins2 = (int) (Math.random() * ((10 - 0) + 1) + 0); | |
scoreplayer2 = scoreplayer2 + pins2; | |
displayScorePlayer2(scoreplayer2); | |
FallPins2(pins2); | |
findViewById(R.id.blackball).setEnabled(true); | |
findViewById(R.id.redball).setEnabled(false); | |
Winner(v); | |
} | |
public void Round(View V){ | |
if (Counter2 <= 10 && Counter2>=0) { | |
if (Counter1 > Counter2) { | |
TextView Round = (TextView) findViewById(R.id.round); | |
Round.setText(String.valueOf("Round " + Counter1 + " / 10")); | |
} else { | |
TextView Round = (TextView) findViewById(R.id.round); | |
Round.setText(String.valueOf("Round " + Counter2 + " / 10")); | |
} | |
} | |
} | |
@RequiresApi(api = Build.VERSION_CODES.M) | |
@SuppressLint("ResourceAsColor") | |
public void Playagain(View v) { | |
scoreplayer1 = 0; | |
scoreplayer2 = 0; | |
Counter1 = 0; | |
Counter2 = 0; | |
TextView Round = (TextView) findViewById(R.id.round); | |
Round.setText(String.valueOf("Round "+ Counter1 +" / 10")); | |
FallPins1(0); | |
FallPins2(0); | |
TextView Winner = (TextView) findViewById(R.id.player1vsplayer2); | |
Winner.setText(String.valueOf("Player1 Vs Player2")); | |
Winner.setTextColor(getColor(R.color.PVP)); | |
displayScorePlayer1(scoreplayer1); | |
displayScorePlayer2(scoreplayer2); | |
findViewById(R.id.blackball).setEnabled(true); | |
findViewById(R.id.redball).setEnabled(true); | |
} | |
/** | |
* Displays Player Winner. | |
*/ | |
@RequiresApi(api = Build.VERSION_CODES.M) | |
@SuppressLint("ResourceAsColor") | |
public void Winner(View v) { | |
if (Counter1==10&& Counter2==10) { | |
findViewById(R.id.blackball).setEnabled(false); | |
findViewById(R.id.redball).setEnabled(false); | |
if (scoreplayer1 > scoreplayer2) { | |
TextView Winner = (TextView) findViewById(R.id.player1vsplayer2); | |
Winner.setText(String.valueOf("Player1 Winner")); | |
Winner.setTextColor(getColor(R.color.player1));; | |
} else { | |
TextView Winner = (TextView) findViewById(R.id.player1vsplayer2); | |
Winner.setText(String.valueOf("Player2 Winner")); | |
Winner.setTextColor(getColor(R.color.player2)); | |
} | |
MediaPlayer Mp = MediaPlayer.create(this,R.raw.cheering); | |
Mp.start(); | |
} | |
} | |
/** | |
* Displays the given score for Player1. | |
*/ | |
public void displayScorePlayer1(int score1) { | |
TextView scoreplayer1 = (TextView) findViewById(R.id.scoreplayer1); | |
scoreplayer1.setText(String.valueOf(score1)); | |
} | |
/** | |
* Displays the given score for Player 2. | |
*/ | |
public void displayScorePlayer2(int score2) { | |
TextView scoreplayer2 = (TextView) findViewById(R.id.scoreplayer2); | |
scoreplayer2.setText(String.valueOf(score2)); | |
} | |
/** | |
* Displays the given Pins for Player 2. | |
*/ | |
public void FallPins1(int pins1) { | |
TextView pins = (TextView) findViewById(R.id.PinsFall1); | |
pins.setText(String.valueOf(pins1)); | |
} | |
/** | |
* Displays the given Pins for Player 2. | |
*/ | |
public void FallPins2(int pins2) { | |
TextView pins = (TextView) findViewById(R.id.PinsFall2); | |
pins.setText(String.valueOf(pins2)); | |
} | |
/** | |
* ATTENTION: This was auto-generated to implement the App Indexing API. | |
* See https://g.co/AppIndexing/AndroidStudio for more information. | |
*/ | |
public Action getIndexApiAction() { | |
Thing object = new Thing.Builder() | |
.setName("Main Page") // TODO: Define a title for the content shown. | |
// TODO: Make sure this auto-generated URL is correct. | |
.setUrl(Uri.parse("http://[ENTER-YOUR-URL-HERE]")) | |
.build(); | |
return new Action.Builder(Action.TYPE_VIEW) | |
.setObject(object) | |
.setActionStatus(Action.STATUS_TYPE_COMPLETED) | |
.build(); | |
} | |
@Override | |
public void onStart() { | |
super.onStart(); | |
// ATTENTION: This was auto-generated to implement the App Indexing API. | |
// See https://g.co/AppIndexing/AndroidStudio for more information. | |
client.connect(); | |
AppIndex.AppIndexApi.start(client, getIndexApiAction()); | |
} | |
@Override | |
public void onStop() { | |
super.onStop(); | |
// ATTENTION: This was auto-generated to implement the App Indexing API. | |
// See https://g.co/AppIndexing/AndroidStudio for more information. | |
AppIndex.AppIndexApi.end(client, getIndexApiAction()); | |
client.disconnect(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment