Skip to content

Commit

Permalink
Finaliza jogo
Browse files Browse the repository at this point in the history
  • Loading branch information
terciotales committed Oct 9, 2022
1 parent 22242ed commit 2451483
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 2 deletions.
9 changes: 9 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".TelaFinal"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand Down
36 changes: 36 additions & 0 deletions app/src/main/java/com/example/campominado/TelaFinal.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,49 @@
package com.example.campominado;

import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.SoundPool;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class TelaFinal extends AppCompatActivity {

TextView tentativas;
SoundPool snd;
MediaPlayer musica;
Button voltar;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tela_final);

tentativas = findViewById(R.id.tentativas_final);
voltar = findViewById(R.id.button_start);

Intent dadosRecebidos = getIntent();
String numTentativas = dadosRecebidos.getStringExtra("tentativas");
String tentativas_string = "Número de tentativas: " + numTentativas;

tentativas.setText(tentativas_string);

snd = new SoundPool(4, AudioManager.STREAM_MUSIC, 8);
musica = MediaPlayer.create(TelaFinal.this, R.raw.vitoria);
musica.start();

voltar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(TelaFinal.this, MainActivity.class);
startActivity(intent);
finish();
}
});
}
}
12 changes: 10 additions & 2 deletions app/src/main/java/com/example/campominado/TelaJogo.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
Expand All @@ -24,12 +25,14 @@ protected void onCreate(Bundle savedInstanceState) {
grid.setAdapter(mineGridRecyclerAdapter);

TextView bomb = findViewById(R.id.activity_main_bomb);
TextView tentativas = findViewById(R.id.tentativas);

bomb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
BombMine = new BombMineGame(8);
mineGridRecyclerAdapter.setCells(BombMine.getMineGrid().getCells());
tentativas.setText("0");
}
});
}
Expand All @@ -38,8 +41,13 @@ public void cellClick(Cell cell) {
TextView tentativas = findViewById(R.id.tentativas);

if (BombMine.ganhouJogo(cell)) {

} else if (!cell.foiRevelado()) {
int numTentativas = (Integer.parseInt(tentativas.getText().toString())) + 1;
tentativas.setText(String.valueOf(numTentativas));
Intent intent = new Intent(TelaJogo.this, TelaFinal.class);
intent.putExtra("tentativas", tentativas.getText().toString());
startActivity(intent);
finish();
} else {
int numTentativas = (Integer.parseInt(tentativas.getText().toString())) + 1;
tentativas.setText(String.valueOf(numTentativas));
}
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/layout/tela_final.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@
android:textColor="#FFFFFF"
android:textSize="20dp" />

<Button
android:id="@+id/button_start"
android:layout_width="200dp"
android:layout_height="50dp"
android:layout_below="@+id/tentativas_final"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:backgroundTint="#F87611"
android:text="Voltar ao início"
android:textColor="#FFFFFF"
android:textSize="16dp"
android:textStyle="bold" />

<TextView
android:id="@+id/author"
android:layout_width="wrap_content"
Expand Down
Binary file added app/src/main/res/raw/vitoria.mp3
Binary file not shown.

0 comments on commit 2451483

Please sign in to comment.