189
社区成员




这个作业属于哪个课程 | 构建之法-2021秋-福州大学软件工程 https://bbs.csdn.net/forums/fzuSoftwareEngineering2021?category=0 |
---|---|
这个作业要求在哪里 | 2021秋软工实践第二次结对编程作业 https://bbs.csdn.net/topics/601189945 |
个人学号 | 031902401 |
结对成员学号 | 031902431 |
结对小伙伴的作业博客链接 | https://bbs.csdn.net/topics/601429220 |
GitHub 仓库地址 | https://github.com/The-homework-for-Software-Engineering/unity |
视频演示链接 | demo2.0 https://www.bilibili.com/video/BV1UP4y1t7mC?spm_id_from=444.41.0.0 |
PSP | Personal Software Process Stages | 预估耗(分钟) | 实际耗时(分钟) |
---|---|---|---|
Planning | 计划 | 60 | 120 |
Estimate | 估计这个任务需要多少时间 | 10 | 30 |
Development | 开发 | 1000 | 1200 |
Analysis | 需求分析 (包括学习新技术) | 900 | 1200 |
Design Spec | 生成设计文档 | 30 | 30 |
Design Review | 设计复审 (审核设计文档) | - | - |
Coding Standard | 代码规范 (为目前的开发制定合适的规范) | 60 | 60 |
Design | 具体设计 | 200 | 200 |
Coding | 具体编码 | 400 | 600 |
Code Review | 代码复审 | - | 100 |
Test | 测试(自我测试,修改代码,提交修改) | 60 | 60 |
Reporting | 报告 | 30 | 30 |
Test Report | 测试报告 | - | - |
Size Measurement | 计算工作量 | 10 | 20 |
Postmortem & Process Improvement Plan | 事后总结, 并提出过程改进计划 | 30 | 60 |
Total | 合计 | 2730 | 3590 |
第N周 | 新增代码(行) | 累计代码(行) | 本周学习耗时(小时) | 累计学习耗时(小时) | 重要成长 |
---|---|---|---|---|---|
1 | 200 | 200 | 36 | 36 | 学会了unity界面使用,UI构建和C#的基本语法 |
2 | 300 | 500 | 36 | 72 | 学会了unity脚本的编写,以及将逻辑代码转变成脚本语言 |
博饼是源于福建闽南的一项传统民俗活动,是中秋节时的一种大众娱乐活动,用六粒骰子投掷结果组合来决定参与者的奖品。在如今的新冠疫情期间,线下家族聚会也十分不便,以及博饼所需要的道具也难以随身携带。于是,我们开发了一款博饼软件,用户可以随时随刻在任何地方进行博饼活动。即使和家人朋友远隔千里,也可以其乐融融的博饼助兴。
下图为开始界面,可以实现单人游戏,多人游戏,设置界面的跳转,并加有退出游戏的功能
下图为设置界面,可以在这里调节BGM大小和开关BGM,并可以由此界面进入到奖品设置界面
下图为奖品设置页面,用户可以在这里输入各级别的奖品。这个界面目前采用的是输入框模式,后续可能改为列表输入模式
下图为单人游戏与多人游戏界面,用户可以在这里输入ID,并点击返回按钮回到主菜单,通过点击下一步按钮前往游戏界面
下图为游戏界面,拥有查看规则与隐藏规则的功能,以及具有前往结果页面查看的功能
下图为结果页面,用户可以在这里查看自己投中的结果
仓库页面 https://github.com/The-homework-for-Software-Engineering/unity
由于要实现用户即时调整BGM的功能,unity里面没有现成的功能,故需要自己编写功能脚本来实现,这个脚本主要通过调用C#和unity的库函数
代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class BGM : MonoBehaviour
{
public AudioSource audioSource;
public Slider sd; //用于滑条控制音量
//开始、停止播放
public void play_stop_music()
{
Debug.Log("s");
if (!audioSource.isPlaying)
{
audioSource.Play();
}
else
{
audioSource.Stop();
}
}
//暂停播放
public void pause_music()
{
if (audioSource.isPlaying)
{
audioSource.Pause();
}
}
//改变音量
public void change_volume()
{
audioSource.volume = sd.value; //将音量和滑条对应
}
}
由于在开始投掷的过程中,骰子是不断变动的。所以就采用更换材质的脚本,以实现骰子变换动画的功能
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChangeTexture : MonoBehaviour
{
public Texture[] texList;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
gameObject.GetComponent<Renderer> ().material.mainTexture = texList[Random.Range(0, 6)]; //给骰子加上贴图,以随机显示贴图的形式来完成骰子变换动画
}
}
由于unity上切换场景会导致GameObject被销毁,所以需要运行此脚本,用于保护GameObject和挂在其上面的脚本和参数,虽然此功能没有直接在游戏上体现,但是这个功能是核心中的核心
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class Initiation : MonoBehaviour
{
private static Initiation instance = null;
public static Initiation Instance
{
get { return instance; }
}
private void Awake()
{
if (instance != null && instance != this)
{
Destroy(this.gameObject);
return;
}
else
{
instance = this;
}
DontDestroyOnLoad(this.gameObject);//使对象目标在加载新场景时不被自动销毁。
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class NewBehaviourScript : MonoBehaviour
{
public int[] r = new int[10];
void Start()
{
int r1 = GameObject.Find("D1").GetComponent<ChangeTexture>().ran; //引用上一脚本的变量
int r2 = GameObject.Find("D2").GetComponent<ChangeTexture>().ran;
int r3 = GameObject.Find("D3").GetComponent<ChangeTexture>().ran;
int r4 = GameObject.Find("D4").GetComponent<ChangeTexture>().ran;
int r5 = GameObject.Find("D5").GetComponent<ChangeTexture>().ran;
int r6 = GameObject.Find("D6").GetComponent<ChangeTexture>().ran;
void add() //数组赋值
{
r[1] = r1;
r[2] = r2;
r[3] = r3;
r[4] = r4;
r[5] = r5;
r[6] = r6;
}
}
struct player
{
public int level;
//level为玩家的组合等级
public int result;
//result为该组合中的大小权重,level = 0, 1, 2, 3, 4, 6, 7, 8时需要使用
public int rank;
//结果排序
}
player[] p = new player[20];
void SortDice() //冒泡排序
{
int t;
for (int i = 1; i < 6; i++)
{
for (int j = i; j < 6; j++)
{
if (r[j] < r[j + 1])
{
t = r[j];
r[j] = r[j + 1];
r[j] = t;
}
}
}
}
/*等级判定:
level0 = 无, level1 = 一秀
level2 = 二举,level3 = 四进
level4 = 三红,level5 = 对堂
level6 = 状元,level7 = 五黑
level8 = 五红,level9 = 六博黑
level10 = 六博红,level11 = 状元插金花
将该玩家的本次投掷结果送入SortLevel
*/
void SortLevel(player p)
{
int num1=0, num2=0, num3=0, num4=0, num5 =0, num6 = 0;
for (int i = 1; i <= 6; i++) //计数
{
switch (r[i])
{
case 1: num1++; break;
case 2: num2++; break;
case 3: num3++; break;
case 4: num4++; break;
case 5: num5++; break;
case 6: num6++; break;
}
}
Text text;
text = GameObject.Find("Canvas/游戏界面/结果榜/获得奖项").GetComponent<Text>();
if (num4 == 4 && num1 == 2) //评判并输出结果
{
p.level = 11;
text = "状元插金花";
}
else if (num4 == 6)
{
p.level = 10;
text = "六博红";
}
else if (num2 == 6)
{
p.level = 9;
text = "六博黑";
}
else if (num4 == 5)
{
p.level = 8;
text = "五红";
}
else if (num2 == 5)
{
p.level = 7;
text = "五黑";
}
else if (num4 == 4)
{
p.level = 6;
text = "状元";
}
else if (num1 == 1 && num2 == 1 && num3 == 1 && num4 == 1 && num5 == 1 && num6 == 1)
{
p.level = 5;
text = "对堂";
}
else if (num4 == 3)
{
p.level = 4;
text = "三红";
}
else if (num2 == 4)
{
p.level = 3;
text = "四进";
}
else if (num4 == 2)
{
p.level = 2;
text = "二举";
}
else if (num4 == 1)
{
p.level = 1;
text = "一秀";
}
else
{
p.level = 0;
text = "未中奖";
}
}
}
本周的结对任务中,我深刻地体会到了结对的重要性。分则难以推进,合则其利断金。曾遇到过自己遇到不会的部分,不断查阅资料却毫无进展,白费了一整个下午;在晚上进行结对工作时队友三下五除二解决问题的情况。结对时最重要的部分就是两个人互帮互助,明确分工,互补短处。一个人能学习、维护的代码是有限的,而各司其职则可以达到1+1>2的效果。 ——来自队友<031902431>
这两周的结对任务,是一次非常难忘的经历,在这两周中,我和我的队友迅速学会了unity的操作。但是在开发过程中,仍然遇到了多次的瓶颈,但是两个人一起解决的效率,会比一个人解决高出好几倍。以及在开发过程中,学会一定程度的妥协是一项非常重要的能力,在开发过程中,由于时间和技术力的限制,很多预想的功能难以实现,所以,必须时刻调整工程的方向,一切以完成任务为主。拓展功能可以之后再加。 ——<031902401>
这次由于时间太短,加上学的东西还不够多,所以之做出了.exe 的版本。一些预想的功能,如网络联机,奖品实时更新,BGM切换,案件音效和引导语音等功能没有实现,之后等学会了小程序开发,有更富裕的时间之后,我打算把这个软件,改造成微信小程序版本,在过年的时候,邀请家里的长辈,还有群里的亲朋好友一起来博饼!另外由于时间限制,UI素材很多都不是原创的,在之后的日子里,我打算把素材全换成原创的,然后名正言顺的发布。