Special Games Version 1.2 (Source Code)

September 16, 2012 11:51 am C

นี่คือ Source Code ของเกมส์ Special Games Version 1.2 ซึ่งเป็นรายงานของกลุ่มผมในวิชา Computer and Programming ครับ

 

Host by img.kusumoto.co

 

Download Games Now!

#include <stdio.h> //standard function
#include <stdlib.h> //system function
#include <conio.h> //costom function
#include <time.h> //time function
/*
Special Games 
Version 1.2
Mainframe programs by Weerayut Hongsa
http://kusumoto.co
*/
 
FILE *fptr; //Setup file method
 
//function header
void about(void); 
void level1(void);
void level2(void);
void level3(void);
void score(void);
void end(void);
 
int main(void) {
	system("title Special Level Games (Version 1.2) :: Main Manu"); //set title bar
	int a; 
	int b;
	//start manu user interface
	printf("\t########################################\n");
	printf("\t######### Special Level Games ##########\n");
	printf("\t############# Version 1.2 ##############\n");
	printf("\t########## http://kusumoto.co ##########\n");
	printf("\t########################################\n");
	printf("\n\n");
 
	printf("Please Select Manu ?\n");
	printf("1. Play Continue\n");
	printf("2. New Game\n");
	printf("3. Report Score\n");
	printf("4. About\n");
	printf("5. Exit\n");
	printf("Please Select :: ");
	scanf("%d",&a);
	//end manu user interface
	switch(a) {
		case 1 : 
		//Open File for reading
		fptr = fopen("C:\\save.dat", "rb");
		if (fptr == NULL) { //Check File in part
			printf("Save File not found!\n");
			system("pause");
			system("cls");
			main(); 
		}
		rewind(fptr);
		fread(&b, sizeof(int), 1, fptr);
			if (feof(fptr)) break;
		//	printf("%d",b); //Degug save game
		if (b==1) {
		level2();
		//Open File for writing
 
		fptr = fopen("c:\\save.dat", "wb");
		if (fptr == NULL) { //Check File in part
			printf("\n Error open file");
			exit(1); 
		}
		b = 2;
		fwrite(&b, sizeof(int), 1, fptr);
		fclose(fptr); //Close File
 
	 	level3();
	 	//Open File for writing
 
		fptr = fopen("c:\\save.dat", "wb");
		if (fptr == NULL) { //Check File in part
			printf("\n Error open file");
			exit(1); 
		}
		b = 3;
		fwrite(&b, sizeof(int), 1, fptr);
		fclose(fptr); //Close File
 
		}
		if (b==2) {
		level3();
		if (fptr == NULL) { //Check File in part
			printf("\n Error open file");
			exit(1); 
		}
		b = 3;
		fwrite(&b, sizeof(int), 1, fptr);
		fclose(fptr); //Close File
		}
		if (b==3) {
           system("cls"); //clear screen
		printf("Thanks you for playing ^_^\n");
		system("pause");
		system("cls"); //clear screen
		main();
	}
		break;
		case 2 :
 
  		//Open File for writing
 
		fptr = fopen("c:\\save.dat", "wb");
		if (fptr == NULL) { //Check File in part
			printf("\n Error open file");
			exit(1); 
		}
		level1();
		b = 1;
		fwrite(&b, sizeof(int), 1, fptr);
		fclose(fptr); //Close File
		level2();
		//Open File for writing
		fptr = fopen("c:\\save.dat", "wb");
		if (fptr == NULL) { //Check File in part
			printf("\n Error open file");
			exit(1); 
		}
		b = 2;
		fwrite(&b, sizeof(int), 1, fptr);
		fclose(fptr); //Close File
		level3();
		//Open File for writing
		fptr = fopen("c:\\save.dat", "wb");
		if (fptr == NULL) { //Check File in part
			printf("\n Error open file");
			exit(1); 
		}
		b = 3;
		fwrite(&b, sizeof(int), 1, fptr);
		fclose(fptr); //Close File
		printf("\n");
		about();
		break;
		case 3 :
		score();
		break;
		case 4 :
		//printf("Test4"); //Test Manu
		about();
		break;
		case 5 :
		end();
		break;
		default:
		printf("Error :: Number is incorect!\n");
		system("pause");
		system("cls");
		main();
	}
}
void about(void) {
	system("cls"); //clear screen
	system("title Special Level Games (Version 1.2) :: About"); //set title bar
	printf("######### About this games ##########\n");
	printf("############ Programmer #############\n\n");
	printf("1. Weerayut Hongsa (Kusumoto) \n");
	printf("2. Chanwit Julrod\n");
	printf("3. Pongsakorn Thongnuan\n");
	printf("4. Anawat Leatongkam\n");
	printf("5. Nuttapant Kasetwatanapol\n");
	system("pause"); //pause screen
	system("cls"); //clear screen
	main();
}
void level1(void) {
	system("cls"); //clear screen
	system("title Special Level Games (Version 1.2) :: Level 1"); //set title bar
	int x,y;
	char t;
	printf("############## Level 1 #################\n\n");
	//Programs by Chanwit
	printf("Math For Nutty Game Y^_^Y \n\n\n");
	//Math Ex1
	do{
		printf("1) x + 5 = 10\n");
		printf("x = ? >>>");
		scanf("%d",&y);
		if(y==5){
			printf(">>True (^_^) <<\n");
			printf("Do you want to Next? press >>N<< ");
		}else{
			printf(">>False (>_<) <<\n");
			printf("Try agine press >>A<< OR Next press >>N<<\n");
		}
		scanf("%s",&t);
	}while(t!= 'n' && t!= 'N');
		//Math Ex2
	do{
		printf("2) 2x + 16 = 30\n");
		printf("x = ? >>>");
		scanf("%d",&y);
		if(y==7){
			printf(">>True (^_^) <<\n");
			printf("Do you want to Next? press >>N<< ");
		}else{
		printf(">>False (>_<) <<\n");
		printf("Try agine press >>A<< OR Next press >>N<<\n");
		}
		scanf("%s",&t);
	}while(t!= 'n' && t!= 'N');
		//math Ex3
	do{
		printf("3) 3x + 5 = 2x + 20\n");
		printf("x = ? >>>");
		scanf("%d",&y);
		if(y==15){
			printf(">>True (^_^) <<\n");
			printf("Do you want to Next? press >>N<< ");
		}else{
		printf(">>False (>_<) <<\n");
		printf("Try agine press >>A<< OR Next press >>N<<\n");
		}
		scanf("%s",&t);
	}while(t!= 'n' && t!= 'N');
		//Math Ex4
	do{
		printf("4) 5x + 5 = 3x + 45\n");
		printf("x = ? >>>");
		scanf("%d",&y);
		if(y==20){
			printf(">>True (^_^) <<\n");
			printf("Do you want to Next? press >>N<< ");
		}else{
			printf(">>False (>_<) <<\n");
			printf("Try agine press >>A<< OR Next press >>N<<\n");
		}
		scanf("%s",&t);
	}while(t!= 'n' && t!= 'N');
		//Math Ex5
	do{
		printf("5) 3x - 5 = -x + 11\n");
	printf("x = ? >>>");
	scanf("%d",&y);
	if(y==4){
		printf(">>True (^_^) <<\n");
		printf("Do you want to Next? press >>N<< ");
	}else{
		printf(">>False (>_<) <<\n");
		printf("Try agine press >>A<< OR Next press >>N<<\n");
	}
	scanf("%s",&t);
	}while(t!= 'n' && t!= 'N');
		//Math Ex6
	do{
		printf("6) 2(x - 5) = -x + 5\n");
		printf("x = ? >>>");
		scanf("%d",&y);
		if(y==5){
			printf(">>True (^_^) <<\n");
			printf("Do you want to Next? press >>N<< ");
		}else{
			printf(">>False (>_<) <<\n");
			printf("Try agine press >>A<< OR Next press >>N<<\n");
		}
		scanf("%s",&t);
	}while(t!= 'n' && t!= 'N');
		//Math Ex7
	do{
		printf("7) 5(x - 5) = 3(x + 1)\n");
		printf("x = ? >>>");
		scanf("%d",&y);
		if(y==14){
			printf(">>True (^_^) <<\n");
			printf("Do you want to Next? press >>N<< ");
		}else{
			printf(">>False (>_<) <<\n");
			printf("Try agine press >>A<< OR Next press >>N<<\n");
		}
		scanf("%s",&t);
	}while(t!= 'n' && t!= 'N');
		//Math Ex8
	do{
		printf("8) 3(x - 5) = -x + 25\n");
		printf("x = ? >>>");
		scanf("%d",&y);
		if(y==10){
			printf(">>True (^_^) <<\n");
			printf("Do you want to Next? press >>N<< ");
		}else{
			printf(">>False (>_<) <<\n");
			printf("Try agine press >>A<< OR Next press >>N<<\n");
		}
		scanf("%s",&t);
	}while(t!= 'n' && t!= 'N');
		//Math Ex9
	do{
		printf("9) [2(x+1)-(x+2)] = -x + 100\n");
		printf("x = ? >>>");
		scanf("%d",&y);
		if(y==50){
			printf(">>True (^_^) <<\n");
			printf("Do you want to Next? press >>N<< ");
		}else{
			printf(">>False (>_<) <<\n");
			printf("Try agine press >>A<< OR Next press >>N<<\n");
		}
		scanf("%s",&t);
	}while(t!= 'n' && t!= 'N');
		//Math Ex10
	do{
		printf("10) [3(x+1)-(x-1002)] = x + 999\n");
		printf("x = ? >>>");
		scanf("%d",&y);
		if(y==0){
			printf(">>True (^_^) <<\n");
			printf("Do you want to Next? press >>N<< ");
		}else{
			printf(">>False (>_<) <<\n");
			printf("Try agine press >>A<< OR Next press >>N<<\n");
		}
		scanf("%s",&t);
	}while(t!= 'n' && t!= 'N');
		printf("\n\n");
		printf("Level 1 Complete!\n");
		printf("Game Saved\n");
		system("pause");
}
 
void level2(void) {
	system("title Special Level Games (Version 1.2) :: Level 2");//set title bar
 
	system("cls"); //clear screen
	printf("############## Level 2 #################\n\n");
	//Program by Anawat
	int ran;
	int g;
	int c=1;
	srand(time(NULL)); //use srand by time
	ran = 1 + rand( ) % 100; //random number 1-100 to variable
	printf("Random 1-100\n");
	do{
		printf("%d : ",c); //numberial to answer
		scanf("%d",&g);
		c++; //numberial to answer + 1
		if(g > ran)
			printf("!!! little more !!!\n");
		else if(g < ran)
			printf("!!! more than !!!\n");
	}while(ran != g);
	printf("--- the number %d is correct number in random ---\n",g);
	printf("--- you guess is %d count ---\n",c-1);
	printf("\n\n");
		printf("Level 2 Complete!\n");
		printf("Game Saved\n");
		system("pause"); //pause screen
}
 
void level3(void) {
	//Program by Pongsakorn
	system("cls"); //clear screen
	system("title Special Level Games (Version 1.2) :: Level 3"); //set title bar
	printf("############## Level 3 #################\n\n\n\n");
	printf("####  Twenty Four Games  ###\n\n\n");
	int j1,k1;
	int o1[4];
	int i1;
	int data1[2][2]={4,7,7,7};
	for(j1=0;j1<2;j1++){
		for(k1=0;k1<2;k1++){
			printf("    %d",data1[j1][k1]);
		}
	printf("\n\n");
	}
	printf("\n");
	do{
	printf("1.) __ - ( __ / __ ) * __ = 24\n\n");
	for(i1=0;i1<=3;i1++){
	printf("%d = ",i1+1);
	scanf("%d",&o1[i1]);
	}
	if(o1[0]==7 && o1[1]==7 && o1[2]==7 && o1[3]==4){
	printf("True\n");	printf("\n");
	printf("\n");
	}
	else{
	printf("False\n");		printf("\n");
	printf("\n");
	}
	}while(o1[0]!=7 || o1[1]!=7 || o1[2]!=7 || o1[3]!=4);
	printf("\n");
	printf("\n");
	//end 1
	int j2,k2;
	int o2[4];
	int i2;
	int data2[2][2]={2,2,5,8};
	for(j2=0;j2<2;j2++){
		for(k2=0;k2<2;k2++){
			printf("    %d",data2[j2][k2]);
		}
	printf("\n\n");
	}
	printf("\n");
	do{
	printf("2.) (( __ + __ ) * __ ) - __ = 24\n\n");
	for(i2=0;i2<=3;i2++){
	printf("%d = ",i2+1);
	scanf("%d",&o2[i2]);
	}
	if(o2[0]==5,8 && o2[1]==8,5 && o2[2]==2 && o2[3]==2){
	printf("True\n");	printf("\n");
	printf("\n");
	}
	else{
	printf("False\n");		printf("\n");
	printf("\n");
	}
	}while(o2[0]!=5 || o2[1]!=8 || o2[2]!=2 || o2[3]!=2);
		printf("\n");
	printf("\n");
	//end
	int j3,k3;
	int o3[4];
	int i3;
	int data3[2][2]={3,7,4,7};
	for(j3=0;j3<2;j3++){
		for(k3=0;k3<2;k3++){
			printf("    %d",data3[j3][k3]);
		}
	printf("\n\n");
	}
	printf("\n");
	do{
	printf("3.) ( __ * __ ) - ( __ - __ ) = 24\n\n");
	for(i3=0;i3<=3;i3++){
	printf("%d = ",i3+1);
	scanf("%d",&o3[i3]);
	}
	if(o3[0]==4 && o3[1]==7 && o3[2]==7 && o3[3]==3){
	printf("True\n");	printf("\n");
	printf("\n");
	}
	else{
	printf("False\n");		printf("\n");
	printf("\n");
	}
	}while(o3[0]!=4 || o3[1]!=7 || o3[2]!=7 || o3[3]!=3);
		printf("\n");
	printf("\n");
	//end 3
	int j4,k4;
	int o4[4];
	int i4;
	int data4[2][2]={2,6,5,3};
	for(j4=0;j4<2;j4++){
		for(k4=0;k4<2;k4++){
			printf("    %d",data4[j4][k4]);
		}
	printf("\n\n");
	}
	printf("\n");
	do{
	printf("4.) ( __ * __ * __ ) - __ = 24\n\n");
	for(i4=0;i4<=3;i4++){
	printf("%d = ",i4+1);
	scanf("%d",&o4[i4]);
	}
	if(o4[0]==2,5,3 && o4[1]==5,2,3 && o4[2]==3,5,2 && o4[3]==6){
	printf("True\n");	printf("\n");
	printf("\n");
	}
	else{
	printf("False\n");		printf("\n");
	printf("\n");
	}
	}while(o4[0]!=2 || o4[1]!=3 || o4[2]!=5 || o4[3]!=6);
		printf("\n");
	printf("\n");
	//end 4
	int j5,k5;
	int o5[4];
	int i5;
	int data5[2][2]={3,7,8,5};
	for(j5=0;j5<2;j5++){
		for(k5=0;k5<2;k5++){
			printf("    %d",data5[j5][k5]);
		}
	printf("\n\n");
	}
	printf("\n");
	do{
	printf("5.) ( __ * __ ) + ( __ - __ ) = 24\n\n");
	for(i5=0;i5<=3;i5++){
	printf("%d = ",i5+1);
	scanf("%d",&o5[i5]);
	}
	if(o5[0]==3,7 && o5[1]==7,3 && o5[2]==8 && o5[3]==5){
	printf("True\n");	printf("\n");
	printf("\n");
	}
	else{
	printf("False\n");		printf("\n");
	printf("\n");
	}
	}while(o5[0]!=3 || o5[1]!=7 || o5[2]!=8 || o5[3]!=5);
		printf("\n");
	printf("\n");
	//end 5
		printf("\n\n");
		printf("Level 3 Complete!\n");
		printf("Game Saved\n");
		system("pause"); //pause screen
		system("cls"); //clear screen
		printf("Thanks you for playing ^_^\n");
		system("pause");
		system("cls");
	}
 
void score(void) {
	system("title Special Level Games (Version 1.2) :: Score View"); //set title bar
	int b;
	//Open File for reading
		fptr = fopen("C:\\save.dat", "rb");
		if (fptr == NULL) { //Check File in part
			printf("Save File not found!\n");
			system("pause");
			system("cls");
			main();
		}
		rewind(fptr);
		fread(&b, sizeof(int), 1, fptr);
			if (feof(fptr)) exit(1);
 
		printf("Your Level :: %d\n",b);
		printf("Your Score :: %d\n",b*10);
		system("pause");
		system("cls");
		main();
}
 
void end(void) {
	system("cls");
	system("title Special Level Games (Version 1.2) :: Exit"); //set title bar
	char a;
 
	printf("     $$$**                                  **$$$\n");
 
printf("     $$$$$$$$*                          ,,$$$$$$$$*\n"); 
 
printf("      $$$$$$$$$$,,                   ,,$$$$$$$$$$*\n");
 
printf("       $$$$$$$$$$$$   .         .   $$$$$$$$$$$$\n");
 
printf("        $$$$$$$$$$$$$, '.     .' ,,$$$$$$$$$$$$$\n");
 
printf("        $$$$$$$$$$$$$$,, '. ,'  $$$$$$$$$$$$$$$\n");
 
printf("          $$$$$$$$$$$$$$$$.@:.$$$$$$$$$$$$$$$$\n");
 
printf("            ***$$$$$$$$$$$@@$$$$$$$$$$$***\n");
 
printf("             ,,,,,,,*$$$$$$@.$$$$$$,,,,,,\n");
 
printf("          ,,$$$$$$$$$$$$$* @ *$$$$$$$$$$$$,,\n");
 
printf("          *$$$$$$$$$$$$$* @@  *$$$$$$$$$$$$$\n");
 
printf("      ,,*$$$$$$$$$$$$$*   .@.   *$$$$$$$$$$$$$,,\n");
 
printf("   ,,*   *$$$$$$$$$$$      *      *$$$$$$$$$$*    *',, \n");
 
printf(" *     ,,*$$$$$$$$$$                $$$$$$$$$$*,,      * \n");
 
printf("         ,;***,$$**'                **'$$***,,\n");
 
printf("      ,;'*     .*                     .*      '*,, \n");
 
printf(",,,,.;*                                          '**,,,, \n");
printf("Do you want to Exit games ? (y/n)");
scanf("%s",&a);
if (a == 'y') {
	exit(1);
} else {
	system("cls");
	main();
}
}