人品计算器-小游戏

来源:互联网 发布:苹果弹琴软件 编辑:程序博客网 时间:2024/05/21 15:06

闲来无聊,做了一个随机数为基础的人品计算器小游戏。
这样就可以娱乐一下。测试一下每时每刻的人品值啦。

先来几张效果图:

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

直接上代码了:

package com.wzq.game;import android.content.Intent;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.Toast;import java.util.Random;public class MainActivity extends AppCompatActivity {    private EditText et;    private Button btn;    private String name;    private int count;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        initView();    }    private void initView() {        et = (EditText) findViewById(R.id.et);        btn = (Button) findViewById(R.id.button1);        btn.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                name = et.getText().toString();                if (name.equals("")) {                    Toast.makeText(MainActivity.this, "请输入你的姓名", Toast.LENGTH_LONG).show();                } else {                    count = testRandom();                    Intent intent = new Intent(MainActivity.this, Main2Activity.class);                    intent.putExtra("name", name);                    intent.putExtra("count", count);                    startActivity(intent);                }            }        });    }    private int testRandom() {        Random random = new Random();        int i = random.nextInt(101);        return i;    }}

第二Activity:

package com.wzq.game;import android.content.Intent;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.TextView;public class Main2Activity extends AppCompatActivity {    private String string_count;    private int count;    private String name;    private TextView tv_count;    private TextView tv_name;    private TextView tv_text;    private TextView tv_author;    private String text;    private Button btn;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main2);        Intent intent = getIntent();        name = intent.getStringExtra("name");        count = intent.getIntExtra("count", 0);        string_count = count + "";        initData();        initView();    }    private void initData() {        if (count<=0) {            text = "衰极之至!\n" +                    "活着浪费空气!\n" +                    "死了浪费土地!\n" +                    "*⊥* 软件宝宝已经无法计算你的人品了!";        } else if(0 < count && count < 10){            text = "极差人品!\n个位数人品的你,\n不该活在这个世上!";        }        else if (10 <= count && count < 20) {            text = "这TMD人品:真是活见鬼了!";        } else if (20 <= count && count < 30) {            text = "人品低不是你的错!\n但是人品低到你这种程度的,\n还出来丢人就是你的不对了!";        } else if (30 <= count && count < 40) {            text = "人世间有种捉急的智商叫:\n明明自己人品低,还非要测试出来告诉别人!";        } else if (40 <= count && count < 50) {            text = "随地大小便的事情,\n你没少干吧!";        } else if (50 <= count && count < 60) {            text = "“隔壁老王”\n就是专门用来形容你的吧!";        } else if (60 <= count && count < 70) {            text = "你不适合靠人品吃饭!\n去靠才华吧!";        } else if (70 <= count && count < 80) {            text = "哎哟!不错哦!\n人品佳!";        } else if (80 <= count && count < 90) {            text = "请允许我叫你一声:\n天使!";        } else if (90 <= count && count < 96) {            text = "!我屮艸芔茻 !\n" +                    "!人品爆棚 !\n" +                    "买彩票必中大奖!\n" +                    "向男神(女神)表白必定成功!\n" +                    "心想必定成功!\n" +                    "此时此刻的你适合做任何事情!";        } else if (96 <= count && count < 99) {            text = "!我屮艸芔茻!\n" +                    "人品爆炸\n" +                    "你已成仙成佛";        } else if (99 <= count) {            text = "......" +                    "请联系作者,要红包!";        }    }    private void initView() {        tv_count = (TextView) findViewById(R.id.tv_count);        tv_name = (TextView) findViewById(R.id.tv_name);        tv_text = (TextView) findViewById(R.id.tv_text);        tv_author = (TextView) findViewById(R.id.tv_author);        btn = (Button) findViewById(R.id.btn);        tv_name.setText(name);        tv_count.setText(string_count);        tv_text.setText(text);        btn.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                finish();            }        });        tv_author.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                Intent intent = new Intent(Main2Activity.this, Main3Activity.class);                startActivity(intent);            }        });    }}

第三Activity:

package com.wzq.game;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;public class Main3Activity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main3);    }    public void backB(View view){        finish();    }}

XML文件:

M1:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="@mipmap/a"    android:gravity="center_horizontal"    android:orientation="vertical"    tools:context="com.wzq.game.MainActivity">    <TextView        android:id="@+id/tv"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginTop="20dp"        android:text="测试你的实时人品"        android:textColor="#fdfdfd"        android:textSize="30sp"        android:textStyle="bold" />    <TextView        android:id="@+id/tv1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginTop="20dp"        android:text="请输入您的姓名:"        android:textColor="#fdfdfd"        android:textSize="20sp"        android:textStyle="bold" />    <EditText        android:id="@+id/et"        android:layout_width="200dp"        android:gravity="center_horizontal"        android:layout_height="wrap_content"        android:layout_marginTop="10dp"        android:background="#f7f7f7" />    <Button        android:id="@+id/button1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="点击测试"        android:textStyle="bold"        android:textSize="20sp"        android:layout_marginTop="350dp"        android:layout_gravity="center_horizontal" /></LinearLayout>

M2:

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context="com.wzq.game.Main2Activity">    <TextView        android:id="@+id/tv_name"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="——"        android:textStyle="bold"        android:textSize="35sp"        android:layout_marginTop="20dp"        android:layout_centerHorizontal="true" />    <TextView        android:id="@+id/tv_2"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="你的此时此刻的人品值是:"        android:textSize="20sp"        android:layout_marginTop="20dp"        android:layout_below="@+id/tv_name"        android:layout_centerHorizontal="true" />    <TextView        android:id="@+id/tv_count"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="——"        android:textSize="50sp"        android:layout_marginTop="20dp"        android:layout_below="@+id/tv_2"        android:layout_centerHorizontal="true"         />    <TextView        android:id="@+id/tv_evaluate"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="评价:"        android:textColor="#ff0000"        android:textSize="20sp"        android:layout_marginTop="20dp"        android:layout_below="@+id/tv_count"        android:layout_centerHorizontal="true"        />    <TextView        android:id="@+id/tv_text"        android:layout_width="match_parent"        android:gravity="center_horizontal"        android:layout_height="wrap_content"        android:text="——"        android:textSize="25sp"        android:layout_marginTop="20dp"        android:layout_below="@+id/tv_evaluate"        android:layout_centerHorizontal="true"        />    <Button        android:id="@+id/btn"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="重新测算"        android:layout_alignParentBottom="true"        android:layout_marginBottom="50dp"        android:layout_centerHorizontal="true"/>    <TextView        android:id="@+id/tv_author"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="联系作者"        android:layout_alignParentRight="true"        android:layout_alignParentBottom="true"         /></RelativeLayout>

M3:

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context="com.wzq.game.Main3Activity"><Button    android:id="@+id/button"    android:text="← 返回"    android:textSize="20sp"    android:onClick="backB"    android:layout_alignParentTop="true"    android:layout_alignParentLeft="true"    android:layout_width="wrap_content"    android:layout_height="wrap_content" />    <TextView        android:id="@+id/tv_qq"        android:text="联系QQ:630886916"        android:layout_centerHorizontal="true"        android:layout_marginTop="80dp"        android:textSize="25sp"        android:layout_width="wrap_content"        android:layout_height="wrap_content" />    <TextView        android:id="@+id/tv_weixin"        android:text="联系微信:lovex520-"        android:layout_centerHorizontal="true"        android:layout_marginTop="10dp"        android:textSize="25sp"        android:layout_below="@+id/tv_qq"        android:layout_width="wrap_content"        android:layout_height="wrap_content" />    <ImageView        android:id="@+id/iv_weixin"        android:layout_width="200dp"        android:layout_height="200dp"        android:layout_marginTop="10dp"        android:layout_centerHorizontal="true"        android:layout_below="@+id/tv_weixin"        android:src="@mipmap/weixin"/>    <TextView        android:id="@+id/tv_author"        android:text="By:大企鹅"        android:layout_centerHorizontal="true"        android:layout_marginTop="20dp"        android:textSize="25sp"        android:layout_below="@+id/iv_weixin"        android:layout_width="wrap_content"        android:layout_height="wrap_content" />    <TextView        android:id="@+id/tv_text"        android:gravity="center_horizontal"        android:text="本App纯属娱乐制作,仅供大家娱乐。\n作者不承担任何法律责任\n如有违法嫌疑请联系作者删除,谢谢合作!"        android:layout_centerHorizontal="true"        android:layout_marginTop="20dp"        android:layout_below="@+id/tv_author"        android:layout_width="wrap_content"        android:layout_height="wrap_content" /></RelativeLayout>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.exam.jacli.weatherapp">    <uses-permission android:name="android.permission.INTERNET"/>    <application        android:allowBackup="true"        android:icon="@mipmap/ic_launcher"        android:label="@string/app_name"        android:supportsRtl="true"        android:theme="@style/AppTheme">        <activity android:name=".MainActivity">            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application></manifest>

完成收工。其实很简单。图片资源就不留了。

人品计算器小游戏_AS下载地址

http://download.csdn.net/detail/w630886916/9682324

0 0