EE308FZ_Lab_2_2

1.Basic Information

The Link Your Classhttps://bbs.csdn.net/forums/MUEE308FZU202201
The Link of Requirement of This Assignmenthttps://bbs.csdn.net/topics/608859318
MU STU ID and FZU STU ID20123337_832002126
Teammate’s MU STU ID and FZU STU ID20122110_832002114
Teammate’s blog link
GitHub linkhttps://github.com/LittleMatcher/EE308FZ_LAB
Video demo linkhttps://www.bilibili.com/video/BV17Y411f7xn/?share_source=copy_web&vd_source=92239ffbff74f37245aad0e213386e6c

bilibili

2.PSP

PSP2.1Estimated time(min)Actual time(min)
Planning3020
· Estimate1010
Development2010
· Analysis10080
· Design Spec3015
· Design Review1025
· Coding Standard53
· Design400 (Prototype design)420
· Coding600540
· Code Review3040
· Test3020
Reporting6060
· Test Report1010
· Size Measurement510
· Postmortem & Process Improvement Plan2015
Total13901278

3.Soft Configur

在这里插入图片描述

4.KeyCode

 1)MainActivity.java

  The main screen contains the most content, and the logic is in the comments

import androidx.appcompat.app.AppCompatActivity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    Button button_setting,button_gemerule,button_login,button_solitary_game;
    private SoundPool.Builder builder;
    SharedPreferences preferences;
    final boolean On = true;
    private SoundPool soundpool;
    private int soundId;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.menu);
        findViewById(R.id.gamerule).setOnClickListener(this);
        Connect11.mymysql();
        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        preferences = getSharedPreferences("music1", Context.MODE_PRIVATE);
//-----------------------------------music-----------------------------------------------------
        Boolean state = preferences.getBoolean("flag",true);
        builder = new SoundPool.Builder();
        //AudioAttributes is a method that encapsulates various attributes of audio
        AudioAttributes.Builder attrBuilder = new AudioAttributes.Builder();
        //Set the appropriate properties for the audio stream
        attrBuilder.setLegacyStreamType(AudioManager.STREAM_SYSTEM);
        soundpool = builder.build();
        soundId = soundpool.load(MainActivity.this, R.raw.fight_landown_with_peasant, 1);
        //Listens for whether the load is complete
        if(state==On){
            soundpool.setOnLoadCompleteListener((soundPool, sampleId, status) -> {
                //When it is loaded, play it again
                soundpool.play(soundId, 1f, 1f, 0, 0, 1);
            });
            //Whether the Boolean value was passed successfully
            //Toast.makeText(MainActivity.this, "Button On!", Toast.LENGTH_LONG).show();
        }else if(state==false){
            //Whether the Boolean value was passed successfully
            //Toast.makeText(MainActivity.this, "Button Off!", Toast.LENGTH_LONG).show();
        }

//--------------------------------------------------------------------------------
//-----------------------------------back_page/next_page--------------------------
        button_gemerule=findViewById(R.id.gamerule);
        button_setting=findViewById(R.id.setting);
        button_login=findViewById(R.id.online_game);
        button_solitary_game=findViewById(R.id.solitary_play);
        button_solitary_game.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(MainActivity.this,solitary_game.class);//Jump from MainActivity to nextActivity
                soundpool.stop(soundId);
                startActivity(intent);
            }
        });
        button_setting.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(MainActivity.this,setting.class);//从MainActivity跳转到nextActivity
                soundpool.stop(soundId);
                startActivity(intent);
            }
        });
        button_gemerule.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(MainActivity.this,gamerule.class);//Jump from MainActivity to nextActivity
                soundpool.stop(soundId);
                startActivity(intent);
            }
        });
        button_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(MainActivity.this,LoginActivity.class);//Jump from MainActivity to login
                soundpool.stop(soundId);
                startActivity(intent);
            }
        });
//-------------------------------------------------------------------------------
    }
    @Override
    public void onClick(View view) {


    }


//-------------------------quit button function-----------------------------------
    public void showdialog(View view)
    {
        // Define a new dialog object
        AlertDialog.Builder alertdialogbuilder=new AlertDialog.Builder(this);
        //Set the dialog box prompt content
        alertdialogbuilder.setMessage("确定要退出程序吗?");
        //Defines the dialog box's two button titles and functions that accept events
        alertdialogbuilder.setPositiveButton("确定",click1);
        alertdialogbuilder.setNegativeButton("取消",click2);
        //Create and display the dialog box
        AlertDialog alertdialog1=alertdialogbuilder.create();
        alertdialog1.show();

    }
    private DialogInterface.OnClickListener click1=new DialogInterface.OnClickListener()
    {
        //This flag is used to enhance the program's compile-time checking. If the method is not a method that overrides the parent class, the compiler will report an error at compile time.
        @Override

        public void onClick(DialogInterface arg0,int arg1)
        {
            //Execute the end process when click1 is pressed
            finishAffinity();
        }
    };
    private DialogInterface.OnClickListener click2=new DialogInterface.OnClickListener()
    {
        @Override
        public void onClick(DialogInterface arg0,int arg1)
        {
            //The operation is cancelled when click2 is pressed
            arg0.cancel();
        }
    };

}

 2)UserDao.java

  Using Mysql, using their own computer as a server

package dao;

import com.example.bobing_1.Connect11;

import android.util.Log;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;

import entity.User;
import utils.JDBCUtils;

public class UserDao {

    private static final String TAG = "mysql-party-UserDao";

    public int login(String userAccount, String userPassword) {

        HashMap<String, Object> map = new HashMap<>();
        // Establish a connection based on the database name
        Connection connection = JDBCUtils.getConn();
        int msg = 0;
        try {
            // mysql simple query statement. In this case, a record is queried based on the userAccount field of the user table
            String sql = "select * from user where userAccount = ?";
            if (connection != null) {// If connection is not null, a connection is established with the database
                PreparedStatement ps = connection.prepareStatement(sql);
                System.out.println(11111);
                System.out.println(11111);
                System.out.println(11111);
                System.out.println(11111);
                if (ps != null) {
                    System.out.println(22222);
                    System.out.println(22222);
                    System.out.println(22222);
                    System.out.println(22222);
                    System.out.println(22222);
                    Log.e(TAG, "账号:" + userAccount);
                    //Query by account
                    ps.setString(1, userAccount);
                    // Execute sql query statements and return result sets
                    ResultSet rs = ps.executeQuery();
                    int count = rs.getMetaData().getColumnCount();
                    //Store the lookup in a map
                    while (rs.next()) {
                        // Note: The subscript starts with 1
                        for (int i = 1; i <= count; i++) {
                            String field = rs.getMetaData().getColumnName(i);
                            map.put(field, rs.getString(field));
                        }
                    }
                    connection.close();
                    ps.close();

                    if (map.size() != 0) {
                        System.out.println(map);
                        System.out.println(map);
                        System.out.println(map);
                        System.out.println(map);
                        System.out.println(map);
                        StringBuilder s = new StringBuilder();
                        //Look for a password match
                        for (String key : map.keySet()) {
                            if (key.equals("userPassword")) {

                                if (userPassword.equals(map.get(key))) {

                                    msg = 1;            //Correct password
                                } else {
                                    msg = 2;            //Incorrect password
                                }

                                break;
                            }
                        }
                    } else {
                        Log.e(TAG, "查询结果为空");
                        msg = 3;
                    }
                } else {
                    System.out.println(33333);
                    System.out.println(3333);
                    System.out.println(3333);
                    System.out.println(3333);
                    System.out.println(3333);
                    msg = 0;
                }
            } else {
                System.out.println(44444);
                System.out.println(4444);
                System.out.println(4444);
                System.out.println(4444);
                System.out.println(4444);

                msg = 0;
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.d(TAG, "异常login:" + e.getMessage());
            msg = 0;
        }
        return msg;
    }


    /**
     * function: registered
     */
    public boolean register(User user) {
        HashMap<String, Object> map = new HashMap<>();
        // Establish a connection based on the database name
        Connection connection = JDBCUtils.getConn();

        try {
            String sql = "insert into user(userAccount,userPassword,userName) values (?,?,?)";
            if (connection != null) {// If connection is not null, a connection is established with the database
                PreparedStatement ps = connection.prepareStatement(sql);
                if (ps != null) {

                    //Insert data into the database
                    ps.setString(1, user.getUserAccount());
                    ps.setString(2, user.getUserPassword());
                    ps.setString(3, user.getUserName());

                    // Execute sql query statements and return result sets
                    int rs = ps.executeUpdate();
                    if (rs > 0)
                        return true;
                    else
                        return false;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.e(TAG, "异常register:" + e.getMessage());
            return false;
        }

    }

    /**
     * function: Check whether the user exists based on the account
     */
    public User findUser(String userAccount) {

        // Establish a connection based on the database name
        Connection connection = JDBCUtils.getConn();
        User user = null;
        try {
            String sql = "select * from user where userAccount = ?";
            if (connection != null) {// If connection is not null, a connection is established with the database
                PreparedStatement ps = connection.prepareStatement(sql);
                if (ps != null) {
                    ps.setString(1, userAccount);
                    ResultSet rs = ps.executeQuery();

                    while (rs.next()) {
                        //Note: The subscript starts at 1
                        int id = rs.getInt(1);
                        String userAccount1 = rs.getString(2);
                        String userPassword = rs.getString(3);
                        String userName = rs.getString(4);
                        user = new User(id, userAccount1, userPassword, userName);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.d(TAG, "异常findUser:" + e.getMessage());
            return null;
        }
        return user;
    }

}

5.About Network Connection

  In the attitude of learning, and the nature of doing. We found that the campus network of Fuzhou University fully satisfied our study and practice, so we gave up renting the server and turned to FZU. The server is a desktop computer located in the dorm room. When we are on campus, if we are connected to fzu, we can directly log in to the game. If we are using mobile network, we can use fzu VPN Tianrongxin.

6.Key Events

 1)Control of Music
 2)Store the results of the game
 3)Unable to stay logged in after logging in

7.Pair programming

 1)Improved code quality

  By working together, we were able to decouple the code as much as possible, truly allowing a function to be used multiple times, reducing a lot of tedious and unnecessary code. It also reduces the appearance of bugs.

 2)Increased efficiency

  Pair programming allows everyone to build on their strengths and avoid their weaknesses, achieving a degree of complementarity. For example, a person has database project experience, but has not developed an app; The other person has app development experience, but is not familiar with the database, so we can complement each other.

 3)Improve the personal level

  A considerable amount of knowledge can be transferred between two people

8.Version iteration

 1)The first version

  a.Complete unit game, exit game, gameplay introduction.

  b.The game is not finished yet, and you can’t control the background music and dice sounds on the main screen

  c.The login game has not been completed, so the account registration and login functions cannot be performed

 2)The second version

  a.Game Settings can control the main screen background music and dice rolling sound

  b.The loading page was added

 3)The third version

  a.Use Mysql as a database, so that the game can achieve account login and registration functions

  b.The scoring feature was added to the game, and the scoring rules were added in the gameplay introduction

  c.To realize the room function, the current account ID and account nickname can be displayed when entering the room after checking the account

4.The logic of app activity stack is improved

9.Picture

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值