Android ——游戏开发之文字冒险游戏

Android ——游戏开发之文字冒险游戏Android游戏开发之文字冒险游戏文字冒险游戏—迷雾森林文字冒险游戏以软件模拟情境,令玩家使用文字指令控制角色,以影响周边的情境。迷雾森林是使用AndroidStudio开发的按钮点击式游戏。通过按钮点击实现全部操作,只涉及Android基础知识。运行界面源代码(1)Java文件:MainActivitypublicclassMainActivityextendsA…

大家好,欢迎来到IT知识分享网。

Android 游戏开发之文字冒险游戏

文字冒险游戏—迷雾森林

文字冒险游戏以软件模拟情境,令玩家使用文字指令控制角色,以影响周边的情境。迷雾森林是使用Android Studio开发的按钮点击式游戏。通过按钮点击实现全部操作,只涉及Android基础知识。

运行界面

界面1界面2
界面3界面4
界面5界面6

源代码

(1)Java文件:MainActivity

public class MainActivity extends AppCompatActivity implements View.OnClickListener { 
   

    @Override
    protected void onCreate(Bundle savedInstanceState) { 
   
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //"开始游戏"按钮监听
        Button button1=findViewById(R.id.button1);
        button1.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) { 
    //点击“开始游戏”跳转到DengLu的Activity
        switch (v.getId()) { 
   
            case R.id.button1: { 
   
                Intent intent=new Intent();
                intent.setClass(MainActivity.this,DengLu.class);
                startActivity(intent);
            }
        }
    }
    @Override
    protected void onNewIntent(Intent intent) { 
   
        super.onNewIntent(intent);
        String tag = intent.getStringExtra("EXIT_TAG");
        if (tag != null&& !TextUtils.isEmpty(tag)) { 
   
            if ("SINGLETASK".equals(tag)) { 
   //退出程序
                finish();
            }
        }
    }
}

(2)布局文件:MainActivity.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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=".MainActivity">

    <ImageView
        android:src="@drawable/z00"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="fitXY"
        />
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="开始游戏"
            android:layout_marginLeft="150dp"
            android:layout_marginTop="490dp"
            />
    </RelativeLayout>

</android.support.constraint.ConstraintLayout>

(3)Java文件:DengLu

public class DengLu extends AppCompatActivity implements View.OnClickListener { 
   
    EditText editText;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) { 
   
        super.onCreate(savedInstanceState);
        setContentView(R.layout.denglu);
        Button button1=findViewById(R.id.button1);
        button1.setOnClickListener(this);
        editText=findViewById(R.id.edittext);
    }

    public void onClick(View v) { 
   
        switch (v.getId()) { 
   
            case R.id.button1: { 
   
                Intent intent = new Intent();
                Bundle bundle=new Bundle();
                //获取编辑框输入内容,赋值给Shuju类中z
                Shuju.z=editText.getText().toString();
                //点击跳转到Xingzou的Activity
                intent.setClass(DengLu.this,Xingzou.class);
                startActivity(intent);
            }
            break;
        }
    }
}

(4)Java文件:Shuju

public class Shuju { 
   
    //定义静态变量
    public static String z;
    public static int x=100;
    public static int y=100;
    public static int q=0;
}

(5)布局文件:denglu.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:src="@drawable/tp"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="fitXY"
        />
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="100dp"
            android:layout_marginTop="50dp"
            android:width="200dp"
            android:singleLine="false"
            android:text="年轻的冒险者,在进入森林之前,告诉我你的名字!"
            android:textSize="24dp"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <EditText
            android:id="@+id/edittext"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="120dp"
            android:layout_marginTop="300dp"
            android:inputType="text"
            android:hint="我的名字:"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="进入森林"
            android:layout_marginLeft="150dp"
            android:layout_marginTop="440dp"
            />
    </LinearLayout>
</android.support.constraint.ConstraintLayout>

(6)Java文件:Xingzou

public class Xingzou extends AppCompatActivity implements View.OnClickListener { 
   
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) { 
   
        super.onCreate(savedInstanceState);
        setContentView(R.layout.xingzou);
        Button button1=findViewById(R.id.button1);
        button1.setOnClickListener(this);
        Button button2=findViewById(R.id.button2);
        button2.setOnClickListener(this);
        Button button3=findViewById(R.id.button3);
        button3.setOnClickListener(this);
        //播放音乐
        final MediaPlayer player=MediaPlayer.create(this,R.raw.zhuti);
        player.start();
        player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { 
   
            @Override
            public void onCompletion(MediaPlayer mp) { 
   
                player.start();
            }
        });
        TextView textView1 = findViewById(R.id.textView1);
        //显示关卡
        textView1.setText(Shuju.z);
        TextView textView2 = findViewById(R.id.textView5);
        TextView textView3 = findViewById(R.id.textView4);
        //显示生命和意志
        textView2.setText(Shuju.x+"");
        textView3.setText(Shuju.y+"");
    }
    public void onClick(View v) { 
   
        switch (v.getId()) { 
   
            case R.id.button1: { 
   
                Intent intent=new Intent();
                //产生随机数
                double zz=Math.random()*10;
                //判断随机数大小,产生跳转
                if (zz>5) { 
   
                    intent.setClass(Xingzou.this,Lang.class);
                }else { 
   
                    intent.setClass(Xingzou.this,Lei.class);
                }
                startActivity(intent);
            }
            break;
            case R.id.button2: { 
   
                Intent intent=new Intent();
                intent.setClass(Xingzou.this,She.class);
                startActivity(intent);
            }
            break;
            case R.id.button3:{ 
   
                Intent intent = new Intent();
                intent.setClass(Xingzou.this, Nuwu.class);
                startActivity(intent);
            }
            break;
        }
    }
}

(7)布局文件xingzou.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:src="@drawable/zzx"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="fitXY"
        />
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="50dp"
            android:layout_marginTop="50dp"
            android:text="name"
            android:textSize="24dp"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="100dp"
            android:layout_marginTop="50dp"
            android:singleLine="false"
            android:text="生命:"
            android:textSize="24dp"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="200dp"
            android:layout_marginTop="50dp"
            android:singleLine="false"
            android:text="意志:"
            android:textSize="24dp"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="250dp"
            android:layout_marginTop="50dp"
            android:singleLine="false"
            android:text="100"
            android:textSize="24dp"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TextView
            android:id="@+id/textView5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="150dp"
            android:layout_marginTop="50dp"
            android:singleLine="false"
            android:text="100"
            android:textSize="24dp"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="向左"
            android:layout_marginLeft="0dp"
            android:layout_marginTop="440dp"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="前进"
            android:layout_marginLeft="150dp"
            android:layout_marginTop="440dp"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <Button
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="向右"
            android:layout_marginLeft="300dp"
            android:layout_marginTop="440dp"
            />
    </LinearLayout>
</android.support.constraint.ConstraintLayout>

(8)Java文件:Lang

public class Lang extends AppCompatActivity { 
   
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) { 
   
        super.onCreate(savedInstanceState);
        setContentView(R.layout.lang);
        //播放音乐
        MediaPlayer player=MediaPlayer.create(this,R.raw.lang);
        player.start();
        //关卡数加1
        Shuju.q=Shuju.q+1;
        //定时器3秒,自动跳转
        Timer timer = new Timer();
        timer.schedule(new MyTask(),3000);
    }
    class MyTask extends TimerTask { 
   
        @Override
        public void run() { 
   
            Intent intent;
            //判断关卡数是否达到20,达到跳转结束页面,否则跳转对应事件页面
            if (Shuju.q==20) { 
   
                intent = new Intent(Lang.this,Over.class);
                startActivity(intent);
            }else { 
   
                intent = new Intent(Lang.this,Lang0.class);
                startActivity(intent);
            }
        }
    }
}

(9)布局文件:lang.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:src="@drawable/q1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="fitXY"
        />
</android.support.constraint.ConstraintLayout>

(10)Java文件:Lang0

public class Lang0 extends AppCompatActivity implements View.OnClickListener { 
   
    int a=-10,b=-5;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) { 
   
        super.onCreate(savedInstanceState);
        setContentView(R.layout.js);
        TextView textView = findViewById(R.id.textView);
        //显示文字内容
        textView.setText("你遭遇了恶狼");
        TextView textView1 = findViewById(R.id.textView3);
        textView1.setText(a+"");
        TextView textView2 = findViewById(R.id.textView4);
        textView2.setText(b+"");
        Button button=findViewById(R.id.button);
        button.setOnClickListener(this);
        //生命和意志改变
        Shuju.x=Shuju.x+a;
        Shuju.y=Shuju.y+b;
        if (Shuju.x<=0||Shuju.y<=0) { 
   
            Intent intent = new Intent();
            intent.setClass(Lang0.this,Over.class);
            startActivity(intent);
        }
        //当生命和意志数值大于100变更为100
        if (Shuju.x>100) { 
   
            Shuju.x=100;
        }
        if (Shuju.y>100) { 
   
            Shuju.y=100;
        }
    }
    public void onClick(View v) { 
   
        switch (v.getId()) { 
   
            case R.id.button: { 
   
                Intent intent = new Intent();
                intent.setClass(Lang0.this,Xingzou.class);
                //跳转后结束中间页面
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
            }
            break;
        }
    }
}

(11)Java文件:Lei

public class Lei extends AppCompatActivity { 
   
    protected void onCreate(Bundle savedInstanceState) { 
   
        super.onCreate(savedInstanceState);
        setContentView(R.layout.lei);
        MediaPlayer player=MediaPlayer.create(this,R.raw.lei);
        player.start();
        Shuju.q=Shuju.q+1;
        Timer timer = new Timer();
        timer.schedule(new MyTask(),3000);
    }
    class MyTask extends TimerTask { 
   
        @Override
        public void run() { 
   
            Intent intent;
            if (Shuju.q==20) { 
   
                intent = new Intent(Lei.this,Over.class);
                startActivity(intent);
            }else { 
   
                intent = new Intent(Lei.this,Lei0.class);
                startActivity(intent);
            }
        }
    }
}

(12)布局文件:lei.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:src="@drawable/q2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="fitXY"
        />
</android.support.constraint.ConstraintLayout>

(13)Java文件:Lei0

public class Lei0 extends AppCompatActivity implements View.OnClickListener { 
   
    int a=0,b=-10;
    protected void onCreate(Bundle savedInstanceState) { 
   
        super.onCreate(savedInstanceState);
        setContentView(R.layout.js);
        TextView textView = findViewById(R.id.textView);
        textView.setText("闪电突然来临,受到惊吓");
        TextView textView1 = findViewById(R.id.textView3);
        textView1.setText(a+"");
        TextView textView2 = findViewById(R.id.textView4);
        textView2.setText(b+"");
        Button button=findViewById(R.id.button);
        button.setOnClickListener(this);
        Shuju.x=Shuju.x+a;
        Shuju.y=Shuju.y+b;
        if (Shuju.x<=0||Shuju.y<=0) { 
   
            Intent intent = new Intent();
            intent.setClass(Lei0.this,Over.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
        }
        if (Shuju.x>100) { 
   
            Shuju.x=100;
        }
        if (Shuju.y>100) { 
   
            Shuju.y=100;
        }
    }
    public void onClick(View v) { 
   
        switch (v.getId()) { 
   
            case R.id.button: { 
   
                Intent intent = new Intent();
                intent.setClass(Lei0.this,Xingzou.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
            }
            break;
        }
    }
}

(14)Java文件:She

public class She extends AppCompatActivity { 
   
    protected void onCreate(Bundle savedInstanceState) { 
   
        super.onCreate(savedInstanceState);
        setContentView(R.layout.she);
        MediaPlayer player=MediaPlayer.create(this,R.raw.she);
        player.start();
        Shuju.q=Shuju.q+1;
        Timer timer = new Timer();
        timer.schedule(new MyTask(),3000);
    }
    class MyTask extends TimerTask { 
   
        @Override
        public void run() { 
   
            Intent intent;
            if (Shuju.q==20) { 
   
                intent = new Intent(She.this,Over.class);
                startActivity(intent);
            }else { 
   
                intent = new Intent(She.this,She0.class);
                startActivity(intent);
            }
        }
    }
}

(15)布局文件:she.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:src="@drawable/q3"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="fitXY"
        />
</android.support.constraint.ConstraintLayout>

(16)Java文件:She0

public class She0 extends AppCompatActivity implements View.OnClickListener { 
   
    int a=10,b=-10;
    protected void onCreate(Bundle savedInstanceState) { 
   
        super.onCreate(savedInstanceState);
        setContentView(R.layout.js);
        TextView textView = findViewById(R.id.textView);
        textView.setText("你遭遇了蛇");
        TextView textView1 = findViewById(R.id.textView3);
        textView1.setText(a+"");
        TextView textView2 = findViewById(R.id.textView4);
        textView2.setText(b+"");
        Button button=findViewById(R.id.button);
        button.setOnClickListener(this);
        Shuju.x=Shuju.x+a;
        Shuju.y=Shuju.y+b;
        if (Shuju.x<=0||Shuju.y<=0) { 
   
            Intent intent = new Intent();
            intent.setClass(She0.this,Over.class);
            startActivity(intent);
        }
        if (Shuju.x>100) { 
   
            Shuju.x=100;
        }
        if (Shuju.y>100) { 
   
            Shuju.y=100;
        }
    }
    public void onClick(View v) { 
   
        switch (v.getId()) { 
   
            case R.id.button: { 
   
                Intent intent = new Intent();
                intent.setClass(She0.this,Xingzou.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
            }
            break;
        }
    }
}

(17)Java文件:Nuwu

public class Nuwu extends AppCompatActivity { 
   
    protected void onCreate(Bundle savedInstanceState) { 
   
        super.onCreate(savedInstanceState);
        setContentView(R.layout.lei);
        MediaPlayer player=MediaPlayer.create(this,R.raw.nuwu);
        player.start();
        Shuju.q=Shuju.q+1;
        Timer timer = new Timer();
        timer.schedule(new MyTask(),3000);
    }
    class MyTask extends TimerTask { 
   
        @Override
        public void run() { 
   
            Intent intent;
            if (Shuju.q==20) { 
   
                intent = new Intent(Nuwu.this,Over.class);
                startActivity(intent);
            }else { 
   
                intent = new Intent(Nuwu.this,Nuwu0.class);
                startActivity(intent);
            }
        }
    }
}

(18)布局文件:nuwu.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:src="@drawable/q5"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="fitXY"
        />
</android.support.constraint.ConstraintLayout>

(19)Java文件:Nuwu0

public class Nuwu0 extends AppCompatActivity implements View.OnClickListener { 
   
    int a=10,b=-10;
    protected void onCreate(Bundle savedInstanceState) { 
   
        super.onCreate(savedInstanceState);
        setContentView(R.layout.js);
        TextView textView = findViewById(R.id.textView);
        textView.setText("你遭遇了女巫");
        TextView textView1 = findViewById(R.id.textView3);
        textView1.setText(a+"");
        TextView textView2 = findViewById(R.id.textView4);
        textView2.setText(b+"");
        Button button=findViewById(R.id.button);
        button.setOnClickListener(this);
        Shuju.x=Shuju.x+a;
        Shuju.y=Shuju.y+b;
        if (Shuju.x<=0||Shuju.y<=0) { 
   
            Intent intent = new Intent();
            intent.setClass(Nuwu0.this,Over.class);
            startActivity(intent);
        }
        if (Shuju.x>100) { 
   
            Shuju.x=100;
        }
        if (Shuju.y>100) { 
   
            Shuju.y=100;
        }
    }
    public void onClick(View v) { 
   
        switch (v.getId()) { 
   
            case R.id.button: { 
   
                Intent intent = new Intent();
                intent.setClass(Nuwu0.this,Xingzou.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
            }
            break;
        }
    }

}

(20)布局文件:js.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:src="@drawable/tp"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="fitXY"
        />
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="100dp"
            android:layout_marginTop="50dp"
            android:width="200dp"
            android:singleLine="false"
            android:text=" "
            android:textSize="24dp"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="50dp"
            android:layout_marginTop="340dp"
            android:width="200dp"
            android:singleLine="false"
            android:text="生命"
            android:textSize="24dp"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="150dp"
            android:layout_marginTop="340dp"
            android:width="200dp"
            android:singleLine="false"
            android:text="意志"
            android:textSize="24dp"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="100dp"
            android:layout_marginTop="340dp"
            android:width="200dp"
            android:singleLine="false"
            android:text="sm"
            android:textSize="24dp"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="200dp"
            android:layout_marginTop="340dp"
            android:width="200dp"
            android:singleLine="false"
            android:text="yz"
            android:textSize="24dp"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="继续"
            android:layout_marginLeft="150dp"
            android:layout_marginTop="440dp"
            />
    </LinearLayout>
</android.support.constraint.ConstraintLayout>

(21)Java文件:Over

public class Over extends AppCompatActivity { 
   
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) { 
   
        super.onCreate(savedInstanceState);
        setContentView(R.layout.over);
        Button button=findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() { 
   
            @Override
            public void onClick(View v) { 
   
                Intent intent = new Intent(Over.this, MainActivity.class);
                intent.putExtra("EXIT_TAG", "SINGLETASK");
                startActivity(intent);
            }
        });
    }
}

(22)布局文件:over.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/tp">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="450dp"
        android:gravity="center">
        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="100dp"
            android:layout_marginTop="50dp"
            android:width="200dp"
            android:singleLine="false"
            android:text="游戏结束!"
            android:textSize="24dp"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center">
        <Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="over"/>
    </LinearLayout>
</LinearLayout>

(23)AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.a86155.zzx">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar">
        <activity android:name=".MainActivity"
            android:launchMode="singleTask">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".DengLu">
            <intent-filter android:priority="2">
                <action android:name="android.intent.action.MY_ACTION" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity android:name=".Xingzou">
            <action android:name="android.intent.action.MY_ACTION" />
            <category android:name="android.intent.category.DEFAULT" />
        </activity>
        <activity android:name=".Lang">
            <action android:name="android.intent.action.MY_ACTION" />
            <category android:name="android.intent.category.DEFAULT" />
        </activity>
        <activity android:name=".Lang0">
            <action android:name="android.intent.action.MY_ACTION" />
            <category android:name="android.intent.category.DEFAULT" />
        </activity>
        <activity android:name=".Lei">
            <action android:name="android.intent.action.MY_ACTION" />
            <category android:name="android.intent.category.DEFAULT" />
        </activity>
        <activity android:name=".Lei0">
            <action android:name="android.intent.action.MY_ACTION" />
            <category android:name="android.intent.category.DEFAULT" />
        </activity>
        <activity android:name=".She">
            <action android:name="android.intent.action.MY_ACTION" />
            <category android:name="android.intent.category.DEFAULT" />
        </activity>
        <activity android:name=".She0">
            <action android:name="android.intent.action.MY_ACTION" />
            <category android:name="android.intent.category.DEFAULT" />
        </activity>
        <activity android:name=".Nuwu">
            <action android:name="android.intent.action.MY_ACTION" />
            <category android:name="android.intent.category.DEFAULT" />
        </activity>
        <activity android:name=".Nuwu0">
            <action android:name="android.intent.action.MY_ACTION" />
            <category android:name="android.intent.category.DEFAULT" />
        </activity>
        <activity android:name=".Over">
            <action android:name="android.intent.action.MY_ACTION" />
            <category android:name="android.intent.category.DEFAULT" />
        </activity>
    </application>

</manifest>

以上是迷雾森林全部代码,是初学Android时运用基础知识写的小程序,按照步骤来做,应该能直接运行。

欢迎大家指正。

迷雾森林代码

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/10399.html

(0)

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

关注微信