装备

在Layout下创建两个xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_equip"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="cn.itcast.select.equip.EquipActivity">
    <ImageView
        android:id="@+id/TP"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="30dp"
        android:src="@drawable/baby"
        />
<TextView
    android:id="@+id/wz"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="亲爱的小宝宝!"
    android:textSize="20dp"
    android:layout_marginTop="200dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:textColor="@color/colorAccent"></TextView>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        <TextView
            android:id="@+id/shengming"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:hint="生命值"
        android:textColorHint="@color/colorPrimary"
        android:textSize="20dp"/><TextView />
        <ProgressBar
            android:id="@+id/progressBar1"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="2"/>

    <TextView
        android:layout_width="20dp"
        android:layout_height="wrap_content"
        android:id="@+id/shengmingzhi"
        android:text="0"
        android:layout_gravity="center"
        android:textColor="@color/colorAccent"></TextView>
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/gongjili"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:hint="攻击力"
                android:textColorHint="@color/colorPrimary"
                android:textSize="20dp"/><TextView />
            <ProgressBar
                android:id="@+id/progressBar2"
                style="?android:attr/progressBarStyleHorizontal"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_weight="2"/>

            <TextView
                android:layout_width="20dp"
                android:layout_height="wrap_content"
                android:id="@+id/gongjizhi"
                android:text="0"
                android:layout_gravity="center"
                android:textColor="@color/colorAccent"></TextView>
        </TableRow>
        <TableRow
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/minjiedu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:hint="敏捷度"
        android:textColorHint="@color/colorPrimary"
        android:textSize="20dp"/><TextView />
    <ProgressBar
        android:id="@+id/progressBar3"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="2"/>

    <TextView
        android:layout_width="20dp"
        android:layout_height="wrap_content"
        android:id="@+id/minjiezhi"
        android:text="0"
        android:layout_gravity="center"
        android:textColor="@color/colorAccent"></TextView>
</TableRow>
    </LinearLayout>
        <Button
            android:id="@+id/click"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawablePadding="3dp"
            android:background="#FF1"
            android:layout_centerHorizontal="true"
            android:layout_alignParentBottom="true"
            android:onClick="click"
            android:text="快给小宝宝购买装备啊"
            android:textSize="20dp"/>
    </RelativeLayout>


<?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:id="@+id/activity_equip"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:oriention="vertial"
    tools:context="cn.itcast.select.equip.EquipActivity">

    <TextView
        android:id="@+id/tv_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
       android:layout_centerHorizontal="true"
        android:layout_alignParentTop="true"
        android:textSize="30dp"
        android:textColor="#FFCCOO"
        android:text="欢迎进入商店" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:orientation="vertical"
        android:layout_below="@id/tv_name">
            <RadioButton
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/huanying"
                android:drawableLeft="@drawable/cx"
                android:text="敏捷+60,攻击+30,防御+10"
                android:textSize="20dp"/>
        <RadioButton
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/shangpin"
            android:drawableLeft="@drawable/tb"
            android:text="敏捷+10,攻击+50,防御+10"
            android:textSize="20dp"/>
    </LinearLayout>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="购买"
        android:textSize="20dp"
        android:textColor="#FC1"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="30dp"/>
</RelativeLayout>

新建一个包,里面新建一个iteminfo的类,同来存储装备信息

package cn.itcast.domain;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class ItemInfo extends AppCompatActivity {
    private String name;
    private int acctack;
    private int life;
    private int speed;
    public ItemInfo(String name,int acctack,int life,int speed){
        this.name=name;
        this.acctack=acctack;
        this.life=life;
        this.speed=speed;
    }
    public String getName(){
        return name;
    }
    public void setName(String name){
        this.name=name;
    }
    public int  getAcctack(){
        return acctack;
    }
    public void setAcctack(int acctack){
        this.acctack=acctack;
    }
    public int  getLife(){
        return life;
    }
    public void setLife(int life){
        this.life=life;
    }
    public int getSpeed(){
        return speed;
    }
    public void setSpeed(int speed){
        this.speed=speed;
    }
    public String toString(){
        return " [name="+name+",acctack="+acctack+",life="+life+",speed="+speed+"]";
    }
}

创建Activity

package cn.itcast.select.equip;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

public class EquipActivity extends AppCompatActivity {
    private ProgressBar mProgressBar1;
    private ProgressBar mProgressBar2;
    private ProgressBar mProgressBar3;
    private TextView mLifeTV;
    private TextView mAttackTV;
    private TextView mSpeedTV;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_equip);
        TextView mLifeTV=(TextView)findViewById(R.id.tv_life_progress);
        TextView mSpeedTV=(TextView)findViewById(R.id.tv_speed_progress);
        TextView mAttackTV=(TextView)findViewById(R.id.tv_attack_progress);
        initProgress();
    }
    private void initProgress(){
        mProgressBar1=(mProgressBar)findViewById(R.id.progressBar1);
        mProgressBar2=(mProgressBar)findViewById(R.id.progressBar2);
        mProgressBar3=(mProgressBar)findViewById(R.id.progressBar3);
        mProgressBar1.setMax(1000);
        mProgressBar2.setMax(1000);
        mProgressBar3.setMax(1000);
    }
    public void click(View view){
        Intent intent=new Intent(this,ShopActivity.class);
        startActivityForResult(intent,1);
    }
    protected void onActivityResult(int requestCode,int resultCode,Intent data){
        super.onActivityResult(requestCode,resultCode,data);
        if(data!=null){
            if(resultCode==1){
                if(requestCode==1)
                ItemInfo info(ItemInfo)data.getSerializableExtra("equipment");
                updateProgress(info);
            }
        }
    }
}
private void updateProgress(ItemInfo info){
    int progress1=mProgressBar1.getProgress();
    int progress2=mProgressBar2.getProgress();
    int progress3=mProgressBar3.getProgress();
    mProgressBar1.setProgress(progress1+info.getLife());
    mProgressBar2.setProgress(progress2+info.getAcctack());
    mProgressBar3.setProgress(progress3+info.getSpeed());
    mLifeTV.setText(mProgressBar1.getProgress()+"");
    mAttackTV.setText(mProgressBar1.getProgress()+"");
    mSpeedTV.setText(mProgressBar1.getProgress()+"");
}
}
package cn.itcast.select.equip;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class ShopActivity extends AppCompatActivity {
    private ItemInfo itemInfo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shop);
        itemInfo=new ItemInfo("jinjian",100,20,20);
        findViewById(R.id.r1).setOnClickListener(this);
        TextView mLifeTV=(TextView)findViewById(R.id.tv_life);
        TextView mNameTV=(TextView)findViewById(R.id.tv_name);
        TextView mSpeedTV=(TextView)findViewById(R.id.tv_speed);
        TextView mAttackTV=(TextView)findViewById(R.id.tv_attack);
        mLifeTV.setText("生命值+"itemInfo.getLife());
        mNameTV.setText(itemInfo.getName()+"");
        mSpeedTV.setText("敏捷度+"itemInfo.getSpeed());
        mAttackTV.setText("攻击力+"itemInfo.getAcctack());
    }
    public void onClick(View view){
        switch (view.getId()){
            case R.id.r1:
                Intent intent=new Intent();
                intent.putExtra("equipment",itemInfo);
                setResult(1,intent);
                finish();
                break;

        }
    }
}

实验结果图
这里写图片描述

这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
资源包主要包含以下内容: ASP项目源码:每个资源包都包含完整的ASP项目源码,这些源码采用了经典的ASP技术开发,结构清晰、注释详细,帮助用户轻松理解整个项目的逻辑和实现方式。通过这些源码,用户可以学习到ASP的基本语法、服务器端脚本编写方法、数据库操作、用户权限管理等关键技术。 数据库设计文件:为了方便用户更好地理解系统的后台逻辑,每个项目都附带了完整的数据库设计文件。这些文件通常包括数据库结构图、数据表设计文档,以及示例数据SQL脚本。用户可以通过这些文件快速搭建项目所需的数据库环境,并了解各个数据表之间的关系和作用。 详细的开发文档:每个资源包都附有详细的开发文档,文档内容包括项目背景介绍、功能模块说明、系统流程图、用户界面设计以及关键代码解析等。这些文档为用户提供了深入的学习材料,使得即便是从零开始的开发者也能逐步掌握项目开发的全过程。 项目演示与使用指南:为帮助用户更好地理解和使用这些ASP项目,每个资源包都包含项目的演示文件和使用指南。演示文件通常以视频或图文形式展示项目的主要功能和操作流程,使用指南则详细说明了如何配置开发环境、部署项目以及常见问题的解决方法。 毕业设计参考:对于正在准备毕业设计的学生来说,这些资源包是绝佳的参考材料。每个项目不仅功能完善、结构清晰,还符合常见的毕业设计要求和标准。通过这些项目,学生可以学习到如何从零开始构建一个完整的Web系统,并积累丰富的项目经验。
资源包主要包含以下内容: ASP项目源码:每个资源包都包含完整的ASP项目源码,这些源码采用了经典的ASP技术开发,结构清晰、注释详细,帮助用户轻松理解整个项目的逻辑和实现方式。通过这些源码,用户可以学习到ASP的基本语法、服务器端脚本编写方法、数据库操作、用户权限管理等关键技术。 数据库设计文件:为了方便用户更好地理解系统的后台逻辑,每个项目都附带了完整的数据库设计文件。这些文件通常包括数据库结构图、数据表设计文档,以及示例数据SQL脚本。用户可以通过这些文件快速搭建项目所需的数据库环境,并了解各个数据表之间的关系和作用。 详细的开发文档:每个资源包都附有详细的开发文档,文档内容包括项目背景介绍、功能模块说明、系统流程图、用户界面设计以及关键代码解析等。这些文档为用户提供了深入的学习材料,使得即便是从零开始的开发者也能逐步掌握项目开发的全过程。 项目演示与使用指南:为帮助用户更好地理解和使用这些ASP项目,每个资源包都包含项目的演示文件和使用指南。演示文件通常以视频或图文形式展示项目的主要功能和操作流程,使用指南则详细说明了如何配置开发环境、部署项目以及常见问题的解决方法。 毕业设计参考:对于正在准备毕业设计的学生来说,这些资源包是绝佳的参考材料。每个项目不仅功能完善、结构清晰,还符合常见的毕业设计要求和标准。通过这些项目,学生可以学习到如何从零开始构建一个完整的Web系统,并积累丰富的项目经验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值