189
社区成员




这个作业属于哪个课程 | 构建之法-2021秋-福州大学软件工程 https://bbs.csdn.net/forums/fzuSoftwareEngineering2021 |
---|---|
这个作业要求在哪里 | 2021秋软工实践第二次结对编程作业 https://bbs.csdn.net/topics/601189945 |
个人学号 | 031902434 |
结对成员学号 | 031902432 |
结对小伙伴的作业博客链接 | https://blog.csdn.net/qq_50709731/article/details/120657796 |
GitHub 仓库地址 | https://github.com/huuu-code/dice.git |
视频演示链接 | https://www.bilibili.com/video/bv13f4y1c7eB |
PSP2.1 | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟) |
---|---|---|---|
Planning | 计划 | 10 | 15 |
· Estimate | · 估计这个任务需要多少时间 | 10 | 15 |
Development | 开发 | 960 | 930 |
· Analysis | · 需求分析 (包括学习新技术) | 300 | 400 |
· Design Spec | · 生成设计文档 | ||
· Design Review | · 设计复审 (和同事审核设计文档) | ||
· Coding Standard | · 代码规范 (为目前的开发制定合适的规范) | 30 | 20 |
· Design | · 具体设计 | 180 | 120 |
· Coding | · 具体编码 | 300 | 210 |
· Code Review | · 代码复审 | 30 | 20 |
· Test | · 测试(自我测试,修改代码,提交修改) | 120 | 160 |
Reporting | 报告 | 70 | 50 |
· Test Report | · 测试报告 | ||
· Size Measurement | · 计算工作量 | 60 | 40 |
· Postmortem & Process Improvement Plan | · 事后总结, 并提出过程改进计划 | 10 | 10 |
合计 | 1040 | 995 |
通过判断鼠标点击事件进行页面切换(仅展示部分页面跳转)
while True:
for event in pygame.event.get ( ):
# 主页跳转游戏页面
if event.type == pygame.MOUSEBUTTONDOWN:
if button1.is_down ( event.pos, window ):
pass
if event.type == pygame.MOUSEBUTTONUP:
if button1.is_up ( event.pos, window ):
bg_game ( ) #背景设置
button5.draw1 ( window ) #添加摇骰子按钮
#show_number()
pygame.display.update ( )
# 游戏页面跳转结束页面
if event.type == pygame.MOUSEBUTTONDOWN:
if button5.is_down ( event.pos, window ):
pass
if event.type == pygame.MOUSEBUTTONUP:
if button5.is_up ( event.pos, window ):
bg_game ( )
button5.draw1 ( window ) #添加摇骰子按钮
button6.draw1 ( window) #添加结束游戏按钮
show_result() #显示结果
pygame.display.update ( )
按钮的创建与点击事件
# 定义一个Button类
class Button:
# 初始化按钮。传入按钮文字,坐标,大小,背景颜色,文字颜色,默认文字大小32
def __init__ ( self, title, pos, size, bg_color, text_color, font_size=32 ):
self.title = title
self.pos = pos
self.size = size
self.bg_color = bg_color
self.text_color = text_color
self.font_size = font_size
self.old_color = bg_color
# 画按钮
def draw1 ( self, window ):
self.rect = pygame.Rect ( self.pos [ 0 ], self.pos [ 1 ], self.size [ 0 ], self.size [ 1 ] )
pygame.draw.rect ( window, self.bg_color, self.rect ) #绘制矩形
self.font = pygame.font.Font ( '素材/字体1.ttf', self.font_size )
text = self.font.render ( self.title, True, self.text_color )
t_w, t_h = text.get_size ( )
window.blit ( text,(self.pos [ 0 ] + self.size [ 0 ] / 2 - t_w / 2, self.pos [ 1 ] + self.size [ 1 ] / 2 - t_h / 2) )
# 当鼠标按下
def is_down ( self, pos, window ):
m_x, m_y = pos
btn_x, btn_y = self.pos
btn_w, btn_h = self.size
if btn_x <= m_x <= btn_x + btn_w and btn_y <= m_y <= btn_y + btn_h:
self.bg_color = (200, 200, 200)
self.draw1 ( window )
pygame.display.update ( )
return True
else:
return False
# 当鼠标弹起
def is_up ( self, pos, window ):
m_x, m_y = pos
btn_x, btn_y = self.pos
btn_w, btn_h = self.size
if btn_x <= m_x <= btn_x + btn_w and btn_y <= m_y <= btn_y + btn_h:
self.bg_color = self.old_color #更改画按钮时的矩形颜色以达成动画效果
self.draw1 ( window )
pygame.display.update ( )
return True
else:
return False
随机六个骰子的点数并判断结果
# 创建虚拟骰子的类
class Die():
def __init__(self, die_sides=6):
self.die_sides = die_sides
def roll(self): #随机骰子点数
return randint(1, self.die_sides)
bb_award = [A, B, C, D, E, F, G, H, I, J, K, L, M]
bb_result = []
#检查每次摇骰子结果并对应规则进行判断
def check_result():
if bb().count(1) == 2 and bb().count(4) == 4:
bb_result.append(A)
elif bb().count(4) == 6:
bb_result.append(B)
elif bb().count(1) == 6:
bb_result.append(C)
elif bb().count(2) == 6 or bb().count(3) == 6 or bb().count(5) == 6 or bb().count(6) == 6:
bb_result.append(D)
elif bb().count(4) == 5:
bb_result.append(E)
elif bb().count(1) == 5 or bb().count(2) == 5 or bb().count(3) == 5 or bb().count(5) == 5 or bb().count(6) == 5:
bb_result.append(F)
elif bb().count(4) == 4:
bb_result.append(G)
elif bb().count(1) == 1 and bb().count(2) == 1 and bb().count(3) == 1 and bb().count(4) == 1 and bb().count(5) == 1 and bb().count(6) == 1:
bb_result.append(H)
elif bb().count(4) == 3:
bb_result.append(I)
elif bb().count(1) == 4 or bb().count(2) == 4 or bb().count(3) == 4 or bb().count(5) == 4 or bb().count(6) == 4:
bb_result.append(J)
elif bb().count(4) == 2:
bb_result.append(K)
elif bb().count(4) == 1:
bb_result.append(L)
else:
bb_result.append(M)
return bb_result
代码模块的安排与整体框架:
一开始茫然,只能先确定必须完成的功能:核心的摇骰子功能以及页面的图片与按钮的实现。然后再结合原型模型开始入手设想,而后结合 pygame 的学习,再参考一些其他游戏的框架逻辑,再随着编码的开始,对整体做出以下安排:
第N周 | 新增代码(行) | 累计代码(行) | 本周学习耗时(小时) | 累计学习耗时(小时) | 重要成长 |
---|---|---|---|---|---|
1 | 300 | 300 | 10 | 10 | 简单地恶补了下Pygame的使用 |
··· |
这次结对编程增加了 Git 的使用,使得对于如何使用 Git 协作有了更深的了解,确实也方便了在编写代码过程之中的两人不同的各种修改。而至于此次沟通环节上,相较于上一次有了更默契顺畅的交流,能够平和且清晰地进行不同问题探讨,个人主观上就觉得作业进行地更加顺畅且愉快了。在此真诚地感谢结对伙伴了。可能结对编程最大的快乐就是拉着一个人共沉沦吧