當前位置:首頁 » 編程軟體 » 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-05-14 03:48:52 瀏覽:529
動圖在線壓縮 發布:2025-05-14 03:35:24 瀏覽:132
w7共享無法訪問 發布:2025-05-14 03:35:24 瀏覽:482
為什麼微信會出現賬號密碼錯誤 發布:2025-05-14 03:03:30 瀏覽:692
幻影腳本官網 發布:2025-05-14 03:01:13 瀏覽:826
servlet的webxml怎麼配置 發布:2025-05-14 02:51:46 瀏覽:772
怎麼取消手勢密碼 發布:2025-05-14 02:51:11 瀏覽:639
openvpn搭建vpn伺服器搭建 發布:2025-05-14 02:47:52 瀏覽:998
密碼忘了從哪裡找 發布:2025-05-14 02:39:09 瀏覽:548
我的世界什麼伺服器有前途 發布:2025-05-14 02:30:31 瀏覽:528