Ⅰ c語言如何控制文字輸出速度
顯示一行是和快的,至少肉眼感覺是這樣的。
在顯示完一行後,適當延時(延時方法可用循環語句來完成,時長通過改變循環終值來控制),再輸出下一行。
Ⅱ c語言怎麼實現滾動的字母比如一排文字,從下面一直平移到上面
用一個二維數組,記錄。
比如10行10列按序輸出顯示,
寫個循環遍歷數組每次將下一行內容復制給上一行。
再看看別人怎麼說的。
Ⅲ C語言用鍵盤控制 一個字母 移動 就這么簡單的功能 代碼最好寫簡單點 注釋下 控制台最好了 謝謝
#include<stdio.h>
#include<conio.h>
#include<iostream>
voidmain()
{
intd[9][9]={0},x=0,y=0;//定義地圖與坐標
d[x][y]=1;//定義小人
for(inti=0;i<9;i++)//顯示地圖
{
for(intk=0;k<9;k++)
printf("%d",d[i][k]);
printf(" ");
}
while(charc=getch())//阻塞方式獲取鍵盤按下的值
{
switch(c)//判斷按下的是哪個鍵並分別作處理
{
case'w':
if(x-1>=0&&x-1<9)
{
d[x][y]=0;
d[--x][y]=1;
}
break;
case'a':
if(y-1>=0&&y-1<9)
{
d[x][y]=0;
d[x][--y]=1;
}
break;
case's':
if(x+1>=0&&x+1<9)
{
d[x][y]=0;
d[++x][y]=1;
}
break;
case'd':
if(y+1>=0&&y+1<9)
{
d[x][y]=0;
d[x][++y]=1;
}
break;
}
system("cls");//清空控制台輸出
for(inti=0;i<9;i++)//更新地圖顯示
{
for(intk=0;k<9;k++)
printf("%d",d[i][k]);
printf(" ");
}
}
}
Ⅳ c語言怎麼實現滾動的字母比如一排文字,從下面一直平移到上面
下面是貪吃蛇簡化版代碼,可以參考。
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<conio.h>
#include<windows.h>//Sleep
int x=1,y=4;
char dir='d';
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); //獲取標准輸出的句柄 <windows.h>
//句柄 :標志應用程序中的不同對象和同類對象中的不同的實例 方便操控,
void gotoxy(int x, int y)//設置游標位置
{
COORD pos = {x,y}; //定義一個字元在控制台屏幕上的坐標POS
SetConsoleCursorPosition(hConsole, pos); //定位游標位置的函數<windows.h>
}
void SetColor(int color)//設置顏色
{
SetConsoleTextAttribute(hConsole, color);
//是API設置字體顏色和背景色的函數 格式:SetConsoleTextAttribute(句柄,顏色);
}
int move()
{
if(kbhit())//keyboard hit,in conio.h
{
switch(getch())
{
case 0x77:
dir = 'w';
break;
case 0x73:
dir = 's';
break;
case 0x61:
dir = 'a';
break;
case 0x64:
dir = 'd';
break;
default:
break;
}
}
switch(dir)
{
case 'w':
y--;break;
case 's':
y++;break;
case 'a':
x--;break;
case 'd':
x++;break;
}
return 0;
}
void check()
{
if(x==0||y==0);
}
int main()
{
int interval=500;//列;行。
system("mode con:cols=60 lines=60");//設置窗體大小 ,超過會自動清除前面的//錯題集
system("color 47");//black background
while(1)
{
gotoxy(x,y);
SetColor(0xf);
printf("※");
Sleep(interval);
system("CLS");
move();
}
return 0;
}
Ⅳ 在C語言中,怎麼編寫用游標鍵控制一個字元上下左右移動。
先用背景色在字元原地列印一次,再移動到要列印的位置,設置為前景色,列印該字元.
Ⅵ C語言打字練習游戲中怎樣實現字母掉落,不用換行和隨機坐標還有別的方法嗎
可以指定游標位置進行printf輸出字元,多字元同時出現,最好使用多線程,下面是個簡單的例子,希望對你有幫助
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
#include<time.h>
voidsetxy(intx,inty)
{
COORDcoord={x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
intmain()
{
CONSOLE_CURSOR_INFOcci;
cci.bVisible=FALSE;
cci.dwSize=sizeof(cci);
HANDLEhandle=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorInfo(handle,&cci);
srand((unsigned)time(0));
intx,y;
intc;
while(1)
{
c=rand()%26;
c+='A';
x=rand()%40;
y=0;
while(1)
{
setxy(x,y);
printf("%c",c);
sleep(1);
setxy(x,y);
printf("");
y++;
if(y>5)
{
break;
}
}
}
return0;
}
Ⅶ 移動字母 C語言
如圖,源代碼在網頁端發
#include<stdio.h>
#include<string.h>
#defineMAXS100
voidShift(chars[]);
voidGetString(chars[]);/*實現細節在此不表*/
intmain()
{
chars[MAXS];
GetString(s);
Shift(s); //交換
printf("%s
",s);
return0;
}
voidGetString(chars[]){//不寫這個無法驗證
scanf("%s",s);
}
voidShift(chars[]){
chara[3];
inti,j;
for(i=0;i<3;i++){
a[i]=s[i];//將前3個字母存到a
}
//此時i已經=3
for(;s[i]!='