鱼C论坛

 找回密码
 立即注册
查看: 2916|回复: 4

[技术交流] 为一个游戏添加边框

[复制链接]
发表于 2017-11-19 20:41:34 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<windows.h>
  4. int main()
  5. {
  6.         int i,j;
  7.         int x=0;
  8.         int y=5;
  9.         int velocity_y=1;
  10.         int velocity_x=1;         
  11.         int left=0;
  12.         int right =20;
  13.         int top=0;
  14.         int bottom=10;

  15.         while(1)
  16.         {
  17.                 x=x+velocity_x;
  18.                 y=y+velocity_y;
  19.                 system("cls");     //清屏函数

  20.                 for(i=0;i<x;i++)   //输出小球上面的空行
  21.                 {
  22.                         printf("\n");
  23.                 }

  24.                 for(j=0;j<y;j++)      //输出小球左边的空格
  25.                 {
  26.                         printf(" ");
  27.                 }

  28.                 printf("o");           //输出小球o
  29.                 printf("\n");
  30.                 Sleep(50);               //在输出小球后等待50毫秒
  31.                                    
  32.                 if((x==top)||(x==bottom))        //碰到上下边界要变化速度
  33.                 {
  34.                         velocity_x = -velocity_x;
  35.                         printf("\a");
  36.                 }
  37.                 if((y==left)||(y==right))
  38.                 {
  39.                         velocity_y = -velocity_y;
  40.                         printf("\a");
  41.                 }

  42.         }
  43.         return 0;
  44. }
复制代码



代码如上,大家可在自己的编译器上跑一下,我的目的的为这个小球弹跳的边界加一个眼睛可以看到的边框,就打印*以表示边框吧。我自己写的边框就出现看一瞬间就消失了,不知道怎么搞,求助大家
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2017-11-19 21:01:29 From FishC Mobile | 显示全部楼层
在return前加一句
system("pause");
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-11-22 00:14:58 | 显示全部楼层
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<windows.h>
  4. int main()
  5. {
  6.         int i, j;
  7.         int x = 0;
  8.         int y = 5;
  9.         int velocity_y = 1;
  10.         int velocity_x = 1;
  11.         int left = 0;
  12.         int right = 20;
  13.         int top = 0;
  14.         int bottom = 10;

  15.         while (1)
  16.         {
  17.                 x = x + velocity_x;
  18.                 y = y + velocity_y;
  19.                 system("cls");//清屏函数
  20.                 printf("***********************\n");//输出顶端边框
  21.                 for (i = 0; i < x; i++)//输出小球上面的空行
  22.                 {
  23.                         printf("*                     *\n");//输出小球出现前的左右边框
  24.                 }
  25.                 printf("*");//输出小球出现行左边边框
  26.                 for (j = 0; j < y; j++)//输出小球左边的空格
  27.                 {
  28.                         printf(" ");
  29.                 }
  30.                 printf("o");//输出小球o
  31.                 for (j = y + 1; j <= 20; j++)//输出小球右边空格
  32.                 {
  33.                         printf(" ");
  34.                 }
  35.                 printf("*\n");//输出小球右边边框
  36.                 for (i = x + 1; i <=10; i++)
  37.                 {
  38.                         printf("*                     *\n");//输出小球出现后的左右边框
  39.                 }
  40.                 printf("***********************\n");//输出底边框
  41.                 Sleep(50);//在输出小球后等待50毫秒

  42.                 if ((x == top) || (x == bottom))  //碰到上下边界要变化速度
  43.                 {
  44.                         velocity_x = -velocity_x;
  45.                         printf("\a");
  46.                 }
  47.                 if ((y == left) || (y == right))
  48.                 {
  49.                         velocity_y = -velocity_y;
  50.                         printf("\a");
  51.                 }

  52.         }
  53.         return 0;
  54. }
复制代码

随便试了下,大概这个样子,没有仔细考虑位置关系   重新捡c过程中,忘的差不多了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2018-3-10 20:15:05 | 显示全部楼层
BngThea 发表于 2017-11-19 21:01
在return前加一句
system("pause");

你好!你的方法我试了,不行耶。您可以参考您楼下那位的解答。很抱歉,鱼C论坛我以前不够重视,来的比较少
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-3-10 20:16:18 | 显示全部楼层
freefox213 发表于 2017-11-22 00:14
随便试了下,大概这个样子,没有仔细考虑位置关系   重新捡c过程中,忘的差不多了

首先抱歉额,以前鱼C论坛我不够重视,来的比较少。刚刚试了下您的改进,确实如我想要,谢谢!好人一声平安哈哈哈
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-9 04:20

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表