"dasturlash uslublari va paradigmalari " fanidan mustaqil ishi
bet 1/4 Sana 24.06.2021 Hajmi 232,5 Kb. #100103
Bog'liq
Dasturlash uslublari va paradigmalar
O‘ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGYALARI VA KOMMUNIKATSIYALARINI RIVOLANTIRISH VAZIRLIGI
MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI SAMARQAND FILIALI
“KOMPYUTER INJINIRINGI” FAKULTETI
“DASTURIY INJINIRINGI” YO’NALISHI
“DASTURLASH USLUBLARI VA PARADIGMALARI ” FANIDAN
MUSTAQIL ISHI
Bajardi: 312-guruh talabasi
Hamzayev Yoqub.
SAMARQAND – 2020
BACKAND
package com.example.stonepuzzle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Chronometer;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.Collections;
public class Game extends AppCompatActivity {
private Button[][] buttons;
private ViewGroup group;
TextView steps;
Integer ana;
MediaPlayer mediaPlayer1;
String youWin1, stepsYouWin;
Drawable backs;
MediaPlayer mediaPlayer ;
int r=0;
int p=0;
Chronometer chronometer;
private final int SIZE = 4;
private ArrayList data;
private Coordinate emptyObject = new Coordinate(SIZE - 1,SIZE - 1);
@Override
protected void onCreate(Bundle savedInstanceState) {
super .onCreate(savedInstanceState);
setContentView(R.layout.game );
Bundle bundle=getIntent().getExtras();
loadViews();
loadData();
loadDataToViews();
}
private void loadViews() {
buttons = new Button[SIZE][SIZE];
group = findViewById(R.id.groupButtons );
for (int i = 0; i < group.getChildCount(); i++) {
buttons[i / SIZE][i % SIZE] = (Button) group.getChildAt(i);
group.getChildAt(i).setTag(new Coordinate(i / SIZE, i % SIZE));
group.getChildAt(i).setOnClickListener(this ::onClick);
}
}
private void onClick(View view) {
Button button = (Button) view;
Coordinate c = (Coordinate) button.getTag();
boolean t1 = Math.abs (emptyObject.getX() - c.getX()) == 1;
boolean t2 = emptyObject.getY() - c.getY() == 0;
boolean t3 = emptyObject.getX() - c.getX() == 0;
boolean t4 = Math.abs (emptyObject.getY() - c.getY()) == 1;
Button emptyButton = buttons[emptyObject.getX()][emptyObject.getY()];
if (t1 && t2 || t3 && t4){
emptyButton.setText(button.getText());
button.setText("");
emptyObject.swap(c);
p++;
steps = findViewById(R.id.steps );
steps.setText(p + "");
mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.abc );
mediaPlayer.start();
emptyObject.swap(c);
for (int i = 0; i <15 ; i++) {
boolean t= buttons[i/SIZE][i%SIZE].getText().equals(i+1+"");
if (t) {
++r;
}
}
if (r==15){
youWin1= (String)chronometer.getText();
stepsYouWin=p+"";//i//ehf
Intent intent1=new Intent(this ,YouWin.class );
intent1.putExtra("steps1",stepsYouWin);
intent1.putExtra("watch",youWin1);
startActivityForResult(intent1 ,1);
}
else {
r=0;
}
}
}
private void loadData() {
data = new ArrayList<>();
15> Do'stlaringiz bilan baham: