李小龙游戏java_仿Android疯狂猜图

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_gravity="center_vertical"

android:layout_marginTop="200dp"

android:gravity="center_vertical|center_horizontal"

android:text="@string/win"

android:textColor="#FF0000"

android:textSize="30sp"

android:textStyle="bold" />

接下来是几个类的java代码:

1、CrazyActivity.java用于启动应用,显示主界面和处理用户的回答交互,完成答案的比对,重选,提示和金币充值等业务

package com.vekaco.crazyguesspic;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.util.Log;

import android.view.View;

import android.view.View.OnClickListener;

import android.view.ViewGroup;

import android.widget.Button;

import android.widget.ImageView;

import android.widget.LinearLayout;

import android.widget.TableLayout;

import android.widget.TableRow;

import android.widget.TextView;

import android.widget.Toast;

public class CrazyActivity extends Activity implements OnClickListener {

int count = 3;// 用来记忆关卡

Button back;// 返回上一题按钮

TextView showtv;// 显示当前关卡

ImageView iv;// 猜图图片

Button[] rightButton;// 用来存储正确的答案的按钮

Button[] chooseButton;// 用来存储选项按钮

TextView coins;// 积分

Button delete;

Button prompt;

int current = 0;

int length;

int[] location;

String ans = "";

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.crazy_body);

back = (Button) this.findViewById(R.id.button_back);

showtv = (TextView) this.findViewById(R.id.show_tv);

iv = (ImageView) this.findViewById(R.id.p_w_picpathView2);

coins = (TextView) this.findViewById(R.id.textView1);

delete = (Button) this.findViewById(R.id.button2);

prompt = (Button) this.findViewById(R.id.button3);

delete.setOnClickListener(this);

prompt.setOnClickListener(this);

// 设置当前关卡

showtv.setText("" + (count + 1));

initPic(count);

back.setOnClickListener(this);

initLinearLayout();

initTableLayout();

location = new int[length];

Log.i("length", "" + length);

}

// 改变图片的

public void initPic(int count) {

int num = Entity.rightPic[count];

iv.setImageResource(num);

}

// 加载正确答案的按钮

public void initLinearLayout() {

LinearLayout ll = (LinearLayout) findViewById(R.id.mylinearlayout);

// 把布局里面的空间清空

ll.removeAllViews();

ll.removeAllViewsInLayout();

// 拿到正确答案的长度

length = Entity.rightAnswer[count].length();

// 正确答案的按钮,方便以后调用

rightButton = new Button[length];

for (int i = 0; i < length; i++) {

Button b = new Button(this);

rightButton[i] = b;

// 设置相应的监听事件

rightButton[i].setOnClickListener(this);

// rightButton[i].setEnabled(false);

rightButton[i].setText("");

rightButton[i].setEnabled(false);

// b.setText(i + "");

b.setWidth(40);

b.setHeight(40);

ll.addView(rightButton[i]);// 把按钮添加到布局中

}

}

// 加载选项的按钮

public void initTableLayout() {

TableLayout tl = (TableLayout) findViewById(R.id.mytablelayout);

tl.setStretchAllColumns(true);

tl.removeAllViewsInLayout();

tl.removeAllViews();

chooseButton = new Button[24];

// 一共三行

for (int row = 0; row < 3; row++) {

TableRow tableRow = new TableRow(this);

for (int col = 0; col < 8; col++) {

Button btn = new Button(this);

// 存储24个按钮,分别放在不同位置

chooseButton[row * 8 + col] = btn;

// 设置相应的监听事件

chooseButton[row * 8 + col].setOnClickListener(this);

String s = Entity.chooseAnswer[count].substring(row * 8 + col,

row * 8 + col + 1);

chooseButton[row * 8 + col].setText(s);

// btn.setText(s);

tableRow.addView(chooseButton[row * 8 + col]);// 把按钮添加到布局中

}

// 把tablerow加载到布局中,并指定他的宽和高

tl.addView(tableRow, new TableRow.LayoutParams(

ViewGroup.LayoutParams.MATCH_PARENT,

ViewGroup.LayoutParams.WRAP_CONTENT));

}

}

public void onClick(View v) {

if (v == back) {

count--;

if (count < 0) {

Toast.makeText(CrazyActivity.this, "到顶了亲!", Toast.LENGTH_SHORT)

.show();

count = 0;

}

// if (v == delete) {

//

// }

// if (v == prompt) {

// Log.i("ok", "click");

// rightButton[current].setText(Entity.rightAnswer[count]

// .substring(current, current + 1));

// }

else {

Log.i("info", "" + count);

showtv.setText(count + 1 + "");

initPic(count);

initLinearLayout();

initTableLayout();

current = 0;

}

} else {

if (v == delete) {

// String[] answer = null;

// for (int i = 0; i < Entity.rightAnswer[count].length(); i++)

// {

// answer[i] = Entity.rightAnswer[count].substring(i, i + 1);

//

// }

// for (int i = 0; i < 24; i++) {

// int j;

// if (i > Entity.rightAnswer[count].length()) {

// j = Entity.rightAnswer[count].length();

// } else {

// j = i;

// }

// if (chooseButton[i].getText().toString() != (String)

// answer[j]) {

// chooseButton[i].setText("");

// }

// }

}

if (v == prompt) {

Log.i("ok", "click");

rightButton[current].setText(Entity.rightAnswer[count]

.substring(current, current + 1));

rightButton[current].setEnabled(true);

int flag = 1;

for (int row = 0; row < 3; row++) {

for (int col = 0; col < 8; col++) {

if (chooseButton[row * 8 + col]

.getText()

.toString()

.equals(Entity.rightAnswer[count].substring(

current, current + 1))) {

chooseButton[row * 8 + col].setText("");

chooseButton[row * 8 + col].setEnabled(false);

flag = 0;

break;

}

}

if (flag == 0) {

break;

}

}

if (current == length - 1) {

for (int i = 0; i < Entity.rightAnswer[count].length(); i++) {

ans += rightButton[i].getText().toString();

}

}

if (ans.equals(Entity.rightAnswer[count])) {

if ((count + 1) == Entity.rightPic.length) {

Toast.makeText(CrazyActivity.this, "恭喜你已经通关了!",

Toast.LENGTH_SHORT).show();

Intent intent = new Intent();

intent.setClass(CrazyActivity.this, WinActivity.class);

startActivity(intent);

finish();

ans = "";

} else {

count = count + 1;

showtv.setText(count + 1 + "");

initPic(count);

initLinearLayout();

initTableLayout();

current = 0;

ans = "";

int temp = Integer.parseInt(coins.getText().toString());

temp += 5;

coins.setText("" + temp);

}

} else {

current++;

}

}

for (int row = 0; row < 3; row++) {

for (int col = 0; col < 8; col++) {

if (v == chooseButton[row * 8 + col]) {

if (current < length) {

rightButton[current].setEnabled(true);

String s = Entity.chooseAnswer[count].substring(row

* 8 + col, row * 8 + col + 1);

rightButton[current].setText(s);

chooseButton[row * 8 + col].setText("");

location[current] = row * 8 + col;

Log.i("temp", "" + current + "" + location[current]);

chooseButton[row * 8 + col].setEnabled(false);

if (current == length - 1) {

for (int i = 0; i < Entity.rightAnswer[count]

.length(); i++) {

ans += rightButton[i].getText().toString();

}

}

if (ans.equals(Entity.rightAnswer[count])) {

if ((count + 1) == Entity.rightPic.length) {

Toast.makeText(CrazyActivity.this,

"恭喜你已经通关了!", Toast.LENGTH_SHORT)

.show();

Intent intent = new Intent();

intent.setClass(CrazyActivity.this,

WinActivity.class);

startActivity(intent);

finish();

ans = "";

} else {

count = count + 1;

showtv.setText(count + 1 + "");

initPic(count);

initLinearLayout();

initTableLayout();

current = 0;

ans = "";

int temp = Integer.parseInt(coins.getText()

.toString());

temp += 5;

coins.setText("" + temp);

}

} else {

current++;

}

}

if (current == length) {

Toast.makeText(CrazyActivity.this,

"已经填满了,但是答案不对哦,亲!", Toast.LENGTH_SHORT)

.show();

ans = "";

}

}

}

}

for (int i = 0; i < length; i++) {

if (v == rightButton[i]) {

Log.i("location", i + "" + location[i]);

int temp_location = location[i];

chooseButton[temp_location].setEnabled(true);

String temp_text = rightButton[i].getText().toString();

chooseButton[temp_location].setText(temp_text);

rightButton[i].setEnabled(false);

rightButton[i].setText("");

current--;

ans = "";

}

}

}

}

}

2、Entity.java实体类用于存放资源图片、正确答案和备选答案

package com.vekaco.crazyguesspic;

public class Entity {

// 存储正确答案

public static String[] rightAnswer = new String[] { "周杰伦", "黄晓明", "科比",

"GOOGLE", "霹雳娇娃", "李小龙", "泰坦尼克号" };

//

public static int[] rightPic = new int[] { R.drawable.__00490,

R.drawable.__00551, R.drawable.__00096, R.drawable.__00109,

R.drawable.__00006, R.drawable.__00018, R.drawable.__00067

};

public static String[] chooseAnswer = new String[] {

"周杰伦王李四张三陈天翔王李四张三傻不拉王李四张三", "黄晓明王李四张三陈天翔王李四张三傻不拉王李四张三",

"科比额王李四张三陈天翔王李四张三傻不拉王李四张三", "GOOGLEYAHOBAIDUJAVAANDRO",

"明王李四霹雳张三陈娇娃天翔王李四张三傻不拉王李四", "黄晓明王李四张三小龙翔王李四张三傻不拉王李四张三",

"黄晓明王李四张三陈泰王坦李四尼三傻克拉号李四张三" };

}

3、WinActivity.java用于用户通关成功后启动交互,告知用户已成功完成游戏!

package com.vekaco.crazyguesspic;

import android.app.Activity;

import android.os.Bundle;

import android.view.Window;

import android.view.WindowManager;

public class WinActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_NO_TITLE);

setContentView(R.layout.win);

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,

WindowManager.LayoutParams.FLAG_FULLSCREEN);

}

}

有时间再具体注视各行重要代码的作用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 内容概要 《计算机试卷1》是一份综合性的计算机基础和应用测试卷,涵盖了计算机硬件、软件、操作系统、网络、多媒体技术等多个领域的知识点。试卷包括单选题和操作应用两大类,单选题部分测试学生对计算机基础知识的掌握,操作应用部分则评估学生对计算机应用软件的实际操作能力。 ### 适用人群 本试卷适用于: - 计算机专业或信息技术相关专业的学生,用于课程学习或考试复习。 - 准备计算机等级考试或职业资格认证的人士,作为实战演练材料。 - 对计算机操作有兴趣的自学者,用于提升个人计算机应用技能。 - 计算机基础教育工作者,作为教学资源或出题参考。 ### 使用场景及目标 1. **学习评估**:作为学校或教育机构对学生计算机基础知识和应用技能的评估工具。 2. **自学测试**:供个人自学者检验自己对计算机知识的掌握程度和操作熟练度。 3. **职业发展**:帮助职场人士通过实际操作练习,提升计算机应用能力,增强工作竞争力。 4. **教学资源**:教师可以用于课堂教学,作为教学内容的补充或学生的课后练习。 5. **竞赛准备**:适合准备计算机相关竞赛的学生,作为强化训练和技能检测的材料。 试卷的目标是通过系统性的题目设计,帮助学生全面复习和巩固计算机基础知识,同时通过实际操作题目,提高学生解决实际问题的能力。通过本试卷的学习与练习,学生将能够更加深入地理解计算机的工作原理,掌握常用软件的使用方法,为未来的学术或职业生涯打下坚实的基础。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值