diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 00000000..3cefc3b7 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,66 @@ +{ + "configurations": [ + { + "name": "Mac", + "includePath": [ + "${workspaceRoot}", + "/usr/include", + "/usr/local/include" + ], + "defines": [], + "browse": { + "path": [ + "/usr/include", + "/usr/local/include" + ], + "limitSymbolsToIncludedHeaders": true, + "databaseFilename": "" + } + }, + { + "name": "Linux", + "includePath": [ + "${workspaceRoot}", + "/usr/include", + "/usr/local/include" + ], + "defines": [], + "browse": { + "path": [ + "/usr/include", + "/usr/local/include" + ], + "limitSymbolsToIncludedHeaders": true, + "databaseFilename": "" + } + }, + { + "name": "Win32", + "includePath": [ + "${workspaceRoot}", + "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include/*", + "C:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/um", + "C:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/ucrt", + "C:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/shared", + "C:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/winrt" + ], + "defines": [ + "_DEBUG", + "UNICODE" + ], + "browse": { + "path": [ + "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include/*", + "C:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/um", + "C:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/ucrt", + "C:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/shared", + "C:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/winrt" + ], + "limitSymbolsToIncludedHeaders": true, + "databaseFilename": "" + } + } + + + ] +} diff --git a/practices/c/level0/0-9.c b/practices/c/level0/0-9.c new file mode 100644 index 00000000..3897d3a6 --- /dev/null +++ b/practices/c/level0/0-9.c @@ -0,0 +1,20 @@ +#include +int main(void) +{ + int number[10]={0}; + int i,j; + + for(i=1;i<=5;i++){ + scanf("%d",&j); + number[j]=1; + } + + for(i=1;i<=9;i++){ + if(number[i]==0){ + printf("%d",i); + } + + } + return 0; +} + diff --git "a/practices/c/level0/10000\342\200\224hello.c" "b/practices/c/level0/10000\342\200\224hello.c" new file mode 100644 index 00000000..98cc2d69 --- /dev/null +++ "b/practices/c/level0/10000\342\200\224hello.c" @@ -0,0 +1,14 @@ +#include + +int main(void) +{ + int i = 0; + + for(i = 0;i <1000;++i){ + printf("Hello!\n"); + } + + return 0; + +} + diff --git a/practices/c/level0/100_ou_shu.c b/practices/c/level0/100_ou_shu.c new file mode 100644 index 00000000..0cf91799 --- /dev/null +++ b/practices/c/level0/100_ou_shu.c @@ -0,0 +1,15 @@ +#include + +int main(void) +{ + int ou,i=0; + + for(ou = 2;i < 50;++i){ + printf("%d\n",ou); + ou += 2; + } + + return 0; + +} + diff --git "a/practices/c/level0/13\347\232\204\345\200\215\346\225\260\345\210\244\346\226\255.c" "b/practices/c/level0/13\347\232\204\345\200\215\346\225\260\345\210\244\346\226\255.c" new file mode 100644 index 00000000..10a744f6 --- /dev/null +++ "b/practices/c/level0/13\347\232\204\345\200\215\346\225\260\345\210\244\346\226\255.c" @@ -0,0 +1,15 @@ +#include + +int main(void) +{ + int n = 0; + printf("Please input n:"); + scanf("%d",&n); + + if (0==n%13) + printf("%d ÊÇ13µÄ±¶Êý",n); + else + printf("%d ²»ÊÇ13µÄ±¶Êý",n); + + return 0; +} diff --git a/practices/c/level0/3_5.c b/practices/c/level0/3_5.c new file mode 100644 index 00000000..5954d28b --- /dev/null +++ b/practices/c/level0/3_5.c @@ -0,0 +1,17 @@ +#include + +int main(void) +{ + int k,i=0; + + for(k =0 ;i <= 100;++i){ + k = ++k; + if(0 == k % 3 && 0 != k % 5){ + printf("%d\n",k); + } + } + + return 0; + +} + diff --git a/practices/c/level0/7.c b/practices/c/level0/7.c new file mode 100644 index 00000000..874db0de --- /dev/null +++ b/practices/c/level0/7.c @@ -0,0 +1,22 @@ +#include + +int main(void) +{ + int k,j=0,i=0; + + for(k =0 ;i < 100;++i){ + k = ++k; + if(0 == k % 7 ){ + printf("%d\n",k); + } + } + + for( j = 0;j<10;++j){ + printf("%d\n",k=j*10+7); + } + + + return 0; + +} + diff --git a/practices/c/level0/99.c b/practices/c/level0/99.c new file mode 100644 index 00000000..adb1db5b --- /dev/null +++ b/practices/c/level0/99.c @@ -0,0 +1,16 @@ +#include + +int main(void) +{ + int i,j; + + for(i=1;i<=9;++i){ + for(j=1;j<=i;++j) + printf("%d*%d=%d\t",j,i,i*j); + printf("\n"); + } + + + return 0; +} + diff --git a/practices/c/level0/99.exe b/practices/c/level0/99.exe new file mode 100644 index 00000000..ae633c15 Binary files /dev/null and b/practices/c/level0/99.exe differ diff --git a/practices/c/level0/99.o b/practices/c/level0/99.o new file mode 100644 index 00000000..dc15c62b Binary files /dev/null and b/practices/c/level0/99.o differ diff --git a/practices/c/level0/factorial.c b/practices/c/level0/factorial.c new file mode 100644 index 00000000..4b46bc00 --- /dev/null +++ b/practices/c/level0/factorial.c @@ -0,0 +1,26 @@ +#include + + int fac(int i){ + if (1 == i) + return 1; + else + return i*fac(i-1); + } + +int main(void){ + + int i,j; + printf("Please input j:"); + scanf("%d",&j); + + for (i=1;i<=j;++i){ + fac(j); + } + + printf("%d! = %d",j,fac(j)); + + + + + return 0; +} diff --git a/practices/c/level0/fibonacci.c b/practices/c/level0/fibonacci.c new file mode 100644 index 00000000..62d45cb4 --- /dev/null +++ b/practices/c/level0/fibonacci.c @@ -0,0 +1,26 @@ +#include +#define SIZE 10 + +int fibonacci(int n) +{ + if (n == 0) + return 0; + else if (n == 1) + return 1; + else + return fibonacci(n-1)+fibonacci(n-2); +} + +int main(void) +{ + int i,j; + printf("Input j:"); + scanf("%d",&j); + + for (i=0;i + +/* run this program using the console pauser or add your own getch, system("pause") or input loop */ + +int main(int argc, char *argv[]) { + printf("hello world,I am Duan Linlin!"); + return 0; +} diff --git a/practices/c/level0/n.c b/practices/c/level0/n.c new file mode 100644 index 00000000..07b20556 --- /dev/null +++ b/practices/c/level0/n.c @@ -0,0 +1,27 @@ +#include +#define M 10000 +int main(void) +{ + int i,j=0,n; + int a[M],b[M]; + + printf("please input n:\n"); + scanf("%d",&n); + printf("please input %d numbers:\n",n); + + for(i=1;i<=n;++i){ + scanf("%d",&a[i]); + } + + for(i=n;i>=0;i--){ + b[++j]=a[i]; + } + + for(i=1;i<=n;++i){ + printf("%d\t",b[i]); + } + + return 0; +} + + diff --git a/practices/c/level0/pai_xu.c b/practices/c/level0/pai_xu.c new file mode 100644 index 00000000..dd5168d1 --- /dev/null +++ b/practices/c/level0/pai_xu.c @@ -0,0 +1,27 @@ +#include +#include +int main(void) + +{ + int array[10]; + int i,j,k; + + for(i=0;i<=9;++i){ + array[i]=0; + } + + for(i=1;i<=5;++i){ + scanf("%d",&k); + array[k]++; + } + + for(i=0;i<=9;++i){ + for(j=1;j<=array[i];++j){ + printf("%d\t",i); + } + } + + system("pause"); + + return 0; +} diff --git a/practices/c/level0/rate.c b/practices/c/level0/rate.c new file mode 100644 index 00000000..c467c499 --- /dev/null +++ b/practices/c/level0/rate.c @@ -0,0 +1,15 @@ +#include +#define RATE 6.90698365 + +int main(void){ + int dollar,RMB; + printf("Please input dollar:"); + scanf("%d",&dollar); + RMB = dollar * RATE; + printf("%d dollar = %d RMB",dollar,RMB); + + return 0; + + + +} diff --git a/practices/c/level0/run_nian.c b/practices/c/level0/run_nian.c new file mode 100644 index 00000000..3484e321 --- /dev/null +++ b/practices/c/level0/run_nian.c @@ -0,0 +1,17 @@ +#include + +int main(void) +{ + int year = 0; + + printf("Please input year:"); + scanf("%d",&year); + + if ((0 != year % 100 && 0 == year % 4) || 0 == year % 400) + + printf("%d is leap year",year); + else + printf("%d 不是闰年",year); + + return 0; +} diff --git a/practices/c/level0/shu_zu_he.c b/practices/c/level0/shu_zu_he.c new file mode 100644 index 00000000..c8d00ba0 --- /dev/null +++ b/practices/c/level0/shu_zu_he.c @@ -0,0 +1,23 @@ +#include +#define SIZE 10 + +int main(void) +{ + int array[SIZE]; + int i,j,sum=0; + printf("Please input shu_zu_yuan_su:"); + + for (i=0;i<10;i++){ + scanf("%d",&j); + array[i]=j; + } + + for (i=0;i<10;i++){ + sum = sum + array[i]; + } + + printf("The sum of array[%d] is:%d ",SIZE,sum); + + return 0; +} + diff --git a/practices/c/level0/zhi_jiao_triangle.c b/practices/c/level0/zhi_jiao_triangle.c new file mode 100644 index 00000000..0525877c --- /dev/null +++ b/practices/c/level0/zhi_jiao_triangle.c @@ -0,0 +1,15 @@ +#include + +int main(void){ + int a,b,c; + printf("Please input a,b,c of triangle:\n"); + scanf("%d,%d,%d",&a,&b,&c); + + if(a*a == b*b + c*c || b*b == c*c + a*a || c*c == a*a + b*b) + printf("Ϊֱ\n"); + else + printf("βֱ\n"); + + return 0; + +} diff --git "a/practices/c/level0/\345\217\226n\344\270\252\346\225\260\344\270\255\346\234\200\345\244\247\346\225\260.c" "b/practices/c/level0/\345\217\226n\344\270\252\346\225\260\344\270\255\346\234\200\345\244\247\346\225\260.c" new file mode 100644 index 00000000..055e5985 --- /dev/null +++ "b/practices/c/level0/\345\217\226n\344\270\252\346\225\260\344\270\255\346\234\200\345\244\247\346\225\260.c" @@ -0,0 +1,23 @@ +#include + +int main(void) +{ + int m,n,l,s,i; + printf("您想输入几个数字:"); + scanf("%d",&n); + printf("please input %d numbers:\n",n); + + for(i=0;il){ + s=m; + l=s;} + } + + printf("%d 是这些数字中最大的",s); + + + return 0; + +} + diff --git "a/practices/c/level0/\345\245\207\345\201\266\346\255\243\350\264\237.c" "b/practices/c/level0/\345\245\207\345\201\266\346\255\243\350\264\237.c" new file mode 100644 index 00000000..6a21a3e4 --- /dev/null +++ "b/practices/c/level0/\345\245\207\345\201\266\346\255\243\350\264\237.c" @@ -0,0 +1,23 @@ +#include + +int main(void) +{ + int n = 0; + + printf("Please input n:"); + scanf("%d",&n); + + if (n>0) + printf("%d is positive number\n",n); + else if (n<0) + printf("%d is negative number\n",n); + else + printf("%d is zero\n",n); + + if (0 == n % 2) + printf("%d is a even\n",n); + else + printf("%d is a obb\n",n); + + return 0; +} diff --git a/practices/c/level1/p01_runningLetter/Runningletter.c b/practices/c/level1/p01_runningLetter/Runningletter.c new file mode 100644 index 00000000..07808aaf --- /dev/null +++ b/practices/c/level1/p01_runningLetter/Runningletter.c @@ -0,0 +1,38 @@ +#include +#include +#include +#define TIME 10 +#define RUOTE 118 + +void runningletter(int i); + +int main(void) +{ + int i=RUOTE; + + while(1){ + runningletter(i); + } + return 0; +} + +void runningletter(int i){ + int j,k; + for(j=0;j=0;j--){ + for(k=0;k<=j;k++){ + printf(" "); + } + printf("s"); + Sleep(TIME); + system("cls"); + } +} diff --git a/practices/c/level1/p02_isPrime/is_prime.c b/practices/c/level1/p02_isPrime/is_prime.c new file mode 100644 index 00000000..3a40822a --- /dev/null +++ b/practices/c/level1/p02_isPrime/is_prime.c @@ -0,0 +1,28 @@ +#include +#include + +int is_prime(int n){ + if(n<2) + return 0; + if(n==2) + return 1; + else + for(int i=2;i<=sqrt(n);i++){ + if(n%i==0){ + return 0; + break; + } + } + return 1; +} + +int main(void){ + int n; + printf("please input n:\n"); + scanf("%d",&n); + if(is_prime(n)) + printf("%d is a prime",n); + else + printf("%d is not a prime",n); + return 0; +} diff --git a/practices/c/level1/p03_Diophantus/Diophantus.c b/practices/c/level1/p03_Diophantus/Diophantus.c new file mode 100644 index 00000000..4008acb3 --- /dev/null +++ b/practices/c/level1/p03_Diophantus/Diophantus.c @@ -0,0 +1,12 @@ +#include + +int main() +{ + int age; + for(age = 1;age <= 250; age++){ + if((age/6 + age/7 + age/12 + 5 + age/2 + 4 == age & age%6==0 & age%7==0 & age%12==0)){ + printf("The age is %d.\n",age-4); + } + } + return 0; +} diff --git a/practices/c/level1/p04_ narcissus/shui_xian_shu.c b/practices/c/level1/p04_ narcissus/shui_xian_shu.c new file mode 100644 index 00000000..11318684 --- /dev/null +++ b/practices/c/level1/p04_ narcissus/shui_xian_shu.c @@ -0,0 +1,23 @@ +#include + +int main(void) +{ + int bai,shi,ge; + int shui_xian_shu; + + printf("Please output all shui_xian_shus:\n"); + for(bai=1;bai<10;++bai){ + for(shi=0;shi<10;++shi){ + for(ge=0;ge<10;++ge){ + shuixianshu = bai*100 + shi*10 + ge; + + if (bai*bai*bai + shi*shi*shi + ge*ge*ge == shui_xian_shu) + printf("%5d\n",shui_xian_shu); + } + } + } + + printf("\n"); + + return 0; +} diff --git a/practices/c/level1/p05_allPrimes/All_prime.c b/practices/c/level1/p05_allPrimes/All_prime.c new file mode 100644 index 00000000..ceea6fa9 --- /dev/null +++ b/practices/c/level1/p05_allPrimes/All_prime.c @@ -0,0 +1,28 @@ +#include +#include +#include +#define MAX 1000000 + +int main(void) +{ + int i=1,number1,number2; + for(number1 = 2 ; number1 <= MAX ; number1++){ + int k = sqrt(number1 + 1); + for(number2 = 2 ; number2 <= k ; number2++){ + if(number1 % number2 != 0){ + i=1; + } + else{ + i=0; + break; + } + } + if(i == 1) + printf("%d\t",number1); + } + printf("\n"); + printf("The time is %d.\n",clock()); + + return 0; +} + diff --git a/practices/c/level1/p06_Goldbach/Goldbach(plus).c b/practices/c/level1/p06_Goldbach/Goldbach(plus).c new file mode 100644 index 00000000..f5accbd8 --- /dev/null +++ b/practices/c/level1/p06_Goldbach/Goldbach(plus).c @@ -0,0 +1,53 @@ +#include +#include +#include +#define MAX 10000 + +int prime(int a); +int Goldbahe(int b); +int pri[MAX]={0}; + +int main(void){ + int n; + printf("please input n(4~%dÖ®¼äµÄżÊý):",MAX); + scanf("%d",&n); + + if(n%2 == 0){ + prime(MAX); + Goldbahe(n); + } + + else{ + printf("error input"); + } + + return 0; + } + +int prime(int a){ + int i,j; + + if(i=1){ + pri[i]=1;} + if(i=2){ + pri[i]=0;} + for(i=3;i<=MAX;i++){ + for(j=2;j<=sqrt(i);j++){ + if(i%j==0){ + pri[i]=1; + } + } + } +} + +int Goldbahe(int b){ + int i,j; + for(i=1;i<=MAX;i++){ + for(j=i;j<=MAX;j++){ + if(pri[i]==0&pri[j]==0&b==i+j){ + printf("%d = %d + %d\n",b,i,j); + } + } + } + } + diff --git a/practices/c/level1/p06_Goldbach/Goldbach.c b/practices/c/level1/p06_Goldbach/Goldbach.c new file mode 100644 index 00000000..506c2c2a --- /dev/null +++ b/practices/c/level1/p06_Goldbach/Goldbach.c @@ -0,0 +1,42 @@ +#include +#include +#include + +int main(void) +{ + int a=1000,i,j,n; + int pri[1000]={0}; + + if(i=1){ + pri[i]=1;} + if(i=2){ + pri[i]=0;} + for(i=3;i<=a;i++){ + for(j=2;j<=sqrt(i);j++){ + if(i%j==0) + { + pri[i]=1; + break; + + } + } + } + + + printf("please input n(4~1000֮ż):"); + scanf("%d",&n); + + for(int i=1;i<=n/2;i++){ + for(int j=n/2;j<=n;j++){ + if(pri[i]==0 & pri[j]==0 & n==i+j){ + printf("%d=%d+%d\n",n,i,j); + } + } + } + + + return 0; +} + + + diff --git a/practices/c/level1/p07_encrypt_decrypt/encrypt_decrypt.c b/practices/c/level1/p07_encrypt_decrypt/encrypt_decrypt.c new file mode 100644 index 00000000..39d72018 --- /dev/null +++ b/practices/c/level1/p07_encrypt_decrypt/encrypt_decrypt.c @@ -0,0 +1,73 @@ +#include +#include +#define SIZE 10000 +#define SIZE1 10000 + +void encrypt(void); +void decrypt(void); +char array[SIZE]; +char array1[SIZE1]; +int i=0; + +int main(void){ + + printf("please input the txt that you want to encrypt:\n"); + encrypt(); + printf("\n"); + decrypt(); + printf("\n"); + + return 0; +} + +void encrypt(void){ + char txt; + while((txt=getchar()) != EOF){ + if(100<=txt<=126){ + array1[i]=txt; + txt=txt-23; + putchar(txt); + array[i]=txt; + i++; + } + + else if(32<=txt<=45){ + array1[i]=txt; + txt=txt+11; + putchar(txt); + array[i]=txt; + i++; + } + + else if(45 +#include + +void hanoi(int n,char start,char medium,char end); + +int main() +{ + int n; + + printf("input n:"); + scanf("%d",&n); + hanoi(n,'A','B','C'); + + return 0; +} + +void hanoi(int n,char start,char medium,char end){ + if(1 == n){ + printf("%c->%c\n",start,end); + } + + else{ + hanoi(n-1,start,end,medium); + printf("%c->%c\n",start,end); + hanoi(n-1,medium,start,end); + } +} + + diff --git a/practices/c/level1/p09_maze/maze.c b/practices/c/level1/p09_maze/maze.c new file mode 100644 index 00000000..1f1915c5 --- /dev/null +++ b/practices/c/level1/p09_maze/maze.c @@ -0,0 +1,166 @@ +#include +#include +#include +#define N1 100 +#define N2 100 + +int m,n,room; +char maze[N1][N2]; +void Init_maze(int room); +void Create_maze(int room); +void Move(int room); + +//#代表墙; +//P代表人物; + +int main(void) +{ + int room; + + printf("你想输出多大的迷宫(在100*100范围内):"); + scanf("%d",&room); + printf("请注意:由于作者水平不够,迷宫出口请设置在第一行中间,否则要出BUG!!!!!\n请输入迷宫(只能输入0或1并且输入一个数字后回车一下或者按一下空格,1代表墙,0代表空处,输完所有数字后请回车!)\n游戏规则:w,s,a,d分别代表上,下,左,右。\n\n"); + + Init_maze(room); + Move(room); + + return 0; +} + + + +void Init_maze(int room) +{ + for(m=0;m=room*room) + { + printf("抱歉,该迷宫无解!\n"); + break; + } + + + + walk=getch(); + if('w'==walk&&maze[i-1][j]!='#'&&i!=0) + { + maze[i-1][j]='P'; + maze[i][j]=' '; + step++; + i--; + } + + if('s'==walk&&maze[i+1][j]!='#'&&i!=room) + { + maze[i+1][j]='P'; + maze[i][j]=' '; + step++; + i++; + } + + if('a'==walk&&maze[i][j-1]!='#'&&j!=0) + { + maze[i][j-1]='P'; + maze[i][j]=' '; + step++; + j--; + } + + if('d'==walk&&maze[i][j+1]!='#'&&j!=room) + { + maze[i][j+1]='P'; + maze[i][j]=' '; + step++; + j++; + } + + system("cls"); + + } + +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/practices/c/level1/p10_pushBoxes/map1.txt b/practices/c/level1/p10_pushBoxes/map1.txt new file mode 100644 index 00000000..b0d80e37 --- /dev/null +++ b/practices/c/level1/p10_pushBoxes/map1.txt @@ -0,0 +1,9 @@ +0 0 0 0 1 0 0 0 0 +0 0 0 1 4 1 0 0 0 +0 0 0 1 3 1 0 0 0 +0 1 1 1 0 1 1 1 0 +1 4 3 0 2 0 3 4 1 +0 1 1 1 0 1 1 1 0 +0 0 0 1 3 1 0 0 0 +0 0 0 1 4 1 0 0 0 +0 0 0 0 1 0 0 0 0 diff --git a/practices/c/level1/p10_pushBoxes/map2.txt b/practices/c/level1/p10_pushBoxes/map2.txt new file mode 100644 index 00000000..53684790 --- /dev/null +++ b/practices/c/level1/p10_pushBoxes/map2.txt @@ -0,0 +1,9 @@ +1 1 1 1 1 1 1 1 1 +1 1 1 1 4 1 1 1 1 +1 1 0 0 0 0 0 1 1 +1 1 0 3 0 3 0 1 1 +1 4 0 0 2 0 0 4 1 +1 1 0 3 0 3 0 1 1 +1 1 0 0 0 0 0 1 1 +1 1 1 1 4 1 1 1 1 +1 1 1 1 1 1 1 1 1 diff --git a/practices/c/level1/p10_pushBoxes/pushboxes.c b/practices/c/level1/p10_pushBoxes/pushboxes.c new file mode 100644 index 00000000..01d9cb89 --- /dev/null +++ b/practices/c/level1/p10_pushBoxes/pushboxes.c @@ -0,0 +1,191 @@ +#include +#include +#include +#define SIZE1 9 +#define SIZE2 9 + +int map[SIZE1][SIZE2]; +FILE *score; +void Choose(); +void Printf_map(); +void Push(); + +int main(void) +{ + Choose(); + Push(); + + return 0; +} + + +void Choose() +{ + printf("ѡؿ:\n1.level 1;\n2.level 2;\n"); + FILE *fp; + int n; + scanf("%d",&n); + system("cls"); + switch(n) + { + case 1: + fp=fopen("map1.txt","r"); + for(int i=0;i<=SIZE1-1;i++) + { + for(int j=0;j<=SIZE2-1;j++) + { + fscanf(fp,"%d",&map[i][j]); + } + } + fclose(fp); + break; + case 2: + fp=fopen("map2.txt","r"); + for(int i=0;i<=SIZE1-1;i++) + { + for(int j=0;j<=SIZE2-1;j++) + { + fscanf(fp,"%d",&map[i][j]); + } + } + fclose(fp); + break; + } +} + + +void Printf_map() +{ + for(int i=0;i<=SIZE1-1;i++) + { + for(int j=0;j<=SIZE2-1;j++) + { + if(map[i][j]==0) + { + map[i][j]=' ';//յ + } + else if(map[i][j]==1) + { + map[i][j]='*';//ǽ + } + else if(map[i][j]==2) + { + map[i][j]='P';// + } + else if(map[i][j]==3) + { + map[i][j]='#';// + } + else if(map[i][j]==4) + { + map[i][j]='D';//Ŀĵ + } + } + } + + for(int i=0;i<=SIZE1-1;i++) + { + for(int j=0;j<=SIZE2-1;j++) + { + printf("%c",map[i][j]); + } + printf("\n"); + } +} + + +void Push() +{ + int step=0; + int x=4,y=4; + char walk; + score=fopen("score.txt","w+"); + while(1) + { + Printf_map(); + printf("ֹǰ㹲%d\n",step); + if(map[1][4]!='D'&&map[4][7]!='D'&&map[4][1]!='D'&&map[7][4]!='D') + { + printf("ϲѾɹӡ\n"); + fprintf(score,"ijɼΪ%d",step); + break; + } + walk=getch(); + if(walk=='w') + { + if(map[x-1][y]==' ') + { + map[x][y]=0; + map[x-1][y]=2; + --x; + ++step; + } + else if(map[x-1][y]=='#' && map[x-2][y]!='*') + { + map[x][y]=0; + map[x-1][y]=2; + map[x-2][y]=3; + --x; + ++step; + } + } + + else if(walk=='s') + { + if(map[x+1][y]==' ') + { + map[x][y]=0; + map[x+1][y]=2; + ++x; + ++step; + } + else if(map[x+1][y]=='#'&&map[x+2][y]!='*') + { + map[x][y]=0; + map[x+1][y]=2; + map[x+2][y]=3; + ++x; + ++step; + } + } + + else if(walk=='a') + { + if(map[x][y-1]==' ') + { + map[x][y]=0; + map[x][y-1]=2; + --y; + ++step; + } + else if(map[x][y-1]=='#'&&map[x][y-2]!='*') + { + map[x][y]=0; + map[x][y-1]=2; + map[x][y-2]=3; + --y; + ++step; + } + } + + else if(walk=='d') + { + if(map[x][y+1]==' ') + { + map[x][y]=0; + map[x][y+1]=2; + ++y; + ++step; + } + else if(map[x][y+1]=='#'&&map[x][y+2]!='*') + { + map[x][y]=0; + map[x][y+1]=2; + map[x][y+2]=3; + ++y; + ++step; + } + } + system("cls"); + } +} diff --git a/practices/c/level1/p11_linkedList/linkedlist.c b/practices/c/level1/p11_linkedList/linkedlist.c new file mode 100644 index 00000000..3994b315 --- /dev/null +++ b/practices/c/level1/p11_linkedList/linkedlist.c @@ -0,0 +1,169 @@ +#include +#include + +struct node +{ + int data; + struct node * next; +}*head_ptr,*pre_ptr; + + +void Init_list(); +void Build_list(); +void Printf_list(); +void Overturn_list(); +void Search_list(int x); +void free_list(struct node* head); + +int main(void) +{ + Init_list(); + Build_list(); + + int choice; + printf("what do you want to do:\n"); + printf("1.print linkedlist \n2.overturn the linkedlist \n3.search a member in the linkenlist \n4.quit\n"); + scanf("%d",&choice); + fflush(stdin); + int x; + + switch(choice) + { + case 1: + Printf_list(); + free_list(head_ptr); + break; + case 2: + Overturn_list(); + Printf_list(); + free_list(head_ptr); + break; + case 3: + + printf("input the number you want to search:\n"); + scanf("%d",&x); + fflush(stdin); + Search_list(x); + free_list(head_ptr); + break; + case 4: + free_list(head_ptr); + break; + default: + free_list(head_ptr); + printf("error\n"); + } + + return 0; +} + + + + +void Init_list() +{ + head_ptr=(struct node*)malloc(sizeof(struct node)); + /*if(head_ptr == NULL) + { + printf("Fail to request for room!\N"); + }*/ + head_ptr->next=NULL; + pre_ptr=(struct node*)malloc(sizeof(struct node)); + /*if(pre_ptr == NULL) + { + printf("Fail to request for room!\N"); + }*/ + pre_ptr->next=NULL; +} + +void Build_list() +{ + printf("The number of the list you want to build:\n"); + + int n; + scanf("%d",&n); + fflush(stdin); + + printf("Input all members:\n"); + int x; + for(int i=0;idata=x; + ptr->next=NULL; + if(head_ptr->next==NULL) + { + head_ptr->next=ptr; + pre_ptr=ptr; + } + pre_ptr->next=ptr; + pre_ptr=ptr; + + } +} + + +void Printf_list() +{ + struct node* ptr; + ptr = head_ptr->next; + while(ptr != NULL) + { + printf("%d\t",ptr->data); + ptr=ptr->next; + } + +} + +void Overturn_list() +{ + struct node *ptr,*next_ptr,*now_ptr; + ptr=head_ptr->next; + pre_ptr=ptr; + now_ptr=NULL; + while(ptr != NULL) + { + next_ptr=ptr->next; + ptr->next=now_ptr; + now_ptr=ptr; + ptr=next_ptr; + } + head_ptr->next=now_ptr; +} + +void Search_list(int x) +{ + int turn=1,seache_result=0; + struct node *ptr; + ptr=head_ptr->next; + while(ptr!=NULL) + { + if(ptr->data == x) + { + seache_result=1; + printf("%d\n",turn); + } + ptr=ptr->next; + ++turn; + } + if(seache_result==0) + { + printf("-1\n"); + } +} + +void free_list(struct node* head) +{ + while(head!=NULL) + { + struct node* tem=head->next; + free(head); + head=tem; + } + +} + + diff --git a/practices/c/level1/p12_warehouse/data.txt b/practices/c/level1/p12_warehouse/data.txt new file mode 100644 index 00000000..4b6ec7bc --- /dev/null +++ b/practices/c/level1/p12_warehouse/data.txt @@ -0,0 +1,2 @@ + +15 \ No newline at end of file diff --git a/practices/c/level1/p12_warehouse/warehouse.c b/practices/c/level1/p12_warehouse/warehouse.c new file mode 100644 index 00000000..778b2a9f --- /dev/null +++ b/practices/c/level1/p12_warehouse/warehouse.c @@ -0,0 +1,188 @@ +#include +#include +#include +#define N 20 + +typedef struct node +{ + char name[N]; + int quantity; + struct node *next; +}Node; + +Node *phead; +int quantity; +int n=0; +char name[N]; + +void init(); +void show(); +void input(); +void output(); +void save(); + +int main(void) +{ + init(); + while(1) + { + int choice; + printf("Please choose which one you want to do:\n1.show\n2.input\n3.output\n4.quit\n"); + scanf("%d",&choice); + if(choice==1) + { + show(); + } + else if(choice==2) + { + input(); + } + else if(choice==3) + { + output(); + } + else if(choice==4) + { + save(); + break; + } + else + { + printf("Error!Please choose again!\n"); + } + } +} + +void init() +{ + phead=(Node*)malloc(sizeof(Node)); + phead->next=NULL; + FILE *fp; + fp=fopen("data.txt","r"); + if(fscanf(fp,"%d",&n) != EOF) + { + for(int i=0;inext; + if(p==NULL) + { + printf("It is empty now!\n"); + } + while(p!=NULL) + { + printf("Name: %s Quantity: %d\n",p->name,p->quantity); + p=p->next; + } +} + +void input() +{ + int temp=0; + Node *p; + p=phead->next; + printf("Input name.\n"); + scanf("%s",name); + printf("Input quantity.\n"); + scanf("%d",&quantity); + while(p!=NULL) + { + if(strcmp(p->name,name)==0) + { + temp=1; + p->quantity += quantity; + } + p=p->next; + } + + if(temp==0) + { + Node *p; + p=(Node*)malloc(sizeof(Node)); + strcpy(p -> name,name); + p -> quantity = quantity; + p -> next = phead -> next; + phead -> next = p; + n++; + } + +} + +void output() +{ + int search=0; + int enough=0; + Node *p,*q; + p = phead -> next; + q = phead; + printf("Input name.\n"); + scanf("%s",name); + printf("Input quantity.\n"); + scanf("%d",&quantity); + while(p!=NULL) + { + if(strcmp(p->name,name)==0) + { + search=1; + if(p -> quantity < quantity) + { + break; + } + p -> quantity -= quantity; + if(p -> quantity == 0) + { + enough=2; + } + if(p -> quantity > 0) + { + enough=1; + } + break; + } + q = p; + p = p -> next; + } + if(search==0) + { + printf("Not found %s\n",name); + return; + } + if (enough == 0) + { + printf("Not enough!\n"); + return; + } + if (enough == 2) + { + q -> next = p -> next; + free(p); + n--; + } +} +void save() +{ + FILE *fp; + fp = fopen("Data","w"); + fprintf(fp,"%d\n",n); + Node *p, *q; + p = phead -> next; + q = phead; + free(q); + while (p != NULL) { + fprintf(fp,"%s\n",p -> name); + fprintf(fp,"%d\n",p -> quantity); + q = p; + p = p -> next; + free(q); + } +} diff --git a/practices/cpp/level1/Fighters/.vs/Fighters/v14/.suo b/practices/cpp/level1/Fighters/.vs/Fighters/v14/.suo new file mode 100644 index 00000000..aa14da05 Binary files /dev/null and b/practices/cpp/level1/Fighters/.vs/Fighters/v14/.suo differ diff --git a/practices/cpp/level1/Fighters/Debug/Fighters.exe b/practices/cpp/level1/Fighters/Debug/Fighters.exe new file mode 100644 index 00000000..b1e1735c Binary files /dev/null and b/practices/cpp/level1/Fighters/Debug/Fighters.exe differ diff --git a/practices/cpp/level1/Fighters/Debug/Fighters.ilk b/practices/cpp/level1/Fighters/Debug/Fighters.ilk new file mode 100644 index 00000000..a799cc27 Binary files /dev/null and b/practices/cpp/level1/Fighters/Debug/Fighters.ilk differ diff --git a/practices/cpp/level1/Fighters/Debug/Fighters.pdb b/practices/cpp/level1/Fighters/Debug/Fighters.pdb new file mode 100644 index 00000000..7a9638f6 Binary files /dev/null and b/practices/cpp/level1/Fighters/Debug/Fighters.pdb differ diff --git a/practices/cpp/level1/Fighters/Debug/openal32.dll b/practices/cpp/level1/Fighters/Debug/openal32.dll new file mode 100644 index 00000000..40b2aa0f Binary files /dev/null and b/practices/cpp/level1/Fighters/Debug/openal32.dll differ diff --git a/practices/cpp/level1/Fighters/Debug/sfml-audio-2.dll b/practices/cpp/level1/Fighters/Debug/sfml-audio-2.dll new file mode 100644 index 00000000..be8d3bf6 Binary files /dev/null and b/practices/cpp/level1/Fighters/Debug/sfml-audio-2.dll differ diff --git a/practices/cpp/level1/Fighters/Debug/sfml-audio-d-2.dll b/practices/cpp/level1/Fighters/Debug/sfml-audio-d-2.dll new file mode 100644 index 00000000..5c6a1974 Binary files /dev/null and b/practices/cpp/level1/Fighters/Debug/sfml-audio-d-2.dll differ diff --git a/practices/cpp/level1/Fighters/Debug/sfml-graphics-2.dll b/practices/cpp/level1/Fighters/Debug/sfml-graphics-2.dll new file mode 100644 index 00000000..bc104451 Binary files /dev/null and b/practices/cpp/level1/Fighters/Debug/sfml-graphics-2.dll differ diff --git a/practices/cpp/level1/Fighters/Debug/sfml-graphics-d-2.dll b/practices/cpp/level1/Fighters/Debug/sfml-graphics-d-2.dll new file mode 100644 index 00000000..97f24aaa Binary files /dev/null and b/practices/cpp/level1/Fighters/Debug/sfml-graphics-d-2.dll differ diff --git a/practices/cpp/level1/Fighters/Debug/sfml-network-2.dll b/practices/cpp/level1/Fighters/Debug/sfml-network-2.dll new file mode 100644 index 00000000..b279505e Binary files /dev/null and b/practices/cpp/level1/Fighters/Debug/sfml-network-2.dll differ diff --git a/practices/cpp/level1/Fighters/Debug/sfml-network-d-2.dll b/practices/cpp/level1/Fighters/Debug/sfml-network-d-2.dll new file mode 100644 index 00000000..43a1917f Binary files /dev/null and b/practices/cpp/level1/Fighters/Debug/sfml-network-d-2.dll differ diff --git a/practices/cpp/level1/Fighters/Debug/sfml-system-2.dll b/practices/cpp/level1/Fighters/Debug/sfml-system-2.dll new file mode 100644 index 00000000..3ed8c6ce Binary files /dev/null and b/practices/cpp/level1/Fighters/Debug/sfml-system-2.dll differ diff --git a/practices/cpp/level1/Fighters/Debug/sfml-system-d-2.dll b/practices/cpp/level1/Fighters/Debug/sfml-system-d-2.dll new file mode 100644 index 00000000..6fbed79a Binary files /dev/null and b/practices/cpp/level1/Fighters/Debug/sfml-system-d-2.dll differ diff --git a/practices/cpp/level1/Fighters/Debug/sfml-window-2.dll b/practices/cpp/level1/Fighters/Debug/sfml-window-2.dll new file mode 100644 index 00000000..8f198530 Binary files /dev/null and b/practices/cpp/level1/Fighters/Debug/sfml-window-2.dll differ diff --git a/practices/cpp/level1/Fighters/Debug/sfml-window-d-2.dll b/practices/cpp/level1/Fighters/Debug/sfml-window-d-2.dll new file mode 100644 index 00000000..cdd02d06 Binary files /dev/null and b/practices/cpp/level1/Fighters/Debug/sfml-window-d-2.dll differ diff --git a/practices/cpp/level1/Fighters/Debug/sound.wav b/practices/cpp/level1/Fighters/Debug/sound.wav new file mode 100644 index 00000000..e47d8d79 Binary files /dev/null and b/practices/cpp/level1/Fighters/Debug/sound.wav differ diff --git a/practices/cpp/level1/Fighters/Fighters.VC.VC.opendb b/practices/cpp/level1/Fighters/Fighters.VC.VC.opendb new file mode 100644 index 00000000..64d67eaf Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters.VC.VC.opendb differ diff --git a/practices/cpp/level1/Fighters/Fighters.VC.db b/practices/cpp/level1/Fighters/Fighters.VC.db new file mode 100644 index 00000000..e5b0a1b1 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters.VC.db differ diff --git a/practices/cpp/level1/Fighters/Fighters.sln b/practices/cpp/level1/Fighters/Fighters.sln new file mode 100644 index 00000000..3fa4e396 --- /dev/null +++ b/practices/cpp/level1/Fighters/Fighters.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Fighters", "Fighters\Fighters.vcxproj", "{CC21D290-6261-4CEA-8987-B5ADB23DB08D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CC21D290-6261-4CEA-8987-B5ADB23DB08D}.Debug|x64.ActiveCfg = Debug|x64 + {CC21D290-6261-4CEA-8987-B5ADB23DB08D}.Debug|x64.Build.0 = Debug|x64 + {CC21D290-6261-4CEA-8987-B5ADB23DB08D}.Debug|x86.ActiveCfg = Debug|Win32 + {CC21D290-6261-4CEA-8987-B5ADB23DB08D}.Debug|x86.Build.0 = Debug|Win32 + {CC21D290-6261-4CEA-8987-B5ADB23DB08D}.Release|x64.ActiveCfg = Release|x64 + {CC21D290-6261-4CEA-8987-B5ADB23DB08D}.Release|x64.Build.0 = Release|x64 + {CC21D290-6261-4CEA-8987-B5ADB23DB08D}.Release|x86.ActiveCfg = Release|Win32 + {CC21D290-6261-4CEA-8987-B5ADB23DB08D}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/practices/cpp/level1/Fighters/Fighters/Action.cpp b/practices/cpp/level1/Fighters/Fighters/Action.cpp new file mode 100644 index 00000000..12a6f359 --- /dev/null +++ b/practices/cpp/level1/Fighters/Fighters/Action.cpp @@ -0,0 +1,58 @@ +#include "Action.h" + +Action::Action() +{ + //ctor + direction.x = 0.0; + direction.y = 1.0; +} + +Action::~Action() +{ + //dtor +} + +void Action::move(sf::Vector2f direction) { + + this->direction = direction; + sf::Vector2f temp = this->direction; + temp.x = this->direction.x*speed; + temp.y = this->direction.y*speed; + this->setPosition(this->getPosition() + temp); + +} + + +void Action::move() { + + + sf::Vector2f temp = this->direction; + temp.x = this->direction.x*bullet_speed; + temp.y = this->direction.y*bullet_speed; + this->setPosition(this->getPosition() + temp); + + + +} + +void Action::bossBulletMove(int i) +{ + + double dx = cos((2*i*Pi)/10); + double dy = sin((2*i*Pi)/10); + sf::Vector2f temp = this->direction; + temp.x = dx*bullet_speed; + temp.y = dy*bullet_speed; + this->setPosition(this->getPosition() + temp); + +} + +void Action::setSpeed(float speed) +{ + this->speed = speed; +} + +void Action::setBulletSpeed(float bullet_speed) +{ + this->bullet_speed = bullet_speed; +} \ No newline at end of file diff --git a/practices/cpp/level1/Fighters/Fighters/Action.h b/practices/cpp/level1/Fighters/Fighters/Action.h new file mode 100644 index 00000000..3fd93505 --- /dev/null +++ b/practices/cpp/level1/Fighters/Fighters/Action.h @@ -0,0 +1,25 @@ +#ifndef ACTION_H +#define ACTION_H +#include +#include +#define Pi 3.14 +class Action :public sf::Sprite +{ +public: + Action(); + virtual ~Action(); + void move(sf::Vector2f direction); + void move(); + void bossBulletMove(int i); + void setSpeed(float speed); + void setBulletSpeed(float bullet_speed); + +protected: + sf::Vector2f direction; + +private: + float speed = 1.0f; + float bullet_speed = 1.0f; +}; + +#endif // ACTION_H diff --git a/practices/cpp/level1/Fighters/Fighters/Bonus.cpp b/practices/cpp/level1/Fighters/Fighters/Bonus.cpp new file mode 100644 index 00000000..6e7f1a4c --- /dev/null +++ b/practices/cpp/level1/Fighters/Fighters/Bonus.cpp @@ -0,0 +1,73 @@ +#include "Bonus.h" +#include "Game.h" + + + +Bonus::Bonus(float x,float y) +{ + uniform_int_distribution b(0,3); + switch (b(Game::random)) + { + case 0: + texture = &RTexture::LIFE; + set_bonusstate(0); + break; + case 1: + texture = &RTexture::RANDBONUS; + set_bonusstate(1); + this->scale(0.5, 0.5); + break; + case 2: + texture = &RTexture::BULLETBONUS; + set_bonusstate(2); + break; + case 3: + texture = &RTexture::ENERGY; + set_bonusstate(3); + break; + } + this->setPosition(x, y); + this->setTexture(*texture); +} + + +Bonus::~Bonus() +{ +} + +void Bonus::MoveRand() +{ + uniform_int_distribution t(0, 4); + int T = t(Game::random); + switch (T) + { + case 0: + direction = sf::Vector2(1.0, 0); + break; + case 1: + direction = sf::Vector2(-1.0, 0); + break; + case 2: + direction = sf::Vector2(0, 1); + break; + case 3: + direction = sf::Vector2(0, 1); + break; + case 4: + direction = sf::Vector2(0, 1); + break; + default: + break; + } + this->move(direction); +} + +void Bonus::set_bonusstate(int bonusstate) +{ + this->bonusstate = bonusstate; +} + +int Bonus::get_bonusstate() +{ + return bonusstate; +} diff --git a/practices/cpp/level1/Fighters/Fighters/Bonus.h b/practices/cpp/level1/Fighters/Fighters/Bonus.h new file mode 100644 index 00000000..49d36d55 --- /dev/null +++ b/practices/cpp/level1/Fighters/Fighters/Bonus.h @@ -0,0 +1,22 @@ +#ifndef BONUS_H +#define BONUS_H +#include +#include "Action.h" +#include "RTexture.h" + +class Bonus:public Action +{ +public: + Bonus(float x, float y); + virtual~Bonus(); + void MoveRand(); + void set_bonusstate(int bonusstate); + int get_bonusstate(); + + +private: + sf::Vector2f direction; + sf::Texture *texture; + int bonusstate = 0; +}; +#endif //BONUS_H diff --git a/practices/cpp/level1/Fighters/Fighters/Bullet.cpp b/practices/cpp/level1/Fighters/Fighters/Bullet.cpp new file mode 100644 index 00000000..53e9340e --- /dev/null +++ b/practices/cpp/level1/Fighters/Fighters/Bullet.cpp @@ -0,0 +1,15 @@ +#include "Bullet.h" + +Bullet::Bullet(sf::Texture texture, int A, sf::Vector2f direction) +{ + //ctor + this->Attack = A; + this->texture = texture; + this->setTexture(this->texture); + this->direction = direction; +} + +Bullet::~Bullet() +{ + //dtor +} diff --git a/practices/cpp/level1/Fighters/Fighters/Bullet.h b/practices/cpp/level1/Fighters/Fighters/Bullet.h new file mode 100644 index 00000000..ac4666a5 --- /dev/null +++ b/practices/cpp/level1/Fighters/Fighters/Bullet.h @@ -0,0 +1,21 @@ +#ifndef BULLET_H +#define BULLET_H +#include +#include "RTexture.h" +#include "Action.h" + +class Bullet :public Action +{ +public: + Bullet(sf::Texture texture, int A, sf::Vector2f direction = sf::Vector2f(0.0, 1.0)); + virtual ~Bullet(); + int Attack = 1; + sf::Sprite bulletq; + +protected: + +private: + sf::Texture texture; +}; + +#endif // BULLET_H diff --git a/practices/cpp/level1/Fighters/Fighters/Debug/Action.obj b/practices/cpp/level1/Fighters/Fighters/Debug/Action.obj new file mode 100644 index 00000000..f1756c1e Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/Debug/Action.obj differ diff --git a/practices/cpp/level1/Fighters/Fighters/Debug/Bonus.obj b/practices/cpp/level1/Fighters/Fighters/Debug/Bonus.obj new file mode 100644 index 00000000..bfc256ef Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/Debug/Bonus.obj differ diff --git a/practices/cpp/level1/Fighters/Fighters/Debug/Bullet.obj b/practices/cpp/level1/Fighters/Fighters/Debug/Bullet.obj new file mode 100644 index 00000000..1348a857 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/Debug/Bullet.obj differ diff --git a/practices/cpp/level1/Fighters/Fighters/Debug/Enemy.obj b/practices/cpp/level1/Fighters/Fighters/Debug/Enemy.obj new file mode 100644 index 00000000..79af3159 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/Debug/Enemy.obj differ diff --git a/practices/cpp/level1/Fighters/Fighters/Debug/Fighters.Build.CppClean.log b/practices/cpp/level1/Fighters/Fighters/Debug/Fighters.Build.CppClean.log new file mode 100644 index 00000000..d3df24a9 --- /dev/null +++ b/practices/cpp/level1/Fighters/Fighters/Debug/Fighters.Build.CppClean.log @@ -0,0 +1,23 @@ +h:\c++\fighters\fighters\debug\vc140.pdb +h:\c++\fighters\fighters\debug\vc140.idb +h:\c++\fighters\fighters\debug\action.obj +h:\c++\fighters\fighters\debug\bonus.obj +h:\c++\fighters\fighters\debug\bullet.obj +h:\c++\fighters\fighters\debug\enemy.obj +h:\c++\fighters\fighters\debug\game.obj +h:\c++\fighters\fighters\debug\hero.obj +h:\c++\fighters\fighters\debug\load.obj +h:\c++\fighters\fighters\debug\main.obj +h:\c++\fighters\fighters\debug\mmusic.obj +h:\c++\fighters\fighters\debug\plane.obj +h:\c++\fighters\fighters\debug\rtexture.obj +h:\c++\fighters\fighters\debug\world.obj +h:\c++\fighters\debug\fighters.ilk +h:\c++\fighters\debug\fighters.exe +h:\c++\fighters\debug\fighters.pdb +h:\c++\fighters\fighters\debug\fighters.tlog\cl.command.1.tlog +h:\c++\fighters\fighters\debug\fighters.tlog\cl.read.1.tlog +h:\c++\fighters\fighters\debug\fighters.tlog\cl.write.1.tlog +h:\c++\fighters\fighters\debug\fighters.tlog\link.command.1.tlog +h:\c++\fighters\fighters\debug\fighters.tlog\link.read.1.tlog +h:\c++\fighters\fighters\debug\fighters.tlog\link.write.1.tlog diff --git a/practices/cpp/level1/Fighters/Fighters/Debug/Fighters.log b/practices/cpp/level1/Fighters/Fighters/Debug/Fighters.log new file mode 100644 index 00000000..7e83bb43 --- /dev/null +++ b/practices/cpp/level1/Fighters/Fighters/Debug/Fighters.log @@ -0,0 +1,7 @@ + World.cpp +h:\c++\fighters\fighters\world.cpp(247): warning C4804: “<=”: 在操作中使用类型“bool”不安全 +h:\c++\fighters\fighters\world.cpp(257): warning C4804: “<=”: 在操作中使用类型“bool”不安全 +h:\c++\fighters\fighters\world.cpp(403): warning C4804: “<=”: 在操作中使用类型“bool”不安全 +h:\c++\fighters\fighters\world.cpp(485): warning C4244: “参数”: 从“int”转换到“float”,可能丢失数据 + Fighters.vcxproj -> H:\C++\Fighters\Debug\Fighters.exe + Fighters.vcxproj -> H:\C++\Fighters\Debug\Fighters.pdb (Full PDB) diff --git a/practices/cpp/level1/Fighters/Fighters/Debug/Fighters.tlog/CL.command.1.tlog b/practices/cpp/level1/Fighters/Fighters/Debug/Fighters.tlog/CL.command.1.tlog new file mode 100644 index 00000000..72990b7b Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/Debug/Fighters.tlog/CL.command.1.tlog differ diff --git a/practices/cpp/level1/Fighters/Fighters/Debug/Fighters.tlog/CL.read.1.tlog b/practices/cpp/level1/Fighters/Fighters/Debug/Fighters.tlog/CL.read.1.tlog new file mode 100644 index 00000000..c0be34f2 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/Debug/Fighters.tlog/CL.read.1.tlog differ diff --git a/practices/cpp/level1/Fighters/Fighters/Debug/Fighters.tlog/CL.write.1.tlog b/practices/cpp/level1/Fighters/Fighters/Debug/Fighters.tlog/CL.write.1.tlog new file mode 100644 index 00000000..7a5aaac0 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/Debug/Fighters.tlog/CL.write.1.tlog differ diff --git a/practices/cpp/level1/Fighters/Fighters/Debug/Fighters.tlog/Fighters.lastbuildstate b/practices/cpp/level1/Fighters/Fighters/Debug/Fighters.tlog/Fighters.lastbuildstate new file mode 100644 index 00000000..328dc92b --- /dev/null +++ b/practices/cpp/level1/Fighters/Fighters/Debug/Fighters.tlog/Fighters.lastbuildstate @@ -0,0 +1,2 @@ +#TargetFrameworkVersion=v4.0:PlatformToolSet=v140:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=8.1 +Debug|Win32|H:\C++\Fighters\| diff --git a/practices/cpp/level1/Fighters/Fighters/Debug/Fighters.tlog/link.command.1.tlog b/practices/cpp/level1/Fighters/Fighters/Debug/Fighters.tlog/link.command.1.tlog new file mode 100644 index 00000000..51627b43 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/Debug/Fighters.tlog/link.command.1.tlog differ diff --git a/practices/cpp/level1/Fighters/Fighters/Debug/Fighters.tlog/link.read.1.tlog b/practices/cpp/level1/Fighters/Fighters/Debug/Fighters.tlog/link.read.1.tlog new file mode 100644 index 00000000..a81f462d Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/Debug/Fighters.tlog/link.read.1.tlog differ diff --git a/practices/cpp/level1/Fighters/Fighters/Debug/Fighters.tlog/link.write.1.tlog b/practices/cpp/level1/Fighters/Fighters/Debug/Fighters.tlog/link.write.1.tlog new file mode 100644 index 00000000..4912f4fe Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/Debug/Fighters.tlog/link.write.1.tlog differ diff --git a/practices/cpp/level1/Fighters/Fighters/Debug/Game.obj b/practices/cpp/level1/Fighters/Fighters/Debug/Game.obj new file mode 100644 index 00000000..a2d23cca Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/Debug/Game.obj differ diff --git a/practices/cpp/level1/Fighters/Fighters/Debug/Hero.obj b/practices/cpp/level1/Fighters/Fighters/Debug/Hero.obj new file mode 100644 index 00000000..0bb205a2 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/Debug/Hero.obj differ diff --git a/practices/cpp/level1/Fighters/Fighters/Debug/Load.obj b/practices/cpp/level1/Fighters/Fighters/Debug/Load.obj new file mode 100644 index 00000000..49b49cd1 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/Debug/Load.obj differ diff --git a/practices/cpp/level1/Fighters/Fighters/Debug/MMusic.obj b/practices/cpp/level1/Fighters/Fighters/Debug/MMusic.obj new file mode 100644 index 00000000..1f802848 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/Debug/MMusic.obj differ diff --git a/practices/cpp/level1/Fighters/Fighters/Debug/Plane.obj b/practices/cpp/level1/Fighters/Fighters/Debug/Plane.obj new file mode 100644 index 00000000..50b8e782 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/Debug/Plane.obj differ diff --git a/practices/cpp/level1/Fighters/Fighters/Debug/RTexture.obj b/practices/cpp/level1/Fighters/Fighters/Debug/RTexture.obj new file mode 100644 index 00000000..c9c885b2 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/Debug/RTexture.obj differ diff --git a/practices/cpp/level1/Fighters/Fighters/Debug/World.obj b/practices/cpp/level1/Fighters/Fighters/Debug/World.obj new file mode 100644 index 00000000..2daf9e12 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/Debug/World.obj differ diff --git a/practices/cpp/level1/Fighters/Fighters/Debug/main.obj b/practices/cpp/level1/Fighters/Fighters/Debug/main.obj new file mode 100644 index 00000000..01414e83 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/Debug/main.obj differ diff --git a/practices/cpp/level1/Fighters/Fighters/Debug/sound.wav b/practices/cpp/level1/Fighters/Fighters/Debug/sound.wav new file mode 100644 index 00000000..e47d8d79 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/Debug/sound.wav differ diff --git a/practices/cpp/level1/Fighters/Fighters/Debug/vc140.idb b/practices/cpp/level1/Fighters/Fighters/Debug/vc140.idb new file mode 100644 index 00000000..3030d05e Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/Debug/vc140.idb differ diff --git a/practices/cpp/level1/Fighters/Fighters/Debug/vc140.pdb b/practices/cpp/level1/Fighters/Fighters/Debug/vc140.pdb new file mode 100644 index 00000000..db196f0f Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/Debug/vc140.pdb differ diff --git a/practices/cpp/level1/Fighters/Fighters/Enemy.cpp b/practices/cpp/level1/Fighters/Fighters/Enemy.cpp new file mode 100644 index 00000000..18adb799 --- /dev/null +++ b/practices/cpp/level1/Fighters/Fighters/Enemy.cpp @@ -0,0 +1,186 @@ +#include "Enemy.h" +#include "World.h" +#include "Game.h" +#include +#include +#define Pi 3.14 +#define ENEMY_SPEED 0.9f +Enemy::Enemy(World *world) :Plane(world) +{ + //ctor + + uniform_int_distribution u(0, 200); + uniform_int_distribution v(250, 500); + uniform_int_distribution w(550, 700); + if (u(Game::random) <= 150) { + this->live = 1; + this->setScale(0.8f, 0.8f); + this->setTexture(RTexture::ENEMY); + } + else { this->setTexture(RTexture::BOSS1); + this->setScale(1.3f, 1.3f); + this->set_bossState(1); + this->live = 8; + } + + + + static int i = 1; + switch (i) + { + case 1: + this->setPosition(u(Game::random), 0); + i++; + break; + case 2: + this->setPosition(v(Game::random), 0); + i++; + break; + case 3: + this->setPosition(w(Game::random), 0); + i = 1; + break; + } + + this->setSpeed(ENEMY_SPEED); + +} + +Enemy::~Enemy() +{ + //dtor +} + +void Enemy::Fire() +{ + int speedd=100; + uniform_int_distribution k(0, 300); + speedd = k(Game::random); + + if (speedd>0 && speedd<35) + { + AddEnemyBullet(); + + } + else {}; +} + +void Enemy::enemyMove() +{ + + direction = sf::Vector2f(0, 1); + + this->move(direction); + +} + +void Enemy::boomCheck(int state) +{ + if (state == 10) { + + this->BOOM.play(); + + } + sf::Sprite boom; + boom.setTexture(BOOMP); + boom.setScale(1, 1); + boom.setPosition(this->getPosition().x, this->getPosition().y); + this->world->window->draw(boom); +} + +void Enemy::set_bossState(int i) +{ + this->bossState = i; +} + +int Enemy::get_bossState() +{ + return bossState; +} + +void Enemy::AddEnemyBullet() +{ + + static int i = 0; + static int j = 0; + if (i > 50) + { + if (this->bossState == 0) + { + Bullet *bullet = new Bullet(RTexture::BULLET3, 1); + bullet->setPosition(this->getPosition().x + 30, this->getPosition().y); + this->world->addBullet(bullet, 2); + + + } + + if (this->bossState == 1) + { + if (j > 0) { + + Bullet *bullet1 = new Bullet(RTexture::BOSSBULLET1, 1); + Bullet *bullet2 = new Bullet(RTexture::BOSSBULLET1, 1); + Bullet *bullet3 = new Bullet(RTexture::BOSSBULLET1, 1); + Bullet *bullet4 = new Bullet(RTexture::BOSSBULLET1, 1); + Bullet *bullet5 = new Bullet(RTexture::BOSSBULLET1, 1); + Bullet *bullet6 = new Bullet(RTexture::BOSSBULLET1, 1); + Bullet *bullet7 = new Bullet(RTexture::BOSSBULLET1, 1); + Bullet *bullet8 = new Bullet(RTexture::BOSSBULLET1, 1); + Bullet *bullet9 = new Bullet(RTexture::BOSSBULLET1, 1); + Bullet *bullet10 = new Bullet(RTexture::BOSSBULLET1, 1); + + bullet1->setPosition(this->getPosition().x + 50, this->getPosition().y + 50); + bullet2->setPosition(this->getPosition().x + 50, this->getPosition().y + 50); + bullet3->setPosition(this->getPosition().x + 50, this->getPosition().y + 50); + bullet4->setPosition(this->getPosition().x + 50, this->getPosition().y + 50); + bullet5->setPosition(this->getPosition().x + 50, this->getPosition().y + 50); + bullet6->setPosition(this->getPosition().x + 50, this->getPosition().y + 50); + bullet7->setPosition(this->getPosition().x + 50, this->getPosition().y + 50); + bullet8->setPosition(this->getPosition().x + 50, this->getPosition().y + 50); + bullet9->setPosition(this->getPosition().x + 50, this->getPosition().y + 50); + bullet10->setPosition(this->getPosition().x + 50, this->getPosition().y + 50); + + bullet1->setSpeed(10); + bullet2->setSpeed(10); + bullet3->setSpeed(10); + bullet4->setSpeed(10); + bullet5->setSpeed(10); + bullet6->setSpeed(10); + bullet7->setSpeed(10); + bullet8->setSpeed(10); + bullet9->setSpeed(10); + bullet10->setSpeed(10); + + bullet1->move(sf::Vector2(cos((2 * 1 * Pi) / 10), sin((2 * 1 * Pi) / 10))); + bullet2->move(sf::Vector2(cos((2 * 2 * Pi) / 10), sin((2 * 2 * Pi) / 10))); + bullet3->move(sf::Vector2(cos((2 * 3 * Pi) / 10), sin((2 * 3 * Pi) / 10))); + bullet4->move(sf::Vector2(cos((2 * 4 * Pi) / 10), sin((2 * 4 * Pi) / 10))); + bullet5->move(sf::Vector2(cos((2 * 5 * Pi) / 10), sin((2 * 5 * Pi) / 10))); + bullet6->move(sf::Vector2(cos((2 * 6 * Pi) / 10), sin((2 * 6 * Pi) / 10))); + bullet7->move(sf::Vector2(cos((2 * 7 * Pi) / 10), sin((2 * 7 * Pi) / 10))); + bullet8->move(sf::Vector2(cos((2 * 8 * Pi) / 10), sin((2 * 8 * Pi) / 10))); + bullet9->move(sf::Vector2(cos((2 * 9 * Pi) / 10), sin((2 * 9 * Pi) / 10))); + bullet10->move(sf::Vector2(cos((2 * 10 * Pi) / 10), sin((2 * 10 * Pi) / 10))); + + this->world->addBullet(bullet1, 2); + this->world->addBullet(bullet2, 2); + this->world->addBullet(bullet4, 2); + this->world->addBullet(bullet3, 2); + this->world->addBullet(bullet5, 2); + this->world->addBullet(bullet6, 2); + this->world->addBullet(bullet7, 2); + this->world->addBullet(bullet8, 2); + this->world->addBullet(bullet9, 2); + this->world->addBullet(bullet10, 2); + + j = 0; + } + else { j++; } + + } + i = 0; + } + + else { i++; } + +} diff --git a/practices/cpp/level1/Fighters/Fighters/Enemy.h b/practices/cpp/level1/Fighters/Fighters/Enemy.h new file mode 100644 index 00000000..7b576df4 --- /dev/null +++ b/practices/cpp/level1/Fighters/Fighters/Enemy.h @@ -0,0 +1,31 @@ +#ifndef ENEMY_H +#define ENEMY_H +#include +#include "MMusic.h" +#include "Plane.h" + +class Enemy :public Plane +{ +public: + Enemy(World *world); + virtual ~Enemy(); + void enemyMove(); + void Fire(); + void AddEnemyBullet(); + void boomCheck(int state); + int state = 0; + int mark; + int live; + void set_bossState(int i); + int get_bossState(); + int bulletState = 0; + +protected: + sf::Vector2f direction; + int bossState = 0; + +private: + //int bulletState = 0; +}; + +#endif // ENEMY_H diff --git a/practices/cpp/level1/Fighters/Fighters/Fighters.vcxproj b/practices/cpp/level1/Fighters/Fighters/Fighters.vcxproj new file mode 100644 index 00000000..2b6e35b5 --- /dev/null +++ b/practices/cpp/level1/Fighters/Fighters/Fighters.vcxproj @@ -0,0 +1,184 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {CC21D290-6261-4CEA-8987-B5ADB23DB08D} + Win32Proj + Fighters + 8.1 + + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + C:\Users\Administrator\Desktop\SFML-2.4.2-windows-vc14-32-bit\SFML-2.4.2\include + + + Console + true + C:\Users\Administrator\Desktop\SFML-2.4.2-windows-vc14-32-bit\SFML-2.4.2\lib + sfml-graphics-d.lib;sfml-window-d.lib;sfml-audio-d.lib;sfml-system-d.lib;%(AdditionalDependencies) + + + + + + + Level3 + Disabled + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + C:\Users\Administrator\Desktop\SFML-2.4.2-windows-vc14-32-bit\SFML-2.4.2\include + + + Console + true + true + true + C:\Users\Administrator\Desktop\SFML-2.4.2-windows-vc14-32-bit\SFML-2.4.2\lib + sfml-graphics.lib;sfml-window.lib;sfml-audio.lib;sfml-system.lib;%(AdditionalDependencies) + + + + + Level3 + + + MaxSpeed + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/practices/cpp/level1/Fighters/Fighters/Fighters.vcxproj.filters b/practices/cpp/level1/Fighters/Fighters/Fighters.vcxproj.filters new file mode 100644 index 00000000..6f862d90 --- /dev/null +++ b/practices/cpp/level1/Fighters/Fighters/Fighters.vcxproj.filters @@ -0,0 +1,90 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + \ No newline at end of file diff --git a/practices/cpp/level1/Fighters/Fighters/Fighters.vcxproj.user b/practices/cpp/level1/Fighters/Fighters/Fighters.vcxproj.user new file mode 100644 index 00000000..c36328de --- /dev/null +++ b/practices/cpp/level1/Fighters/Fighters/Fighters.vcxproj.user @@ -0,0 +1,6 @@ + + + + WindowsLocalDebugger + + \ No newline at end of file diff --git a/practices/cpp/level1/Fighters/Fighters/Game.cpp b/practices/cpp/level1/Fighters/Fighters/Game.cpp new file mode 100644 index 00000000..7d9f2d45 --- /dev/null +++ b/practices/cpp/level1/Fighters/Fighters/Game.cpp @@ -0,0 +1,213 @@ +#include "Game.h" +#define HERO_INIT_X 340 +#define HERO_INIT_Y 750 +std::default_random_engine Game::random(time(NULL)); +Game::Game(World* world) +{ + //ctor + this->world = world; + //Score.setColor(sf::Color::Red); + //GameOver.setColor(sf::Color::White); + Score.setFont(RTexture::FONT); + GameOver.setFont(RTexture::FONT); + GameOver.setScale(1.5, 1.5); + float x(4.0), y(3.0); + GameOver.setPosition(this->world->getGlobalBounds().height / x, this->world->getGlobalBounds().height / y); +} + +Game::~Game() +{ + //dtor +} + +void Game::play_music() +{ + BGM.play(); + BGM.setLoop(true); +} + +void Game::pause_music() +{ + BGM.stop(); +} + +void Game::init() +{ + gameover_mark = 0; + restart = 0; + world->hero->setPosition(340,750); + world->ClearAll(true); + world->window->clear(); + world->hero->init(); +} + +void Game::MainLoop() +{ + this->play_music(); + while (world->window->isOpen()) + { + sf::Event event; + if (this->world->loading) { + + + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Return)) { + this->world->loading = false; + this->init(); + //this->LOAD_BGM.stop(); + + + } + + + + } + if (gameover_mark == 1) { + + + if (sf::Keyboard::isKeyPressed(sf::Keyboard::R)) { + init(); + continue; + } + + } + else if (this->world->loading == false) { + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { + if (this->world->hero->getPosition().x > 0) { + + world->hero->move(sf::Vector2f(-1.0, 0.0)); + } + } + + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { + if (this->world->hero->getPosition().x < this->world->getTextureRect().width - 430) { + + world->hero->move(sf::Vector2f(1.0, 0.0)); + } + } + + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { + if (this->world->hero->getPosition().y > 0) { + world->hero->move(sf::Vector2f(0.0, -1.0)); + } + } + + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { + if (this->world->hero->getPosition().y < 800) { + + world->hero->move(sf::Vector2f(0.0, 1.0)); + } + } + + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) { + + this->world->hero->shoot(this->world->hero->get_bulletmuch()); + } + + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Q)&&this->world->hero->MP==100) { + + this->world->Skill(); + this->world->hero->MP = 0; + } + } + + + while (world->window->pollEvent(event)) { + + if (event.type == sf::Event::Closed) { + world->window->close(); + + return; + } + } + if (gameover_mark == 1&&restart==0) + { + + + GameOvers(win); + restart = 1; + continue; + } + else if ((this->world->hero->GetScore()) >= 1000) { + win = true; + GameOvers(win); + restart = 1; + gameover_mark = 1; + world->ClearAll(true); + world->window->clear(); + continue; + + } + else if (gameover_mark == 0) { + if (world->killed()) + { + if ((world->hero->blood) < 0) { + + if (world->hero->dead()) + { + gameover_mark = 1; + world->hero->setPosition(HERO_INIT_X, HERO_INIT_Y); + world->ClearAll(true); + world->window->clear(); + continue; + } + this->world->hero->unbeatable = 301; + world->hero->setPosition(HERO_INIT_X, HERO_INIT_Y); + world->ClearAll(false); + } + } + + world->addEnemy(); + world->EnemyShoot(); + world->BonusFunction(); + world->moveBullet(); + world->cleanBullet(); + world->Refresh(); + if (this->world->loading) { + sf::Sprite load; + load.setTexture(RTexture::LOAD); + this->world->window->draw(load); + + + } + if (!this->world->loading) { ShowInfo(); } + world->window->display(); + } + } +} + +void Game::GameOvers(bool win) +{ + char str[120]; + if (win) { + sprintf_s(str, "Congratulations!\nYou Win!\nYour Score: %d \nPress R To Retart!", this->world->hero->GetScore()); + + } + else { + sprintf_s(str, "Regrettable!\nYou Failed!\nYOUR Score: %d \nPress R To Retart!", this->world->hero->GetScore()); + } + + GameOver.setString(str); + world->window->draw(GameOver); + world->window->display(); +} + +void Game::ShowInfo() +{ + sf::RectangleShape rectangle(sf::Vector2f((this->world->hero->GetBlood()) * 2.0, 40)); + rectangle.setPosition(0, 50); + rectangle.setFillColor(sf::Color::Red); + this->world->window->draw(rectangle); + + sf::RectangleShape rectangleS(sf::Vector2f((this->world->hero->get_mp()) * 2.0, 40)); + rectangleS.setPosition(0, 90); + rectangleS.setFillColor(sf::Color::Green); + this->world->window->draw(rectangleS); + + this->life_now = world->hero->GetLife(); + char INFO[120]; + sprintf_s(INFO, "Score: %d Life: %d", this->world->hero->GetScore(), this->life_now); + Score.setString(INFO); + Score.setCharacterSize(40); + Score.setPosition(0, 0); + this->world->window->draw(Score); +} diff --git a/practices/cpp/level1/Fighters/Fighters/Game.h b/practices/cpp/level1/Fighters/Fighters/Game.h new file mode 100644 index 00000000..a4381d9e --- /dev/null +++ b/practices/cpp/level1/Fighters/Fighters/Game.h @@ -0,0 +1,37 @@ +#ifndef GAME_H +#define GAME_H +#include +#include +#include "World.h" +#include +#include +#include "MMusic.h" +#include +class Game +{ +public: + static std::default_random_engine random; + Game(World *world); + virtual ~Game(); + void init(); + void MainLoop(); + void GameOvers(bool win); + void ShowInfo(); + +protected: + +private: + World *world; + int life_now; + sf::Text Score; + sf::Text Loading; + sf::Text GameOver; + bool win = false; + int gameover_mark = 0; + int restart = 0; + void play_music(); + void pause_music(); + sf::Music &BGM = Music::BGM; +}; + +#endif // GAME_H diff --git a/practices/cpp/level1/Fighters/Fighters/Hero.cpp b/practices/cpp/level1/Fighters/Fighters/Hero.cpp new file mode 100644 index 00000000..e6b3a852 --- /dev/null +++ b/practices/cpp/level1/Fighters/Fighters/Hero.cpp @@ -0,0 +1,156 @@ +#include "Hero.h" +#include "World.h" +#define HERO_SPEED 8 +#define SHOOT_SPEED 12 +Hero::Hero(World *world) :Plane(world) +{ + //ctor + this->setTexture(this->texture); + this->setPosition(340, 750); + this->setSpeed(HERO_SPEED); +} + +Hero::~Hero() +{ + //dtor +} + +void Hero::init() +{ + this->life = 3; + this->score = 0; + this->blood = 100; + this->setPosition(340,750); + +} + +void Hero::shoot(int j) +{ + int k; + if (j == 1) {k = 50 * j;} + if (j == 2) { k = 20 * j; } + if (j == 3) { k = 8 * j; } + + static int i = 0; + + if (i>k) { + if (j == 3) { + Music::Fire.play(); + Bullet *bulletM = new Bullet(RTexture::BULLET1,1, sf::Vector2f(0.0, -1.0)); + Bullet *bulletR = new Bullet(RTexture::BULLET2,1, sf::Vector2f(0.0, -1.0)); + Bullet *bulletL = new Bullet(RTexture::BULLET2,1, sf::Vector2f(0.0, -1.0)); + bulletM->setScale(1, 1); + bulletR->setScale(1, 1); + bulletL->setScale(1, 1); + bulletM->setBulletSpeed(SHOOT_SPEED); + bulletR->setBulletSpeed(SHOOT_SPEED); + bulletL->setBulletSpeed(SHOOT_SPEED); + bulletM->setPosition(this->getPosition().x + 63, this->getPosition().y); + bulletR->setPosition(this->getPosition().x + 88, this->getPosition().y); + bulletL->setPosition(this->getPosition().x + 10, this->getPosition().y); + this->world->addBullet(bulletM, 1); + this->world->addBullet(bulletR, 1); + this->world->addBullet(bulletL, 1); + + } + if (j == 2) + { + Music::Fire.play(); + Bullet *bulletR = new Bullet(RTexture::BULLET2,1, sf::Vector2f(0.0, -1.0)); + Bullet *bulletL = new Bullet(RTexture::BULLET2,1, sf::Vector2f(0.0, -1.0)); + bulletR->setScale(1, 1); + bulletL->setScale(1, 1); + bulletR->setBulletSpeed(SHOOT_SPEED); + bulletL->setBulletSpeed(SHOOT_SPEED); + bulletR->setPosition(this->getPosition().x + 88, this->getPosition().y); + bulletL->setPosition(this->getPosition().x + 10, this->getPosition().y); + this->world->addBullet(bulletR, 1); + this->world->addBullet(bulletL, 1); + } + if(j==1) { + Music::Fire.play(); + Bullet *bulletM = new Bullet(RTexture::BULLET1,1, sf::Vector2f(0.0, -1.0)); + bulletM->setScale(1, 1); + bulletM->setBulletSpeed(SHOOT_SPEED); + bulletM->setPosition(this->getPosition().x + 63, this->getPosition().y); + this->world->addBullet(bulletM, 1); + } + i = 0; + } + else { + i++; + } +} + +void Hero::AddScore(int score) +{ + this->score += score; +} + +void Hero::AddLife() +{ + if (blood >= 100) { + life++; + } + else if (blood < 100) { blood+=20; } +} +int Hero::GetBlood() +{ + return blood; +} +void Hero::add_mp() +{ + if (MP < 100) { this->MP = MP + 10; } +} +int Hero::get_mp() +{ + return this->MP; +} +int Hero::GetLife() +{ + return this->life; +} + +int Hero::GetScore() +{ + return score; +} + +void Hero::set_bulletmuch(int BulletMuch) +{ + this->BulletMuch = BulletMuch; +} + +int Hero::get_bulletmuch() +{ + return BulletMuch; +} + +bool Hero::dead() +{ + + if (blood < 0) { + this->BOOM.play(); + life--; + sf::Sprite boom; + boom.setTexture(BOOMP); + boom.scale(1.5, 1.5); + boom.setPosition(this->getPosition().x, this->getPosition().y); + world->window->draw(boom); + world->window->display(); + sf::Time s = sf::seconds(0.3f); + sf::sleep(s); + } + return life == 0; +} + + +void Hero::set_bonusmuch(int bonusmuch) +{ + this->bonusmuch = bonusmuch; +} + +int Hero::get_bonusmuch() +{ + return bonusmuch; +} diff --git a/practices/cpp/level1/Fighters/Fighters/Hero.h b/practices/cpp/level1/Fighters/Fighters/Hero.h new file mode 100644 index 00000000..acd9d0d9 --- /dev/null +++ b/practices/cpp/level1/Fighters/Fighters/Hero.h @@ -0,0 +1,42 @@ + +#ifndef HERO_H +#define HERO_H +#include "Plane.h" +#include "MMusic.h" +#include "RTexture.h" +#include +class Hero :public Plane +{ +public: + Hero(World *world); + virtual ~Hero(); + bool dead(); + void init(); + void shoot(int j); + void AddScore(int score); + void AddLife(); + int GetBlood(); + int unbeatable = -10; + int life = 3; + int blood = 100; + int MP = 100; + void add_mp(); + int get_mp(); + int GetLife(); + int GetScore(); + void set_bulletmuch(int BulletMuch); + int get_bulletmuch(); + void set_bonusmuch(int bonusmuch); + int get_bonusmuch(); + friend class World; +protected: + +private: + int score; + int BulletMuch = 1; + int bonusmuch = 0; + sf::Texture texture=RTexture::PLAYER2 ; + +}; + +#endif // HERO_H diff --git a/practices/cpp/level1/Fighters/Fighters/Load.cpp b/practices/cpp/level1/Fighters/Fighters/Load.cpp new file mode 100644 index 00000000..459a5a3d --- /dev/null +++ b/practices/cpp/level1/Fighters/Fighters/Load.cpp @@ -0,0 +1,17 @@ +#include "Load.h" + +Load::Load() +{ + //ctor +} + +Load::~Load() +{ + //dtor +} + +void Load::loading() +{ + Music::load(); + RTexture::load(); +} diff --git a/practices/cpp/level1/Fighters/Fighters/Load.h b/practices/cpp/level1/Fighters/Fighters/Load.h new file mode 100644 index 00000000..03ca1b29 --- /dev/null +++ b/practices/cpp/level1/Fighters/Fighters/Load.h @@ -0,0 +1,18 @@ +#ifndef LOAD_H +#define LOAD_H +#include "MMusic.h" +#include "RTexture.h" + +class Load +{ +public: + Load(); + virtual ~Load(); + static void loading(); + +protected: + +private: +}; + +#endif // LOAD_H diff --git a/practices/cpp/level1/Fighters/Fighters/MMusic.cpp b/practices/cpp/level1/Fighters/Fighters/MMusic.cpp new file mode 100644 index 00000000..0bb0e8a2 --- /dev/null +++ b/practices/cpp/level1/Fighters/Fighters/MMusic.cpp @@ -0,0 +1,26 @@ +#include "MMusic.h" +#include +#include +sf::Music Music::BGM; +sf::Music Music::BOOM; +sf::Music Music::Fire; +sf::Music Music::ENEMY_BOOM; +sf::Music Music::BOSS_BOOM; +Music::Music() +{ + //ctor +} + +Music::~Music() +{ + //dtor +} + +void Music::load() +{ + BGM.openFromFile("resource/music/BGM.ogg"); + BOOM.openFromFile("resource/music/BOOM.wav"); + Fire.openFromFile("resource/music/fire.wav"); + BOSS_BOOM.openFromFile("resource/music/boss_boom.wav"); + ENEMY_BOOM.openFromFile("resource/music/enemy_boom.wav"); +} diff --git a/practices/cpp/level1/Fighters/Fighters/MMusic.h b/practices/cpp/level1/Fighters/Fighters/MMusic.h new file mode 100644 index 00000000..144a0b34 --- /dev/null +++ b/practices/cpp/level1/Fighters/Fighters/MMusic.h @@ -0,0 +1,22 @@ +#ifndef MUSIC_H +#define MUSIC_H +#include + +class Music +{ +public: + Music(); + virtual ~Music(); + static sf::Music BGM; + static sf::Music BOOM; + static sf::Music Fire; + static sf::Music ENEMY_BOOM; + static sf::Music BOSS_BOOM; + static void load(); + +protected: + +private: +}; + +#endif // MUSIC_H diff --git a/practices/cpp/level1/Fighters/Fighters/Plane.cpp b/practices/cpp/level1/Fighters/Fighters/Plane.cpp new file mode 100644 index 00000000..64e24f16 --- /dev/null +++ b/practices/cpp/level1/Fighters/Fighters/Plane.cpp @@ -0,0 +1,16 @@ +#include "Plane.h" +#include "World.h" +#include "RTexture.h" +Plane::Plane(World *world) +{ + + + //ctor + this->world = world; +} + +Plane::~Plane() +{ + //dtor +} + diff --git a/practices/cpp/level1/Fighters/Fighters/Plane.h b/practices/cpp/level1/Fighters/Fighters/Plane.h new file mode 100644 index 00000000..8d272039 --- /dev/null +++ b/practices/cpp/level1/Fighters/Fighters/Plane.h @@ -0,0 +1,22 @@ +#ifndef PLANE_H +#define PLANE_H +#include +#include "RTexture.h" +#include "MMusic.h" +#include "Action.h" +class World; +class Plane :public Action +{ +public: + Plane(World *world); + virtual ~Plane(); + +protected: + World *world; + sf::Texture BOOMP = RTexture::BOOM1; + sf::Music &BOOM = Music::ENEMY_BOOM; + sf::Music &FIRE = Music::Fire; +private: +}; + +#endif // PLANE_H diff --git a/practices/cpp/level1/Fighters/Fighters/RTexture.cpp b/practices/cpp/level1/Fighters/Fighters/RTexture.cpp new file mode 100644 index 00000000..b94de49e --- /dev/null +++ b/practices/cpp/level1/Fighters/Fighters/RTexture.cpp @@ -0,0 +1,59 @@ +#include "RTexture.h" +#include +sf::Texture RTexture::PLAYER; +sf::Texture RTexture::BULLET1; +sf::Texture RTexture::BULLET2; +sf::Texture RTexture::BULLET3; +sf::Texture RTexture::ENEMY; +sf::Texture RTexture::BACK_GROUND; +sf::Texture RTexture::BOOM1; +sf::Texture RTexture::PLAYER1; +sf::Texture RTexture::LIFE; +sf::Font RTexture::FONT; +sf::Texture RTexture::BOSS; +sf::Texture RTexture::BOSS1; +sf::Texture RTexture::BOSSBULLET; +sf::Texture RTexture::BOSSBULLET1; +sf::Texture RTexture::BOSSNULLET2; +sf::Texture RTexture::PLAYER2; +sf::Texture RTexture::BULLETBONUS; +sf::Texture RTexture::RANDBONUS; +sf::Texture RTexture::PLAYER3; +sf::Texture RTexture::ENERGY; +sf::Texture RTexture::PROTECT; +sf::Texture RTexture::LOAD; +RTexture::RTexture() +{ + //ctor +} + +RTexture::~RTexture() +{ + //dtor +} + +void RTexture::load() +{ + BOSS.loadFromFile("resource/image/enemy1.png"); + BOSS1.loadFromFile("resource/image/boss1.png"); + BOSSBULLET.loadFromFile("resource/image/bossbullet.png"); + BOSSBULLET1.loadFromFile("resource/image/bossbullet1.png"); + BOSSNULLET2.loadFromFile("resource/image/bossbullet2.png"); + RANDBONUS.loadFromFile("resource/image/randBonus.png"); + BULLETBONUS.loadFromFile("resource/image/bulletBonus.png"); + PLAYER2.loadFromFile("resource/image/hero1.png"); + PLAYER1.loadFromFile("resource/image/NULL.png"); + PLAYER.loadFromFile("resource/image/hero.png"); + BULLET1.loadFromFile("resource/image/bullet.png"); + BULLET2.loadFromFile("resource/image/bullet1.png"); + BULLET3.loadFromFile("resource/image/bullet3.png"); + ENEMY.loadFromFile("resource/image/enemy1.png"); + BACK_GROUND.loadFromFile("resource/image/back.jpg"); + BOOM1.loadFromFile("resource/image/boom.png"); + LIFE.loadFromFile("resource/image/life.png"); + FONT.loadFromFile("resource/font/font.ttf"); + PLAYER3.loadFromFile("resource/image/hero2.png"); + PROTECT.loadFromFile("resource/image/protect.png"); + ENERGY.loadFromFile("resource/image/ENERGY.png"); + LOAD.loadFromFile("resource/image/Load.png"); +} diff --git a/practices/cpp/level1/Fighters/Fighters/RTexture.h b/practices/cpp/level1/Fighters/Fighters/RTexture.h new file mode 100644 index 00000000..a425b80a --- /dev/null +++ b/practices/cpp/level1/Fighters/Fighters/RTexture.h @@ -0,0 +1,40 @@ +#ifndef RTEXTURE_H +#define RTEXTURE_H +#include + + +class RTexture +{ +public: + RTexture(); + virtual ~RTexture(); + static sf::Texture PLAYER; + static sf::Texture ENEMY; + static sf::Texture BULLET1; + static sf::Texture BULLET2; + static sf::Texture BACK_GROUND; + static sf::Texture BOOM1; + static sf::Texture BULLET3; + static sf::Texture PLAYER1; + static sf::Texture LIFE; + static sf::Texture BOSS; + static sf::Texture BOSS1; + static sf::Texture BOSSBULLET; + static sf::Texture BOSSBULLET1; + static sf::Texture BOSSNULLET2; + static sf::Texture PLAYER2; + static sf::Texture BULLETBONUS; + static sf::Texture RANDBONUS; + static sf::Texture PLAYER3; + static sf::Texture ENERGY; + static sf::Texture PROTECT; + static sf::Texture LOAD; + static sf::Font FONT; + static void load(); + +protected: + +private: +}; + +#endif // RTEXTURE_H diff --git a/practices/cpp/level1/Fighters/Fighters/World.cpp b/practices/cpp/level1/Fighters/Fighters/World.cpp new file mode 100644 index 00000000..8599aec3 --- /dev/null +++ b/practices/cpp/level1/Fighters/Fighters/World.cpp @@ -0,0 +1,497 @@ +#include "World.h" +#include "Game.h" +#include +#define ENEMY_BULLET_SPEED 1.3f + +World::World(sf::RenderWindow *window) +{ + //ctor + this->window = window; + this->setTexture(this->texture); + this->setScale(1.0f*this->window->getSize().x / this->texture.getSize().x, 1.0f*this->window->getSize().y / this->texture.getSize().y); + +} + +World::~World() +{ + //dtor +} + +void World::add(Hero *Hero) { + this->hero = Hero; + +} + + +void World::Refresh() { + + + + this->window->clear(); + this->window->draw(*this); + this->window->draw(*(this->hero)); + + for (auto enemy = this->smallBoss.begin(); enemy != (this->smallBoss.end());) + { + auto temp = enemy; + (*enemy)->enemyMove(); + + if ((*enemy)->state >= 1 && (*enemy)->state <= 10) + { + (*enemy)->boomCheck(((*enemy)->state)++); + break; + } + + else if ((*enemy)->state == 11) + { + + delete *enemy; + enemy = (this->smallBoss).erase(enemy); + break; + } + + if ((*enemy)->getPosition().y>1000) + { + delete *enemy; + enemy = (this->smallBoss).erase(enemy); + break; + } + for (auto sprite = this->heroBullets.begin(); sprite != (this->heroBullets.end());) + { + if ((*enemy)->getGlobalBounds().intersects((*sprite)->getGlobalBounds())) + { + this->heroBullets.erase(sprite); + if ((((*enemy)->live -= 2) < 0)) { + (*enemy)->state = 1; + this->hero->AddScore(10); + bonusState = 1; + AddBonus((*enemy)->getPosition().x, (*enemy)->getPosition().y); + + + + break; + + } + break; + } + sprite++; + } + + if ((*enemy)->getPosition().y>1000) + { + delete *enemy; + enemy = (this->enemyPlanes).erase(enemy); + break; + } + + this->window->draw(**enemy); + if (temp == enemy) { ++enemy; } + + } + + + + + + + for (auto enemy = this->enemyPlanes.begin(); enemy != (this->enemyPlanes.end());) + { + auto temp = enemy; + (*enemy)->enemyMove(); + if ((*enemy)->state >= 1 && (*enemy)->state <= 10) + { + (*enemy)->boomCheck(((*enemy)->state)++); + break; + } + else if ((*enemy)->state == 11) + { + + delete *enemy; + enemy = (this->enemyPlanes).erase(enemy); + break; + } + + for (auto sprite = this->heroBullets.begin(); sprite != (this->heroBullets.end());) + { + if ((*enemy)->getGlobalBounds().intersects((*sprite)->getGlobalBounds())) + { + this->heroBullets.erase(sprite); + if ((((*enemy)->live -= 2) < 0)) { + (*enemy)->state = 1; + this->hero->AddScore(5); + bonusState = 0; + AddBonus((*enemy)->getPosition().x, (*enemy)->getPosition().y); + + + + break; + + } + break; + } + sprite++; + } + + if ((*enemy)->getPosition().y>1000) + { + delete *enemy; + enemy = (this->enemyPlanes).erase(enemy); + break; + } + this->window->draw(**enemy); + if (temp == enemy) { ++enemy; } + + } + + /*sf::RectangleShape rectangle(sf::Vector2f((this->hero->GetBlood()) * 2.0, 40)); + rectangle.setPosition(0, 50); + rectangle.setFillColor(sf::Color::Red); + this->window->draw(rectangle);*/ + for (auto &sprite : this->heroBullets) + { + this->window->draw(*sprite); + } + + for (auto &sprite : this->smallBossBullet) + { + this->window->draw(*sprite); + } + + + for (auto &sprite : this->enemyBullets) + { + + this->window->draw(*sprite); + } + + for (auto &sprite : this->bonuss) + { + this->window->draw(*sprite); + } +} + +void World::addBullet(Bullet *bullet, int mark) +{ + switch (mark) + { + case 1: + this->heroBullets.insert(bullet); + break; + case 2: + + this->enemyBullets.insert(bullet); + break; + case 3: + this->smallBossBullet.insert(bullet); + + break; + + } +} + +void World::moveBullet() +{ + for (auto &bullet : this->heroBullets) { + bullet->move(); + } + + for (auto &bullet : this->enemyBullets) { + bullet->setBulletSpeed(ENEMY_BULLET_SPEED); + bullet->move(); + } + + +} + +void World::cleanBullet() { + + for (auto bullet = this->heroBullets.begin(); bullet != (this->heroBullets.end());) + { + if ((*bullet)->getPosition().y<0) { + + delete *bullet; + + bullet = (this->heroBullets).erase(bullet); + + } + else { + bullet++; + } + } + + for (auto bullet = this->enemyBullets.begin(); bullet != (this->enemyBullets.end());) + { + if ((*bullet)->getPosition().y>1000) { + + delete *bullet; + + bullet = (this->enemyBullets).erase(bullet); + + } + else { + bullet++; + } + } + + + +} + +void World::addEnemy() +{ + uniform_int_distribution E(0, 10); + static int i = 0; + if (i >= 90) + { + Enemy* enemy1 = new Enemy(this); + if (0 <= E(Game::random) <= 6&&enemy1->get_bossState()==0) { + //Enemy* enemy1 = new Enemy(this); + //// Enemy* enemy2 = new Enemy(this); + //// Enemy* enemy3 = new Enemy(this); + // this->enemyPlanes.insert(enemy3); + this->enemyPlanes.insert(enemy1); + enemy1->bulletState = 0; + //bonusState = 0; + // this->enemyPlanes.insert(enemy2); + } + if (7 <= E(Game::random) <= 10&& enemy1->get_bossState()==1) + { + //Enemy *enemy4 = new Enemy(this); + enemy1->bulletState = 1; + //bonusState = 1; + this->smallBoss.insert(enemy1); + } + i = 0; + } + else { i++; } + + +} + +void World::EnemyShoot() +{ + for (auto enemy = this->enemyPlanes.begin(); enemy != this->enemyPlanes.end();) + { + (*enemy)->Fire(); + enemy++; + + } + + for (auto enemy = this->smallBoss.begin(); enemy != this->smallBoss.end();) + { + + (*enemy)->Fire(); + enemy++; + } +} + +bool World::killed() +{ + if (this->hero->blood < 0) { + + if ((--this->hero->unbeatable) > 0) + { + static bool Mark = true; + this->hero->set_bulletmuch(1); + this->hero->set_bonusmuch(0); + if (Mark) + { + this->hero->setTexture(RTexture::PLAYER1); + Mark = false; + } + else + { + this->hero->setTexture(RTexture::PLAYER2); + Mark = true; + } + return false; + } + this->hero->blood = 100; + } + if(loading) + { + return false; + } + + for (auto &bullet : this->enemyBullets) + { + if ((bullet)->getGlobalBounds().intersects((this->hero)->getGlobalBounds())) + { + delete bullet; + (this->enemyBullets).erase(bullet); + this->hero->blood -= 20; + return true; + } + + } + + for (auto &bullet : this->smallBossBullet) + { + if ((bullet)->getGlobalBounds().intersects((this->hero)->getGlobalBounds())) + { + delete bullet; + (this->smallBossBullet).erase(bullet); + this->hero->blood -= 50; + return true; + } + + } + + for (auto &enemy : this->smallBoss) + { + if ((enemy)->getGlobalBounds().intersects((this->hero)->getGlobalBounds())) + { + this->hero->blood =-1; + return true; + } + } + + for (auto &enemy : this->enemyPlanes) + { + if ((enemy)->getGlobalBounds().intersects((this->hero)->getGlobalBounds())) + { + this->hero->blood = -2; + return true; + } + } + + return false; +} + +void World::ClearAll(bool mark) +{ + for (auto &bullet : this->enemyBullets) + { + delete bullet; + } + + if (mark) + { + for (auto &plane : this->enemyPlanes) + { + delete plane; + } + enemyPlanes.clear(); + + for (auto &plane : this->smallBoss) + { + delete plane; + } + smallBoss.clear(); + } + smallBossBullet.clear(); + enemyBullets.clear(); + heroBullets.clear(); + bonuss.clear(); + +} + + + +void World::AddBonus(float x,float y) +{ + uniform_int_distribution a(0, 50); + + if (a(Game::random) <3&&bonusState==0) + { + + Bonus *bonus = new Bonus(x, y); + bonuss.insert(bonus); + + } + + if (4<=a(Game::random) <=35 &&bonusState == 1) + { + Bonus *bonus = new Bonus(x, y); + bonuss.insert(bonus); + } +} + +void World::BonusFunction() +{ + for (auto &bonus : this->bonuss) + { + bonus->MoveRand(); + + if (bonus->getGlobalBounds().intersects(this->hero->getGlobalBounds()) && bonus->get_bonusstate() == 3) + { + this->hero->add_mp(); + delete bonus; + this->bonuss.erase(bonus); + break; + } + + + if (bonus->getGlobalBounds().intersects(this->hero->getGlobalBounds())&&bonus->get_bonusstate() == 0) + { + this->hero->AddLife(); + delete bonus; + this->bonuss.erase(bonus); + break; + } + if (bonus->getGlobalBounds().intersects(this->hero->getGlobalBounds()) && bonus->get_bonusstate() == 2) + { + if (this->hero->get_bonusmuch() == 0) { + this->hero->set_bulletmuch(2); + this->hero->setTexture(RTexture::PLAYER3); + this->hero->set_bonusmuch(1); + } + else if (this->hero->get_bonusmuch() == 1) + { + this->hero->setTexture(RTexture::PLAYER); + this->hero->set_bulletmuch(3); + + } + delete bonus; + this->bonuss.erase(bonus); + break; + } + + if (bonus->getGlobalBounds().intersects(this->hero->getGlobalBounds()) && bonus->get_bonusstate() == 1) + { + uniform_int_distribution c(0, 2); + switch (c(Game::random)) + { + case 0: + + this->hero->set_bulletmuch(3); + this->hero->setTexture(RTexture::PLAYER); + this->hero->set_bonusmuch(2); + break; + case 1: + this->hero->life++; + break; + case 2: + this->hero->add_mp(); + default: + break; + } + + delete bonus; + this->bonuss.erase(bonus); + break; + } + } +} + +void World::Skill() +{ + int x = 0; + + for (int i = 0; i<20; i++) + { + Bullet *bullet = new Bullet(RTexture::BULLET2, 1, sf::Vector2(0.0, -1.0)); + bullet->setScale(1.0f, 1.0f); + bullet->setPosition(x, 800); + this->heroBullets.insert(bullet); + x += 40; + + } + + + + +} + + + diff --git a/practices/cpp/level1/Fighters/Fighters/World.h b/practices/cpp/level1/Fighters/Fighters/World.h new file mode 100644 index 00000000..251e01d0 --- /dev/null +++ b/practices/cpp/level1/Fighters/Fighters/World.h @@ -0,0 +1,47 @@ +#ifndef MAINLOOP_H +#define MAINLOOP_H +#include +#include "Hero.h" +#include enemyPlanes; + unordered_set heroBullets; + unordered_set enemyBullets; + unordered_set smallBossBullet; + unordered_set smallBoss; + unordered_set bonuss; + +}; + +#endif // MAINLOOP_H diff --git a/practices/cpp/level1/Fighters/Fighters/main.cpp b/practices/cpp/level1/Fighters/Fighters/main.cpp new file mode 100644 index 00000000..0c5c7e11 --- /dev/null +++ b/practices/cpp/level1/Fighters/Fighters/main.cpp @@ -0,0 +1,22 @@ +#include +#include +#include "MMusic.h" +#include "RTexture.h" +#include "World.h" +#include "Hero.h" +#include "Load.h" +#include "Game.h" + +int main() +{ + sf::RenderWindow window(sf::VideoMode(800, 1000), "Fighter"); + + Load::loading(); + World world(&window); + Hero hero(&world); + world.add(&hero); + Game game(&world); + window.setFramerateLimit(120); + game.MainLoop(); + return 0; +} diff --git a/practices/cpp/level1/Fighters/Fighters/resource/font/font.ttf b/practices/cpp/level1/Fighters/Fighters/resource/font/font.ttf new file mode 100644 index 00000000..d85fbc81 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/font/font.ttf differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/image/BOSS.png b/practices/cpp/level1/Fighters/Fighters/resource/image/BOSS.png new file mode 100644 index 00000000..63eee60b Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/image/BOSS.png differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/image/ENERGY.png b/practices/cpp/level1/Fighters/Fighters/resource/image/ENERGY.png new file mode 100644 index 00000000..e45f3b15 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/image/ENERGY.png differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/image/Load.png b/practices/cpp/level1/Fighters/Fighters/resource/image/Load.png new file mode 100644 index 00000000..8471f868 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/image/Load.png differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/image/Load1.jpg b/practices/cpp/level1/Fighters/Fighters/resource/image/Load1.jpg new file mode 100644 index 00000000..3800de4a Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/image/Load1.jpg differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/image/back.jpg b/practices/cpp/level1/Fighters/Fighters/resource/image/back.jpg new file mode 100644 index 00000000..14f44177 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/image/back.jpg differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/image/back1.jpg b/practices/cpp/level1/Fighters/Fighters/resource/image/back1.jpg new file mode 100644 index 00000000..722a3f97 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/image/back1.jpg differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/image/back2.jpg b/practices/cpp/level1/Fighters/Fighters/resource/image/back2.jpg new file mode 100644 index 00000000..3800de4a Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/image/back2.jpg differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/image/boom.png b/practices/cpp/level1/Fighters/Fighters/resource/image/boom.png new file mode 100644 index 00000000..8a447b12 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/image/boom.png differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/image/boss1.png b/practices/cpp/level1/Fighters/Fighters/resource/image/boss1.png new file mode 100644 index 00000000..6a28aa2d Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/image/boss1.png differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/image/bossbullet.png b/practices/cpp/level1/Fighters/Fighters/resource/image/bossbullet.png new file mode 100644 index 00000000..efbed45d Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/image/bossbullet.png differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/image/bossbullet1.png b/practices/cpp/level1/Fighters/Fighters/resource/image/bossbullet1.png new file mode 100644 index 00000000..9330273f Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/image/bossbullet1.png differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/image/bossbullet2.png b/practices/cpp/level1/Fighters/Fighters/resource/image/bossbullet2.png new file mode 100644 index 00000000..0199e3de Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/image/bossbullet2.png differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/image/bullet.png b/practices/cpp/level1/Fighters/Fighters/resource/image/bullet.png new file mode 100644 index 00000000..adc257e4 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/image/bullet.png differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/image/bullet1.png b/practices/cpp/level1/Fighters/Fighters/resource/image/bullet1.png new file mode 100644 index 00000000..2e5f0377 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/image/bullet1.png differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/image/bullet3.png b/practices/cpp/level1/Fighters/Fighters/resource/image/bullet3.png new file mode 100644 index 00000000..7b1505a7 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/image/bullet3.png differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/image/bulletBonus.png b/practices/cpp/level1/Fighters/Fighters/resource/image/bulletBonus.png new file mode 100644 index 00000000..e334f5e5 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/image/bulletBonus.png differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/image/enemy1.png b/practices/cpp/level1/Fighters/Fighters/resource/image/enemy1.png new file mode 100644 index 00000000..ed557856 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/image/enemy1.png differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/image/enemy2.png b/practices/cpp/level1/Fighters/Fighters/resource/image/enemy2.png new file mode 100644 index 00000000..416763b2 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/image/enemy2.png differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/image/hero.png b/practices/cpp/level1/Fighters/Fighters/resource/image/hero.png new file mode 100644 index 00000000..dbd18ad1 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/image/hero.png differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/image/hero1.png b/practices/cpp/level1/Fighters/Fighters/resource/image/hero1.png new file mode 100644 index 00000000..67e99497 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/image/hero1.png differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/image/hero2.png b/practices/cpp/level1/Fighters/Fighters/resource/image/hero2.png new file mode 100644 index 00000000..972b52c7 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/image/hero2.png differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/image/life.png b/practices/cpp/level1/Fighters/Fighters/resource/image/life.png new file mode 100644 index 00000000..9f345219 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/image/life.png differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/image/protect.png b/practices/cpp/level1/Fighters/Fighters/resource/image/protect.png new file mode 100644 index 00000000..78055e2b Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/image/protect.png differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/image/randBonus.png b/practices/cpp/level1/Fighters/Fighters/resource/image/randBonus.png new file mode 100644 index 00000000..56be02b4 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/image/randBonus.png differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/music/BGM.ogg b/practices/cpp/level1/Fighters/Fighters/resource/music/BGM.ogg new file mode 100644 index 00000000..ef30d126 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/music/BGM.ogg differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/music/BGM.wav b/practices/cpp/level1/Fighters/Fighters/resource/music/BGM.wav new file mode 100644 index 00000000..65a14996 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/music/BGM.wav differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/music/BOOM.wav b/practices/cpp/level1/Fighters/Fighters/resource/music/BOOM.wav new file mode 100644 index 00000000..8c2c776a Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/music/BOOM.wav differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/music/BOOM1.wav b/practices/cpp/level1/Fighters/Fighters/resource/music/BOOM1.wav new file mode 100644 index 00000000..2c540600 Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/music/BOOM1.wav differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/music/boss_boom.wav b/practices/cpp/level1/Fighters/Fighters/resource/music/boss_boom.wav new file mode 100644 index 00000000..82a07d8c Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/music/boss_boom.wav differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/music/enemy_boom.wav b/practices/cpp/level1/Fighters/Fighters/resource/music/enemy_boom.wav new file mode 100644 index 00000000..8c2c776a Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/music/enemy_boom.wav differ diff --git a/practices/cpp/level1/Fighters/Fighters/resource/music/fire.wav b/practices/cpp/level1/Fighters/Fighters/resource/music/fire.wav new file mode 100644 index 00000000..ebb1f77e Binary files /dev/null and b/practices/cpp/level1/Fighters/Fighters/resource/music/fire.wav differ diff --git a/practices/cpp/level1/Fighters/Todolist.md b/practices/cpp/level1/Fighters/Todolist.md new file mode 100644 index 00000000..e3613277 --- /dev/null +++ b/practices/cpp/level1/Fighters/Todolist.md @@ -0,0 +1,30 @@ +编号 | 任务(功能)                   | Value   | Effort   | 是否已完成   +-----|-------------------------------|-----------|-----------|------------| +1 | 完成SFML配置,显示“SFML works” | 0 | 0 | OK | +2 | 显示一架静止的飞机于屏幕底部 | 5 | 1 | OK | +3 | 背景音乐 | 1 | 1 | OK | +4 | 左右键,控制移动飞机 | 10 | 1 | OK | +5 | 限制左右边界 | 1 | 1 | OK | +6 | 空格键开炮,显示运动的炮弹 | 5 | 5 | OK | +7 | 炮弹飞出边界处理 | 2 | 1 | OK | +8 | 随机产生敌机,并向下运动 | 10 | 5 | OK | +9 | 敌机飞出边界处理 | 2 | 1 | OK | +10 | 碰撞处理(敌机与炮弹碰撞) | 10 | 5 | OK | +11 | 显示敌机爆炸过程 | 10 | 1 | OK | +12 | 爆炸声音 | 2 | 1 | OK | +13 | 计分及显示 | 5 | 3 | OK | +14 | 敌机炮弹处理 | 10 | 5 | OK | +15 | 被敌机击中处理(炸毁、3条命) | 10 | 5 | OK | +16 | 过关控制(过关需要计分、游戏速度控制)| 20 | 5 | OK | +17 | 实现了一个技能 | 10 | 2 | OK | +18 | 飞机以及子弹的变身 | 10 | 2 | OK | | +19 | 血条和魔法值条 | 10 | 2 | OK | +20 | 加入物品系统 | 10 | 3 | OK | +21 |死后三秒无敌状态 |5 |1 |OK | +22 |实现游戏开始界面 |5 |2 |OK | +23 |实现游戏结束后可选择重新开始游戏 |5 |2 |OK | +合计   |完成打飞机游戏                         |       158   |       55   |     OK     | + + + + diff --git a/practices/cpp/level1/fighter/TodoList.md b/practices/cpp/level1/fighter/TodoList.md new file mode 100644 index 00000000..63a023c2 --- /dev/null +++ b/practices/cpp/level1/fighter/TodoList.md @@ -0,0 +1,24 @@ + | 任务(功能) | Value | Effort | 是否已完成 +编号 | 任务(功能)                   | Value   | Effort   | 是否已完成   +-----|-------------------------------|-----------|-----------|------------| +1 | 完成SFML配置,显示“SFML works” | 0 | 0 | OK | +2 | 显示一架静止的飞机于屏幕底部 | 5 | 1 | OK | +3 | 背景音乐 | 1 | 1 | OK | +4 | 左右键,控制移动飞机 | 10 | 1 | OK | +5 | 限制左右边界 | 1 | 1 | OK | +6 | 空格键开炮,显示运动的炮弹 | 5 | 5 | OK | +7 | 炮弹飞出边界处理 | 2 | 1 | OK | +8 | 随机产生敌机,并向下运动 | 10 | 5 | OK | +9 | 敌机飞出边界处理 | 2 | 1 | OK | +10 | 碰撞处理(敌机与炮弹碰撞) | 10 | 5 | OK | +11 | 显示敌机爆炸过程 | 10 | 1 | OK | +12 | 爆炸声音 | 2 | 1 | OK | +13 | 计分及显示 | 5 | | | +14 | 敌机炮弹处理 | 10 | | OK | +15 | 被敌机击中处理(炸毁、3条命) | 10 | | OK | +16 | 过关控制(过关需要计分、游戏速度控制)| 20 | | | +17 | | | | | +18 | | | | | +19 | | | | | +20 | | | | | +合计 | | | | | diff --git a/practices/cpp/level1/p01_Queue/Queue.cpp b/practices/cpp/level1/p01_Queue/Queue.cpp new file mode 100644 index 00000000..1252addb --- /dev/null +++ b/practices/cpp/level1/p01_Queue/Queue.cpp @@ -0,0 +1,58 @@ +#include "Queue.h" +#include + +using namespace std; + +Queue::Queue():i(0) +{ + //ctor +} + +Queue::~Queue() +{ + //dtor +} + +void Queue::append(int number) +{ + data[i]=number; + i++; + if(i==100)i=0; +} + +void Queue::pop() +{ + for(int j = 0 ; j < 100 ; j++){ + cout << data[j] < +#include "Queue.h" + +using namespace std; + +int main() +{ + Queue queue; + int choice; + + while(1){ + cout<<"what do you want to do?\n" <<"1.append queue\n"<<"2.pop queue\n"<<"3.judge full\n"<<"4.exit"<>choice; + if(choice == 1) + { + for(int i=0;i<=9;i++){ + int number; + cin>>number; + queue.append(number); + } + } + + else if(choice == 2) + { + queue.pop(); + } + + else if(choice == 3) + { + queue.IsFull(); + queue.IsEmpty(); + } + + else if(choice == 4) + { + break; + } + +} + return 0; +} diff --git a/practices/cpp/level1/p02_Stack/Stack.cbp b/practices/cpp/level1/p02_Stack/Stack.cbp new file mode 100644 index 00000000..e299e5a1 --- /dev/null +++ b/practices/cpp/level1/p02_Stack/Stack.cbp @@ -0,0 +1,47 @@ + + + + + + diff --git a/practices/cpp/level1/p02_Stack/Stack.cpp b/practices/cpp/level1/p02_Stack/Stack.cpp new file mode 100644 index 00000000..121c9ea7 --- /dev/null +++ b/practices/cpp/level1/p02_Stack/Stack.cpp @@ -0,0 +1,37 @@ +#include "Stack.h" + +Stack::Stack() +{ + //ctor +} + +Stack::~Stack() +{ + //dtor +} + +void Stack::append(int number) +{ + container[head++] = number; +} + +void Stack::pop() +{ + head--; +} + +int Stack::show() +{ + if(head - 1 < 0) return -1; + else return container[head-1]; +} + +bool Stack::IsFull() +{ + return head == TOP; +} + +bool Stack::IsEmpty() +{ + return head == 0; +} diff --git a/practices/cpp/level1/p02_Stack/Stack.h b/practices/cpp/level1/p02_Stack/Stack.h new file mode 100644 index 00000000..563c0fd4 --- /dev/null +++ b/practices/cpp/level1/p02_Stack/Stack.h @@ -0,0 +1,22 @@ +#ifndef STACK_H +#define STACK_H + + +class Stack +{ + public: + Stack(); + void append(int number); + void pop(); + int show(); + bool IsFull(); + bool IsEmpty(); + virtual ~Stack(); + + private: + int *container; + int head=0; + int TOP=100; +}; + +#endif // STACK_H diff --git a/practices/cpp/level1/p02_Stack/main.cpp b/practices/cpp/level1/p02_Stack/main.cpp new file mode 100644 index 00000000..efdc1d41 --- /dev/null +++ b/practices/cpp/level1/p02_Stack/main.cpp @@ -0,0 +1,44 @@ +#include +#include "Stack.h" + +using namespace std; + +int main() +{ + Stack stack; + + + + while(1){ + cout<<"what do you want to do?\n" <<"1.append stack\n"<<"2.pop stack\n"<<"3.judge full\n"<<"4.exit"<>choice; + if(choice == 1) + { + for(int i=0;i<=9;i++){ + int number; + cin>>number; + stack.append(number); + } + } + + else if(choice == 2) + { + stack.pop(); + } + + else if(choice == 3) + { + stack.IsFull(); + stack.IsEmpty(); + } + + else if(choice == 4) + { + break; + } + +} + return 0; +} diff --git a/practices/cpp/level1/p03_SafeArray/SafeArray.cbp b/practices/cpp/level1/p03_SafeArray/SafeArray.cbp new file mode 100644 index 00000000..8d530a94 --- /dev/null +++ b/practices/cpp/level1/p03_SafeArray/SafeArray.cbp @@ -0,0 +1,47 @@ + + + + + + diff --git a/practices/cpp/level1/p03_SafeArray/SafeArray.cpp b/practices/cpp/level1/p03_SafeArray/SafeArray.cpp new file mode 100644 index 00000000..e5c71a55 --- /dev/null +++ b/practices/cpp/level1/p03_SafeArray/SafeArray.cpp @@ -0,0 +1,21 @@ +#include "SafeArray.h" +#include +using namespace std; + + +void SafeArray::init(int number,int value) +{ + safearray[number]=value; +} + +void SafeArray::see(int n) +{ + if(n>0&&n +#include "SafeArray.h" +#include +#include + +using namespace std; + +int main() +{ + int n; + cout<<"how many numbers you want to save?"<>n; + SafeArray array(n); + + srand(time(0)); + for(int i=0;i>m; + array.see(m); + } + +} diff --git a/practices/cpp/level1/p04_cppScoreManagement/ScoreManager.cpp b/practices/cpp/level1/p04_cppScoreManagement/ScoreManager.cpp new file mode 100644 index 00000000..e885f890 --- /dev/null +++ b/practices/cpp/level1/p04_cppScoreManagement/ScoreManager.cpp @@ -0,0 +1,163 @@ +#include +#include +#include +#include +#include +#include +#include + + +using namespace std; + +class Student +{ + private: + int number, score; + string name; + + public: + Student(int number, string name) : number(number), name(name) + { + score = -1; + } + + int getNumber() + { + return this->number; + } + + int getScore() + { + return this->score; + } + void setScore(int n) + { + this->score = n; + } + string getName() + { + return this->name; + } +}; +list students; + +void Init(); +void ShowMenu(); +void ShowList(); +void Add(); +void Delete(); +void InputScore(); + +int main() +{ + int n; + Init(); + while (1) + { + ShowMenu(); + cin >> n; + switch (n) + { + case 1: + ShowList(); + break; + case 2: + Add(); + break; + case 3: + Delete(); + break; + case 4: + InputScore(); + break; + case 5: + return 0; + break; + } + + } + return 0; +} +void Init() +{ + students.push_back(Student(1, "")); + students.push_back(Student(2, "С")); +} +void ShowMenu() +{ + cout<<"\nwhat do you want to do?"<::iterator it; + for (it = students.begin(); it != students.end(); it++) + { + cout <<" "<< (*it).getNumber() << " " << (*it).getName() <<" "; + if ((*it).getScore() == -1) + { + cout << "no score" << endl; + } + else + { + cout << (*it).getScore() << endl; + } + } +} +void Add() +{ + int number; + string name; + cout << "enter number and name" << endl; + cin >> number >> name; + students.push_back(Student(number, name)); +} +void Delete() +{ + int number; + cout << "enter number of the student you want to remove" << endl; + cin >> number; + for (list::iterator it = students.begin(); it != students.end();) + { + if ((*it).getNumber() == number) + { + it = students.erase(it); + } + else + { + it++; + } + } +} +void InputScore() +{ + int number, score; + while (1) + { + cout << "enter a number you want to log a score" << endl; + cin >> number; + cout << "enter the student's score" << endl; + cin >> score; + for (list::iterator it = students.begin(); it != students.end(); it++) + { + if ((*it).getNumber() == number) + { + (*it).setScore(score); + break; + } + } + string judge; + cout << "if you want to continue(Y or N)" << endl; + cin >> judge; + if (judge == ("Y")) + ; + else + break; + } +} diff --git a/practices/cpp/level1/p04_cppScoreManagement/todolist.txt b/practices/cpp/level1/p04_cppScoreManagement/todolist.txt new file mode 100644 index 00000000..3865428a --- /dev/null +++ b/practices/cpp/level1/p04_cppScoreManagement/todolist.txt @@ -0,0 +1,9 @@ +˵ +student +Աݽṹ +Ԥ +鿴ѧ +ѡ +˿ +Ǽdzɼ +˳ɼ \ No newline at end of file diff --git a/practices/cpp/level1/p05_Canvas/Canvas.cpp b/practices/cpp/level1/p05_Canvas/Canvas.cpp new file mode 100644 index 00000000..28c1a4ed --- /dev/null +++ b/practices/cpp/level1/p05_Canvas/Canvas.cpp @@ -0,0 +1,23 @@ +#include "Canvas.h" + + +Canvas::Canvas(int can){ + this->Can=can; + Last=1; + if(Can>0){ + shapes=new Shape*[Can]; + } +} + +Canvas::~Canvas(){} + +void Canvas::add(Shape* shape,int tag){ + shapes[Last]=shape; + Last++; +} + +void Canvas::draw(){ + for(int i=1;idraw(); + } +} diff --git a/practices/cpp/level1/p05_Canvas/Canvas.h b/practices/cpp/level1/p05_Canvas/Canvas.h new file mode 100644 index 00000000..2ca02e97 --- /dev/null +++ b/practices/cpp/level1/p05_Canvas/Canvas.h @@ -0,0 +1,19 @@ +#ifndef CANVAS_H +#define CANVAS_H + +#include "Shape.h" + +class Canvas +{ + private: + Shape** shapes; + int Can,Last + ; + public: + Canvas(int Can); + ~Canvas(); + void add(Shape* shape,int tag); + void draw(); +}; + +#endif // CANVAS_H diff --git a/practices/cpp/level1/p05_Canvas/Circle.cpp b/practices/cpp/level1/p05_Canvas/Circle.cpp new file mode 100644 index 00000000..5690e591 --- /dev/null +++ b/practices/cpp/level1/p05_Canvas/Circle.cpp @@ -0,0 +1,13 @@ +#include "Circle.h" +#include + + +Circle::Circle(int r,int x,int y): Shape(x,y){ + this->r=r; +} + +Circle::~Circle(){} + +void Circle::draw(){ + printf("Circle: Radius: %d, center: (%d,%d)\n",r,x,y); +} diff --git a/practices/cpp/level1/p05_Canvas/Circle.h b/practices/cpp/level1/p05_Canvas/Circle.h new file mode 100644 index 00000000..987935b1 --- /dev/null +++ b/practices/cpp/level1/p05_Canvas/Circle.h @@ -0,0 +1,16 @@ +#ifndef CIRCLE_H +#define CIRCLE_H + +#include "Shape.h" + +class Circle: public Shape +{ + private: + int r; + public: + Circle(int r,int x,int y); + ~Circle(); + virtual void draw(); +}; + +#endif // CIRCLE_H diff --git a/practices/cpp/level1/p05_Canvas/Rect.cpp b/practices/cpp/level1/p05_Canvas/Rect.cpp new file mode 100644 index 00000000..9f5c832b --- /dev/null +++ b/practices/cpp/level1/p05_Canvas/Rect.cpp @@ -0,0 +1,14 @@ +#include "Rect.h" +#include + + +Rect::Rect(int x1,int y1,int x,int y): Shape(x,y){ + this->x1=x1; + this->y1=y1; +} + +Rect::~Rect(){} + +void Rect::draw(){ + printf("Rect: the diagonal Point of the Rect: (%d,%d),the other diagonal Point of the Rect: (%d,%d)\n",x1,y1,x,y); +} diff --git a/practices/cpp/level1/p05_Canvas/Rect.h b/practices/cpp/level1/p05_Canvas/Rect.h new file mode 100644 index 00000000..ee8d83ab --- /dev/null +++ b/practices/cpp/level1/p05_Canvas/Rect.h @@ -0,0 +1,17 @@ +#ifndef RECT_H +#define RECT_H + +#include "Shape.h" +class Rect:public Shape +{ + private: + int x1,y1; + public: + + + Rect(int x1,int y1,int x,int y); + ~Rect(); + virtual void draw(); +}; + +#endif // RECT_H diff --git a/practices/cpp/level1/p05_Canvas/Shape.cpp b/practices/cpp/level1/p05_Canvas/Shape.cpp new file mode 100644 index 00000000..5e944b38 --- /dev/null +++ b/practices/cpp/level1/p05_Canvas/Shape.cpp @@ -0,0 +1,17 @@ +#include "Shape.h" +#include + +Shape::Shape() +{ + //ctor +} + +Shape::~Shape() +{ + //dtor +} + +Shape::Shape(int x,int y){ + this->x=x; + this->y=y; +} diff --git a/practices/cpp/level1/p05_Canvas/Shape.h b/practices/cpp/level1/p05_Canvas/Shape.h new file mode 100644 index 00000000..c35e2b82 --- /dev/null +++ b/practices/cpp/level1/p05_Canvas/Shape.h @@ -0,0 +1,20 @@ +#ifndef SHAPE_H +#define SHAPE_H + + +class Shape +{ + public: + Shape(); + virtual ~Shape(); + Shape(int x,int y); + virtual void draw() = 0; + + + protected: + int x,y; + + private: +}; + +#endif // SHAPE_H diff --git a/practices/cpp/level1/p05_Canvas/main.cpp b/practices/cpp/level1/p05_Canvas/main.cpp new file mode 100644 index 00000000..03689b8d --- /dev/null +++ b/practices/cpp/level1/p05_Canvas/main.cpp @@ -0,0 +1,21 @@ +#include "Circle.h" +#include "Rect.h" +#include "Canvas.h" +#include + +using namespace std; + +int main(){ + int x,y,r,x1,y2; + Canvas canvas(1000); + + Circle circle(1,1,1); + canvas.add(&circle,1); + + Rect rect(1,1,4,4); + canvas.add(&rect,2); + + canvas.draw(); + + return 0; +} diff --git a/practices/cpp/level1/p06_CircleAndPoint/Circle.cpp b/practices/cpp/level1/p06_CircleAndPoint/Circle.cpp new file mode 100644 index 00000000..84973d37 --- /dev/null +++ b/practices/cpp/level1/p06_CircleAndPoint/Circle.cpp @@ -0,0 +1,52 @@ +#include "Circle.h" +#include "Point.h" +#include + +using namespace std; + +Circle::Circle() +{ + //ctor +} + +Circle::~Circle() +{ + //dtor +} + +void Circle:: SetCenter(Point O) +{ + this->center=O; +} + +Point Circle::GetCenter() +{ + return center; +} + +void Circle::SetR(int r) +{ + this->r = r; +} + +int Circle::GetR() +{ + return r; +} + +void Circle::Move(int x,int y) +{ + center.SetX(center.GetX() + x); + center.SetY(center.GetY() + y); +} + +void Circle::ChangeSize(int r) +{ + SetR(r); +} + +void Circle::Show() +{ + cout<<"Բ:"<<"("<x=x; +} + +void Point::SetY(int y) +{ + this->y=y; +} + +int Point::GetX() +{ + return x; +} + +int Point::GetY() +{ + return y; +} diff --git a/practices/cpp/level1/p06_CircleAndPoint/Point.h b/practices/cpp/level1/p06_CircleAndPoint/Point.h new file mode 100644 index 00000000..a206ba6e --- /dev/null +++ b/practices/cpp/level1/p06_CircleAndPoint/Point.h @@ -0,0 +1,19 @@ +#ifndef POINT_H +#define POINT_H + + +class Point +{ + public: + Point(); + virtual ~Point(); + void SetX(int x); + int GetX(); + void SetY(int y); + int GetY(); + + private: + int x,y; +}; + +#endif // POINT_H diff --git a/practices/cpp/level1/p06_CircleAndPoint/main.cpp b/practices/cpp/level1/p06_CircleAndPoint/main.cpp new file mode 100644 index 00000000..3080a241 --- /dev/null +++ b/practices/cpp/level1/p06_CircleAndPoint/main.cpp @@ -0,0 +1,28 @@ +#include +#include "Circle.h" +#include "Point.h" + +using namespace std; + +int main(void) { + Circle circle; + Point point; + point.SetX(1); + point.SetY(1); + circle.SetCenter(point); + circle.SetR(1); + circle.Show(); + cout<<"\n"; + + circle.Move(2,2); + cout<<"ƶԲĺ"<