龟兔赛跑游戏程序模块分析.docVIP

  • 5
  • 0
  • 约2.66千字
  • 约 3页
  • 2018-05-08 发布于河南
  • 举报
龟兔赛跑游戏程序模块分析

龟兔赛跑游戏程序模块分析: 游戏程序第一层主函数模块样式: main() { int hare = 0, tortoise = 0, timer = 0; //timer是计时器,从0开始计时 while (hare RACE_END tortoise RACE_END) { tortoise += 乌龟根据他这一时刻的行为移动的距离; hare += 兔子根据他这一时刻的行为移动的距离; 输出当前计时和兔子乌龟的位置; ++timer; } if (hare tortoise) cout \n hare wins!; else cout \n tortoise wins!; } 抽取函数模块: 乌龟在这一秒的移动距离: int move_tortoise(); 兔子在这一秒的移动距离: int move_hare(); 输出当前计时和兔子与乌龟的位置 void print_position(int timer, int tortoise, int hare); 由功能分成三个模块(分类模块): 主模块 移动模块 move_tortoise move_hare() 输出模块 print_position 程序代码: //文件:Random.h

文档评论(0)

1亿VIP精品文档

相关文档