c語言簡單pos機下載
1、c語言,編寫一個售貨機(POS)計算程序,用于水果店售貨員算賬.蘋果每千克...
#include <stdio.h>
int main(void)
{
float p[4] = {3.2, 1.96, 3, 24};
float w[4] = {1.5, 2, 3, 1.5};
float s = 0;
int i;
for(i=0;i<4;i++)
s+= p[i]*w[i];
printf("%s%12s%12s%13s\n", "名稱", "單價", "重量", "應付價錢");
printf("---------------------------------------------\n");
printf("%s%12.2f%12.2f%13.3f\n","蘋果", p[0], w[0], p[0]*w[0]);
printf("%s%12.2f%12.2f%13.3f\n","梨 ", p[1], w[1], p[1]*w[1]);
printf("%s%12.2f%12.2f%13.3f\n","香蕉", p[2], w[2], p[2]*w[2]);
printf("%s%12.2f%12.2f%13.3f\n","櫻桃", p[3], w[3], p[3]*w[3]);
printf("---------------------------------------------\n");
printf("%s%37.2f\n", "總計", s);
printf("%s%37.2f\n", "付款", 100.0);
printf("%s%37.2f\n", "找零", 100.0 - s);
return 0;
}
2、C語言編寫的收銀臺結算程序。
//以下是參考代碼有相似結構,數據結構自己設計一下。
//如果沒參考價值,手下留情,別點不采納。
#define MAXPARKINGPOS 100
#define MAXPRICETYPE 3
#define MAXLINE 4096
struct detail
{
char num[MAXLINE];
char name[MAXLINE];
double pricePerHour;
time_t start;
time_t end;
double period;
double cost;
};
static int currentParkingNum = 0;
static struct detail detailBuf[MAXPARKINGPOS];
static double priceBuf[MAXPRICETYPE] = {11.0,22.0,33.0};
int main(void) {
char buf[MAXLINE];
struct detail *myParking;
int iChoice,leavingIndex,i,numEexisted;
struct tm *begin,*end;
while(true) {
selectService:
printf("Service type,what is your choice?\n1.park\n2.leave\n3.exit\n");
gets(buf);
if(strcmp(buf,"3") == 0) {
return 0;
}
if(strcmp(buf,"1") == 0) {
//park
if(currentParkingNum == MAXPARKINGPOS) {
printf("Sorry,not empty!\n\n");
continue;
}
myParking = detailBuf+currentParkingNum;
printf("your name:\n");
gets(myParking->name);
printf("your parking num:\n");
gets(myParking->num);
numEexisted = 0;
for(i=0;i<currentParkingNum;i++) {
if(strcmp(detailBuf[i].num,myParking->num) == 0) {
numEexisted =1;
break;
}
}
if(numEexisted != 0) {
printf("The car %s is in\n\n",myParking->num);
goto selectService;
}
selectPrice:
printf("Service cost,what is your choice?\n");
for(int i=0;i < MAXPRICETYPE; i++) {
printf("%d.$%.2f per hour\n",i+1,priceBuf[i]);
}
gets(buf);
iChoice = atoi(buf);
if(!(iChoice >= 1 && iChoice <=MAXPRICETYPE)) {
printf("Your choice is incorrect!\n\n");
goto selectPrice;
}
myParking->pricePerHour=priceBuf[iChoice-1];
time(&myParking->start);
currentParkingNum++;
printf("Parcking ok!\n\n");
}else if(strcmp(buf,"2") == 0) {
//leave
printf("your parking num:\n");
gets(buf);
myParking = NULL;
for(i=0;i<currentParkingNum;i++) {
if(strcmp(detailBuf[i].num,buf) == 0) {
myParking = &detailBuf[i];
leavingIndex = i;
break;
}
}
if(myParking ==NULL) {
printf("Cannot find your car!\n\n");
continue;
}
myParking->end = time(&myParking->end);
myParking->period = difftime(myParking->end,myParking->start);
myParking->cost= myParking->period/3600.0*myParking->pricePerHour;
printf("****** Cost Details ******\n");
printf("name:%s\n",myParking->name);
printf("number:%s\n",myParking->num);
printf("price:%.2f\n",myParking->pricePerHour);
begin = localtime(&myParking->start);
strftime(buf,sizeof(buf),"%Y-%m-%d %H:%M:%S",begin);
printf("begin:%s\n",buf);
end = localtime(&myParking->end);
strftime(buf,sizeof(buf),"%Y-%m-%d %H:%M:%S",end);
printf("end:%s\n",buf);
printf("period:%.2f hour(s)\n",myParking->period/3600.0);
printf("cost:$%.2f\n",myParking->cost);
printf("service:$%.2f per hour\n",myParking->pricePerHour);
for(i = leavingIndex; i < currentParkingNum;i++) {
if(i+1 < currentParkingNum) {
detailBuf[i]=detailBuf[i+1];
}
}
detailBuf[currentParkingNum-1].cost=0.0;
detailBuf[currentParkingNum-1].end=0;
detailBuf[currentParkingNum-1].name[0]='\0';
detailBuf[currentParkingNum-1].num[0]='\0';
detailBuf[currentParkingNum-1].period=0.0;
detailBuf[currentParkingNum-1].pricePerHour=0.0;
detailBuf[currentParkingNum-1].start=0;
currentParkingNum--;
printf("Leaving ok!\n\n");
}else{
printf("Your choice is incorrect!\n\n");
continue;
}
}
return 0;
}
建立商品庫
建立出售庫
每刷一毛,查詢商品庫,記錄出售庫。。。。。直到結算,開始新一筆。。。。。。。。。。如此循環
C++的要不要?
C的太麻煩了,除非就實現簡單的功能
3、c語言中pos是什么意思
位置。pos是position的縮寫,意思是位置,主要用在標準庫函數find中,多用于查找位置。語言是由詞按照一定的語言規則所組成的符號系統,如漢語、英語、 俄語 等。4、求C語言小游戲源程序
簡易“推箱子”游戲C代碼:
#include <stdio.h>
#include <conio.h>
#include<stdlib.h>
#include<windows.h>
int m =0; //m代表第幾關
struct maps{short a[9][11]; };
struct maps map[5]={ 0,0,0,0,0,0,0,0,0,0,0, //共5關,每關9行
0,1,1,1,1,1,1,1,0,0,0,
0,1,0,0,0,0,0,1,1,1,0,
1,1,4,1,1,1,0,0,0,1,0, //0空地,1墻
1,5,0,0,4,0,0,4,0,1,0, //4是箱子,5是人
1,0,3,3,1,0,4,0,1,1,0, //3是目的地
1,1,3,3,1,0,0,0,1,0,0, //7是箱子在目的地(4+3)
0,1,1,1,1,1,1,1,1,0,0, //8是人在目的地(5+3)
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,1,1,1,1,0,0,0,0,0,
0,0,1,5,0,1,1,1,0,0,0,
0,0,1,0,4,0,0,1,0,0,0,
0,1,1,1,0,1,0,1,1,0,0,
0,1,3,1,0,1,0,0,1,0,0,
0,1,3,4,0,0,1,0,1,0,0,
0,1,3,0,0,0,4,0,1,0,0,
0,1,1,1,1,1,1,1,1,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,1,1,1,1,1,1,1,0,
0,0,1,1,0,0,1,0,5,1,0,
0,0,1,0,0,0,1,0,0,1,0,
0,0,1,4,0,4,0,4,0,1,0,
0,0,1,0,4,1,1,0,0,1,0,
1,1,1,0,4,0,1,0,1,1,0,
1,3,3,3,3,3,0,0,1,0,0,
1,1,1,1,1,1,1,1,1,0,0,
0,1,1,1,1,1,1,1,1,1,0,
0,1,0,0,1,1,0,0,0,1,0,
0,1,0,0,0,4,0,0,0,1,0,
0,1,4,0,1,1,1,0,4,1,0,
0,1,0,1,3,3,3,1,0,1,0,
1,1,0,1,3,3,3,1,0,1,1,
1,0,4,0,0,4,0,0,4,0,1,
1,0,0,0,0,0,1,0,5,0,1,
1,1,1,1,1,1,1,1,1,1,1,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,1,1,1,1,1,1,0,0,
0,1,1,1,0,0,0,0,1,0,0,
1,1,3,0,4,1,1,0,1,1,0,
1,3,3,4,0,4,0,0,5,1,0,
1,3,3,0,4,0,4,0,1,1,0,
1,1,1,1,1,1,0,0,1,0,0,
0,0,0,0,0,1,1,1,1,0,0,
0,0,0,0,0,0,0,0,0,0,0 };
void DrMap( ) //繪制地圖
{ CONSOLE_CURSOR_INFO cursor_info={1,0}; //隱藏光標的設置
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
printf("\n\n \t\t\b推箱子");
printf("\n \t");
for (int i = 0; i < 9; i++)
{for (int j = 0; j < 11; j++)
{switch (map[m].a[i][j])
{case 0: printf(" "); break;
case 1: printf("■"); break;
case 3: printf("◎");break;
case 4: printf("□"); break;
case 5: printf("♀"); break; //5是人
case 7: printf("□"); break; //4 + 3箱子在目的地中
case 8: printf("♀");break; // 5 + 3人在目的地中
}
}
printf("\n\t");
}
}
void gtxy(int x, int y) //控制光標位置的函數
{ COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void start( ) //開始游戲
{ int r, c; //存儲人的下標
for (int i = 0; i < 9; i++)
{ for (int j = 0; j < 11; j++)
{if (map[m].a[i][j] == 5||map[m].a[i][j]==8) { r = i; c = j; } } //i j 人的下標
}
char key;
key = getch( );
switch (key)
{case 'W':
case 'w':
case 72:
if (map[m]. a[r - 1][c] == 0|| map[m]. a [r - 1][c] == 3)
{ gtxy(2*c+8,r-1+3); printf("♀"); // gtxy(2*c+8,r-1+3)是到指定位置輸出字符
if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }
if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}
map[m]. a [r - 1][c] += 5; map[m]. a [r][c] -= 5; }
else if (map[m]. a [r - 1][c] == 4 || map[m]. a [r - 1][c] == 7)
{ if (map[m]. a [r - 2][c] == 0 || map[m]. a [r - 2][c] == 3)
{ gtxy(2*c+8,r-2+3); printf("□"); gtxy(2*c+8,r-1+3); printf("♀");
if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }
if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}
map[m]. a [r - 2][c] += 4; map[m]. a [r - 1][c] += 1;
map[m]. a [r][c] -= 5; }
} break;
case 'S':
case 's':
case 80:
if (map[m]. a [r + 1][c] == 0 || map[m]. a [r + 1][c] == 3)
{ gtxy(2*c+8,r+1+3); printf("♀");
if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }
if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}
map[m]. a [r + 1][c] += 5; map[m]. a [r][c] -= 5; }
else if (map[m]. a [r + 1][c] == 4 || map[m]. a [r+ 1][c] == 7)
{ if (map[m]. a [r + 2][c] == 0 || map[m]. a [r + 2][c] == 3)
{ gtxy(2*c+8,r+2+3); printf("□"); gtxy(2*c+8,r+1+3); printf("♀");
if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }
if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}
map[m]. a [r + 2][c] += 4; map[m]. a [r + 1][c] += 1;
map[m]. a [r][c] -= 5; }
}break;
case 'A':
case 'a':
case 75:
if (map[m]. a [r ][c - 1] == 0 || map[m]. a [r ][c - 1] == 3)
{ gtxy(2*(c-1)+8,r+3); printf("♀");
if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }
if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}
map[m]. a [r ][c - 1] += 5; map[m]. a [r][c] -= 5; }
else if (map[m]. a [r][c - 1] == 4 || map[m]. a [r][c - 1] == 7)
{if (map[m]. a [r ][c - 2] == 0 || map[m]. a [r ][c - 2] == 3)
{ gtxy(2*(c-2)+8,r+3); printf("□"); gtxy(2*(c-1)+8,r+3); printf("♀");
if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }
if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}
map[m]. a [r ][c - 2] += 4; map[m]. a [r ][c - 1] += 1;
map[m]. a [r][c] -= 5; }
}break;
case 'D':
case 'd':
case 77:
if (map[m]. a [r][c + 1] == 0 || map[m]. a [r][c + 1] == 3)
{ gtxy(2*(c+1)+8,r+3); printf("♀");
if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }
if(map[m]. a[r ][c] == 8) {gtxy(2*c+8,r+3); printf("◎");}
map[m]. a [r][c + 1] += 5; map[m]. a [r][c] -= 5; }
else if (map[m]. a [r][c + 1] == 4 || map[m]. a [r][c + 1] == 7)
{ if (map[m]. a [r][c + 2] == 0 || map[m]. a [r][c + 2] == 3)
{ gtxy(2*(c+2)+8,r+3); printf("□"); gtxy(2*(c+1)+8,r+3); printf("♀");
if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }
if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}
map[m]. a [r][c + 2] += 4; map[m]. a [r][c + 1] += 1;
map[m]. a [r][c] -= 5; }
}break;
}
}
int ifwan( ) //是否完成(1是0否)
{ if(m==0){if(map[m].a[5][2]==7&& map[m].a[5][3]==7&&
map[m].a[6][2]==7&& map[m].a[6][3]==7) return 1;}
if(m==1){if(map[m].a[5][2]==7&& map[m].a[6][2]==7&&
map[m].a[7][2]==7) return 1;}
if(m==2){if(map[m].a[7][1]==7&& map[m].a[7][2]==7&& map[m].a[7][3]==7&&
map[m].a[7][4]==7&& map[m].a[7][5]==7) return 1;}
if(m==3){if(map[m].a[4][4]==7&& map[m].a[4][5]==7&& map[m].a[4][6]==7&&
map[m].a[5][4]==7&& map[m].a[5][5]==7&& map[m].a[5][6]==7) return 1;}
if(m==4){if(map[m].a[3][2]==7&& map[m].a[4][1]==7&& map[m].a[4][2]==7&&
map[m].a[5][1]==7&& map[m].a[5][2]==7) return 1;}
return 0;
}
int main( ) //主函數
{ while (1)
{ system("cls");
DrMap( );
while (1)
{ start( );
if(ifwan()){printf("\007");break;} //完成后響鈴
}
m+=1;
}
return 0;
}
學習一下數字版“拼圖”代碼寫法:
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<windows.h>
int i, j, r, k; //i、j、r用于循環, k存放隨機數值
int m, n; // m、n是當前空位的下標
int a[4][4]; //存儲4×4共16個數字的數組
void show(void); //輸出數組表格
void csh(void); //初始化界面
int yes(void); //判斷排序是否成功
void up(void); //數字向上移動到空位(空位則下移)
void down(void); //數字向下移
void left(void); //數字向左移
void rght(void); //數字向右移
void inkey(void); //按鍵操作
void gtxy(int x, int y) ; //控制光標位置的函數
int main(void)
{ while(1)
{ csh( );
while(1)
{ inkey();
show();
if ( yes( ) )
{gtxy(6,12); printf("你成功了! 再來一局y/n?"); break;}
}
if(getch( )== 'n')break;
}
return 0;
}
void csh(void) //初始化界面
{ r=0;
CONSOLE_CURSOR_INFO cursor_info={1,0}; //以下兩行是隱藏光標的設置
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
for(i=0;i<4;i++) //給數組a依序賦值
for(j=0;j<4;j++)
{ if (i==3 && j==3) a[i][j]=0;
else a[i][j]=1+r++;
}
m=3; n=3; //記下空格(值為0)的下標
down( ); rght( ); rght( ); down( ); //預演4步
srand((unsigned)time(0)); //初始化隨機數發生器
for(r=0;r<500;r++) //將數組各值打亂
{ k=rand( )%(4);
switch(k)
{ case 0: { up( ); break; }
case 1: {down( ); break; }
case 2: { left( ); break; }
case 3: { rght( ); break; }
}
}
system("cls");
printf("\n\n\t\t 數字拼圖");
printf("\n\t┌──────┬──────┬──────┬──────┐");
printf("\n\t│ │ │ │ │");
printf("\n\t├──────┼──────┼──────┼──────┤");
printf("\n\t│ │ │ │ │");
printf("\n\t├──────┼──────┼──────┼──────┤");
printf("\n\t│ │ │ │ │");
printf("\n\t├──────┼──────┼──────┼──────┤");
printf("\n\t│ │ │ │ │");
printf("\n\t└──────┴──────┴──────┴──────┘");
show( );
}
void show(void) //輸出界面
{for(i=0;i<4;i++)
for(j=0;j<4;j++) //gtxy(7*j+9, 2*i+4)是光標到指定位置輸出數字
{gtxy(7*j+9,2*i+4); if(a[i][j]==0)printf(" │");
else if(a[i][j]>9)printf(" %d │",a[i][j]);
else printf(" %d │",a[i][j]);
}
}
void inkey(void) //按鍵操作
{ int key;
key=getch( );
switch(key)
{ case 72: { up( ); break; }
case 80: {down( ); break; }
case 75: {left( ); break; }
case 77: { rght( ); break; }
}
}
void up(void) //數字向上移
{ if (m!=3) //空位不得在下邊界
{ a[m][n]=a[m+1][n]; m++; a[m][n]=0; }
}
void down(void) //數字向下移
{ if (m!=0) //空位不得在上邊界
{a[m][n]=a[m-1][n]; m--; a[m][n]=0; }
}
void left(void) //數字向左移
{ if (n!=3) //空位不得在右邊界
{ a[m][n]=a[m][n+1]; n++; a[m][n]=0; }
}
void rght(void) //數字向右移
{ if (n!=0) //空位不得在左邊界
{ a[m][n]=a[m][n-1]; n--; a[m][n]=0; }
}
int yes(void) //判斷排序是否成功
{ r=0;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
{ if (a[i][j]!=1+r++) return (r==16)?1:0; }
}
void gtxy(int x, int y) //控制光標位置的函數
{ COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
我的樓主可以自己玩一下試試吧
#define N 200
#include <graphics.h>
#include <stdlib.h>
#include <dos.h>
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define ESC 0x011b
int i,key;
int score=0;/*得分*/
int gamespeed=50000;/*游戲速度自己調整*/
struct Food
{
int x;/*食物的橫坐標*/
int y;/*食物的縱坐標*/
int yes;/*判斷是否要出現食物的變量*/
}food;/*食物的結構體*/
struct Snake
{
int x[N];
int y[N];
int node;/*蛇的節數*/
int direction;/*蛇移動方向*/
int life;/* 蛇的生命,0活著,1死亡*/
}snake;
void Init(void);/*圖形驅動*/
void Close(void);/*圖形結束*/
void DrawK(void);/*開始畫面*/
void GameOver(void);/*結束游戲*/
void GamePlay(void);/*玩游戲具體過程*/
void PrScore(void);/*輸出成績*/
/*主函數*/
void main(void)
{
Init();/*圖形驅動*/
DrawK();/*開始畫面*/
GamePlay();/*玩游戲具體過程*/
Close();/*圖形結束*/
}
/*圖形驅動*/
void Init(void)
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc");
cleardevice();
}
/*開始畫面,左上角坐標為(50,40),右下角坐標為(610,460)的圍墻*/
void DrawK(void)
{
/*setbkcolor(LIGHTGREEN);*/
setcolor(11);
setlinestyle(SOLID_LINE,0,THICK_width="360px",height="auto" /> for(i=50;i<=600;i+=10)/*畫圍墻*/
{
rectangle(i,40,i+10,49); /*上邊*/
rectangle(i,451,i+10,460);/*下邊*/
}
for(i=40;i<=450;i+=10)
{
rectangle(50,i,59,i+10); /*左邊*/
rectangle(601,i,610,i+10);/*右邊*/
}
}
/*玩游戲具體過程*/
void GamePlay(void)
{
randomize();/*隨機數發生器*/
food.yes=1;/*1表示需要出現新食物,0表示已經存在食物*/
snake.life=0;/*活著*/
snake.direction=1;/*方向往右*/
snake.x[0]=100;snake.y[0]=100;/*蛇頭*/
snake.x[1]=110;snake.y[1]=100;
snake.node=2;/*節數*/
PrScore();/*輸出得分*/
while(1)/*可以重復玩游戲,壓ESC鍵結束*/
{
while(!kbhit())/*在沒有按鍵的情況下,蛇自己移動身體*/
{
if(food.yes==1)/*需要出現新食物*/
{
food.x=rand()%400+60;
food.y=rand()%350+60;
while(food.x%10!=0)/*食物隨機出現后必須讓食物能夠在整格內,這樣才可以讓蛇吃到*/
food.x++;
while(food.y%10!=0)
food.y++;
food.yes=0;/*畫面上有食物了*/
}
if(food.yes==0)/*畫面上有食物了就要顯示*/
{
setcolor(GREEN);
rectangle(food.x,food.y,food.x+10,food.y-10);
}
for(i=snake.node-1;i>0;i--)/*蛇的每個環節往前移動,也就是貪吃蛇的關鍵算法*/
{
snake.x[i]=snake.x[i-1];
snake.y[i]=snake.y[i-1];
}
/*1,2,3,4表示右,左,上,下四個方向,通過這個判斷來移動蛇頭*/
switch(snake.direction)
{
case 1:snake.x[0]+=10;break;
case 2: snake.x[0]-=10;break;
case 3: snake.y[0]-=10;break;
case 4: snake.y[0]+=10;break;
}
for(i=3;i<snake.node;i++)/*從蛇的第四節開始判斷是否撞到自己了,因為蛇頭為兩節,第三節不可能拐過來*/
{
if(snake.x[i]==snake.x[0]&&snake.y[i]==snake.y[0])
{
GameOver();/*顯示失敗*/
snake.life=1;
break;
}
}
if(snake.x[0]<55||snake.x[0]>595||snake.y[0]<55||
snake.y[0]>455)/*蛇是否撞到墻壁*/
{
GameOver();/*本次游戲結束*/
snake.life=1; /*蛇死*/
}
if(snake.life==1)/*以上兩種判斷以后,如果蛇死就跳出內循環,重新開始*/
break;
if(snake.x[0]==food.x&&snake.y[0]==food.y)/*吃到食物以后*/
{
setcolor(0);/*把畫面上的食物東西去掉*/
rectangle(food.x,food.y,food.x+10,food.y-10);
snake.x[snake.node]=-20;snake.y[snake.node]=-20;
/*新的一節先放在看不見的位置,下次循環就取前一節的位置*/
snake.node++;/*蛇的身體長一節*/
food.yes=1;/*畫面上需要出現新的食物*/
score+=10;
PrScore();/*輸出新得分*/
}
setcolor(4);/*畫出蛇*/
for(i=0;i<snake.node;i++)
rectangle(snake.x[i],snake.y[i],snake.x[i]+10,
snake.y[i]-10);
delay(gamespeed);
setcolor(0);/*用黑色去除蛇的的最后一節*/
rectangle(snake.x[snake.node-1],snake.y[snake.node-1],
snake.x[snake.node-1]+10,snake.y[snake.node-1]-10);
} /*endwhile(!kbhit)*/
if(snake.life==1)/*如果蛇死就跳出循環*/
break;
key=bioskey(0);/*接收按鍵*/
if(key==ESC)/*按ESC鍵退出*/
break;
else
if(key==UP&&snake.direction!=4)
/*判斷是否往相反的方向移動*/
snake.direction=3;
else
if(key==RIGHT&&snake.direction!=2)
snake.direction=1;
else
if(key==LEFT&&snake.direction!=1)
snake.direction=2;
else
if(key==DOWN&&snake.direction!=3)
snake.direction=4;
}/*endwhile(1)*/
}
/*游戲結束*/
void GameOver(void)
{
cleardevice();
PrScore();
setcolor(RED);
settextstyle(0,0,4);
outtextxy(200,200,"GAME OVER");
getch();
}
/*輸出成績*/
void PrScore(void)
{
char str[10];
setfillstyle(SOLID_FILL,YELLOW);
bar(50,15,220,35);
setcolor(6);
settextstyle(0,0,2);
sprintf(str,"score:%d",score);
outtextxy(55,20,str);
}
/*圖形結束*/
void Close(void)
{
getch();
closegraph();
}
新手要方便寫代碼,可以收藏下面幾個自編函數:
gtxy (6, 3) //光標定位于窗口的第6列,第3行處(準備輸出,行與列都是從0算起)
Color (4, 0) //設置為紅字配黑底 如 Color (10, 0)則是淡綠字配黑底
yinc (1,0) //隱藏光標(第二個參數設為0就隱藏,沒有光標閃爍,yinc代表隱藏)
kou(80,25) //設定窗口緩沖區大小為80列,25行
下面幾個是庫函數,不需自己編寫,只要用#include包含就可以使用。
SetConsoleTitle("俄羅斯方塊"); //設置窗口左上角標題欄處出現"俄羅斯方塊"5個字
srand( (unsigned) time(NULL) ); //初始化隨機數發生器
n= rand( ) % 20; //產生隨機數0-19中的一個. 如 rand( )%5 就產生0-4中的一個數
SetConsoleTitle( )函數在<windows.h>里, srand( )函數與rand( )函數要配合用,
就是同時要用,在<stdlib.h>里。如果 rand( )%10+1 就產生1-10之中的一個數。
Sleep(300); //延時300毫秒(就是程序暫停300毫秒后繼續運行)
system("cls"); //清屏(把窗口里的內容全部清除,光標定于(0,0)位置處)
這兩個函數都在<windows.h>里。開頭4個自編函數 編寫如下:
void gtxy (int x, int y) //控制光標位置的函數
{ COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition ( GetStdHandle (STD_OUTPUT_HANDLE), pos );
}
void Color (short ForeColor= 7, short BackGroundColor= 0) //設定顏色的函數
{ HANDLE hl = GetStdHandle ( STD_OUTPUT_HANDLE );
SetConsoleTextAttribute ( hl, ForeColor + BackGroundColor * 0x10 );
}
聲明時原型可寫 void Color (short x, short y);
void yinc (int x,int y) //隱藏光標的函數
{ CONSOLE_CURSOR_INFO gb={ x , y }; //gb代表光標
SetConsoleCursorInfo ( GetStdHandle(STD_OUTPUT_HANDLE), &gb );
}
void kou(int w,int h) //設置窗口大小的函數
{HANDLE hl=GetStdHandle ( STD_OUTPUT_HANDLE ) ;
COORD size={ w , h };
SetConsoleScreenBufferSize( hl , size );
SMALL_RECT rc={ 0, 0, w, h };
SetConsoleWindowInfo( hl, 1, &rc );
}
最后這個函數,參數w是寬h是高。里邊5行中第一行定義了句柄型變量hl,并給它賦值。
第二行定義了坐標型結構體變量size,它的取值決定了緩沖區的大小。第三行就是使用
size的值設置好緩沖區大小。第四行定義了變量rc,它的值決定當前窗口顯示的位置與
大小(不得超過緩沖區的大小)。前兩個0,0是從緩沖區左上角0列0行位置處開始,后兩
個參數可以小于w和h.比如 rc={0,0,w-10,h-5}; 最后一行使用rc的值設置好窗口,中間
那個參數要為" 1 "或寫“ true ”才有效。
現在都不用tc了那么網上的c語言代碼,graphics。h的庫不能用了
只能用c++的gdi了
簡單點的游戲就貪吃蛇了,沒幾行,至于算法,要么用c++的畫圖函數,要么直接調用api,要么printf加上一些二維數組實現的算法
5、手機pos機怎么安裝下載
為你帶來支付通pos機手機客戶端下載,將支付通pos機下載安裝到手機即可體驗便捷的無線收款功能,還能體驗一站式金融服務。軟件介紹
1、支付通pos機app頁面全新改版,以悅動的橙色為主色調,在滿足商戶收款需求的同時、又重磅推出金融理財服務,帶給商戶不一樣的收款體驗。
2、支付通pos金融理財產品是由金融、法律和電子商務等領域專業人才團隊量身打造并經國有擔保公司擔保,為支付通pos商戶提供更高收益、更高安全、更高靈活的理財產品
3、支付通pos為商戶提供收款服務的同時,解決商戶在經營時不便辦理銀行卡轉賬,信用卡還款、手機充值等業務的燃眉之急。同時也為商戶店面無成本投入下增加客流量,提高店面銷售額。
軟件特色
無線藍牙
借助藍牙技術實現無線收款,無線連接智能升級,智能交易管理。
增值服務
手機充值、信用卡還款、卡卡轉賬、電子錢包充值、水電煤繳費、ETC速通卡充值。
互聯網金融
托管資金,投資理財,保證收益;國有企業擔保產品。
小微“貸”
解決小微商戶資金周轉難題,使其資金流轉效率有效提高。 手機下載軟件方法有很多,為您提供以下幾種方式,請您參考:
1.通過手機中“三星應用商店”或“Galaxy特色訂制”搜索需要的軟件并下載安裝。
2.通過手機瀏覽器搜索需要的軟件下載安裝(若是自帶的瀏覽器,下載的安裝包保存在我的文件-Download文件夾中)。
3.通過第三方助手類軟件下載安裝需要的程序。
4.通過電腦下載APK格式的安裝包,然后傳輸到手機中安裝。 先下載和POS機相匹配的手機軟件然后連接POS機設置就可以用了,很簡單。手續低的pos,我清楚哦 這事5100沒必要找人,現在63都是自己就164可以操作,數是徵

轉載請帶上網址:http://yadikedp.com/posjifour/253211.html
- 上一篇:蘇州怎樣申請個人pos機刷卡器
- 下一篇:poss機低壓保護是什么意思