ហ្គេមតំរៀបលេខ ភាសាC

ទាំងនេះជាហ្គេមតំរៀបលេខដែលសរសេរក្នុងភាសាC ពេលចាប់ផ្តើមលេងវានិងអោយយើង

//វាយលេខចំនួនជួរឈរនិងជួរដេក រួចចាប់ផ្តើមលេង។ លេខត្រូវបានតំរៀបដោយ​ random

//បើ​អ្នក​តំរៀប​លេខ​នោះ​តាម​លំដាប់​កើនចប់​សព្វ​គ្រប់​នោះ​អ្នក​​​និងឈ្នះដោយ​បង្ហាញ​ message យើងអាចធ្វើការរំកិលលេខដោយប្រើ w,a,s,d

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
void ran(int [20][20],int r,int c);
void main()
{
int a[20][20],r,c,i,j;
again:
clrscr();
printf(“ Please enter rows:” );
scanf(“ %d” ,&r);
printf(“ Please enter colums:” );
scanf(“ %d” ,&c);
ran(a,r,c);
clrscr();
char ch;
do
{    clrscr();
printf(“ To EXIT press ‘ESC’!\ta=left,w=up,s=down,d=right\n\n\n” );
for( i=0;i
{    for( j=0;j<c;j++)
{    if(a[i][j]==0)
printf(“      “ );
else
printf(“ %5d” ,a[i][j]);
}
printf(“ \n\n\n” );
}
int z=1;
for(i=0;i
for(j=0;j<c;j++)
if(z==a[i][j])
z++;
else
goto a;
a:
if(z==(r*c))
{    printf(“ You win!” );
printf(“ \nDo u want to play again(y/n):” );
ch=getch();
if(ch==’y’||ch==’Y’)
goto again;
else
goto exit1;
}
ch=getch();
if(ch==’a’||ch==’d’||ch==’s’||ch==’w’)
{    switch(ch)
{    case ‘a’:    for(i=0;i
for(j=0;j<c;j++)
if(a[i][j]==0)
{    if(j==(c-1))
goto exit;
else
{    a[i][j]=a[i][j+1];
a[i][j+1]=0;
}
goto exit;
}
break;
case ‘d’:    for(i=0;i
for(j=0;j<c;j++)
if(a[i][j]==0)
{       if(j==0)
goto exit;
else
{    a[i][j]=a[i][j-1];
a[i][j-1]=0;
}
goto exit;
}
break;
case ‘w’:    for(i=0;i
for(j=0;j<c;j++)
if(a[i][j]==0)
{
if(i==(r-1))
goto exit;
else
{    a[i][j]=a[i+1][j];
a[i+1][j]=0;
}
goto exit;
}
break;
case ‘s’:    for(i=0;i
{    for(j=0;j<c;j++)
if(a[i][j]==0)
{       if(i==0)
goto exit;
else
{    a[i][j]=a[i-1][j];
a[i-1][j]=0;
}
goto exit;
}
}
break;
}
exit:
}
}
while(ch!=27);
getch();
exit1:
}
void ran(int a[20][20],int r,int c)
{  printf(“ Please wait while loading….” );
int b[100],e[100],t=0,j,i;
for(i=0;i<100;i++)
b[i]=0;
for(i=0;i<r*c;i++)
{    again:
randomize();
e[i]=random(10000)%(r*c+1);
for(int j=0;j<=i;j++)
if(b[j]!=e[i])    t++;
else    goto again;
if(t<=i)
{  t=0;
goto again;
}
t=0;
b[i]=e[i];
}
int cre=0,r1,c1,max=r*c;
for(i=0;i<r;i++)
for(j=0;j<c;j++)
{    a[i][j]=e[cre];
cre++;
}
for(i=0;i<r;i++)
for(j=0;j<c;j++)
if(max==a[i][j])
{    r1=i;
c1=j;
}
a[r1][c1]=0;
}

អរគុណចំពោះ ដារ៉ូ មិត្ត​សម្លាញ់ដែល​បាន​ចែកនូវរំលែកកម្មវិធីនេះដល់ខ្ញុំ

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s