| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1980 人关注过本帖, 2 人收藏
标题:开心小程序,重在参与
只看楼主 加入收藏
chenwei435
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:2
帖 子:322
专家分:1611
注 册:2010-11-28
收藏
得分:8 
路过看看 。。。。
2013-12-09 07:08
赵疯子
Rank: 8Rank: 8
来 自:dream
等 级:蝙蝠侠
威 望:2
帖 子:365
专家分:737
注 册:2013-5-5
收藏
得分:8 
挺不错的,比蓝桥赛有意思
2013-12-09 09:07
chenwei435
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:2
帖 子:322
专家分:1611
注 册:2010-11-28
收藏
得分:0 
接分钟。。。
2013-12-09 11:23
liu229118351
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:83
专家分:101
注 册:2013-10-23
收藏
得分:8 
回复 5楼 韶志
你的第三题为啥我编译运行之后按wasd四个都显示输入错误了呢?
图片附件: 游客没有浏览图片的权限,请 登录注册

单曲循环,需要信心+耐心+恒心
2013-12-09 11:23
韶志
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:斗气大陆
等 级:贵宾
威 望:44
帖 子:2223
专家分:13592
注 册:2013-3-22
收藏
得分:0 
回复 14楼 liu229118351
你刚开始输入了什么?
你截的图清屏清掉了  看不见

三十年河东,三十年河西,莫欺少年穷!
2013-12-09 11:47
azzbcc
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:江西财经大学
等 级:贵宾
威 望:81
帖 子:3293
专家分:12919
注 册:2012-11-4
收藏
得分:0 
第一题:
程序代码:
#include <stdio.h>
#include <conio.h>
#include <windows.h>

#define GRAPH_SIZE   30
#define POINT_SIZE   27

void Init();
void print();
void gotoXY(int, int);

POINT point[POINT_SIZE];

int main()
{
    Init();

    point[0].x = point[0].y = 1;
    while (1)
    {
        print();
        
        //游戏结束
        if (point[0].y - point[0].x == GRAPH_SIZE % 2 &&
            point[0].y + point[0].x == GRAPH_SIZE)
        {
            break;
        }

        for (int i = POINT_SIZE - 1; i > 0; i--)
        {
            point[i] = point[i - 1];
        }
        
        //下一步
        if (point[0].x - point[0].y >= -1 &&
            point[0].x + point[0].y <= GRAPH_SIZE - 1)
        {
            point[0].x++;
        }
        else if (point[0].x - point[0].y >= 1 &&
                 point[0].x + point[0].y >= GRAPH_SIZE)
        {
            point[0].y++;
        }
        else if (point[0].x - point[0].y <= 0 &&
                 point[0].x + point[0].y >= GRAPH_SIZE + 1)
        {
            point[0].x--;
        }
        else if (point[0].x - point[0].y <= -2 &&
                 point[0].x + point[0].y <= GRAPH_SIZE)
        {
            point[0].y--;
        }
        Sleep(100);
    }
    _getch();
    return 0;
}

void Init()
{
    CONSOLE_CURSOR_INFO cursor_info;

    //光标不显示
    cursor_info.bVisible = FALSE;
    cursor_info.dwSize   = 20;
    SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);

    //画界面
    for (int i = 0; i <= GRAPH_SIZE; i++)
    {
        printf("%s", "");
    }
    for (int i = 1; i < GRAPH_SIZE; i++)
    {
        gotoXY(0,          i), puts("");
        gotoXY(GRAPH_SIZE, i), puts("");
    }
    for (int i = 0; i <= GRAPH_SIZE; i++)
    {
        printf("%s", "");
    }
}

void gotoXY(int x, int y)
{
    COORD coord = {2 * x, y};
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}

void print()
{
    for (int i = 0; i < POINT_SIZE - 1; i++)
    {
        if (!point[i].x || !point[i].y)
        {
            continue;
        }
        gotoXY(point[i].x, point[i].y);
        putchar(0xa3), putchar(i + 'A' + 0x80);
    }

    //打印空格覆盖多出的字符 Z
    if (!point[POINT_SIZE - 1].x || !point[POINT_SIZE - 1].y)
    {
        return;
    }
    gotoXY(point[POINT_SIZE - 1].x, point[POINT_SIZE - 1].y);
//    putchar(0xa3), putchar(' ' + 0x80);
    putchar(' '), putchar(' ');
}


[ 本帖最后由 azzbcc 于 2013-12-9 14:01 编辑 ]


[fly]存在即是合理[/fly]
2013-12-09 13:50
azzbcc
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:江西财经大学
等 级:贵宾
威 望:81
帖 子:3293
专家分:12919
注 册:2012-11-4
收藏
得分:0 
第二题:
程序代码:
#include <time.h>
#include <stdio.h>
#include <conio.h>
#include <windows.h>

#define GRAPH_SIZE   30
#define POINT_SIZE (GRAPH_SIZE * GRAPH_SIZE)

void Init();
void gotoXY(int, int);

POINT point[POINT_SIZE];

int main()
{
    Init();
    for (int i = 0; i < POINT_SIZE; i++)
    {
        gotoXY(point[i].x, point[i].y);
        putchar(0xa3), putchar('*' + 0x80);
        Sleep(100);
    }
    _getch();
    return 0;
}

void Init()
{
    CONSOLE_CURSOR_INFO cursor_info;

    //光标不显示
    cursor_info.bVisible = FALSE;
    cursor_info.dwSize   = 20;
    SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);

    //画界面
    for (int i = 0; i <= GRAPH_SIZE+1; i++)
    {
        printf("%s", "");
    }
    for (int i = 1; i <= GRAPH_SIZE; i++)
    {
        gotoXY(0,            i), puts("");
        gotoXY(GRAPH_SIZE+1, i), puts("");
    }
    for (int i = 0; i <= GRAPH_SIZE+1; i++)
    {
        printf("%s", "");
    }

    //900个点初始化
    for (int i = 0; i < GRAPH_SIZE; i++)
    for (int j = 0; j < GRAPH_SIZE; j++)
    {
        point[i*GRAPH_SIZE+j].x = i + 1;
        point[i*GRAPH_SIZE+j].y = j + 1;
    }

    //使随机
    srand(time(NULL));
    for (int i = 0; i < POINT_SIZE; i++)
    {
        int tmp = rand() % POINT_SIZE;

        POINT swap;
        swap = point[i], point[i] = point[tmp], point[tmp] = swap;
    }
}

void gotoXY(int x, int y)
{
    COORD coord = {2 * x, y};
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}


[ 本帖最后由 azzbcc 于 2013-12-9 14:20 编辑 ]


[fly]存在即是合理[/fly]
2013-12-09 14:18
azzbcc
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:江西财经大学
等 级:贵宾
威 望:81
帖 子:3293
专家分:12919
注 册:2012-11-4
收藏
得分:0 
第三题:
程序代码:
#include <time.h>
#include <stdio.h>
#include <conio.h>
#include <windows.h>

#define GRAPH_SIZE   30

void Init();
void gotoXY(int, int);

int  X, Y;

int main()
{
    Init();
    while (1)
    {
        gotoXY(X, Y);
        putchar(0xa3), putchar('*' + 0x80);

        while (!_kbhit());

        gotoXY(X, Y);
        putchar(' '), putchar(' ');

        char ch = _getch();        
        if ('q' == ch)
        {
            break;
        }
        switch (ch)
        {
        case 'a':
            X = (X + GRAPH_SIZE - 2) % GRAPH_SIZE + 1;
            break;
        case 's':
            Y = Y % GRAPH_SIZE + 1;
            break;
        case 'd':
            X = X % GRAPH_SIZE + 1;
            break;
        case 'w':
            Y = (Y + GRAPH_SIZE - 2) % GRAPH_SIZE + 1;
            break;
        default:    break;
        }
    }
    
    return 0;
}

void Init()
{
    CONSOLE_CURSOR_INFO cursor_info;

    //光标不显示
    cursor_info.bVisible = FALSE;
    cursor_info.dwSize   = 20;
    SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);

    //画界面
    for (int i = 0; i <= GRAPH_SIZE+1; i++)
    {
        printf("%s", "");
    }
    for (int i = 1; i <= GRAPH_SIZE; i++)
    {
        gotoXY(0,            i), puts("");
        gotoXY(GRAPH_SIZE+1, i), puts("");
    }
    for (int i = 0; i <= GRAPH_SIZE+1; i++)
    {
        printf("%s", "");
    }

    //小孩位置初始化
    srand(time(NULL));
    X = rand() % GRAPH_SIZE;
    Y = rand() % GRAPH_SIZE;    
}

void gotoXY(int x, int y)
{
    COORD coord = {2 * x, y};
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}


[ 本帖最后由 azzbcc 于 2013-12-9 14:41 编辑 ]


[fly]存在即是合理[/fly]
2013-12-09 14:34
azzbcc
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:江西财经大学
等 级:贵宾
威 望:81
帖 子:3293
专家分:12919
注 册:2012-11-4
收藏
得分:8 
第四题:
程序代码:
#include <time.h>
#include <stdio.h>
#include <conio.h>
#include <windows.h>

#define GRAPH_SIZE   29
#define COUNT_MAX    (GRAPH_SIZE / 2)
#define MIDDLE      (GRAPH_SIZE - COUNT_MAX)

void Init();
void gotoXY(int, int);

int main()
{
    Init();
    for (int i = 1; i < MIDDLE; i++)
    {
        gotoXY(i + MIDDLE, MIDDLE);
        putchar(0xa3), putchar('*' + 0x80);

        gotoXY(-i + MIDDLE, MIDDLE);
        putchar(0xa3), putchar('*' + 0x80);

        Sleep(100);
    }
    for (int i = 1; i < MIDDLE; i++)
    {
        gotoXY(MIDDLE, i + MIDDLE);
        putchar(0xa3), putchar('*' + 0x80);
        gotoXY(MIDDLE, -i + MIDDLE);
        putchar(0xa3), putchar('*' + 0x80);
        Sleep(100);
    }

    for (int i = 1; i < MIDDLE; i++)
    {
        for (int j = i; j < MIDDLE; j++)
        {
            gotoXY(j + MIDDLE, -i + MIDDLE);
            putchar(0xa3), putchar('*' + 0x80);

            gotoXY(-j + MIDDLE, -i + MIDDLE);
            putchar(0xa3), putchar('*' + 0x80);
            
            gotoXY(j + MIDDLE, i + MIDDLE);
            putchar(0xa3), putchar('*' + 0x80);

            gotoXY(-j + MIDDLE, i + MIDDLE);
            putchar(0xa3), putchar('*' + 0x80);
            Sleep(100);
        }
        for (int j = i + 1; j < MIDDLE; j++)
        {
            gotoXY(i + MIDDLE, j + MIDDLE);
            putchar(0xa3), putchar('*' + 0x80);

            gotoXY(i + MIDDLE, -j + MIDDLE);
            putchar(0xa3), putchar('*' + 0x80);

            gotoXY(-i + MIDDLE, j + MIDDLE);
            putchar(0xa3), putchar('*' + 0x80);

            gotoXY(-i + MIDDLE, -j + MIDDLE);
            putchar(0xa3), putchar('*' + 0x80);

            Sleep(100);
        }
    }
    _getch();
    return 0;
}

void Init()
{
    CONSOLE_CURSOR_INFO cursor_info;

    //光标不显示
    cursor_info.bVisible = FALSE;
    cursor_info.dwSize   = 20;
    SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);

    //画界面
    for (int i = 0; i <= GRAPH_SIZE+1; i++)
    {
        printf("%s", "");
    }
    for (int i = 1; i <= GRAPH_SIZE; i++)
    {
        gotoXY(0,            i), puts("");
        gotoXY(GRAPH_SIZE+1, i), puts("");
    }
    for (int i = 0; i <= GRAPH_SIZE+1; i++)
    {
        printf("%s", "");
    }    
}

void gotoXY(int x, int y)
{
    COORD coord = {2 * x, y};
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}


[fly]存在即是合理[/fly]
2013-12-09 15:13
azzbcc
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:江西财经大学
等 级:贵宾
威 望:81
帖 子:3293
专家分:12919
注 册:2012-11-4
收藏
得分:0 
第五题:
程序代码:
#include <time.h>
#include <stdio.h>
#include <conio.h>
#include <windows.h>

#define GRAPH_HEIGHT   20
#define GRAPH_WEIGH    60

void Init();
void gotoXY(int, int);

char s[][GRAPH_WEIGH + 1] = {
"                                                            ",
"   *     *        ** *******   *     *         *            ",
"  **     **      **  *     *   **    *         *            ",
" **             **   *     *         *         *    *****   ",
"**    ******** ***   *     *  ****  ****       *            ",
"*     *      * * *   *     *     *  *  *       *            ",
"****  *      *   *   *     *     *  *  *       *            ",
"   *  ******** ***** *******     * **  **      *  ********* ",
"  **  *          *             *** *    *    *****   *      ",
" **   *          *             *   *    **     *     *      ",
"**   **        ***** *******   *  ***    *     *     *      ",
"*    * ******* * * *    *      *  * *    **    *     *      ",
"**** * * * * * * * *    *     **  * *  *  *    *     *      ",
"     * * * * * * * *    *     *  ** *  *  **   * *  **      ",
"   * * ******* * * *  *****   *     *  *       *** **       ",
"  ** * * * * * * * *    *     *  *  ****       ** **    **  ",
" **  * * * * * * * *    *     * **  *      *  **  *      ** ",
"**  ** * * * * * * *    *     ***   *      * **  ***********",
"*  **  * * * * * * ********** **    ******** *  **         *"};

int main()
{
    CHAR_INFO    fill;
    HANDLE hOut       = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD c1          = {GRAPH_WEIGH * 2 + 4, 1};
    COORD c2          = {2, 1};
    COORD c3          = {GRAPH_WEIGH * 2, 1};
    SMALL_RECT block1 = {2, 1, 3, GRAPH_HEIGHT};
    SMALL_RECT block2 = {4, 1, GRAPH_WEIGH * 2 + 1, GRAPH_HEIGHT};
    SMALL_RECT tmp    = {GRAPH_WEIGH * 2 + 4, 1, GRAPH_WEIGH * 2 + 5, GRAPH_HEIGHT};
    CONSOLE_SCREEN_BUFFER_INFO binfo;
    GetConsoleScreenBufferInfo(hOut, &binfo);

    fill.Attributes     = binfo.wAttributes;
    fill.Char.AsciiChar = ' ';
    
    Init();
    while (!_kbhit())
    {
        ScrollConsoleScreenBuffer(hOut, &block1, NULL, c1, &fill);
        ScrollConsoleScreenBuffer(hOut, &block2, NULL, c2, &fill);
        ScrollConsoleScreenBuffer(hOut, &tmp,    NULL, c3, &fill);
        Sleep(100);
    }
    return 0;
}

void Init()
{
    //光标不显示
    CONSOLE_CURSOR_INFO cursor_info;
    cursor_info.bVisible = FALSE;
    cursor_info.dwSize   = 20;
    SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);

    //改变控制台缓冲区大小
    COORD coord = {128, 32};
    SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coord);

    //画界面
    for (int i = 0; i <= GRAPH_WEIGH+1; i++)
    {
        printf("%s", "");
    }
    puts("");
    for (int i = 0; i < GRAPH_HEIGHT; i++)
    {
        printf("%s", "");
        for (int j = 0; j < GRAPH_WEIGH; j++)
        {
            putchar(0xa3), putchar(s[i][j] + 0x80);
        }
        printf("%s\n", "");
    }
    for (int i = 0; i <= GRAPH_WEIGH+1; i++)
    {
        printf("%s", "");
    }
}


[fly]存在即是合理[/fly]
2013-12-09 16:24
快速回复:开心小程序,重在参与
数据加载中...
 
   



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

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