当前位置:首页 » 编程软件 » c控制台编程

c控制台编程

发布时间: 2023-07-12 17:51:27

❶ C语言控制台在指定位置输出字符

控制台程序是没有鼠标定位什么的,你想定位肯定是输出空格字符来完成定位的。这种的简单。如果你用鼠标定位的那么调windows的API在屏幕上的某个位置这个复杂,我也不会

❷ 如何用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&&currentBoxCol==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语言控制台

C语言控制台就是C语言在新建工程时选的一种工程类型,称为Win32控制台应用程序。
控制台应用程序就是模拟DOS环境下运行的程序。

建立Win32控制台应用程序的过程如下:
新建项目--->Win32--->Win32控制台应用程序

建立完控制台应用程序后,就可以在新建的源文件中输入C语言程序,经编译完成后就可以运行在DOS环境中运行(即黑框)。

热点内容
光遇切换账号安卓要输入些什么 发布:2025-02-07 07:10:20 浏览:501
多角线算法 发布:2025-02-07 07:08:56 浏览:273
有效提高ftp传输速度 发布:2025-02-07 07:06:47 浏览:703
寒灵之剑脚本 发布:2025-02-07 06:57:12 浏览:119
解压的窗口 发布:2025-02-07 06:44:34 浏览:798
android身份证 发布:2025-02-07 06:36:43 浏览:431
python的库在哪 发布:2025-02-07 06:30:24 浏览:349
带锁的铅笔如何改密码 发布:2025-02-07 06:18:05 浏览:165
ubuntu搭建samba服务器 发布:2025-02-07 05:52:54 浏览:55
小型企业网如何配置可以互通 发布:2025-02-07 05:33:56 浏览:243