package com.example.administrator.sondestreet.MyView.testPage.wbftestpage;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.view.Display;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.example.administrator.sondestreet.BaseActivity;
import com.example.administrator.sondestreet.MyView.testPage.wbftestpage.untils.TextListUntils;
import com.example.administrator.sondestreet.MyView.testPage.wbftestpage.wbfview.CustomVideoView;
import com.example.administrator.sondestreet.MyView.testPage.wbftestpage.wbfview.MixtureTextView;
import com.example.administrator.sondestreet.R;
import com.example.administrator.sondestreet.Util.MyLoge;
import com.example.administrator.sondestreet.Util.MyToast;
import com.example.administrator.sondestreet.Util.PxtoDpUntils;
import com.gyf.barlibrary.ImmersionBar;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
/**
* Created by Administrator on 2018/10/13 0013.
*/
public class WbfTest extends BaseActivity {
private Context context;
private LinearLayout liner;
private List<TextView> textViewsList = new ArrayList<>();
private int level_index;//当前的关数
private boolean isgo = false;
private boolean gameOver = false;
private boolean isError = false;
private List<String> nowTextList = new ArrayList<>();
private TextView one, two, three, four, judge, next, number;
private List<TextView> questionList = new ArrayList<>();
private int num = 0;//总分
private int level_num = 10;
private ImageView question_img;
@Override
public void addlayout() {
context = this;
ImmersionBar.with(this).statusBarDarkFont(true).init();
setContentView(R.layout.activity_wbftest);
liner = findViewById(R.id.liner);
one = findViewById(R.id.one);
two = findViewById(R.id.two);
three = findViewById(R.id.three);
four = findViewById(R.id.four);
judge = findViewById(R.id.judge);
next = findViewById(R.id.next);
number = findViewById(R.id.number);
question_img = findViewById(R.id.question_img);
number.setText("分数:" + num);
questionList.add(one);
questionList.add(two);
questionList.add(three);
questionList.add(four);
}
@Override
public void initView() {
addTextiew();
}
private void addTextiew() {
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight() - PxtoDpUntils.dp2pxInt(context, 30);
MyLoge.addLoge("addTextiew", width + "-------");
for (int i = 0; i < 4; i++) {
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
liner.addView(linearLayout);
LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams) linearLayout.getLayoutParams();
linearParams.width = width;
linearParams.height = height / 16;
MyLoge.addLoge("LayoutParams", width + " --");
linearLayout.setLayoutParams(linearParams);
for (int j = 0; j < 4; j++) {
TextView textView = new TextView(context);
textView.setBackgroundColor(0xff8BCB8E);
textView.setTextSize(12);
textView.setGravity(Gravity.CENTER);
textView.setTextColor(0xffffffff);
textView.setTag(i + "" + j);
linearLayout.addView(textView);
MyLoge.addLoge("addLoge", linearLayout.getChildCount() + " ---");
textViewsList.add(textView);
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) textView.getLayoutParams();
lp.width = width / 4;
lp.height = LinearLayout.LayoutParams.MATCH_PARENT;
lp.setMargins(3, 3, 3, 3);
textView.setLayoutParams(lp);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (gameOver) {
return;
}
if (textView.getText().toString().equals("")) {
return;
}
if (!isgo) {
for (int k = 0; k < questionList.size(); k++) {
if (questionList.get(k).getTag() == null) {
questionList.get(k).setTag(textView.getTag());
questionList.get(k).setText(textView.getText().toString());
break;
}
}
textView.setText("");
if (one.getTag() != null && two.getTag() != null && three.getTag() != null && four.getTag() != null) {
isgo = true;
success();
} else {
isgo = false;
}
}
}
});
}
}
gettextList();
initlistener();
}
//判断正确
private void success() {
next.setVisibility(View.VISIBLE);
String str = "";
for (int i = 0; i < questionList.size(); i++) {
str = str + questionList.get(i).getText().toString();
}
if (str.equals(TextListUntils.okList[level_index])) {
num = num + level_num;
number.setText("分数:" + num);
level_index++;
if (level_index > TextListUntils.okList.length - 1) {
next.setText("游戏结束");
gameOver = true;
} else {
MyLoge.addLoge("success", "22222222222222");
next.setText("下一关");
next.setBackgroundColor(0xff90E72D);
isError = true;
}
} else {
MyLoge.addLoge("success", "11111111111111111");
isError = false;
next.setText("错误");
next.setBackgroundColor(0xffe91d01);
}
}
//把字还回去
private void goback(TextView textView) {
if (gameOver) {
return;
}
if (textView.getTag() == null) {
return;
}
next.setText("答题");
next.setBackgroundColor(0xff00BCD4);
for (int i = 0; i < textViewsList.size(); i++) {
if (textView.getTag().equals(textViewsList.get(i).getTag())) {
textViewsList.get(i).setText(textView.getText().toString());
}
}
textView.setText("");
textView.setTag(null);
isgo = false;
}
private void initlistener() {
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (gameOver) {
return;
}
if (!isError) {
return;
}
gettextList();
}
});
one.setOnClickListener(new View.OnClickListener
评论0
最新资源