| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2854 人关注过本帖
标题:vs2012编译错误
取消只看楼主 加入收藏
醒山
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:9
帖 子:463
专家分:2071
注 册:2015-5-25
结帖率:88.89%
收藏
已结贴  问题点数:20 回复次数:3 
vs2012编译错误
错误显示为1>c:\users\think\documents\visual studio 2012\projects\win32project1\win32project1\win32project1.cpp(167): error C4996: 'kbhit': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _kbhit. See online help for details.
我在博客上找的c++俄罗斯方块的源代码,用vs2012出现上述问题,不知道怎么破,希望有人可以帮忙解答,谢谢了
源代码如下:
#include<stdio.h>  
#include<stdlib.h>  
#include<windows.h>  
#include<time.h>  
#include<conio.h>  
  
#define MOD 28  
#define SIZE_N 19  
#define SIZE_M 12  
  
int cur_x,cur_y;  
int score,mark,next,map[SIZE_N][SIZE_M],Gamespeed=300;  
  
int shape[28][6]={//这是个比较偷懒的方法,就是7种方块,加上旋转总共28种  
    {0,-1,0,-2,1,0}, {0,1,1,0,2,0}, {-1,0,0,1,0,2}, {0,-1,-1,0,-2,0},  
    {0,-1,0,1,-1,0}, {0,1,1,0,-1,0}, {1,0,0,-1,0,1}, {1,0,-1,0,0,-1},  
    {-1,1,0,1,1,0}, {0,-1,1,0,1,1}, {-1,0,0,-1,1,-1}, {-1,-1,-1,0,0,1},  
    {-1,0,0,1,1,1}, {0,1,1,-1,1,0}, {-1,0,0,1,1,1}, {0,1,1,-1,1,0},  
    {-1,0,0,-1,0,-2}, {-1,0,-2,0,0,1}, {0,1,0,2,1,0}, {0,-1,1,0,2,0},  
    {0,1,1,0,1,1}, {0,-1,1,0,1,-1}, {-1,0,0,-1,-1,-1}, {-1,0,-1,1,0,1},  
    {0,1,0,2,0,3}, {1,0,2,0,3,0}, {0,-1,0,-2,0,-3}, {-1,0,-2,0,-3,0}  
};  
  
void gotoxy(int x,int y){//gotoxy在TC中是在system.h库文件里的一个函  
    COORD c;  
    c.X=x-1; c.Y=y-1;  
    SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c);  
}  
void Gameover(){//游戏结束的判断  
    int i,j,flag=0;  
    for(j=1;j<SIZE_M-1;j++){  
        if(map[1][j]!=0){  
            flag=1;break;  
        }  
    }  
    if(flag==1){  
        for(i=1;i<SIZE_N-1;i++){  
            gotoxy(2,i+1);  
            for(j=1;j<SIZE_M-1;j++){  
                printf("□");  
            }puts("");  
        }  
        gotoxy(7,9);  
        printf("GAME OVER!");  
        gotoxy(1,SIZE_N+1);  
        exit(0);  
    }  
}  
void ShowMap(int id){  
    int i,j;  
    gotoxy(1,1);  
    if(id!=-1){  
        for(i=0;i<SIZE_N;i++){  
            for(j=0;j<SIZE_M;j++){  
                if(i==0&&j==0 || i==0&&j==SIZE_M-1 || j==0&&i==SIZE_N-1 || j==SIZE_M-1&&i==SIZE_N-1)printf(" ");  
                else if(i==0 || i==SIZE_N-1)printf("--");  
                else if(j==0 || j==SIZE_M-1)printf("|");  
                else if(map[i][j]==2) printf("■");  
                else if(i==cur_x+shape[id][0] && j==cur_y+shape[id][1] ||  
                    i==cur_x+shape[id][2] && j==cur_y+shape[id][3] ||  
                    i==cur_x+shape[id][4] && j==cur_y+shape[id][5] ||  
                    i==cur_x && j==cur_y)  
                    printf("■");  
                else if(map[i][j]==0) printf("  ");   
            }  
            if(i==1)printf("   next:");  
            if(i==11)printf("   score :   %d",score);  
            if(i==14)printf("   speed :   %d",score/100+1);  
            puts("");  
        }  
    }  
    else {  
        mark=1;  
        for(i=0;i<SIZE_N;i++){  
            for(j=0;j<SIZE_M;j++){  
                if(i==0&&j==0 || i==0&&j==SIZE_M-1 || j==0&&i==SIZE_N-1 || j==SIZE_M-1&&i==SIZE_N-1)printf(" ");  
                else if(i==0 || i==SIZE_N-1)printf("--");  
                else if(j==0 || j==SIZE_M-1)printf("|");  
                else if(map[i][j]==2) printf("■");  
                else if(map[i][j]==0) printf("  ");   
            }  
            if(i==1)printf("   next:");  
            if(i==11)printf("   score :   %d",score);  
            if(i==14)printf("   speed :   %d",score/100+1);  
            puts("");  
        }  
    }  
    /*对于 next 方块的处理,先擦除再画图*/  
    gotoxy(30,6); printf("  ");  
    for(i=0;i<6;i=i+2){  
        gotoxy(30+2*shape[id][i+1],6+shape[id][i]); printf("  ");  
    }  
    gotoxy(30,6); printf("■");  
    for(i=0;i<6;i=i+2){  
        gotoxy(30+2*shape[next][i+1],6+shape[next][i]); printf("■");  
    }  
    Sleep(Gamespeed);  
}  
  
void init(int id){//初始化函数,cur_x,cur_y是全局变量,标记了移动方块的位置  
    memset(map,0,sizeof(map));  
    for(int i=0;i<SIZE_N;i++){  
        for(int j=0;j<SIZE_M;j++)  
            if(i==SIZE_N-1 || j==0 || j==SIZE_M-1)  
                map[i][j]=-1;  
    }  
    cur_x=0; cur_y=5;  
    ShowMap(id);  
}  
  
int judge_in(int x,int y,int id){//判断是否出界,或者说是否合法  
    if(map[x][y]!=0)return 0;  
    for(int i=0;i<6;i=i+2){  
        if(map[ x+shape[id][i] ][ y+shape[id][i+1] ]!=0)return 0;  
    }return 1;  
}  
  
void fun_score(){//得分,擦除行的闪烁,还有图形的向下平移  
    for(int i=1;i<SIZE_N-1;i++){  
        int flag=0;  
        for(int j=1;j<SIZE_M-1;j++){  
            if(map[i][j]!=2){ flag=1;break; }  
        }  
        if(flag==0){  
            int k=3;  
            while(k--){  
                gotoxy(2,i+1);  
                for(int ii=1;ii<SIZE_M-1;ii++){  
                    if(map[i][ii]==2){  
                        if(k%2==1)printf("  ");  
                        else printf("■");  
                    }  
                }Sleep(100);  
            }  
            for(int ii=i;ii>1;ii--){  
                for(int jj=1;jj<SIZE_M-1;jj++)map[ii][jj]=map[ii-1][jj];  
            }  
            ShowMap(-1);  
            score+=10;  
            if(score%100==0 && score!=0)Gamespeed-=50;  
        }  
    }  
}  
  
void main(){  
    int i,id,set=1;  
      
    srand(time(NULL));  
    id=rand()%MOD; id=(id+MOD)%MOD;  
    next=rand()%MOD; next=(next+MOD)%MOD;  
      
    init(id);  
      
    while(1){  
Here:   mark=0;  
        if(set==0){  
            id=next;  
            next=rand()%MOD; next=(next+MOD)%MOD;  
            cur_x=0;cur_y=5;  
            set=1;  
        }  
         
        while(!kbhit()){  
            Gameover();  
            if(judge_in(cur_x+1,cur_y,id)==1) cur_x++;  
            else {  
                map[cur_x][cur_y]=2;  
                for(i=0;i<6;i=i+2)  
                    map[ cur_x+shape[id][i] ][ cur_y+shape[id][i+1] ]=2;  
                fun_score();  
                set=0;  
            }  
            if(mark!=1)ShowMap(id);  
            goto Here;  
        }//end of while(!kbhit())  
         
        char key;  
        key=getch();  
         
        if(key==72){  
            int tmp=id;  
            id++;  
            if( id%4==0 && id!=0 )id=id-4;  
            if(judge_in(cur_x,cur_y,id)!=1)id=tmp;  
        }  
        else if(key==80 && judge_in(cur_x+1,cur_y,id)==1)cur_x++;  
        else if(key==75 && judge_in(cur_x,cur_y-1,id)==1)cur_y--;  
        else if(key==77 && judge_in(cur_x,cur_y+1,id)==1)cur_y++;  
        else if(key==27){gotoxy(1,SIZE_N+1);exit(0);}  
    }  
}

[ 本帖最后由 醒山 于 2015-7-12 20:56 编辑 ]
搜索更多相关主题的帖子: 俄罗斯方块 documents details include 源代码 
2015-07-12 17:01
醒山
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:9
帖 子:463
专家分:2071
注 册:2015-5-25
收藏
得分:0 
修改之后依然有错误
错误如下:
1>c:\users\think\documents\visual studio 2012\projects\win32project1\win32project1\win32project1.cpp(149): warning C4244: “参数”: 从“time_t”转换到“unsigned int”,可能丢失数据
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainCRTStartup 中被引用
1>C:\Users\THINK\Documents\Visual Studio 2012\Projects\Win32Project1\Debug\Win32Project1.exe : fatal error LNK1120: 1 个无法解析的外部命令
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
帮忙看看到底什么问题谢谢了


修改之后源代码如下:

#include<stdio.h>  
#include<stdlib.h>  
#include<windows.h>  
#include<time.h>  
#include<conio.h>  
  
#define MOD 28  
#define SIZE_N 19  
#define SIZE_M 12  
  
int cur_x,cur_y;  
int score,mark,next,map[SIZE_N][SIZE_M],Gamespeed=300;  
  
int shape[28][6]={//这是个比较偷懒的方法,就是7种方块,加上旋转总共28种  
    {0,-1,0,-2,1,0}, {0,1,1,0,2,0}, {-1,0,0,1,0,2}, {0,-1,-1,0,-2,0},  
    {0,-1,0,1,-1,0}, {0,1,1,0,-1,0}, {1,0,0,-1,0,1}, {1,0,-1,0,0,-1},  
    {-1,1,0,1,1,0}, {0,-1,1,0,1,1}, {-1,0,0,-1,1,-1}, {-1,-1,-1,0,0,1},  
    {-1,0,0,1,1,1}, {0,1,1,-1,1,0}, {-1,0,0,1,1,1}, {0,1,1,-1,1,0},  
    {-1,0,0,-1,0,-2}, {-1,0,-2,0,0,1}, {0,1,0,2,1,0}, {0,-1,1,0,2,0},  
    {0,1,1,0,1,1}, {0,-1,1,0,1,-1}, {-1,0,0,-1,-1,-1}, {-1,0,-1,1,0,1},  
    {0,1,0,2,0,3}, {1,0,2,0,3,0}, {0,-1,0,-2,0,-3}, {-1,0,-2,0,-3,0}  
};  
  
void gotoxy(int x,int y){//gotoxy在TC中是在system.h库文件里的一个函  
    COORD c;  
    c.X=x-1; c.Y=y-1;  
    SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c);  
}  
void Gameover(){//游戏结束的判断  
    int i,j,flag=0;  
    for(j=1;j<SIZE_M-1;j++){  
        if(map[1][j]!=0){  
            flag=1;break;  
        }  
    }  
    if(flag==1){  
        for(i=1;i<SIZE_N-1;i++){  
            gotoxy(2,i+1);  
            for(j=1;j<SIZE_M-1;j++){  
                printf("□");  
            }puts("");  
        }  
        gotoxy(7,9);  
        printf("GAME OVER!");  
        gotoxy(1,SIZE_N+1);  
        exit(0);  
    }  
}  
void ShowMap(int id){  
    int i,j;  
    gotoxy(1,1);  
    if(id!=-1){  
        for(i=0;i<SIZE_N;i++){  
            for(j=0;j<SIZE_M;j++){  
                if(i==0&&j==0 || i==0&&j==SIZE_M-1 || j==0&&i==SIZE_N-1 || j==SIZE_M-1&&i==SIZE_N-1)printf(" ");  
                else if(i==0 || i==SIZE_N-1)printf("--");  
                else if(j==0 || j==SIZE_M-1)printf("|");  
                else if(map[i][j]==2) printf("■");  
                else if(i==cur_x+shape[id][0] && j==cur_y+shape[id][1] ||  
                    i==cur_x+shape[id][2] && j==cur_y+shape[id][3] ||  
                    i==cur_x+shape[id][4] && j==cur_y+shape[id][5] ||  
                    i==cur_x && j==cur_y)  
                    printf("■");  
                else if(map[i][j]==0) printf("  ");   
            }  
            if(i==1)printf("   next:");  
            if(i==11)printf("   score :   %d",score);  
            if(i==14)printf("   speed :   %d",score/100+1);  
            puts("");  
        }  
    }  
    else {  
        mark=1;  
        for(i=0;i<SIZE_N;i++){  
            for(j=0;j<SIZE_M;j++){  
                if(i==0&&j==0 || i==0&&j==SIZE_M-1 || j==0&&i==SIZE_N-1 || j==SIZE_M-1&&i==SIZE_N-1)printf(" ");  
                else if(i==0 || i==SIZE_N-1)printf("--");  
                else if(j==0 || j==SIZE_M-1)printf("|");  
                else if(map[i][j]==2) printf("■");  
                else if(map[i][j]==0) printf("  ");   
            }  
            if(i==1)printf("   next:");  
            if(i==11)printf("   score :   %d",score);  
            if(i==14)printf("   speed :   %d",score/100+1);  
            puts("");  
        }  
    }  
    /*对于 next 方块的处理,先擦除再画图*/  
    gotoxy(30,6); printf("  ");  
    for(i=0;i<6;i=i+2){  
        gotoxy(30+2*shape[id][i+1],6+shape[id][i]); printf("  ");  
    }  
    gotoxy(30,6); printf("■");  
    for(i=0;i<6;i=i+2){  
        gotoxy(30+2*shape[next][i+1],6+shape[next][i]); printf("■");  
    }  
    Sleep(Gamespeed);  
}  
  
void init(int id){//初始化函数,cur_x,cur_y是全局变量,标记了移动方块的位置  
    memset(map,0,sizeof(map));  
    for(int i=0;i<SIZE_N;i++){  
        for(int j=0;j<SIZE_M;j++)  
            if(i==SIZE_N-1 || j==0 || j==SIZE_M-1)  
                map[i][j]=-1;  
    }  
    cur_x=0; cur_y=5;  
    ShowMap(id);  
}  
  
int judge_in(int x,int y,int id){//判断是否出界,或者说是否合法  
    if(map[x][y]!=0)return 0;  
    for(int i=0;i<6;i=i+2){  
        if(map[ x+shape[id][i] ][ y+shape[id][i+1] ]!=0)return 0;  
    }return 1;  
}  
  
void fun_score(){//得分,擦除行的闪烁,还有图形的向下平移  
    for(int i=1;i<SIZE_N-1;i++){  
        int flag=0;  
        for(int j=1;j<SIZE_M-1;j++){  
            if(map[i][j]!=2){ flag=1;break; }  
        }  
        if(flag==0){  
            int k=3;  
            while(k--){  
                gotoxy(2,i+1);  
                for(int ii=1;ii<SIZE_M-1;ii++){  
                    if(map[i][ii]==2){  
                        if(k%2==1)printf("  ");  
                        else printf("■");  
                    }  
                }Sleep(100);  
            }  
            for(int ii=i;ii>1;ii--){  
                for(int jj=1;jj<SIZE_M-1;jj++)map[ii][jj]=map[ii-1][jj];  
            }  
            ShowMap(-1);  
            score+=10;  
            if(score%100==0 && score!=0)Gamespeed-=50;  
        }  
    }  
}  
  
void main(){  
    int i,id,set=1;  
      
    srand(time(NULL));  
    id=rand()%MOD; id=(id+MOD)%MOD;  
    next=rand()%MOD; next=(next+MOD)%MOD;  
      
    init(id);  
      
    while(1){  
Here:   mark=0;  
        if(set==0){  
            id=next;  
            next=rand()%MOD; next=(next+MOD)%MOD;  
            cur_x=0;cur_y=5;  
            set=1;  
        }  
         
        while(!_kbhit()){  
            Gameover();  
            if(judge_in(cur_x+1,cur_y,id)==1) cur_x++;  
            else {  
                map[cur_x][cur_y]=2;  
                for(i=0;i<6;i=i+2)  
                    map[ cur_x+shape[id][i] ][ cur_y+shape[id][i+1] ]=2;  
                fun_score();  
                set=0;  
            }  
            if(mark!=1)ShowMap(id);  
            goto Here;  
        }//end of while(!_kbhit())  
         
        char key;  
        key=_getch();  
         
        if(key==72){  
            int tmp=id;  
            id++;  
            if( id%4==0 && id!=0 )id=id-4;  
            if(judge_in(cur_x,cur_y,id)!=1)id=tmp;  
        }  
        else if(key==80 && judge_in(cur_x+1,cur_y,id)==1)cur_x++;  
        else if(key==75 && judge_in(cur_x,cur_y-1,id)==1)cur_y--;  
        else if(key==77 && judge_in(cur_x,cur_y+1,id)==1)cur_y++;  
        else if(key==27){gotoxy(1,SIZE_N+1);exit(0);}  
    }  
}

[ 本帖最后由 醒山 于 2015-7-13 10:50 编辑 ]
2015-07-13 10:40
醒山
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:9
帖 子:463
专家分:2071
注 册:2015-5-25
收藏
得分:0 
好的我试试
2015-07-13 11:57
醒山
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:9
帖 子:463
专家分:2071
注 册:2015-5-25
收藏
得分:0 
成功了,谢谢;
2015-07-13 12:32
快速回复:vs2012编译错误
数据加载中...
 
   



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

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