| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 515 人关注过本帖
标题:求助:帮忙把C++改成c语言,谢谢
只看楼主 加入收藏
Nostradamas
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2011-6-20
结帖率:50%
收藏
已结贴  问题点数:16 回复次数:4 
求助:帮忙把C++改成c语言,谢谢
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
#include <conio.h>
#include <winnt.h>
 

#define ROW        24    //屏幕的行数
#define COL        81    //屏幕的列数
#define REAL    100

#define NUM        10  //每次下落的流星颗数
#define SPEED    4    //流星下落的最大速度
/*
*******************************************************************************************
*                                FUNCTION PROTOTYPES
*******************************************************************************************
*/
int random(int num);    //返回0--num之间的随机数
static void setSky();    //描绘天空、地面
static void display();    //刷屏
int check_last_row();    //判断是否到底最后一层#号处
void word_n_down();        //n颗流星下落控制
int word_one_down(int begin,int position,int speed,int word,int *word_end);    //1颗流星下落控制
void gotoxy(int x,int y);


/*
*******************************************************************************************
*                                   VARIABLES
*******************************************************************************************
*/
char sky_ground[REAL][COL];
int test = 0;
//int word1_end = 0;
//int word2_end = 0;
int cycle_end = 0;

int word_end[NUM];
int list = 0;
int begin[NUM];
int position[NUM];
int word[NUM];
int speed[NUM];
/*
*******************************************************************************************
*                                        main
*******************************************************************************************
*/
int main()
{
    int end_flag = 0;
    time_t t;
    srand((unsigned) time(&t));        //使得每次运行产生的随机数起始点都不相同
    setSky();
//    display();

    while(!(end_flag = check_last_row()))//判断程序是否结束
    {
        for(int a=0;a<NUM;a++)
            word_end[a] = 0;
        list = 0;
        cycle_end = 0;
        word_n_down();
    }

    system("pause");
    return 0;
}

/*
*******************************************************************************************
*                                        setSky
*******************************************************************************************
*/
static void setSky()
{
    for(int b=0;b<REAL;b++)
    {
        for(int c=0;c<COL-1;c++)
        {
            sky_ground[b][c] = ' ';
        }
        sky_ground[b][COL-1] = '\0';
    }
    for(int d=ROW-5;d<ROW;d++)
    {
        for(int e=0;e<COL-1;e++)
        {
            sky_ground[d][e] = '#';
        }
        sky_ground[d][COL-1] = '\0';
    }   
}

/*
*******************************************************************************************
*                                        display
*******************************************************************************************
*/
static void display()
{
    gotoxy(0,0);
    HANDLE consolehwnd;
    consolehwnd = GetStdHandle(STD_OUTPUT_HANDLE);
    for(int f=0;f<ROW-5;f++)
    {
        
         //设置文字颜色为绿色
        for(int j=0; j<COL-1; j++)
        {
            if(sky_ground[f][j] != ' ')
            {
                SetConsoleTextAttribute(consolehwnd,random(16)+1);
            }
            else SetConsoleTextAttribute(consolehwnd,0);
            printf("%c",sky_ground[f][j]);
         }
    }
     
        for(f=ROW-5; f<ROW; f++)
        {
            for(int j=0; j<COL-1; j++)
            {
                if(sky_ground[f][j]=='#')
                    SetConsoleTextAttribute(consolehwnd,11);
                else SetConsoleTextAttribute(consolehwnd,7);
                    printf("%c",sky_ground[f][j]);
            }
            
        }
    //Sleep(150);            //差不多以ms为单位,刷新频率
}

/*
*******************************************************************************************
*                                        random
*******************************************************************************************
*/
int random(int num)
{
    return(rand() % num);
}

/*
*******************************************************************************************
*                                    check_last_row
*******************************************************************************************
*/
int check_last_row()
{
    for(int g=0;g<COL;g++)
    {
        if(sky_ground[23][g] == ' ')
            return 1;
    }
    return 0;
}

/*
*******************************************************************************************
*                                    word_n_down
*******************************************************************************************
*/
void word_n_down()
{
    for(int h=0;h<NUM;h++)
    {
        begin[h] = random(ROW-5);
        position[h] = random(COL-2);
        word[h] = random(26) + 'A';
        speed[h] = random(SPEED)+1;
    }
    while(1)
    {
        if(cycle_end >= NUM)    //等n颗流星都落地了之后再返回(cycle_end >= n)
            break;
        test = list-1;
        if(test < 0)
            test = 0;
        if(check_last_row())    //判断是否到最后一行#了,若是则退出
        {
            system("pause");
            exit(0);
        }
        for(int i=0;i<NUM;i++)
            word_one_down(begin[i],position[i],speed[i],word[i],&word_end[i]);
        list ++;
        display();
        
        Sleep(200);            //差不多以ms为单位
    }        
   
}

/*
*******************************************************************************************
*                                    word_one_down
*******************************************************************************************
*/
int word_one_down(int begin,int position,int speed,int word,int *word_end)
{
    if((*word_end) == 0)    //判断是否撞上地面,0表示未撞上
    {
        if(begin+list*speed >= ROW)            //保护防止溢出
            return 0;
        sky_ground[begin+test*speed][position] = ' ';    //A表示从第几行开始下落
        if(begin+list*speed >= 19)
        {
            for(int z=19;z<ROW;z++)
            {
                if(sky_ground[z][position] == '#')
                {
                    sky_ground[z][position] = ' ';
                    *word_end = 1;
                    cycle_end ++;
                    break;
                }
            }
        }
        else
        {
            sky_ground[begin+list*speed][position] = word;
        }
    }
    return 0;
}

void gotoxy(int x,int y)
{
     COORD coord;
     coord.X=x;
     coord.Y=y;
     SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), coord );
}


[ 本帖最后由 Nostradamas 于 2011-6-23 09:09 编辑 ]
搜索更多相关主题的帖子: c语言 include 
2011-06-23 09:08
vandychan
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
等 级:贵宾
威 望:18
帖 子:2296
专家分:6418
注 册:2010-8-20
收藏
得分:8 
给钱办事 谢谢

到底是“出来混迟早要还”还是“杀人放火金腰带”?
2011-06-23 10:52
Nostradamas
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2011-6-20
收藏
得分:0 
回复 2楼 vandychan
什么钱啊?怎么付?
2011-06-23 11:00
vandychan
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
等 级:贵宾
威 望:18
帖 子:2296
专家分:6418
注 册:2010-8-20
收藏
得分:0 
转账了 这么简单 重新帮你做一个

到底是“出来混迟早要还”还是“杀人放火金腰带”?
2011-06-23 11:48
smallmoon521
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:4
帖 子:517
专家分:1373
注 册:2008-4-21
收藏
得分:8 
这哪是C++啊,这不就是C语言吗?

为游戏狂~~!!    大家努力编哈!
2011-06-23 12:11
快速回复:求助:帮忙把C++改成c语言,谢谢
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022475 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved