㈠ 如何用c语言编写控制台小游戏
//C语言实例:推箱子小游戏
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
//行和列
#defineROW10
#defineCOL11
/*,system("pause")orinputloop*/
/**
*
*
*/
//地图
charmap[ROW][COL]={
"##########",//0
"#####",//1
"#####",//2
"##AX###",//3
"#####",//4
"######",//5
"###",//6
"#####",//7
"###",//8
"##########"//9
//A:人,X:箱子
};
//打印地图
voidshowMap();
//接收小人的方向
charenterDirection();
//小人向上移动的方法
voidmoveToUp();
//小人向下移动的方法
voidmoveToDown();
//小人向右移动的方法
voidmoveToRight();
//小人向左移动的方法
voidmoveToLeft();
//当前小人的坐标
intcurrentPersonRow=3;
intcurrentPersonCol=2;
//当前箱子的坐标
intcurrentBoxRow=3;
intcurrentBoxCol=3;intmain(intargc,char*argv[]){
//system("clear");
printf("点击回车键开始游戏^_^ ");
//1代表运行0停止
intflag=1;
while(flag==1){
//显示地图
showMap();
//接收小人的方向
chardir=enterDirection();
switch(dir){
//小人向上移动
case'w':
case'W':
moveToUp();
break;
//小人向下移动
case's':
case'S':
moveToDown();
break;
//小人向右移动
case'd':
case'D':
moveToRight();
break;
//小人向左移动
case'a':
case'A':
moveToLeft();
break;
//停止运行
case'q':
case'Q':
printf("你的智商真低!T_T ");
flag=0;
break;
}
showMap();
if(currentBoxRow==8&¤tBoxCol==9){
printf("你的智商真高^_^!!!");
flag=0;
}
}
}
/*
方法的实现
*/
//打印地图
voidshowMap(){
inti;
for(i=0;i<ROW;i++){
printf("%s ",map[i]);
}
printf(" ");
printf("W:上,S:下,A:左,D:右。Q:退出");
printf(" ");
}
//接收小人的方向
charenterDirection(){
//清除SCANF中的缓冲区
rewind(stdin);
chardir;
dir=getch();
//scanf("%c",&dir);
returndir;
}
//小人向上移动的方法
voidmoveToUp(){
//小人的下一个坐标
intnextPersonCol=currentPersonCol;
intnextPersonRow=currentPersonRow-1;
//箱子的下一个坐标
intnextBoxRow=currentBoxRow-1;
intnextBoxCol=currentBoxCol;
//如果小人的下一个坐标是路
if(map[nextPersonRow][nextPersonCol]==''){
map[nextPersonRow][nextPersonCol]='A';
map[currentPersonRow][currentPersonCol]='';
currentPersonRow=nextPersonRow;
currentPersonCol=nextPersonCol;
}
//如果小人的下一个坐标是墙
if(map[nextPersonRow][nextPersonCol]=='#'){
//什么也不做
}
//如果小人的下一个坐标是箱子
if(map[nextPersonRow][nextPersonCol]=='X'){
if(map[nextBoxRow][nextBoxCol]==''){
map[nextPersonRow][nextPersonCol]='A';
map[currentPersonRow][currentPersonCol]='';
map[nextBoxRow][nextBoxCol]='X';
map[currentBoxRow][currentBoxCol]='A';
currentPersonRow=nextPersonRow;
currentPersonCol=nextPersonCol;
currentBoxRow=nextBoxRow;
currentBoxCol=nextBoxCol;
}
}
}
//小人向下移动的方法
voidmoveToDown(){
//小人的下一个坐标
intnextPersonCol=currentPersonCol;
intnextPersonRow=currentPersonRow+1;
//箱子的下一个坐标
intnextBoxRow=currentBoxRow+1;
intnextBoxCol=currentBoxCol;
//如果小人的下一个坐标是路
if(map[nextPersonRow][nextPersonCol]==''){
map[nextPersonRow][nextPersonCol]='A';
map[currentPersonRow][currentPersonCol]='';
currentPersonRow=nextPersonRow;
currentPersonCol=nextPersonCol;
}
//如果小人的下一个坐标是墙
if(map[nextPersonRow][nextPersonCol]=='#'){
//什么也不做
}
//如果小人的下一个坐标是箱子
if(map[nextPersonRow][nextPersonCol]=='X'){
if(map[nextBoxRow][nextBoxCol]==''){
map[nextPersonRow][nextPersonCol]='A';
map[currentPersonRow][currentPersonCol]='';
map[nextBoxRow][nextBoxCol]='X';
map[currentBoxRow][currentBoxCol]='A';
currentPersonRow=nextPersonRow;
currentPersonCol=nextPersonCol;
currentBoxRow=nextBoxRow;
currentBoxCol=nextBoxCol;
}
}
}
//小人向右移动的方法
voidmoveToRight(){
//小人的下一个坐标
intnextPersonCol=currentPersonCol+1;
intnextPersonRow=currentPersonRow;
//箱子的下一个坐标
intnextBoxRow=currentBoxRow;
intnextBoxCol=currentBoxCol+1;
//如果小人的下一个坐标是路
if(map[nextPersonRow][nextPersonCol]==''){
map[nextPersonRow][nextPersonCol]='A';
map[currentPersonRow][currentPersonCol]='';
currentPersonRow=nextPersonRow;
currentPersonCol=nextPersonCol;
}
//如果小人的下一个坐标是墙
if(map[nextPersonRow][nextPersonCol]=='#'){
//什么也不做
}
//如果小人的下一个坐标是箱子
if(map[nextPersonRow][nextPersonCol]=='X'){
if(map[nextBoxRow][nextBoxCol]==''){
map[nextPersonRow][nextPersonCol]='A';
map[currentPersonRow][currentPersonCol]='';
map[nextBoxRow][nextBoxCol]='X';
map[currentBoxRow][currentBoxCol]='A';
currentPersonRow=nextPersonRow;
currentPersonCol=nextPersonCol;
currentBoxRow=nextBoxRow;
currentBoxCol=nextBoxCol;
}
}
}
//小人向左移动的方法
voidmoveToLeft(){
//小人的下一个坐标
intnextPersonCol=currentPersonCol-1;
intnextPersonRow=currentPersonRow;
//箱子的下一个坐标
intnextBoxRow=currentBoxRow;
intnextBoxCol=currentBoxCol-1;
//如果小人的下一个坐标是路
if(map[nextPersonRow][nextPersonCol]==''){
map[nextPersonRow][nextPersonCol]='A';
map[currentPersonRow][currentPersonCol]='';
currentPersonRow=nextPersonRow;
currentPersonCol=nextPersonCol;
}
//如果小人的下一个坐标是墙
if(map[nextPersonRow][nextPersonCol]=='#'){
//什么也不做
}
//如果小人的下一个坐标是箱子
if(map[nextPersonRow][nextPersonCol]=='X'){
if(map[nextBoxRow][nextBoxCol]==''){
map[nextPersonRow][nextPersonCol]='A';
map[currentPersonRow][currentPersonCol]='';
map[nextBoxRow][nextBoxCol]='X';
map[currentBoxRow][currentBoxCol]='A';
currentPersonRow=nextPersonRow;
currentPersonCol=nextPersonCol;
currentBoxRow=nextBoxRow;
currentBoxCol=nextBoxCol;
}
}
}
㈡ C语言编程题,编写一控制台应用程序
#include<stdio.h>
void main() { int x;
scanf("%d",&x);
if ( x>=90 ) printf("优秀。\n");
else if ( x>=80 ) printf("良好。\n");
else if ( x>=70 ) printf("中等。\n");
else if ( x>=60 ) printf("合格。\n");
else printf("不合格。\n");
}
㈢ C语言怎么只能编写控制台应用程序,怎么编写WINDOWS 应用程序
需要些SDK的知识,windows的实现中基本上都是用的C语言,其各种接口基本上都是原生C语言函数,具体比如SDK用的windows API。
使用纯C语言编写windows程序,工作量将会相当大,下面是一个小例子:
/*
* This is a simple windows program, it does nothing but draw an ellipse.
* Windows SDK, Win32 API ,Pure C, (Not C++ or MFC !!)
* Suxpert at gmail dot com, 2008/8/24
* */
#include <windows.h>
LONG WINAPI WndProc( HWND, UINT, WPARAM, LPARAM );
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow ){
/* The Entry for windows program, just like main() in dos */
WNDCLASS wc;
HWND hwnd;
MSG msg;
wc.style = 0; // Class style
wc.lpfnWndProc = (WNDPROC)WndProc; // Window procere address
wc.cbClsExtra = 0; // Class extra bytes
wc.cbWndExtra = 0; // Window extra bytes
wc.hInstance = hInstance; // Instance handle
wc.hIcon = LoadIcon( NULL, IDI_WINLOGO ); // Icon handle
wc.hCursor = LoadCursor( NULL, IDC_ARROW ); // Cursor handle
wc.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 ); // Background color
wc.lpszMenuName = NULL; // Menu name
wc.lpszClassName = "WinSDKtest"; // WNDCLASS name
RegisterClass( &wc );
hwnd = CreateWindow (
"WinSDKtest", // WNDCLASS name
"SDK Application", // Window title
WS_OVERLAPPEDWINDOW, // Window style
CW_USEDEFAULT, // Horizontal position
CW_USEDEFAULT, // Vertical position
CW_USEDEFAULT, // Initial width
CW_USEDEFAULT, // Initial height
HWND_DESKTOP, // Handle of parent window
NULL, // Menu handle
hInstance, // Application's instance handle
NULL // Window-creation data
);
ShowWindow( hwnd, nCmdShow );
UpdateWindow( hwnd );
while ( GetMessage( &msg, NULL, 0, 0 ) ) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam )
{
/* Windows will call this function anytime... */
PAINTSTRUCT ps;
HDC hdc;
switch(message){
case WM_PAINT:
hdc = BeginPaint( hwnd, &ps );
Ellipse( hdc, 0, 0, 800, 600 );
// Here we Draw an ellipse in the window of our program
EndPaint( hwnd, &ps );
break; // Someone like to write return here.
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc( hwnd, message, wParam, lParam );
}
return 0;
}
基本过程就是直接调用windows提供的API函数,完成从窗口创建,显示等界面功能到深层的文件操作,注册表等甚至windows内核调试等高级功能。
㈣ 编写一个控制台应用程序,完成下列功能,并写出运行程序后输出的结果.
楼主你好。:
下是你想要的内容,
class Program
{
static void Main(string[] args)
{
ClassA classA = new ClassA();
Console.WriteLine("调用ClassA中方法返回的结果" + classA.MyMethod(100).ToString());
ClassB classB = new ClassB();
Console.WriteLine("调用ClassB中方法返回的结果" + classB.MyMethod(100).ToString());
Console.ReadLine();
}
}
class ClassA
{
public virtual int MyMethod(int inputNum)
{
int sumNum = inputNum + 10;
return sumNum;
}
}
class ClassB : ClassA
{
public override int MyMethod(int inputNum)
{
int sumNum = inputNum + 50;
return sumNum;
}
}
运行结果:
希望对有帮助,望采纳,谢谢
㈤ C语言,指针数组问题,定义控制台应用程序的入口点的程序
4. fillcircle(p[i]->X, p[i]->Y, 10);
5那里写错了,应该是delete p[i];
㈥ 用vc++创建控制台应用程序的步骤
1、首先打开桌面上本地已经安装的VS2017开发工具IDE,如下图所示。
㈦ C语言编写的怎么都是命令控制台程序
1、控制台程序是基础,有基础了写图形界面的程序就很简单了。学完C++了学windows编程、MFC什么的,到时候就是图形界面了。
2、图形界面需要些SDK的知识,windows的实现中基本上都是用的C语言,其各种接口基本上都是原生C语言函数,具体比如SDK用的windows API。
使用纯C语言编写windows程序,工作量将会相当大,下面是一个小例子:
/*
*Thisisasimplewindowsprogram,itdoesnothingbutdrawanellipse.
*WindowsSDK,Win32API,PureC,(NotC++orMFC!!)
*Suxpertatgmaildotcom,2008/8/24
**/
#include<windows.h>
LONGWINAPIWndProc(HWND,UINT,WPARAM,LPARAM);
intAPIENTRYWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,
LPSTRlpszCmdLine,intnCmdShow){
/*TheEntryforwindowsprogram,justlikemain()indos*/
WNDCLASSwc;
HWNDhwnd;
MSGmsg;
wc.style=0;//Classstyle
wc.lpfnWndProc=(WNDPROC)WndProc;//Windowprocereaddress
wc.cbClsExtra=0;//Classextrabytes
wc.cbWndExtra=0;//Windowextrabytes
wc.hInstance=hInstance;//Instancehandle
wc.hIcon=LoadIcon(NULL,IDI_WINLOGO);//Iconhandle
wc.hCursor=LoadCursor(NULL,IDC_ARROW);//Cursorhandle
wc.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);//Backgroundcolor
wc.lpszMenuName=NULL;//Menuname
wc.lpszClassName="WinSDKtest";//WNDCLASSname
RegisterClass(&wc);
hwnd=CreateWindow(
"WinSDKtest",//WNDCLASSname
"SDKApplication",//Windowtitle
WS_OVERLAPPEDWINDOW,//Windowstyle
CW_USEDEFAULT,//Horizontalposition
CW_USEDEFAULT,//Verticalposition
CW_USEDEFAULT,//Initialwidth
CW_USEDEFAULT,//Initialheight
HWND_DESKTOP,//Handleofparentwindow
NULL,//Menuhandle
hInstance,//Application'sinstancehandle
NULL//Window-creationdata
);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
returnmsg.wParam;
}
LRESULTCALLBACKWndProc(HWNDhwnd,UINTmessage,WPARAMwParam,
LPARAMlParam)
{
/*...*/
PAINTSTRUCTps;
HDChdc;
switch(message){
caseWM_PAINT:
hdc=BeginPaint(hwnd,&ps);
Ellipse(hdc,0,0,800,600);
//
EndPaint(hwnd,&ps);
break;//Someoneliketowritereturnhere.
caseWM_DESTROY:
PostQuitMessage(0);
break;
default:
returnDefWindowProc(hwnd,message,wParam,lParam);
}
return0;
}
基本过程就是直接调用windows提供的API函数,完成从窗口创建,显示等界面功能到深层的文件操作,注册表等甚至windows内核调试等高级功能。
㈧ 请用c语言控制台程序写一个程序
#include<stdio.h>
typedefstructpoint{
intx;
inty;
}quadrangle;
intmain(intargc,charconst*argv[])
{
quadranglefour[4];
inti,j,tmpx,tmpy;
for(i=0;i<4;i++)
{
printf("输入第%d个点,每个点由x轴,y轴坐标表示如:125 ",i+1);
scanf("%d%d",&four[i].x,&four[i].y);
}
for(i=0;i<4;i++)
{
tmpx=four[i].x;
tmpy=four[i].y;
for(j=i+1;j<4;j++)
{
if(four[j].x<tmpx)
{
four[i].x=four[j].x;
four[i].y=four[j].y;
four[j].x=tmpx;
four[j].y=tmpy;
tmpx=four[i].x;
tmpy=four[i].y;
}
}
}
inta[2],b[2],c[2],d[2];
if(four[0].y>four[1].y)
{
a[0]=four[1].x;
a[1]=four[1].y;
d[0]=four[0].x;
d[1]=four[0].y;
}
else{
a[0]=four[0].x;
a[1]=four[0].y;
d[0]=four[1].x;
d[1]=four[1].y;
}
if(four[2].y>four[3].y)
{
b[0]=four[3].x;
b[1]=four[3].y;
c[0]=four[2].x;
c[1]=four[2].y;
}
else
{
b[0]=four[2].x;
b[1]=four[2].y;
c[0]=four[3].x;
c[1]=four[3].y;
}
printf("a(%d,%d)b(%d,%d)c(%d,%d)d(%d,%d) ",
a[0],a[1],b[0],b[1],c[0],c[1],d[0],d[1]);
return0;
}
㈨ C语言 控制台程序
不想调用控制台入口换winmain
底层的编译,在编译成目标文件之后,不要链接成可执行文件,生成别的
二进制文件
或者。。像
Linux内核
一样,编译成可执行文件,装载入内存,然后用内存镜像拷贝出纯二进制文件。。等等方法
至于编译驱动有另外更加专业的方法咯。。
㈩ c语言试题求解 3. 编写一个控制台应用程序,输出1到6的平方值,要求: 1) 用for语句
#include<stdio.h>
void main()
{
int i,m;
for(i=1;i<=6;i++)
{
m=i*i;
printf("%d的平方值=%d\n",i,m);
}
}
运行过了 没有错误,望采纳!