285
社区成员




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.
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.
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);
}
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
}
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);
}
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;
}
Personal SoftwareProcess Stages | Estimated time (minutes) | Real time (minutes) |
---|---|---|
Planning | 10 | 20 |
Estimate | - | - |
Development | 300 | 600 |
Analysis | 30 | 40 |
Design Spec | 60 | 90 |
Design Review | 30 | 30 |
Coding Standard | 10 | 10 |
Design | 30 | 60 |
Coding | 600 | 800 |
Code Review | 30 | 60 |
Test | 60 | 60 |
Reporting | - | - |
Test Report | 20 | 20 |
Size Measurement | 10 | 20 |
Postmortem & Process Improvement Plan | 20 | 60 |
total | 1210 | 1870 |
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