EE308FZ_Lab_2_2

EE308FZ_Lab_2_2

    • 1.Basic Information
    • 2.PSP
    • 3.Soft Configur
    • 4.KeyCode
      •  1)MainActivity.java
      •  2)UserDao.java
    • 5.About Network Connection
    • 6.Key Events
    • 7.Pair programming
      •  1)Improved code quality
      •  2)Increased efficiency
      •  3)Improve the personal level
    • 8.Version iteration
      •  1)The first version
      •  2)The second version
      •  3)The third version
    • 9.Picture

1.Basic Information

The Link Your Class https://bbs.csdn.net/forums/MUEE308FZU202201
The Link of Requirement of This Assignment https://bbs.csdn.net/topics/608859318
MU STU ID and FZU STU ID 20123337_832002126
Teammate’s MU STU ID and FZU STU ID 20122110_832002114
Teammate’s blog link
GitHub link https://github.com/LittleMatcher/EE308FZ_LAB
Video demo link https://www.bilibili.com/video/BV17Y411f7xn/?share_source=copy_web&vd_source=92239ffbff74f37245aad0e213386e6c

bilibili

2.PSP

PSP2.1 Estimated time(min) Actual time(min)
Planning 30 20
· Estimate 10 10
Development 20 10
· Analysis 100 80
· Design Spec 30 15
· Design Review 10 25
· Coding Standard 5 3
· Design 400 (Prototype design) 420
· Coding 600 540
· Code Review 30 40
· Test 30 20
Reporting 60 60
· Test Report 10 10
· Size Measurement 5 10
· Postmortem & Process Improvement Plan 20 15
Total 1390 1278

3.Soft Configur

EE308FZ_Lab_2_2_第1张图片

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

EE308FZ_Lab_2_2_第2张图片

你可能感兴趣的:(EE308FZ,android,android,studio,ide)