diff --git a/README.md b/README.md
index 2d341fe..1bb7114 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,11 @@
# Solitaire
*this game make by C langauge
*download file : esay compile
+*gcc -o main main.c *./main
*play game : you move numbers
if you have only one number , then you win
no license
-github page :
+github page : https://sand621.github.io/Solitaire/
diff --git a/_config.yml b/_config.yml
index c741881..f980e76 100644
--- a/_config.yml
+++ b/_config.yml
@@ -1 +1 @@
-theme: jekyll-theme-slate
\ No newline at end of file
+theme: jekyll-theme-slate
diff --git a/data b/data
new file mode 100644
index 0000000..f8c23a6
Binary files /dev/null and b/data differ
diff --git a/index.md b/index.md
new file mode 100644
index 0000000..3def3fd
--- /dev/null
+++ b/index.md
@@ -0,0 +1,20 @@
+Solitaire
+=========
+*this game make by C langauge *download file : esay compile *gcc -o main main.c *./main
+
+*play game : you move numbers if you have only one number , then you win
+
+no license
+
+github page : https://sand621.github.io/Solitaire/
+
+Tutorial
+=========
+you choose one point of number ex) (3,3) = 3 3 (4,5) = 4 5
+
+and you select direction up, down, left ,right , then the number jumps other number and remove number
+
+
+Game Start
+==========
+If you have only one number , then you win
diff --git a/main b/main
new file mode 100755
index 0000000..525f12c
Binary files /dev/null and b/main differ
diff --git a/main.c b/main.c
index 21224fc..8863d8b 100644
--- a/main.c
+++ b/main.c
@@ -1,166 +1,204 @@
#include
#include
+#include
+#include
+#include
+typedef struct numbers Number;
-char c[7][7];
-void title(void);//게임 시작화면
+int c[7][7];
+void title(Number*);//게임 시작화면
void set_sol(void);//솔리테어 판
-void tuto(void);//튜토리얼모드
-void start_game(void);//게임 시작
-void check_key(void);//입력 받은 키가 가능 한지 판단
+void tuto(Number*);//튜토리얼모드
+void start_game(Number*);//게임 시작
+void check_key(Number*);//입력 받은 키가 가능 한지 판단
+void up(Number*,int, int);
+void down(Number*,int, int);
+void right(Number*,int, int);
+void left(Number*,int, int);
+int gameover(Number*);
-void title(void) {
+struct numbers{
+ int numberOfmove;
+ int numberOfelements;
+};
+
+int gameover(Number* this){
+ if (this->numberOfelements==1)
+ return 1;
+ else
+ return 0;
+}
+Number* newNumber(int x, int y){
+ Number *num;
+
+ num=(Number*)malloc(sizeof(Number));
+ num->numberOfmove=x;
+ num->numberOfelements=y;
+};
+
+void up(Number *this,int x, int y) {
+ if ((c[x - 2][y - 1] == 0) || (c[x - 3][y - 1] != 0)){
+ this->numberOfmove++;
+ printf("move number:%d\n",this->numberOfmove);
+ printf("Fail.\n");
+ }
+ else {
+ c[x - 3][y - 1] = c[x - 1][y - 1];
+ c[x - 2][y - 1] = 0;
+ c[x - 1][y - 1] = 0;
+ this->numberOfmove++;
+ this->numberOfelements--;
+ printf("move number:%d, leave numbers:%d\n",this->numberOfmove,this->numberOfelements);
+ };
+};
+void down(Number *this,int x, int y) {
+ if ((c[x][y - 1] == 0) || (c[x + 1][y - 1] != 0)){
+ this->numberOfmove++;
+ printf("move number:%d\n",this->numberOfmove);
+ printf("Fail.\n");
+ }
+ else {
+ c[x + 1][y - 1] = c[x - 1][y - 1];
+ c[x][y - 1] = 0;
+ c[x - 1][y - 1] = 0;
+ this->numberOfmove++;
+ this->numberOfelements--;
+ printf("move number:%d,leave number:%d\n",this->numberOfmove,this->numberOfelements);
+
+ }
+};
+void right(Number *this,int x, int y) {
+ if ((c[x - 1][y] == 0) || (c[x - 1][y + 1] != 0)){
+ this->numberOfmove++;
+ printf("move number:%d\n",this->numberOfmove);
+ printf("Fail.\n");
+ }
+ else {
+ c[x - 1][y + 1] = c[x - 1][y - 1];
+ c[x - 1][y] = 0;
+ c[x - 1][y - 1] = 0;
+ this->numberOfmove++;
+ this->numberOfelements--;
+ printf("move number:%d,leave number:%d\n",this->numberOfmove,this->numberOfelements);
+
+ }
+};
+void left(Number *this,int x, int y) {
+ if ((c[x - 1][y - 2] == 0) || (c[x - 1][y - 3] != 0)){
+ this->numberOfmove++;
+ printf("move number:%d\n",this->numberOfmove);
+ printf("Fail.\n");
+ }
+ else {
+ c[x - 1][y - 3] = c[x - 1][y - 1];
+ c[x - 1][y - 2] = 0;
+ c[x - 1][y - 1] = 0;
+ this->numberOfmove++;
+ this->numberOfelements--;
+ printf("move number:%d,leave numbers:%d\n",this->numberOfmove,this->numberOfelements);
+
+ }
+};
+
+
+void title(Number* this) {
int a;
printf("Select Mode:(1.Tutorial,2.Game start)\n");
scanf("%d", &a);
if (a == 1) {
system("clear");
- tuto();
+ tuto(this);
}
if (a == 2) {
system("clear");
- start_game();
+ start_game(this);
}
}
-void check_key(void) {
+void check_key(Number* this) {
int x, y, a, b;
+ void(*func[])(Number*,int,int) = {down, right,up,left};
+ while(1){
printf("Select Number (x,y):");
- scanf("%d %d", &x, &y);
- printf("Move Number(1.up 2.right 3.down 4.left):");
- scanf("%d", &a);
- if (a == 1) {
- if( (c[x][y - 1] == 0 )||(c[x+1][y-1]!=0))
- printf("Fail.\n");
- else {
- c[x + 1][y - 1] = c[x - 1][y - 1];
- c[x][y - 1] = 0;
- c[x - 1][y - 1] = 0;
- }
- }
- else if (a == 2) {
- if( (c[x - 1][y] == 0) || (c[x-1][y+1]!=0))
- printf("Fail.\n");
- else {
- c[x - 1][y + 1] = c[x - 1][y - 1];
- c[x - 1][y] = 0;
- c[x - 1][y - 1] = 0;
- }
- }
- else if (a == 3) {
- if ((c[x - 2][y - 1] == 0) || (c[x-3][y-1]!=0))
- printf("Fail.\n");
- else {
- c[x - 3][y - 1] = c[x - 1][y - 1];
- c[x - 2][y - 1] = 0;
- c[x - 1][y - 1] = 0;
- }
+ scanf("%d %d", &y, &x);
+ if (c[x-1][y-1]==0)
+ printf("fail\n");
+ else
+ break;
}
- else if (a == 4) {
- if ((c[x - 1][y - 2] == 0) || (c[x-1][y-2]!=0))
- printf("Fail.\n");
- else {
- c[x - 1][y - 3] = c[x - 1][y - 1];
- c[x - 1][y - 2] = 0;
- c[x - 1][y - 1] = 0;
- }
- };
+ printf("Move Number(1.down 2.right 3.up 4.left):");
+ scanf("%d", &a);
+ func[a-1](this,x,y);
+ fflush(stdin);
+
}
void set_sol(void) {
printf(" "); printf("+---+---+---+\n");
- printf(" "); printf("| %c | %c | %c |\n",c[0][2],c[0][3],c[0][4]);
+ printf(" "); printf("| %d | %d | %d |\n",c[0][2],c[0][3],c[0][4]);
printf(" "); printf("+---+---+---+\n");
printf(" "); printf("+---+---+---+\n");
- printf(" "); printf("| %c | %c | %c |\n",c[1][2],c[1][3],c[1][4]);
+ printf(" "); printf("| %d | %d | %d |\n",c[1][2],c[1][3],c[1][4]);
printf(" "); printf("+---+---+---+\n");
- printf("+---+---+"); printf("+---+---+---+"); printf("+---+---+\n");
- printf("| %c | %c |",c[2][0],c[2][1]); printf("| %c | %c | %c |",c[2][2],c[2][3],c[2][4]); printf("| %c | %c |\n",c[2][5],c[2][6]);
- printf("+---+---+"); printf("+---+---+---+"); printf("+---+---+\n");
- printf("+---+---+"); printf("+---+---+---+"); printf("+---+---+\n");
- printf("| %c | %c |",c[3][0],c[3][1]); printf("| %c | %c | %c |",c[3][2],c[3][3],c[3][4]); printf("| %c | %c |\n",c[3][5],c[3][6]);
- printf("+---+---+"); printf("+---+---+---+"); printf("+---+---+\n");
- printf("+---+---+"); printf("+---+---+---+"); printf("+---+---+\n");
- printf("| %c | %c |",c[4][0],c[4][1]); printf("| %c | %c | %c |",c[4][2],c[4][3],c[4][4]); printf("| %c | %c |\n",c[4][5],c[4][6]);
- printf("+---+---+"); printf("+---+---+---+"); printf("+---+---+\n");
+ printf("+---+---+"); printf("+---+---+---+"); printf("+---+---+\n");
+ printf("| %d | %d |",c[2][0],c[2][1]); printf("| %d | %d | %d |",c[2][2],c[2][3],c[2][4]); printf("| %d | %d |\n",c[2][5],c[2][6]);
+ printf("+---+---+"); printf("+---+---+---+"); printf("+---+---+\n");
+ printf("+---+---+"); printf("+---+---+---+"); printf("+---+---+\n");
+ printf("| %d | %d |",c[3][0],c[3][1]); printf("| %d | %d | %d |",c[3][2],c[3][3],c[3][4]); printf("| %d | %d |\n",c[3][5],c[3][6]);
+ printf("+---+---+"); printf("+---+---+---+"); printf("+---+---+\n");
+ printf("+---+---+"); printf("+---+---+---+"); printf("+---+---+\n");
+ printf("| %d | %d |",c[4][0],c[4][1]); printf("| %d | %d | %d |",c[4][2],c[4][3],c[4][4]); printf("| %d | %d |\n",c[4][5],c[4][6]);
+ printf("+---+---+"); printf("+---+---+---+"); printf("+---+---+\n");
printf(" "); printf("+---+---+---+\n");
- printf(" "); printf("| %c | %c | %c |\n",c[5][2],c[5][3],c[5][4]);
+ printf(" "); printf("| %d | %d | %d |\n",c[5][2],c[5][3],c[5][4]);
printf(" "); printf("+---+---+---+\n");
printf(" "); printf("+---+---+---+\n");
- printf(" "); printf("| %c | %c | %c |\n",c[6][2],c[6][3],c[6][4]);
+ printf(" "); printf("| %d | %d | %d |\n",c[6][2],c[6][3],c[6][4]);
printf(" "); printf("+---+---+---+\n");
return;
}
-void tuto(void) {
- c[3][2] = 3, c[3][3] = 4 ;
+void tuto(Number* this) {
+ c[3][2] = 3; c[3][3] = 4 ;
set_sol();
- while (c[3][3]!=0) {
- int x,y,a,b;
- printf("Select Number (x,y):");
- scanf("%d %d",&x,&y);
- printf("Move Number(1.up 2.right 3.down 4.left):");
- scanf("%d", &a);
- if (a == 1) {
- if ((c[x][y - 1] == 0) )
- printf("Fail.\n");
- else {
- c[x + 1][y - 1] = c[x - 1][y - 1];
- c[x][y - 1] = 0;
- c[x - 1][y - 1] = 0;
- }
- }
- else if (a == 2) {
- if (c[x-1][y] == 0)
- printf("Fail.\n");
- else {
- c[x - 1][y + 1] = c[x - 1][y - 1];
- c[x - 1][y] = 0;
- c[x - 1][y - 1] = 0;
- }
- }
- else if (a == 3) {
- if (c[x-2][y - 1] == 0)
- printf("Fail.\n");
- else {
- c[x - 3][y - 1] = c[x - 1][y - 1];
- c[x - 2][y - 1] = 0;
- c[x - 1][y - 1] = 0;
- }
- }
- else if (a == 4) {
- if (c[x-1][y - 2] == 0)
- printf("Fail.\n");
- else {
- c[x - 1][y - 3] = c[x - 1][y - 1];
- c[x - 1][y - 2] = 0;
- c[x - 1][y - 1] = 0;
- }
- fflush(stdin);
- };
+ while (1) {
+ check_key(this);
set_sol();
+ if (this->numberOfelements ==32)
+ break;
}
printf("clear\n");
}
-void start_game(void) {
- c[0][2] = 3, c[0][3] = 4, c[0][4] = 5; c[1][2] = 13, c[1][3] = 14, c[1][4] = 15;
- c[2][0] = 31, c[2][1] = 32, c[2][2] = 33, c[2][3] = 34, c[2][4] = 35, c[2][5] = 36, c[2][6] = 37;
- c[3][0] = 41, c[3][1] = 42, c[3][2] = 43, c[3][3] = 0, c[3][4] = 45, c[3][5] = 46, c[3][6] = 47;
- c[4][0] = 51, c[4][1] = 52, c[4][2] = 53, c[4][3] = 54, c[4][4] = 55, c[4][5] = 56, c[4][6] = 57;
- c[5][2] = 63, c[5][3] = 64, c[5][4] = 65; c[6][2] = 73, c[6][3] = 74, c[6][4] = 75;
+void start_game(Number* this) {
+ FILE *fp=fopen("data","rb");
+/* c[0][2] = 3, c[0][3] = 4, c[0][4] = 5; c[1][2] = 3, c[1][3] = 4, c[1][4] = 5;
+ c[2][0] = 1, c[2][1] = 2, c[2][2] = 3, c[2][3] = 4, c[2][4] = 5, c[2][5] = 6, c[2][6] = 7;
+ c[3][0] = 1, c[3][1] = 2, c[3][2] = 3, c[3][3] = 0, c[3][4] = 5, c[3][5] = 6, c[3][6] = 7;
+ c[4][0] = 1, c[4][1] = 2, c[4][2] = 3, c[4][3] = 4, c[4][4] = 5, c[4][5] = 6, c[4][6] = 7;
+ c[5][2] = 3, c[5][3] = 4, c[5][4] = 5; c[6][2] = 3, c[6][3] = 4, c[6][4] = 5;
+ fwrite(c,sizeof(*c),49,fp);
+ fclose(fp);
+ fp=fopen("data","rb");*/
+ size_t ret_code =fread(c,sizeof(*c),49,fp);
set_sol();
+ int k=0;
while (1) {
- check_key();
+ check_key(this);
set_sol();
-
+ if (this->numberOfelements==1)
+ break;
}
+ fclose(fp);
}
int main(void) {
- title();
+ Number * this=newNumber(0,33);
+ title(this);
return 0;
+ free(this);
}