C++中华铁路从新手到大神 求大神解答

16:11 提问
菜鸟求大神帮忙解答贪食蛇问题
以下的这段贪食蛇代码是我在百度上看到的,我不理解int tcsZuobiao[2][100];
//蛇的坐标数组for (i = 0; i
tcsZuobiao[0][i] = 1;
tcsZuobiao[1][i] = i + 1;
}这里为什么蛇的坐标是[2][100]呢,还有循环里面的也不懂为什么要这样弄
// 刷新当前屏幕
inline void Refresh(char q[][22], int grade, int gamespeed){
system("cls");
for (i = 0; i
for (j = 0; j
if (i == 0) cout
if (i == 4) cout
if (i == 6) cout
int main(){
char tcsQipan[22][22];
贪吃蛇棋盘是一个二维数组(如22*22,包括墙壁)
for (i = 1; i
for (j = 1; j
tcsQipan[i][j] = ' ';
初始化贪吃蛇棋盘中间空白部分
for (i = 0; i
tcsQipan[0][i] = tcsQipan[21][i] = '-';
//初始化贪吃蛇棋盘上下墙壁
for (i = 1; i
tcsQipan[i][0] = tcsQipan[i][21] = '|';
//初始化贪吃蛇棋盘左右墙壁
int tcsZuobiao[2][100];
//蛇的坐标数组
for (i = 0; i
tcsZuobiao[0][i] = 1;
tcsZuobiao[1][i] = i + 1;
int head = 3, tail = 0;
for (i = 1; i
tcsQipan[1][i] = '*';
tcsQipan[1][4] = '#';
int x1, y1;
// 随机出米
srand(time(0));
x1 = rand() % 20 + 1;
y1 = rand() % 20 + 1;
} while (tcsQipan[x1][y1] != ' ');
tcsQipan[x1][y1] = '*';
int grade = 1, length = 4;
int gamespeed = 500;
//前进时间间隔
for (i = 3; i &= 0; i--){
start = clock();
while (clock() - start &= 1000);
system("cls");
cout && "\n\n\t\t进入倒计时:" && i &&
Refresh(tcsQipan, grade, gamespeed);
char direction = 77;
// 初始情况下,向右运动
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];
case 80: x = tcsZuobiao[0][head] + 1; y = tcsZuobiao[1][head];
case 75: x = tcsZuobiao[0][head]; y = tcsZuobiao[1][head] - 1;
case 77: x = tcsZuobiao[0][head]; y = tcsZuobiao[1][head] + 1;
if (!(direction == 72 || direction == 80 || direction == 75 || direction == 77)){
按键非方向键
cout && "\tGame over!" && return 0;
if (x == 0 || x == 21 || y == 0 || y == 21){
// 碰到墙壁
cout && "\tGame over!" && return 0;
if (tcsQipan[x][y] != ' '&&!(x == x1&&y == y1)){ //
蛇头碰到蛇身
cout && "\tGame over!" && return 0;
if (x == x1 && y == y1){
吃米,长度加1
if (length &= 8){
length -= 8;
if (gamespeed &= 200)
gamespeed = 550 - grade * 50; // 改变自动前进时间间隔
tcsQipan[x][y] = '#';
tcsQipan[tcsZuobiao[0][head]][tcsZuobiao[1][head]] = '*';
head = (head + 1) % 100;
tcsZuobiao[0][head] =
tcsZuobiao[1][head] =
x1 = rand() % 20 + 1;
y1 = rand() % 20 + 1;
} while (tcsQipan[x1][y1] != ' ');
tcsQipan[x1][y1] = '*';
Refresh(tcsQipan, grade, gamespeed);
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] =
tcsZuobiao[1][head] =
tcsQipan[tcsZuobiao[0][head]][tcsZuobiao[1][head]] = '#';
Refresh(tcsQipan, grade, gamespeed);
按赞数排序
其他相关推荐求推荐关于新手学习c++游戏开发的书,最好是实战系列的? - 知乎62被浏览5915分享邀请回答43 条评论分享收藏感谢收起219 条评论分享收藏感谢收起查看更多回答1 个回答被折叠()欢迎加入我们,一同切磋技术。 &
用户名: &&&
密 码: &
共有 16728 人关注过本帖
标题:请问各位大神!!C++中怎样开方!?
等 级:新手上路
&&已结贴√
&&问题点数:20&&回复次数:8&&&
请问各位大神!!C++中怎样开方!?
(b^2-4ac)这个怎么开方!!谢谢大神们!!我是初学者!!求高手解???
搜索更多相关主题的帖子:
来 自:神界
等 级:版主
威 望:360
帖 子:12294
专家分:48573
#include&stdio.h&
#include&math.h&
int main()
&&&&&&double i=36;
&&&&&printf( &36 sqrt=%10.4lf\n&, sqrt(i));
&&&&&return 0;
DO IT YOURSELF !
来 自:北京
等 级:贵宾
威 望:94
帖 子:6779
专家分:16751
用 sqrt() 这个函数,在 cmath 这个头文件里。
等 级:新手上路
采用sqrt()函数就可以了,sqrt(b^2-4ac)
等 级:城市猎人
帖 子:1726
专家分:5757
sqrt(b*b-4*a*c),不过要加头文件cmath
我现在所学的一切都是为了游戏!!!为了游戏,加油!加油!努力!
来 自:江西赣州
等 级:职业侠客
帖 子:141
专家分:337
&&&好好学习!
来 自:内蒙古
等 级:贵宾
威 望:17
帖 子:453
专家分:2351
&&sqrt() 百度百科好好看看这个函数的使用 参数和返回值类型等
马马虎虎 不吝赐教 我是路过蹭分滴
等 级:论坛游侠
帖 子:79
专家分:178
包含头文件#include&cmath&或#include&math.h&其中有一个sqrt()函数!专门干这事的。
等 级:业余侠客
帖 子:119
专家分:266
头文件 cmath
函数&&&sqrt()
其余自己上百度
版权所有,并保留所有权利。
Powered by , Processed in 0.057932 second(s), 7 queries.
Copyright&, BCCN.NET, All Rights Reserved

我要回帖

更多关于 绝地求生新手教学 的文章

 

随机推荐