EE308 Lab 2-2

m0_51284439 2022-11-18 00:26:05

EE306 Lab 2-2

Description of problem-solving ideas

First of all, for this homework, we should know that the last game is a game, so we chose the unity engine that may be used in the final project to complete this homework.

The game is a BoBing game.The BoBing game has two steps: throwing dice and judging rewards.

The first first step is to throw the dice. The throwing dice function will rely on random number generation. Clicking the throw button will generate six dice and random numbers, and pass the random numbers to the dice, the dice completes the preset animation based on the accepted random number, and then destroyed. The above is the solution to finish throwing the dice.

The second part is the judgment reward,There are initially two ideas for the realization of this function, first with regular expressions for judgment, and second with if nesting.Given only the less effort to judge six dice, the second method was chosen to achieve functionality.We count the points by establishing the counter, and judge the reward by the number of points within the counter.

Finally, the multiplayer part. For this part of the function we used photon pun2 to implement.
Here we make the prefabricated dice that need to be synchronized in the room and put them into the photon's resource file to easily synchronize the object at the interface of all players when throwing. Then you rely on the PhotonView components to synchronize the animation.We plan to use photon RPC to achieve simple message transfer in the same room.

Design and implementation process

——————————————Overall structural design————————————————————

请添加图片描述


The overall structure mainly includes the main menu and the UI design of the game interface.

The main menu section will include both the exit and login features.

The main game interface will contain most of the important features. Like view the rules, throw the dice, view the scoreboard, empty the scoreboard, and return to the main menu.

———————Throw dice function—————————————————————————————

请添加图片描述


The partial functional implementation of throwing dice, is shown in Fig.
Specifically to obtain random numbers, transmit to the generated dice that play the animation and destroy in seconds.
The obtained numbers are stored in order and counted, and a series of judgments produce the results.(The implementation will be detailed in the code explanation section below)

—————————————Online part of the function implementation————————————

请添加图片描述


The online part is mainly implemented through photon, and through the photonview component, the dice prefabricated of the photon resource folder is generated in the game interface of the members of the same room.
Adding room functions also depends on photon. Details will be displayed in the code section.

Code description

Connect the Room section code

public void Start()
    {
        PhotonNetwork.ConnectUsingSettings();//Start the connection when the game starts
    }
   public override void OnConnectedToMaster()
   {
        play.SetActive(true);//Login is allowed when the connection is successful
    }

    public void playButton()
    {
        nameUI.SetActive(false);
        PhotonNetwork.NickName = playername.text;//Get the username
        loginUI.SetActive(true);
    }

    public void joinorcreate()//Get the room number and create or connect the room.
    {
       load.SetActive(true);
       SceneManager.LoadScene(1);
        if (roomID.text.Length < 2)
            return;
        loginUI.SetActive(false);

    RoomOptions options = new RoomOptions { MaxPlayers = 4 };
    PhotonNetwork.JoinOrCreateRoom(roomID.text, options,default);
    }

   public override void OnJoinedRoom()//Jump to the game interface after the successful connection
   {
    PhotonNetwork.LoadLevel(1);
   }

Generate the Dice section code

public void creatdice(int sc)
{
    diceplace.position = diceplace.position + Vector3.right * 100;//Modify the Dice Generation Location
    //Generate the dice on the full room via the photon server
    GameObject newdice = PhotonNetwork.Instantiate("dice", diceplace.position, diceplace.rotation);
    newdice.transform.parent = this.transform;
    newdice.GetComponent<dice>().setnumber(sc);//Accept random numbers
}

Throw part of the code

public void roll()
{
    int[] sct = new int[6];
    System.Random rd = new System.Random();

    for (int i = 0; i < 6; i++)
    {
        int sc = rd.Next(1, 7);//Get random numbers

        creatdice(sc);//Call the above method to generate the dice

        sct[i] = sc;
    }
    diceplace.position = diceplace.position + Vector3.left * 600;//Investment generation position is back to positive
    sortsct(sct);
    string kg = checkpoint(sct);// Judge the reward result
    newsc.text = kg;
    showsct(sct, kg); //Transfer the results to the scoreboard
    Invoke("cleansc", 5);

}

Award Winning Judgment partial code

   public string checkpoint(int[] sct)//Reward judgment was made by the priority of the points
{
    string kg = "";
    string name = "";
    int[] total = new int[6];
    for (int i = 0; i < sct.Length; i++)
        total[sct[i] - 1]++;
    if (total[1] == 4)
    {
        kg = "JinShi";
        name = "SiJin";
    }
    else if (total[3] == 4 && total[0] == 2)
    {
        kg = "ZhuangYuan";
        name = "ZhuangYuanChaJinHua";
    }
    else if (total[3] == 6)
    {
        kg = "ZhuangYuan";
        name = "LiuBeiHong";
    }
    else if (total[5] == 6)
    {
        kg = "ZhuangYuan";
        name = "LiuBeiHei";
    }
    else if (total[3] == 5)
    {
        kg = "ZhuangYuan";
        name = "WuWang";
    }
    else if (total[5] == 5)
    {
        kg = "ZhuangYuan";
        name = "WuZiDengKe";
    }
    else if (total[3] == 4)
    {
        kg = "ZhuangYuan";
        name = "ZhuangYuan";
    }
    else if (total[3] == 3)
    {
        kg = "TanHua";
        name = "SanHong";
    }
    else if (total[3] == 2)
    {
        kg = "JuRen";
        name = "ErJu";
    }
    else if (total[3] == 1)
    {
        bool b = true;
        for (int i = 0; i < total.Length; i++)
        {
            if (total[i] != 1)
            {
                b = false;
                break;
            }
        }
        if (b == true)
        {
            kg = "BangYan";
            name = "DuiTang";
        }
        else
        {
            kg = "XiuCai";
            name = "YiJu";
        }
    }
    else
    {
        kg = "No Reward";
    }
    kg = string.Concat(kg, " ", name);
    return kg;
}

PSP

Personal SoftwareProcess StagesEstimated time (minutes)Real time (minutes)
Planning1020
Estimate--
Development300600
Analysis3040
Design Spec6090
Design Review3030
Coding Standard1010
Design3060
Coding600800
Code Review3060
Test6060
Reporting--
Test Report2020
Size Measurement1020
Postmortem & Process Improvement Plan2060
total12101870

summary

The project uses the basic operations of unity2d and how to achieve multiplayer games through photo. Exercise the project organization ability and teamwork ability.

The Link Your Class | https://bbs.csdn.net/forums/MUEE308FZU202201
| ----------- | ----------- |
The Link of Requirement of This Assignment | https://bbs.csdn.net/topics/608734907
MU STU ID and FZU STU ID | 20124635-832002210
Teammate's MU STU ID and FZU STU ID | 20122900-832002207
Teammate's blog link | https://blog.csdn.net/m0_54015927?type=bbs
GitHub link | https://github.com/Aiorang/Lab2
Video demo link | https://www.bilibili.com/video/BV1GW4y1x71B/?vd_source=3b4274550a75f47f7a429318c7bff80c

...全文
171 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

285

社区成员

发帖
与我相关
我的任务
社区描述
福州大学 梅努斯国际工程学院 软件工程(2022秋) 教学
软件工程 高校
社区管理员
  • LinQF39
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧