作业总要求
使用附件“素材”压缩包中的素材完成下列任务:

1.完成小游戏主程序,如图mainActivity.png。

2.在主程序界面当按下游戏介绍按钮时进行游戏介绍界面如图gameintroduce.png,按“返回”按钮则回到主程序界面。

3.在主程序界面按下“进入游戏”按钮则进入游戏界面如图gameScores.png,按“返回”按钮加回主界面同时将子程序界面中的游戏成绩返回到主程序并显示在主程序中如图mainActivity1.png所示。

4.提交程序运行视频
5.所有相关的Java和XML文件。

思路:

一个主页面,四个子页面

主页面

MainActivity.class

package com.example.myapplication1;

import android.content.Intent;
import android.os.Bundle; import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity; import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView; public class MainActivity extends AppCompatActivity { private ImageView imageView1;
private ImageView imageView2;
private ImageView imageView3;
private ImageView imageView4;
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView1=findViewById(R.id.imageView);
imageView2=findViewById(R.id.imageView2);
imageView3=findViewById(R.id.imageView3);
imageView4=findViewById(R.id.imageView4);
textView=findViewById(R.id.textView);
imageView1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivityForResult(new Intent(MainActivity.this,
GameintroduceActivity.class),1);
}
}); imageView2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivityForResult(new Intent(MainActivity.this,
Entergame.class),2);
}
}); imageView3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivityForResult(new Intent(MainActivity.this,
Archivedownload.class),3);
}
}); imageView4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivityForResult(new Intent(MainActivity.this,
Designintroduce.class),4);
}
}); } @Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode){
case 1:
{assert data != null;
String position = data.getStringExtra("position1");
textView.setText(position);
break;}
case 2:{
assert data != null;
String position = data.getStringExtra("position2");
textView.setText(position);
break;}
case 3:{
assert data != null;
String position = data.getStringExtra("position3");
textView.setText(position);
break;} case 4:{
assert data != null;
String position = data.getStringExtra("position4");
textView.setText(position);
break;} default:
{textView.setText("");
break;}
}
}
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/gameface"
android:gravity="center"
android:orientation="vertical"> <ImageView
android:id="@+id/imageView" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@drawable/introduce" /> <ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@drawable/startgame" /> <ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@drawable/icon_load" /> <ImageView
android:id="@+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@drawable/icon_works" /> <TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="60dp"
android:layout_weight="4"
/>
</LinearLayout>

游戏介绍界面

GameIntroduceActivity.class

package com.example.myapplication1;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView; public class GameintroduceActivity extends AppCompatActivity {
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gameintroduce);
textView=findViewById(R.id.textView2);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = getIntent();
String s = textView.getText().toString();
intent.putExtra("position1", s);
setResult(RESULT_OK,intent);
finish();
}
});
}
}

gameintroduce.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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/game1"
tools:context=".GameintroduceActivity"> <TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="这是游戏介绍"
android:textColor="#DC143C"
android:textSize="60dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
/>
</RelativeLayout>

进入游戏界面

Entergame.class

package com.example.myapplication1;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView; public class Entergame extends AppCompatActivity {
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_entergame);
textView=findViewById(R.id.textView3);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = getIntent();
String s = textView.getText().toString();
intent.putExtra("position2", s);
setResult(RESULT_OK,intent);
finish();
}
});
}
}
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/game2"
tools:context=".Entergame"> <TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#DC143C"
android:textSize="60dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="获得游戏分数3600" />
</RelativeLayout>

存档界面

Archivedownload.class

package com.example.myapplication1;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView; public class Archivedownload extends AppCompatActivity {
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_archivedownload);
textView=findViewById(R.id.textView4);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = getIntent();
String s = textView.getText().toString();
intent.putExtra("position3", s);
setResult(RESULT_OK,intent);
finish();
}
});
}
}

activity_archivedownload.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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/game3"
tools:context=".Archivedownload">
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#DC143C"
android:textSize="60dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="这是档案下载"/>
</RelativeLayout>

设计人员界面

Designintroduce.class

package com.example.myapplication1;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView; public class Designintroduce extends AppCompatActivity {
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_designintroduce);
textView=findViewById(R.id.textView5);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = getIntent();
String s = textView.getText().toString();
intent.putExtra("position4", s);
setResult(RESULT_OK,intent);
finish();
}
});
}
}

activity_designintroduce.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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Designintroduce">
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#DC143C"
android:textSize="60dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="这是设计人员"/>
</RelativeLayout>

最新文章

  1. form表单序列化后的数据转json对象
  2. Leetcode 113. Path Sum II
  3. CentOS下httpd下php 连接mysql 本机可以,127.0.0.1不能访问
  4. URAL 1069 Prufer Code(模拟)
  5. SQL备份(全)
  6. atlassian-jira-confluence-bitbucket破解
  7. RedisTemplate.htm
  8. Lotus Sametime
  9. XenCenter注册码一年申请
  10. c#一个简单的实例告诉你,多继承还可以这么来
  11. PHP高效获取远程图片尺寸和大小
  12. Safe Area Layout Guide
  13. IDEA(jetbrain通用)优雅级使用教程(转)
  14. 洛谷P1164 小A点菜 DP入门
  15. Windows下安装pymssql
  16. ubuntu14简介/安装/菜鸟使用手册
  17. git中多账号切换问题的解决方案(转)
  18. Mabatis中#{}和${}的区别
  19. HOJ 2133&POJ 2964 Tourist(动态规划)
  20. maven nexus linux私服搭建

热门文章

  1. Ubuntu18.04安装MySQL(未设置密码或忘记密码)
  2. 封装一个postMessage库,进行iframe跨域交互
  3. Java学习之数组的简单用法
  4. Elasticsearch中最重要的文档CRUD要牢记
  5. 问题笔记 - element表格 操作状态值
  6. Python基础(七):字符串的使用(上)
  7. kubernetes CRD
  8. SQL Server CDC配合Kafka Connect监听数据变化
  9. Matrix Chain Multiplication UVA - 442
  10. 使用yamllint 检查yaml语法