Home > Back-end >  2048 C great god to help me see me where there is wrong!
2048 C great god to help me see me where there is wrong!

Time:09-30

Turn to the great god!
 
#include
#include
#include
#include
#include
//define a global variable
Int step=0;
Int score=0;
Long int Time;
Int Board [4] [4]={
0,0,0,0,
0,0,0,0,
0,0,0,0,
0,0,0,0};

HANDLE hOut;
//function declaration
Void the go (int x, int y);//set the coordinates
C int color (int);//set the text color
Int Tcolor (int I);//according to the different Numbers modify colors
Void drawTheGameBoard ();//to draw game interface
Int * add (int item []);//merge number
Int ifMove (int item []);//determine whether can mobile digital
Void Gstart ();//start the game
Void Regame ();//to game
Int if2n (int x);//determine whether for 2 n
Int the up ();//determine whether can move up
Int down ();//determine whether can decrease
Int right ();//determine whether to move right
Int left ();//determine whether to move left
Int BoardMax ();//returns the maximum board
Int Faile ();//determine whether failure
Int Win ();//determine whether victory
Int Control (int key);//set the keyboard
Void the close ();//close game
Void title ();//draw the title
Void choice ();//to make selection box
Void picture ();//character painting;
Void (rule);//the rules of the game
////to get coordinates
Void the go (int x, int y)
{
COORD c;
C.X=x;
C.Y=y;
SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE), c);
}
//set the text color//
Int color (int) c
{
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), c);
return 0;
}

////
menu item
Void choice ()
{
int n;
Int I, j=1;
Color (13);
The go (32, 8);
Printf (" Let 's play a game ");
Color (14);
For (I=9. i<=20; I++)
{
For (j=15; j<=60; J++)
{
The go (j, I);
If (I==9 | | I==20)
{
Printf ("=");
}
Else if (j==15 | | j==59)
{
Printf (" | | ");
}
}
}
Color (12);
The go (25, 12);
Printf (" 1. Start the game ");
The go (40, 12);
Printf (" 2. The rules of the game ");
The go (dec 25);
Printf (" 3. Quit the game ");

Color (5);
The go (21, 22);
Printf (" please select [1, 2, 3], [] b \ \ b ");
The scanf (" % d ", & amp; n);
The switch (n)
{
Case 1:
System (" CLS ");
Gstart ();
break;
Case 2:
break;
Case 3:
exit(0);
break;

}

}



//draw the game board//

Void drawTheGameBoard ()
{
Int I, j, k;
Color (14);
For (j=2; j<=22; J +=5)
{
The go (15, j);
For (k=1; K<42. K++)
{
Printf (" - ");
}
printf("\n");

}
For (I=3; i<7. I++)
{
The go (15, I);
Printf (" | | | | | ");
}
For (I=8; i<12. I++)
{
The go (15, I);
Printf (" | | | | | ");
}
For (I=13; i<17. I++)
{
The go (15, I);
Printf (" | | | | | ");
}
For (I=18; i<22. I++)
{
The go (15, I);
Printf (" | | | | | ");
}

Color (11);
The go (16, 1);
Printf (" game scores: % ld ", score).

Color (13);
The go (42, 1);
Printf (" perform steps: % ld ", step);

Color (10);
The go (44, 23);
Printf (" available: % d s ", time (NULL) - time).

}

//according to the different digital change color//

Int Tcolor (int number)
{
The switch (number)
{
Case 2:
Return color (12);
break;
Case 4:
Return color (11);
break;
Case 8:
Return color (10);
break;
Case 16:
Return color (14);
break;
A case of 32:
Return color (6);
break;
Case: 64
Return color (5);
break;
Case: 128
Return color (4);
break;
Case: 256
Return color (3);
break;
Case: 512
Return color (15);
break;
Case: 1024
Return color (9);
break;
Case: 2048
Return color (7);
break;
}
return 0;

}




//merge number//

Int * add (int item [])
{
Int I, j=0;
Int the teb [4]=,0,0,0 {0};
Int TMP [4]=,0,0,0 {0};

for(i=0; I<4. I++)
{
If (item [I]!=0)
{
The teb [j++]=item [I];
}
}

for(i=0; I<4. I++)
{
If (teb [I]==teb [I + 1])
{
The teb [I] *=2;
The teb [I + 1)=0;
Score=score + teb [I];
}
}

j=0;
for(i=0; I<4. I++)
{
If (teb [0]!=0)
{
TMP/j++=teb [I];
}
}
Return (int *) (& amp; TMP);
}



//determine whether mobile number//

Int ifMove (int item [])
{
int i=0;
for(i=0; i<3; I++)
{
If (item [I]!=0 & amp; & The item [I]==item [I + 1])
{
return 1;
}
If (item [I]==0 & amp; & The item [I + 1)!=0)
{
return 1;
}

}
return 0;
}



//determine whether for 2 n

Int if2n (int x)
{
Int flag=0;
int n;
For (n=1; n<=11; N++)
{
If (x==pow (2, n))
{
Flag=1;
}
}
Return flag;
}

//determine whether can move up
Int the up ()
{
int i,j;
Int flag=0;
for(j=0; j<4. J++)
for(i=0; i<3; I++)
{
If ((if2n (Board [I] [j] + Board [I + 1] [j])==1) & amp; & Board [I + 1] [j])
{
Flag=1;
}
}
Return flag;
}

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related