| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1752 人关注过本帖
标题:时间显示。解决不了!求教!
只看楼主 加入收藏
yu965634383
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:119
专家分:195
注 册:2017-9-1
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:4 
时间显示。解决不了!求教!
有没有什么办法可以让时间的显示和图形移动两者之间互不干扰的?


////////////2017-10-31////////
# define _CRT_SECURE_NO_WARNINGS        // 忽略警告
# include <stdio.h>                        //输入输出
# include <conio.h>                        //输入输出 getch
# include <windows.h>                    //系统API函数
# include <stdlib.h>                    //动态空间分配
# include <string.h>                    //字符串操作
# include <io.h>                        //浏览文件夹
# include <time.h>                        //时间函数
# include <pthread.h>                    //多线程编程

typedef struct SNAKE
{
    COORD XY;
    SNAKE * next , *previous;
} snake;

void CreateCursorPosition (COORD xy)
{
    HANDLE hOut = GetStdHandle (STD_OUTPUT_HANDLE);
    SetConsoleCursorPosition (hOut , xy);
}

snake* Initsnake(COORD xy)//初始化蛇身
{
     snake *tail , *p , *head;
     int i;
     tail=(snake*)malloc(sizeof(snake));//从蛇尾开始,头插法,以x,y设定开始的位置//
     if (!tail)
         return 0;
//     tail->XY.X =xy.X;
//     tail->XY.Y =xy.Y;
     tail->XY = xy;
     tail->next= tail->previous =NULL;
     p = tail;
     for (i = 1;i <= 4; i++)
     {
         head=(snake*)malloc(sizeof(snake));
         if (!head)
             return 0;
         head->next=tail;
         tail->previous = head;
         head->previous = NULL;
         head->XY.X = xy.X + 2*i;
         head->XY.Y = xy.Y;
         tail=head;
     }
     head->previous = p;//指向尾节点
     while (p != head)
     {
         CreateCursorPosition (p->XY);
         printf ("◆");
         p = p->previous;
     }
     CreateCursorPosition (p->XY);
     printf ("◆");
     return head;
}
 

void SnakeMove (snake * head)
{
    snake * tail , *p , *t;
    tail = t = head->previous;
    while (true)
    {
        p = (snake *) malloc (sizeof (snake));
        if (!p)
            return ;
        p->next = head;
        head->previous = p;
        p->previous = NULL;
        p->XY.X = head->XY.X + 2;
        p->XY.Y = head->XY.Y;
        head = p;
        while (t)
        {
            CreateCursorPosition (t->XY);
            printf ("◆");
            t = t->previous;
        }
        CreateCursorPosition (tail->XY);
        printf (" ");
        t = tail->previous;
        free (tail);
        tail = t;
        if (GetAsyncKeyState (VK_ESCAPE))
            break;
        Sleep (300);
    }
}

void CleanConsole (COORD xy)
{
    HANDLE hOut = GetStdHandle (STD_OUTPUT_HANDLE);
    FillConsoleOutputCharacterA (hOut , ' ' , 80 , xy , NULL);
}

void * showtime (void *)
{
    struct tm * pt;
    time_t t;
    while (true)
    {   
        t = time (NULL);
        pt = localtime (&t);
        COORD xy = {0 , 0};
        CreateCursorPosition (xy);
        printf ("北京时间:%d:%d:%d" , pt->tm_hour , pt->tm_min , pt->tm_sec);
        Sleep (500);
        CleanConsole (xy);
    }
    return 0;
}



void CreateLine (void)
{
    pthread_t thid;
    pthread_attr_t attr;
    pthread_attr_init (&attr);
    pthread_attr_setscope (&attr , PTHREAD_SCOPE_PROCESS);
    pthread_attr_setdetachstate (&attr , PTHREAD_CREATE_JOINABLE);//PTHREAD_CREATE_DETACHDE
    pthread_create (&thid , &attr , showtime , (void*) 0);
//    pthread_join (thid , NULL);
    pthread_detach (thid);
}

int main (void)
{
    snake * head;
   
    COORD xy = {10 , 5};
    head = Initsnake(xy);
    CreateLine ();
    SnakeMove (head);
   
    getch ();
    return 0;
}



[此贴子已经被作者于2017-10-31 20:28编辑过]

搜索更多相关主题的帖子: include previous void head return 
2017-10-31 20:25
huafei666
Rank: 2
等 级:论坛游民
帖 子:8
专家分:14
注 册:2017-10-31
收藏
得分:14 
老哥帮我解决一题呗,出去就能看到我帖子了
2017-10-31 20:43
yu965634383
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:119
专家分:195
注 册:2017-9-1
收藏
得分:0 
递归不太懂啊

菜鸟一枚,求各位大神多多关照。
2017-10-31 20:45
huafei666
Rank: 2
等 级:论坛游民
帖 子:8
专家分:14
注 册:2017-10-31
收藏
得分:0 
回复 3楼 yu965634383
老哥你发的那串代码我都不懂,一看就知道你是大神了,教教我呗;;
2017-10-31 20:48
yu965634383
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:119
专家分:195
注 册:2017-9-1
收藏
得分:0 
回复 4楼 huafei666
这些代码花了2天才搞出来的,没人教,自己查资料,不懂也不知道问谁,只能自己测试,改里面的参数什么的,看有什么效果。其实有好些东西还不是很明白的。

菜鸟一枚,求各位大神多多关照。
2017-10-31 21:00
快速回复:时间显示。解决不了!求教!
数据加载中...
 
   



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

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