z13705245001 z13705245001
关注数: 5 粉丝数: 64 发帖数: 998 关注贴吧数: 13
c++贪吃蛇游戏代码,还有谁! #include<iostream> #include<windows.h> #include<time.h> #include<conio.h> using namespace std; // 刷新当前屏幕 inline void Refresh(char q[][22], int grade, int gamespeed){ system("cls"); // 清屏 int i, j; cout << endl; for (i = 0; i<22; i++){ cout << "\t"; for (j = 0; j<22; j++) cout << q[i][j] << ' '; // 输出贪吃蛇棋盘 if (i == 0) cout << "\t等级为:" << grade; if (i == 4) cout << "\t自动前进时间"; if (i == 6) cout << "\t间隔为:" << gamespeed << "ms"; cout << endl; } } int main(){ char tcsQipan[22][22]; // 贪吃蛇棋盘是一个二维数组(如22*22,包括墙壁) int i, j; for (i = 1; i <= 20; i++) for (j = 1; j <= 20; j++) tcsQipan[i][j] = ' '; // 初始化贪吃蛇棋盘中间空白部分 for (i = 0; i <= 21; i++) tcsQipan[0][i] = tcsQipan[21][i] = '-'; //初始化贪吃蛇棋盘上下墙壁 for (i = 1; i <= 20; i++) tcsQipan[i][0] = tcsQipan[i][21] = '|'; //初始化贪吃蛇棋盘左右墙壁 int tcsZuobiao[2][100]; //蛇的坐标数组 for (i = 0; i<4; i++){ tcsZuobiao[0][i] = 1; tcsZuobiao[1][i] = i + 1; } int head = 3, tail = 0; for (i = 1; i <= 3; i++) tcsQipan[1][i] = '*'; //蛇身 tcsQipan[1][4] = '#'; //蛇头 int x1, y1; // 随机出米 srand((unsigned)time(NULL)); do{ x1 = rand() % 20 + 1; y1 = rand() % 20 + 1; } while (tcsQipan[x1][y1] != ' '); tcsQipan[x1][y1] = '*'; cout << "\n\n\t\t贪吃蛇游戏即将开始 !" << endl;//准备开始;; long start; int grade = 1, length = 4; int gamespeed = 500; //前进时间间隔 for (i = 3; i >= 0; i--){ start = clock(); while (clock() - start <= 1000); system("cls"); if (i>0) cout << "\n\n\t\t进入倒计时:" << i << endl; else Refresh(tcsQipan, grade, gamespeed); } int timeover; char direction = 77; // 初始情况下,向右运动 int x, y; while (1){ timeover = 1; start = clock(); while ((timeover = (clock() - start <= gamespeed)) && !_kbhit()); //如果有键按下或时间超过自动前进时间间隔则终止循环 if (timeover){ _getch(); direction = _getch(); } switch (direction){ case 72: x = tcsZuobiao[0][head] - 1; y = tcsZuobiao[1][head]; break; // 向上 case 80: x = tcsZuobiao[0][head] + 1; y = tcsZuobiao[1][head]; break; // 向下 case 75: x = tcsZuobiao[0][head]; y = tcsZuobiao[1][head] - 1; break; // 向左 case 77: x = tcsZuobiao[0][head]; y = tcsZuobiao[1][head] + 1; // 向右 } if (!(direction == 72 || direction == 80 || direction == 75 || direction == 77)){ // 按键非方向键 cout << "\tGame over!" << endl; return 0; } if (x == 0 || x == 21 || y == 0 || y == 21){ // 碰到墙壁 cout << "\tGame over!" << endl; return 0; } if (tcsQipan[x][y] != ' '&&!(x == x1&&y == y1)){ // 蛇头碰到蛇身 cout << "\tGame over!" << endl; return 0; } if (x == x1 && y == y1){ // 吃米,长度加1 length++; if (length >= 8){ length -= 8; grade++; if (gamespeed >= 200) gamespeed = 550 - grade * 50; // 改变自动前进时间间隔 } tcsQipan[x][y] = '#'; tcsQipan[tcsZuobiao[0][head]][tcsZuobiao[1][head]] = '*'; head = (head + 1) % 100; tcsZuobiao[0][head] = x; tcsZuobiao[1][head] = y; do { x1 = rand() % 20 + 1; y1 = rand() % 20 + 1; } while (tcsQipan[x1][y1] != ' '); tcsQipan[x1][y1] = '*'; Refresh(tcsQipan, grade, gamespeed); } else{ // 不吃米 tcsQipan[tcsZuobiao[0][tail]][tcsZuobiao[1][tail]] = ' '; tail = (tail + 1) % 100; tcsQipan[tcsZuobiao[0][head]][tcsZuobiao[1][head]] = '*'; head = (head + 1) % 100; tcsZuobiao[0][head] = x; tcsZuobiao[1][head] = y; tcsQipan[tcsZuobiao[0][head]][tcsZuobiao[1][head]] = '#'; Refresh(tcsQipan, grade, gamespeed); } } return 0; }
转 【维护】迷你西游2014年5月6日(周二)维护内容 【维护】迷你西游2014年5月6日(周二)维护内容 版本号:1.5.44本周有397K大小的补丁,请注意在合适的网络环境下进行更新,主要针对新手流程及好友绑定进行调整。 新增体验内容: ·公测豪礼天天拿(5.6日维护后~5.12日晚24点) 1.为庆祝《迷你西游》持续位列APP畅销榜前十位,感谢广大玩家的热烈支持和积极参与,5.6日维护后到5.12日晚24点,登录玩家每日将获得218元宝。 2.活动期间,每日首次“登峰造极”招募返还100元宝(免费招募除外)。 ·母亲节活动 5.11日母亲节当天,所有道行等级达到20级以上的玩家首次“登峰造极”招募十连抽返还1500元宝。 战斗平衡调整: ·修正了[如来佛祖]神通[五指山]产生的[早夭10]持续到战斗结束的bug; ·修正了[会猎]状态添加在[元形]单位上失效的bug。 其他体验调整: ·默认显示本vip等级的[VIP周礼包],点击“显示全部”才会列出其他等级礼包进行购买; ·调整了[新手]1-5级的体验流程,现在5级将赠送300元宝。超过5级的玩家将获得补偿; ·[好友绑定]改至人物创建界面,且生效等级由10调整为15级。每天绑定数量最高为10个,总量达50后不再获得奖励; ·[聊天频道]优化,玩家交互增加“屏蔽”选项(加为好友将自动取消屏蔽); ·[挑战星级]中增加了种族标识; ·[排行榜](关卡榜、论道榜)增加了每周奖励结算时间提醒; ·[好友]送礼/收礼优化,增加了收礼的上限数量; ·现在29级以前不会显示[援护](未上阵的缘技能)了; ·调整[战力丹]、[气血丹]的描述,指引玩家如何使用,且在论道中的兑换等级要求调整为25级; ·调整[缘魂]界面魂值的图标,避免误解; ·体力/活力不足时,优先提示使用道具,然后才提示充值; ·现在[更换装备]时装备列表中点击装备图标将可以查看装备信息; ·宝箱等[购买界面]增加“长按”提示。
1 下一页