diff --git a/.gitignore b/.gitignore index 6f1c26fe..9cf7efa2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ slides/.idea +*.DS_Store diff --git a/practices/c/level1/p01_runningLetter/p01_runningLetter.c b/practices/c/level1/p01_runningLetter/p01_runningLetter.c new file mode 100644 index 00000000..169e4c70 --- /dev/null +++ b/practices/c/level1/p01_runningLetter/p01_runningLetter.c @@ -0,0 +1,43 @@ +#include +#include +#include +#include +#define N 20 + +void runLetter(int n); +int checkRight(int t); +int checkLeft(int t); + +char ch[N]; + +int main() { + printf("Input the word or letter:\n"); + gets(ch); + while (1) { + int t = 0; + while (checkRight(t)) { + runLetter(t++); + } + while (checkLeft(--t)) { + runLetter(t); + } + } + return 0; +} + +void runLetter(int n) { + system("clear"); + for (int i = 0; i < n; i++) { + printf(" "); + } + puts(ch); + usleep(50000); +} + +int checkRight(int t) { + return t <= 80 - strlen(ch); +} + +int checkLeft(int t) { + return t >= 0; +} diff --git a/practices/c/level1/p02_isPrime/p02_isPrime.c b/practices/c/level1/p02_isPrime/p02_isPrime.c new file mode 100644 index 00000000..aa143100 --- /dev/null +++ b/practices/c/level1/p02_isPrime/p02_isPrime.c @@ -0,0 +1,20 @@ +#include +#include + +int isPrime(int n); + +int main () { + int n; + scanf("%d",&n); + if (isPrime(n)) printf("Yes!"); + else printf("No!"); + return 0; +} + +int isPrime(int n) { + if (n == 1) return 0; + for (int i = 2; i <= sqrt(n); i++) { + if (n % i == 0) return 0; + } + return 1; +} diff --git a/practices/c/level1/p03_Diophantus/p03_Diophantus.c b/practices/c/level1/p03_Diophantus/p03_Diophantus.c new file mode 100644 index 00000000..65c2df2e --- /dev/null +++ b/practices/c/level1/p03_Diophantus/p03_Diophantus.c @@ -0,0 +1,17 @@ +#include + +int check(int n); + +int main() { + for (int i = 1; i <= 1000; i++) { + if (check(i)) printf("%d ",i - 4); + } + return 0; +} + +int check(int n) { + if (n%6 != 0 || n%12 != 0 || n%7 !=0) return 0; + int x = n/6 + n/12 + n/7 + 5; + int ageSon = n - x - 4; + return n == ageSon * 2; +} diff --git a/practices/c/level1/p04_ narcissus/p04_narcissus.c b/practices/c/level1/p04_ narcissus/p04_narcissus.c new file mode 100644 index 00000000..a488634a --- /dev/null +++ b/practices/c/level1/p04_ narcissus/p04_narcissus.c @@ -0,0 +1,24 @@ +#include + +int Power(int x); +int narcissusChange(int n); + +int main() { + for (int i = 100; i < 1000; i++) { + if (i == narcissusChange(i)) printf("%d\t",i); + } + return 0; +} + +int Power(int x) { + return x*x*x; +} + +int narcissusChange(int n) { + int ans = 0; + while (n) { + ans += Power(n%10); + n = n/10; + } + return ans; +} diff --git a/practices/c/level1/p05_allPrimes/p05_allPrimes.c b/practices/c/level1/p05_allPrimes/p05_allPrimes.c new file mode 100644 index 00000000..299b9f1d --- /dev/null +++ b/practices/c/level1/p05_allPrimes/p05_allPrimes.c @@ -0,0 +1,26 @@ +#include +#include +#define N 1001 + +void init(); + +int isPrime[N]; + +int main() { + init(); + for (int i = 2; i < N; i++) { + if (isPrime[i]) printf("%d\t",i); + } + return 0; +} + +void init() { + memset(isPrime,1,sizeof(isPrime)); + for (int i = 2; i < N; i++) { + if (isPrime[i]) { + for (int j = 2; i*j < N; j++) { + isPrime[i*j] = 0; + } + } + } +} diff --git a/practices/c/level1/p06_Goldbach/p06_Goldbach.c b/practices/c/level1/p06_Goldbach/p06_Goldbach.c new file mode 100644 index 00000000..ddbab197 --- /dev/null +++ b/practices/c/level1/p06_Goldbach/p06_Goldbach.c @@ -0,0 +1,67 @@ +#include +#include +#define N 101 + +int isPrime(int x); +void init(); + +struct Data { + int a,b,c; +}a[N]; + +int primes[20]; +int numberOfPrimes; + +int main() { + init(); + for (int i = 0; i < numberOfPrimes; i++) { + for (int j = i; j < numberOfPrimes; j++) { + int k = primes[i] + primes[j]; + if (k > 100) { + break; + } + a[k].a = primes[i]; + a[k].b = primes[j]; + } + } + + for (int i = 0; i < numberOfPrimes; i++) { + for (int j = i; j < numberOfPrimes; j++) { + for (int k = j; k < numberOfPrimes; k++) { + int x = primes[i] + primes[j] + primes[k]; + if (x > 100) { + break; + } + a[x].a = primes[i]; + a[x].b = primes[j]; + a[x].c = primes[k]; + } + } + } + + printf("不小于6的偶数都是两个素数之和:\n"); + for (int i = 6; i <= 100; i+=2) { + printf("%d = %d + %d\n",i,a[i].a,a[i].b); + } + printf("不小于9的偶数都是三个素数之和:\n"); + for (int i = 9; i < 100; i+=2) { + printf("%d = %d + %d + %d\n",i,a[i].a,a[i].b,a[i].c); + } + return 0; +} + +int isPrime(int x) { + for (int i = 2; i <= sqrt(x); i++) { + if (x%i == 0) return 0; + } + return 1; +} + +void init() { + numberOfPrimes = 0; + for (int i = 3; i < 100; i++) { + if (isPrime(i)) { + primes[numberOfPrimes++] = i; + } + } +} diff --git a/practices/c/level1/p07_encrypt_decrypt/p07_encrypt_decrypt.c b/practices/c/level1/p07_encrypt_decrypt/p07_encrypt_decrypt.c new file mode 100644 index 00000000..08858576 --- /dev/null +++ b/practices/c/level1/p07_encrypt_decrypt/p07_encrypt_decrypt.c @@ -0,0 +1,108 @@ +//丑陋的加密算法 +//只考虑了大小写字母与数字 +//加密只能通过改变Hash值改变 +//总之这个算法特别蠢就是了 + +#include +#include +#define Hash 10007 +#define N 100 + +char numToChar(int x); +char enToDe(char c); +char deToEn(char c); +void encrypt(); +void decrypt(); +void init(); + +int enIntoDe[62]; +int deIntoEn[62]; +char ch[N]; + +int main() { + init(); + while (1) { + int k; + printf("输入要进行的操作序号,1:加密,2:解密,3:退出 : "); + scanf("%d",&k); + if (k == 1) { + encrypt(); + continue; + } + if (k == 2) { + decrypt(); + continue; + } + if (k == 3) { + break; + } + } + return 0; +} + +char numToChar(int x) { + if (x < 10) return (char)(48+x); + if (x < 36) return (char)(55+x); + return (char)(61+x); +} + +char enToDe(char c) { + if ((int)(c) > 47 && (int)(c) < 58) { + return numToChar(enIntoDe[(int)(c) - 48]); + } + if ((int)(c) > 64 && (int)(c) < 91) { + return numToChar(enIntoDe[(int)(c) - 55]); + } + return numToChar(enIntoDe[(int)(c) - 61]); +} + +char deToEn(char c) { + if ((int)(c) > 47 && (int)(c) < 58) { + return numToChar(deIntoEn[(int)(c) - 48]); + } + if ((int)(c) > 64 && (int)(c) < 91) { + return numToChar(deIntoEn[(int)(c) - 55]); + } + return numToChar(deIntoEn[(int)(c) - 61]); +} + +void encrypt() { + printf("输入需要加密的字符串:\n"); + scanf("%s",&ch); + for (int i = 0; i < strlen(ch); i++) { + ch[i] = enToDe(ch[i]); + } + printf("加密后的字符串为:%s\n",ch); +} + +void decrypt() { + printf("输入需要解密的字符串:\n"); + scanf("%s",&ch); + for (int i = 0; i < strlen(ch); i++) { + ch[i] = deToEn(ch[i]); + } + printf("解密后的字符串为:%s\n",ch); +} + +void init() { + memset(enIntoDe,-1,sizeof(enIntoDe)); + memset(deIntoEn,-1,sizeof(deIntoEn)); + for (int i = 0; i < 62; i++) { + int x = (i * Hash) % 62; + if (deIntoEn[x] == -1) { + enIntoDe[i] = x; + deIntoEn[x] = i; + } + } + for (int i = 0; i < 62; i++) { + if (enIntoDe[i] == -1) { + for (int j = 0; j < 62; j++) { + if (deIntoEn[j] == -1) { + enIntoDe[i] = j; + deIntoEn[j] = i; + break; + } + } + } + } +} diff --git a/practices/c/level1/p08_hanoi/p08_hanoi.c b/practices/c/level1/p08_hanoi/p08_hanoi.c new file mode 100644 index 00000000..9ff30309 --- /dev/null +++ b/practices/c/level1/p08_hanoi/p08_hanoi.c @@ -0,0 +1,28 @@ +#include + +void printMove(int x, char A, char B); +void hanoi(int x, char A, char B, char C); + +int tot = 0; + +int main() { + int n; + scanf("%d",&n); + hanoi(n, 'A', 'B', 'C'); + return 0; +} + +void printMove(int x, char A, char B) { + printf("%d: %d %c -> %c\n",++tot, x, A, B); +} + +void hanoi(int x,char A, char B, char C) { + if (x == 1) { + printMove(x, A, C); + } + else { + hanoi(x - 1, A, C, B); + printMove(x, A, C); + hanoi(x - 1, B, A, C); + } +} diff --git a/practices/c/level1/p09_maze/p09_maze.c b/practices/c/level1/p09_maze/p09_maze.c new file mode 100644 index 00000000..2f72d186 --- /dev/null +++ b/practices/c/level1/p09_maze/p09_maze.c @@ -0,0 +1,129 @@ +#include +#include +#include +#define N 8 + +// *表示迷宫边框 +// &表示出口 +// Y表示人物 + +int check(int x,int y); +void mapPut(); +void getDestination(); +void mazeMove(int k); +void init(); + +char mazeMap[N][N]; +int dx[4] = {1,-1,0,0}; +int dy[4] = {0,0,-1,1}; +int x,y; +int destinationX,destinationY; +int isGet = 0; + +int main() { + init(); + +// down 258 +// up 259 +// left 260 +// right 261 + + while (!isGet) { + int k = getch() - 258; + mazeMove(k); + } + + getch(); + endwin(); + return 0; +} + +int check(int x,int y) { + if (x < 0 || x >= N || y < 0 || y >= N) return 0; + if (x == destinationX && y == destinationY) return 2; + if (mazeMap[x][y] == '*') return 0; + return 1; +} + +void mapPut() { + clear(); + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + move(i,j); + addch(mazeMap[i][j]); + } + } + refresh(); +} + +void getDestination() { + clear(); + char ch[] = {"Congratulations!!!"}; + addstr(ch); + refresh(); + isGet = 1; +} + +void mazeMove(int k) { + int xx = x + dx[k]; + int yy = y + dy[k]; + int flag = check(xx,yy); + if (flag == 2) { + getDestination(); + return; + } + if (flag == 0) return; + mazeMap[x][y] = ' '; + x += dx[k]; + y += dy[k]; + mazeMap[x][y] = 'Y'; + mapPut(); +} + +void init() { + FILE *file; + initscr(); + file = fopen("mazeMap","r"); + for (int i = 0; i < N; i++) { + int end = 0; + for (int j = 0; j < N; j++) { + mazeMap[i][j] = getc(file); + if (mazeMap[i][j] == '\n') { + end = 1; + break; + } + } + if (end) { + int x = N - strlen(mazeMap[i]) + 1; + for (int j = N - x - 1; j >= 0; j--) { + mazeMap[i][j + x] = mazeMap[i][j]; + } + for (int j = 0; j < x; j++) { + mazeMap[i][j] = ' '; + } + } + else { + fscanf(file,"\n"); + } + } + + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if (mazeMap[i][j] == 'Y') { + x = i; + y = j; + } + if (mazeMap[i][j] == '&') { + destinationX = i; + destinationY = j; + } + } + } + + + fclose(file); + keypad(stdscr,true); + noecho(); + + mapPut(); +} diff --git a/practices/c/level1/p10_pushBoxes/p10_pushBoxes.c b/practices/c/level1/p10_pushBoxes/p10_pushBoxes.c new file mode 100644 index 00000000..2cc9befd --- /dev/null +++ b/practices/c/level1/p10_pushBoxes/p10_pushBoxes.c @@ -0,0 +1,226 @@ +#include +#include +#include +#define N 8 +#define M 20 + +// *表示地图边框 +// Y表示人物 +// #表示箱子 +// O表示目标位置 +// @表示箱子到达目标位置 + +void mapPut(); +void init(); +int check(int x,int y); +void xyMove(int xx,int yy); +int checkBox(int l,int k); +void boxMove(int k); +void restart(); + +struct box { + int x,y; + int getDestination; +}boxes[M]; +struct destination { + int x,y; + int covered; +}des[M]; + +char boxMap[N][N]; +int dx[4] = {1,-1,0,0}; +int dy[4] = {0,0,-1,1}; +int x,y; +int numBox = 0; +int numDes = 0; +int step = 0; +int isFinish = 0; + +int main() { + init(); + + while (!isFinish) { + int k = getch() - 258; + if (k == -231) { + restart(); + } + boxMove(k); + } + clear(); + printw("Congratulation! You use %d steps!",step); + refresh(); + getch(); + endwin(); + return 0; +} + +void mapPut() { + clear(); + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + move(i,j); + addch(boxMap[i][j]); + } + } + move(x,y); + addch('Y'); + for (int i = 0; i < numBox; i++) { + move(boxes[i].x,boxes[i].y); + addch(boxes[i].getDestination?'@':'#'); + } + isFinish = 1; + for (int i = 0; i < numDes; i++) { + move(des[i].x,des[i].y); + if (!des[i].covered) { + addch('O'); + isFinish = 0; + } + } + move(N,0); + printw("Step = %d",step); + refresh(); +} + +void init() { + initscr(); + FILE *file; + file = fopen("boxMap","r"); + for (int i = 0; i < N; i++) { + int end = 0; + for (int j = 0; j < N; j++) { + boxMap[i][j] = getc(file); + if (boxMap[i][j] == '\n') { + end = 1; + break; + } + } + if (end) { + int x = N - strlen(boxMap[i]) + 1; + for (int j = N - x - 1; j >= 0; j--) { + boxMap[i][j + x] = boxMap[i][j]; + } + for (int j = 0; j < x; j++) { + boxMap[i][j] = ' '; + } + } + else { + fscanf(file,"\n"); + } + } + + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if (boxMap[i][j] == 'Y') { + x = i; + y = j; + boxMap[i][j] = ' '; + } + if (boxMap[i][j] == '#') { + boxes[numBox].x = i; + boxes[numBox].y = j; + boxes[numBox++].getDestination = 0; + boxMap[i][j] = ' '; + } + if (boxMap[i][j] == 'O') { + des[numDes].x = i; + des[numDes].y = j; + des[numDes++].covered = 0; + boxMap[i][j] = ' '; + } + } + } + + fclose(file); + keypad(stdscr,true); + noecho(); + mapPut(); +} + +int check(int x,int y) { + if (x < 0 || x >= N || y < 0 || y >= N) return 0; + if (boxMap[x][y] == '*') return 0; + return 1; +} + +void xyMove(int xx,int yy) { + for (int i = 0; i < numDes; i++) { + if (des[i].x == xx && des[i].y == yy) { + des[i].covered = 1; + } + if (des[i].x == x && des[i].y == y) { + des[i].covered = 0; + } + } + x = xx; y = yy; + step++; +} + +int checkBox(int l,int k) { + int xx = boxes[l].x + dx[k]; + int yy = boxes[l].y + dy[k]; + if (xx < 0 || xx >= N || yy < 0 || yy >= N) return 0; + if (boxMap[xx][yy] == '*') return 0; + for (int i = 0; i < numBox; i++) { + if (xx == boxes[i].x && yy == boxes[i].y) { + return 0; + } + } + for (int i = 0; i < numDes; i++) { + if (xx == des[i].x && yy == des[i].y && !des[i].covered) { + return 2; + } + } + return 1; +} + +void boxMove(int k) { + int xx = x + dx[k]; + int yy = y + dy[k]; + + int isBox = 0; + int boxIndex; + for (int i = 0; i < numBox; i++) { + if (boxes[i].x == xx && boxes[i].y == yy) { + isBox = 1; + boxIndex = i; + break; + } + } + + if (isBox) { + int checkBoxResult = checkBox(boxIndex,k); + if (checkBoxResult == 1) { + if (boxes[boxIndex].getDestination) { + boxes[boxIndex].getDestination = 0; + } + boxes[boxIndex].x += dx[k]; + boxes[boxIndex].y += dy[k]; + xyMove(xx,yy); + } + if (checkBoxResult == 2) { + boxes[boxIndex].x += dx[k]; + boxes[boxIndex].y += dy[k]; + boxes[boxIndex].getDestination = 1; + for (int i = 0; i < numDes; i++) { + if (des[i].x == boxes[boxIndex].x && des[i].y == boxes[boxIndex].y) { + des[i].covered = 1; + } + } + xyMove(xx,yy); + } + } + else { + if (check(xx,yy)) { + xyMove(xx,yy); + } + } + mapPut(); +} + +void restart() { + step = 0; + numBox = 0; numDes = 0; + isFinish = 0; + memset(boxMap,0,sizeof(boxMap)); + init(); +} diff --git a/practices/c/level1/p11_linkedList/p11_linkedList.c b/practices/c/level1/p11_linkedList/p11_linkedList.c new file mode 100644 index 00000000..d94c783b --- /dev/null +++ b/practices/c/level1/p11_linkedList/p11_linkedList.c @@ -0,0 +1,119 @@ +#include +#include + +void initList(); +void pushList(int x); +void findList(int x); +void inputValue(); +void reverseList(); +void displayList(); + +struct node { + int value; + struct node *next; +}*pHead,*pNow; + +int main() { + initList(); + inputValue(); + + while (1) { + printf("请输入需要进行的操作编号: \n"); + printf(" 1:遍历该链表\n 2:将链表节点反序\n 3:查找链表元素\n 0:退出\n"); + int k; + scanf("%d",&k); + if (k == 0) break; + if (k == 1) { + displayList(); + continue; + } + if (k == 2) { + reverseList(); + continue; + } + if (k == 3) { + printf("输入要查找的元素:"); + int x; + scanf("%d",&x); + findList(x); + continue; + } + } + return 0; +} + +void initList() { + pHead = (struct node *)malloc(sizeof(struct node)); + pHead -> next = NULL; + pNow = (struct node *)malloc(sizeof(struct node)); + pNow -> next = NULL; +} + +void pushList(int x) { + struct node *p; + p = (struct node *)malloc(sizeof(struct node)); + p -> value = x; + p -> next = NULL; + if (pHead -> next == NULL) { + pHead -> next = p; + pNow = p; + return; + } + pNow -> next = p; + pNow = p; +} + +void findList(int x) { + int k = 1; + int find = 0; + struct node *p; + p = pHead -> next; + while (p != NULL) { + if (p -> value == x) { + find = 1; + printf("%d ",k); + } + p = p -> next; + k++; + } + if (!find) { + printf("-1"); + } + printf("\n"); +} + +void displayList() { + struct node *p; + p = pHead -> next; + while (p != NULL) { + printf("%d ",p -> value); + p = p -> next; + } + printf("\n"); +} + +void inputValue() { + printf("输入链表元素个数:\n"); + int n; + scanf("%d",&n); + printf("请输入元素:\n"); + int x; + for (int i = 0; i < n; i++) { + scanf("%d",&x); + pushList(x); + } +} + +void reverseList() { + struct node *pPrev, *pNext, *p; + p = pHead -> next; + pNow = p; + pPrev = NULL; + while (p != NULL) { + pNext = p -> next; + p -> next = pPrev; + pPrev = p; + p = pNext; + } + pHead -> next = pPrev; +} diff --git a/practices/c/level1/p12_warehouse/p12_warehouse.c b/practices/c/level1/p12_warehouse/p12_warehouse.c new file mode 100644 index 00000000..704419fa --- /dev/null +++ b/practices/c/level1/p12_warehouse/p12_warehouse.c @@ -0,0 +1,165 @@ +#include +#include +#include +#define N 10 + +void init(); +void pushList(); +void popList(); +void displayList(); +void quiteProgram(); + +struct node { + char name[N]; + int num; + struct node *next; +}*pHead; + +char name[N]; +int num; +int n = 0; + +int main() { + init(); + int flag = 1; + while (flag) { + printf("\n选择所需功能:\n"); + printf(" 1:显示存货列表\n 2:入库\n 3:出库\n 0:退出程序\n"); + int k; + scanf("%d",&k); + switch (k) { + case 0: + quiteProgram(); + flag = 0; + break; + case 1: + displayList(); + break; + case 2: + printf("输入入库货物名:\n"); + scanf("%s",name); + printf("输入入库货物数量:\n"); + scanf("%d",&num); + pushList(); + break; + case 3: + printf("输入出库货物名:\n"); + scanf("%s",name); + printf("输入出库货物数量:\n"); + scanf("%d",&num); + popList(); + break; + } + } + + return 0; +} + +void init() { + pHead = (struct node *)malloc(sizeof(struct node)); + pHead -> next = NULL; + FILE *file; + file = fopen("warehouseDate","r"); + int n; + if (fscanf(file,"%d",&n) != EOF) { + for (int i = 0; i < n; i++) { + fscanf(file,"%s",name); + fscanf(file,"%d",&num); + pushList(); + } + fclose(file); + } +} + +void pushList() { + int find = 0; + struct node *p; + p = pHead -> next; + while (p != NULL) { + if (strcmp(p -> name,name) == 0) { + find = 1; + p -> num += num; + break; + } + p = p -> next; + } + if (!find) { + struct node *q; + q = (struct node *)malloc(sizeof(struct node)); + strcpy(q -> name,name); + q -> num = num; + q -> next = pHead -> next; + pHead -> next = q; + n ++; + } +} + +void popList() { + int find = 0; + int enough = 0; + struct node *p, *pPre; + p = pHead -> next; + pPre = pHead; + while (p != NULL) { + if (strcmp(p -> name,name) == 0) { + find = 1; + if (p -> num < num) { + break; + } + p -> num -= num; + if (p -> num == 0) { + enough = 2; + } + if (p -> num > 0) { + enough = 1; + } + break; + } + pPre = p; + p = p -> next; + } + if (!find) { + printf("未找到名为%s的货物\n",name); + return; + } + if (enough == 0) { + printf("货物数量不足,取出失败\n"); + return; + } + if (enough == 2) { + pPre -> next = p -> next; + free(p); + n --; + } +} + +void displayList() { + struct node *p; + p = pHead -> next; + if (p == NULL) { + printf("当前库存为空\n"); + return; + } + while (p != NULL) { + printf("名称:%s 数量:%d\n",p -> name, p -> num); + p = p -> next; + } +} + +void quiteProgram() { + FILE *file; + file = fopen("warehouseDate","w"); + fprintf(file,"%d\n",n); + struct node *p, *q; + p = pHead -> next; + q = pHead; + free(q); + while (p != NULL) { + fprintf(file,"%s\n",p -> name); + fprintf(file,"%d\n",p -> num); + q = p; + p = p -> next; + free(q); + } +} + diff --git a/practices/cpp/level1/p01_Queue/Queue.cpp b/practices/cpp/level1/p01_Queue/Queue.cpp new file mode 100644 index 00000000..29c19406 --- /dev/null +++ b/practices/cpp/level1/p01_Queue/Queue.cpp @@ -0,0 +1,61 @@ +// +// Queue.cpp +// p01_Queue +// +// Created by Jimmy Fan on 2017/3/30. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include "Queue.h" +#include +using namespace std; + +Queue::Queue(int n) { + head = (Node *)malloc(sizeof(Node)); + head -> next = NULL; + tail = (Node *)malloc(sizeof(Node)); + tail -> next = NULL; + num = 0; + maxNum = n; +} + +void Queue::append(int x) { + Node *p; + p = (Node *)malloc(sizeof(Node)); + p -> x = x; + p -> next = NULL; + if (!num) { + head -> next = p; + tail -> next = p; + } + else { + tail -> next -> next = p; + tail -> next = p; + } + num ++; +} + +int Queue::front() { + return head -> next -> x; +} + +int Queue::back() { + return tail -> next -> x; +} + +void Queue::pop() { + Node *p; + p = head -> next; + head -> next = p -> next; + free(p); + p = NULL; + num --; +} + +bool Queue::isFull() { + return num == maxNum; +} + +bool Queue::isEmpty() { + return num == 0; +} diff --git a/practices/cpp/level1/p01_Queue/Queue.h b/practices/cpp/level1/p01_Queue/Queue.h new file mode 100644 index 00000000..6732a45f --- /dev/null +++ b/practices/cpp/level1/p01_Queue/Queue.h @@ -0,0 +1,34 @@ +// +// Queue.h +// p01_Queue +// +// Created by Jimmy Fan on 2017/3/30. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef Queue_h +#define Queue_h + +struct Node { + int x; + Node *next; +}; + +class Queue { +private: + Node *head, *tail; + int num; + int maxNum; +public: + Queue(int n); + void append(int x); + int front(); + int back(); + void pop(); + bool isFull(); + bool isEmpty(); +}; + + + +#endif /* Queue_h */ diff --git a/practices/cpp/level1/p01_Queue/main.cpp b/practices/cpp/level1/p01_Queue/main.cpp new file mode 100644 index 00000000..f0af53ac --- /dev/null +++ b/practices/cpp/level1/p01_Queue/main.cpp @@ -0,0 +1,82 @@ +// +// main.cpp +// p01_Queue +// +// Created by Jimmy Fan on 2017/3/30. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include "Queue.h" +#define N 100 +using namespace std; + +int main(int argc, const char * argv[]) { + Queue que(N); + bool flag = 1; + while (flag) { + int k; + printf("请输入需要进行的操作编号:\n"); + printf(" 1:入队\n 2:出队\n 3:读取队首元素\n 4:读取队尾元素\n 5:判断队列是否为空\n 6:判断队列是否已满\n 0:退出程序\n"); + scanf("%d",&k); + switch (k) { + case 0: + flag = 0; + break; + case 1: + printf("请输入需要入队的元素:"); + int x; + scanf("%d",&x); + if (que.isFull()) { + printf("Error : 队列已满,入队失败\n"); + } + else { + que.append(x); + } + break; + case 2: + if (que.isEmpty()) { + printf("Erroe : 队列已空,出队失败\n"); + } + else { + que.pop(); + } + break; + case 3: + if (que.isEmpty()) { + printf("Error : 队列为空,读取队首元素失败\n"); + } + else { + printf("队首元素为:%d\n",que.front()); + } + break; + case 4: + if (que.isEmpty()) { + printf("Error : 队列为空,读取队尾元素失败\n"); + } + else { + printf("队尾元素为:%d\n",que.back()); + } + break; + case 5: + if (que.isEmpty()) { + printf("队列已空\n"); + } + else { + printf("队列未空\n"); + } + break; + case 6: + if (que.isFull()) { + printf("队列已满\n"); + } + else { + printf("队列未满\n"); + } + break; + } + } + + + return 0; +} diff --git a/practices/cpp/level1/p02_Stack/Stack.cpp b/practices/cpp/level1/p02_Stack/Stack.cpp new file mode 100644 index 00000000..ca552154 --- /dev/null +++ b/practices/cpp/level1/p02_Stack/Stack.cpp @@ -0,0 +1,49 @@ +// +// Stack.cpp +// p02_Stack +// +// Created by Jimmy Fan on 2017/3/30. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include "Stack.h" +using namespace std; + +template +Stack::Stack(int n) { + stop = 0; + maxNum = n; + s = new T(n); +} + +template +void Stack::push(T x) { + s[stop ++] = x; +} + +template +T Stack::top() { + return s[stop - 1]; +} + +template +void Stack::pop() { + stop --; +} + +template +bool Stack::isFull() { + return stop == maxNum; +} + +template +bool Stack::isEmpty() { + return stop == 0; +} + + +template +Stack::~Stack() { + delete [] s; +} diff --git a/practices/cpp/level1/p02_Stack/Stack.h b/practices/cpp/level1/p02_Stack/Stack.h new file mode 100644 index 00000000..ed8ad420 --- /dev/null +++ b/practices/cpp/level1/p02_Stack/Stack.h @@ -0,0 +1,29 @@ +// +// Stack.h +// p02_Stack +// +// Created by Jimmy Fan on 2017/3/30. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef Stack_h +#define Stack_h + +template +class Stack { +private: + int stop; + T* s; + int maxNum; +public: + Stack(int n); + ~Stack(); + void push(T x); + T top(); + void pop(); + bool isFull(); + bool isEmpty(); +}; + + +#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..b44c961e --- /dev/null +++ b/practices/cpp/level1/p02_Stack/main.cpp @@ -0,0 +1,76 @@ +// +// main.cpp +// p02_Stack +// +// Created by Jimmy Fan on 2017/3/30. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include "Stack.h" +using namespace std; + +int main(int argc, const char * argv[]) { + int n; + printf("请输入栈最大元素个数:"); + scanf("%d",&n); + Stack stack(n); + bool flag = 1; + while (flag) { + int k; + printf("请输入需要进行的操作编号:\n"); + printf(" 1:入栈\n 2:出栈\n 3:读取栈顶元素\n 4:判断栈是否为空\n 5:判断栈是否已满\n 0:退出\n"); + scanf("%d",&k); + switch (k) { + case 0: + flag = 0; + break; + case 1: { + printf("请输入需要入栈的元素:"); + int x; + scanf("%d",&x); + if (stack.isFull()) { + printf("Error : 栈已满,入栈失败\n"); + } + else { + stack.push(x); + } + break; + } + case 2: + if (stack.isEmpty()) { + printf("Erroe : 栈已空,出栈失败\n"); + } + else { + stack.pop(); + } + break; + case 3: + if (stack.isEmpty()) { + printf("Error : 栈已空,读取栈顶元素失败\n"); + } + else { + printf("栈顶元素为:%d\n",stack.top()); + } + break; + case 4: + if (stack.isEmpty()) { + printf("栈已空\n"); + } + else { + printf("栈未空\n"); + } + break; + case 5: + if (stack.isFull()) { + printf("栈已满\n"); + } + else { + printf("栈未满\n"); + } + break; + } + } + + return 0; +} diff --git a/practices/cpp/level1/p03_SafeArray/SafeArray.cpp b/practices/cpp/level1/p03_SafeArray/SafeArray.cpp new file mode 100644 index 00000000..8e6f669c --- /dev/null +++ b/practices/cpp/level1/p03_SafeArray/SafeArray.cpp @@ -0,0 +1,43 @@ +// +// SafeArray.cpp +// p03_SafeArray +// +// Created by Jimmy Fan on 2017/4/24. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include "SafeArray.h" + +template +SafeArray::SafeArray(int n) { + this -> n = n; + a = new T(n); +} + +template +SafeArray::~SafeArray() { + delete [] a; +} + +template +Result SafeArray::getNum(int k) { + Result r; + if (k < 0 || k >= n) { + r.flag = 0; + } + else { + r.flag = 1; + r.data = a[k]; + } + return r; +} + +template +bool SafeArray::addNum(int k,T x) { + if (k < 0 || k >= n) return 0; + else { + a[k] = x; + return 1; + } +} diff --git a/practices/cpp/level1/p03_SafeArray/SafeArray.h b/practices/cpp/level1/p03_SafeArray/SafeArray.h new file mode 100644 index 00000000..110606c7 --- /dev/null +++ b/practices/cpp/level1/p03_SafeArray/SafeArray.h @@ -0,0 +1,32 @@ +// +// SafeArray.h +// p03_SafeArray +// +// Created by Jimmy Fan on 2017/4/24. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef SafeArray_h +#define SafeArray_h + +template +struct Result { + T data; + bool flag; +}; + +template +class SafeArray { +private: + int n; + T *a; +public: + SafeArray(int = 0); + ~SafeArray(); + Result getNum(int k); + bool addNum(int k,T x); +}; + + + +#endif /* SafeArray_h */ diff --git a/practices/cpp/level1/p03_SafeArray/main.cpp b/practices/cpp/level1/p03_SafeArray/main.cpp new file mode 100644 index 00000000..c65a3b0e --- /dev/null +++ b/practices/cpp/level1/p03_SafeArray/main.cpp @@ -0,0 +1,56 @@ +// +// main.cpp +// p03_SafeArray +// +// Created by Jimmy Fan on 2017/4/11. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include "SafeArray.h" + +int main(int argc, const char * argv[]) { + int n; + printf("请输入数组容量:"); + scanf("%d",&n); + SafeArray safeArray(n); + bool flag = 1; + while (flag) { + int k; + printf("请输入所要进行的操作序号:\n"); + printf(" 1:读取元素\n 2:赋值元素\n 0:退出程序\n"); + scanf("%d",&k); + int t,x; + switch (k) { + case 0: + flag = 0; + break; + case 1: { + printf("请输入要读取位置的下标:"); + scanf("%d",&t); + Result r = safeArray.getNum(t); + if (!r.flag) { + printf("Error:数组下标越界!!\n"); + } + else { + printf("元素为:%d\n",r.data); + } + break; + } + case 2: { + printf("请输入赋值下标以及元素值:\n"); + scanf("%d %d",&t,&x); + bool flag = safeArray.addNum(t, x); + if (flag) { + printf("成功赋值!\n"); + } + else { + printf("Error:数组下标越界!!\n"); + } + break; + } + } + + } + return 0; +} diff --git a/practices/cpp/level1/p04_cppScoreManagement/ScoreManagement.cpp b/practices/cpp/level1/p04_cppScoreManagement/ScoreManagement.cpp new file mode 100644 index 00000000..cbf957f1 --- /dev/null +++ b/practices/cpp/level1/p04_cppScoreManagement/ScoreManagement.cpp @@ -0,0 +1,161 @@ +// +// ScoreManagement.cpp +// p04_cppScoreManagement +// +// Created by Jimmy Fan on 2017/4/13. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include +#include "ScoreManagement.h" +#include +#include +using namespace std; + +ScoreManagement::ScoreManagement(int studentNum) { + this -> studentNum = studentNum; + this -> stus = new Student[studentNum]; +} + +bool ScoreManagement::addStudent(Student stu) { + bool flag = 0; + for (int i = 0; i < studentNum; i++) { + if (stus[i].showID() == -1) { + stus[i] = stu; + flag = 1; + break; + } + if (stus[i].showID() == stu.showID()) { + break; + } + } + return flag; +} + +int ScoreManagement::delStudent(char* name) { + int num = 0; + for (int i = 0; i < studentNum; i++) { + if (stus[i].showID() == -1) continue; + if (strcmp(name, stus[i].showName()) == 0) { + num ++; + stus[i].setID(-1); + } + } + return num; +} + +int ScoreManagement::delStudent(long ID) { + int num = 0; + for (int i = 0; i < studentNum; i++) { + if (stus[i].showID() == ID) { + num ++; + stus[i].setID(-1); + } + } + return num; +} + +void ScoreManagement::show() { + bool flag = 0; + for (int i = 0; i < studentNum; i++) { + if (stus[i].showID() != -1) { + printf(" %s %03ld %.2lf\n",stus[i].showName(),stus[i].showID(),stus[i].showScore()); + flag = 1; + } + } + if (!flag) { + printf("当前没有学生信息!\n"); + } +} + +bool cmpScore(Student stu1, Student stu2) { + if (stu1.showScore() == stu2.showScore()) { + return stu1.showID() < stu2.showID(); + } + return stu1.showScore() > stu2.showScore(); +} + +void ScoreManagement::sortByScore() { + sort(stus,stus + studentNum, cmpScore); +} + +bool cmpID(Student stu1, Student stu2) { + return stu1.showID() < stu2.showID(); +} + +void ScoreManagement::sortByID() { + sort(stus,stus + studentNum, cmpID); +} + +void ScoreManagement::inputScore(long ID) { + sortByID(); + bool find = 0; + int stuIndex = 0; + for (int i = 0; i < studentNum; i++) { + if (stus[i].showID() == -1) continue; + if (stus[i].showID() == ID) { + find = 1; + stuIndex = i; + break; + } + } + if (!find) { + printf("Error:未找到学号为%03ld的学生!\n",ID); + return; + } + while (1) { + printf("请输入学生 %s(学号:%03ld)的成绩:",stus[stuIndex].showName(),ID); + double score; + scanf("%lf",&score); + stus[stuIndex ++].setScore(score); + if (stuIndex == studentNum) break; + ID = stus[stuIndex].showID(); + printf("下一名学生姓名为:%s(学号:%03ld)\n *继续录入请输入1\n *结束录入请输入0\n",stus[stuIndex].showName(),ID); + int k; + scanf("%d",&k); + if (k == 0) break; + } +} + +void ScoreManagement::outputToFile() { + freopen("cppScoreManagement", "w", stdout); + printf("%d\n",studentNum); + for (int i = 0; i < studentNum; i++) { + if (stus[i].showID() == -1) { + printf("-1\n"); + } + else { + printf("%ld\n%s\n%lf\n",stus[i].showID(),stus[i].showName(),stus[i].showScore()); + } + } + fclose(stdout); +} + +void ScoreManagement::inputFromFile() { + FILE *file; + file = fopen("cppScoreManagement", "r"); + int studentNum; + bool fileExist = 1; + if (fscanf(file,"%d",&studentNum) == EOF || studentNum == 0) { + printf("请输入学生总人数:"); + scanf("%d",&studentNum); + fileExist = 0; + } + this -> studentNum = studentNum; + this -> stus = new Student[studentNum]; + if (fileExist) { + for (int i = 0; i < studentNum; i++) { + long ID; + fscanf(file,"%ld",&ID); + if (ID == -1) continue; + char *name; + name = (char *)malloc(sizeof(char)); + double score; + fscanf(file,"%s",name); + fscanf(file,"%lf",&score); + stus[i] = Student(name,ID,score); + } + } + fclose(file); +} diff --git a/practices/cpp/level1/p04_cppScoreManagement/ScoreManagement.h b/practices/cpp/level1/p04_cppScoreManagement/ScoreManagement.h new file mode 100644 index 00000000..0281bcfa --- /dev/null +++ b/practices/cpp/level1/p04_cppScoreManagement/ScoreManagement.h @@ -0,0 +1,32 @@ +// +// ScoreManagement.h +// p04_cppScoreManagement +// +// Created by Jimmy Fan on 2017/4/13. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef ScoreManagement_h +#define ScoreManagement_h + +#include "Student.h" + +class ScoreManagement { +private: + int studentNum; + Student *stus; +public: + ScoreManagement(int = 0); + bool addStudent(Student stu); + int delStudent(char* name); + int delStudent(long ID); + void show(); + void sortByScore(); + void sortByID(); + void inputScore(long startID); + void outputToFile(); + void inputFromFile(); +}; + + +#endif /* ScoreManagement_h */ diff --git a/practices/cpp/level1/p04_cppScoreManagement/Student.cpp b/practices/cpp/level1/p04_cppScoreManagement/Student.cpp new file mode 100644 index 00000000..4bd3777b --- /dev/null +++ b/practices/cpp/level1/p04_cppScoreManagement/Student.cpp @@ -0,0 +1,35 @@ +// +// Student.cpp +// p04_cppScoreManagement +// +// Created by Jimmy Fan on 2017/4/13. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include "Student.h" + +Student::Student(char *name, long ID, double score) { + this -> name = name; + this -> ID = ID; + this -> score = score; +} + +long Student::showID() { + return ID; +} + +char* Student::showName() { + return name; +} + +double Student::showScore() { + return score; +} + +void Student::setScore(double score) { + this -> score = score; +} + +void Student::setID(long ID) { + this -> ID = ID; +} diff --git a/practices/cpp/level1/p04_cppScoreManagement/Student.h b/practices/cpp/level1/p04_cppScoreManagement/Student.h new file mode 100644 index 00000000..8a50f54b --- /dev/null +++ b/practices/cpp/level1/p04_cppScoreManagement/Student.h @@ -0,0 +1,29 @@ +// +// Student.h +// p04_cppScoreManagement +// +// Created by Jimmy Fan on 2017/4/13. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef Student_h +#define Student_h + +#include + +class Student { +private: + char *name; + long ID; + double score; +public: + Student(char* = NULL, long = -1, double = 0); + long showID(); + char* showName(); + double showScore(); + void setScore(double score); + void setID(long ID); +}; + + +#endif /* Student_h */ diff --git a/practices/cpp/level1/p04_cppScoreManagement/main.cpp b/practices/cpp/level1/p04_cppScoreManagement/main.cpp new file mode 100644 index 00000000..62644808 --- /dev/null +++ b/practices/cpp/level1/p04_cppScoreManagement/main.cpp @@ -0,0 +1,98 @@ +// +// main.cpp +// p04_cppScoreManagement +// +// Created by Jimmy Fan on 2017/4/13. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include "ScoreManagement.h" +#include "Student.h" + +int main(int argc, const char * argv[]) { + ScoreManagement scoreManagement; + scoreManagement.inputFromFile(); + + bool flag = 1; + while (flag) { + int k; + printf("\n请输入需要进行的操作编号:\n"); + printf(" 1:查看学生名单\n 2:添加学生\n 3:删除学生\n 4:录入成绩\n 0:退出程序\n"); + scanf("%d",&k); + switch (k) { + case 0: { + flag = 0; + scoreManagement.outputToFile(); + break; + } + case 1: { + int t; + printf("*按成绩查看名单请输入1\n*按学号查看名单请输入2\n"); + scanf("%d",&t); + if (t == 1) { + scoreManagement.sortByScore(); + scoreManagement.show(); + } + else { + scoreManagement.sortByID(); + scoreManagement.show(); + } + break; + } + case 2: { + char *name; + name = (char *)malloc(sizeof(char)); + long ID; double score; + printf("请输入学生信息\n"); + printf(" 请输入学生姓名:"); + scanf("%s",name); + printf(" 请输入学生学号:"); + scanf("%ld",&ID); + printf(" 请输入学生成绩:"); + scanf("%lf",&score); + scoreManagement.addStudent(Student(name,ID,score)); + break; + } + case 3: { + int t; + printf("*按姓名删除学生请输入1\n*按学号删除学生请输入2\n"); + scanf("%d",&t); + if (t == 1) { + printf("请输入学生姓名:"); + char *name; + scanf("%s",name); + int num = scoreManagement.delStudent(name); + if (num == 0) { + printf("Error:未找到姓名为%s的学生!!\n",name); + } + else { + printf("共找到%d名姓名为%s的学生,已删除其信息\n",num,name); + } + } + else { + printf("请输入学生姓名:"); + long ID; + scanf("%ld",&ID); + int num = scoreManagement.delStudent(ID); + if (num == 0) { + printf("Error:未找到学号为%03ld的学生!!\n",ID); + } + else { + printf("共找到%d名学号为%03ld的学生,已删除其信息\n",num,ID); + } + } + break; + } + case 4: { + printf("请输入起始学号:"); + long startID; + scanf("%ld",&startID); + scoreManagement.inputScore(startID); + break; + } + } + } + + return 0; +} diff --git a/practices/cpp/level1/p05_Canvas/Canvas.cpp b/practices/cpp/level1/p05_Canvas/Canvas.cpp new file mode 100644 index 00000000..407416bf --- /dev/null +++ b/practices/cpp/level1/p05_Canvas/Canvas.cpp @@ -0,0 +1,29 @@ +// +// Canvas.cpp +// p05_Canvas02 +// +// Created by Jimmy Fan on 2017/4/27. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include "Canvas.h" + +Canvas::Canvas(int n) { + k = 0; + this -> n = n; +} + +void Canvas::addShape(Shape* shape) { + shapes[k ++] = shape; +} + +void Canvas::show() { + for (int i = 0; i < k; i++) { + shapes[i] -> show(); + } +} + +void Canvas::clear() { + k = 0; +} diff --git a/practices/cpp/level1/p05_Canvas/Canvas.h b/practices/cpp/level1/p05_Canvas/Canvas.h new file mode 100644 index 00000000..53816752 --- /dev/null +++ b/practices/cpp/level1/p05_Canvas/Canvas.h @@ -0,0 +1,30 @@ +// +// Canvas.h +// p05_Canvas02 +// +// Created by Jimmy Fan on 2017/4/27. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef Canvas_h +#define Canvas_h + +#include "Circle.h" +#include "Rect.h" +#define N 100 + +class Canvas { +private: + Shape* shapes[N]; + int k; + int n; +public: + Canvas(int = 0); + void addShape(Shape *shape); + void show(); + void clear(); +}; + + + +#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..ad1b42e5 --- /dev/null +++ b/practices/cpp/level1/p05_Canvas/Circle.cpp @@ -0,0 +1,23 @@ +// +// Circle.cpp +// p05_Canvas02 +// +// Created by Jimmy Fan on 2017/4/27. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include "Circle.h" + +Circle::Circle(int x,int y,double r):Point(x,y) { + this -> r = r; +} + +double Circle::area() { + return PI * r * r; +} + +void Circle::show() { + printf("圆心(%d,%d)\n",x,y); + printf("半径为:%.3lf\n",r); +} diff --git a/practices/cpp/level1/p05_Canvas/Circle.h b/practices/cpp/level1/p05_Canvas/Circle.h new file mode 100644 index 00000000..702fb72d --- /dev/null +++ b/practices/cpp/level1/p05_Canvas/Circle.h @@ -0,0 +1,25 @@ +// +// Circle.h +// p05_Canvas02 +// +// Created by Jimmy Fan on 2017/4/27. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef Circle_h +#define Circle_h + +#include "Point.h" +#define PI 3.1415926 + +class Circle: public Point { +private: + double r; +public: + Circle(int = 0, int y = 0, double = 0); + double area(); + void show(); +}; + + +#endif /* Circle_h */ diff --git a/practices/cpp/level1/p05_Canvas/Point.cpp b/practices/cpp/level1/p05_Canvas/Point.cpp new file mode 100644 index 00000000..c62d5b5e --- /dev/null +++ b/practices/cpp/level1/p05_Canvas/Point.cpp @@ -0,0 +1,23 @@ +// +// Point.cpp +// p05_Canvas02 +// +// Created by Jimmy Fan on 2017/4/27. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include "Point.h" + +Point::Point(int x, int y) { + this -> x = x; + this -> y = y; +} + +double Point::area() { + return 0; +} + +void Point::show() { + printf("坐标为(%d,%d)\n",x,y); +} diff --git a/practices/cpp/level1/p05_Canvas/Point.h b/practices/cpp/level1/p05_Canvas/Point.h new file mode 100644 index 00000000..efceb8db --- /dev/null +++ b/practices/cpp/level1/p05_Canvas/Point.h @@ -0,0 +1,23 @@ +// +// Point.h +// p05_Canvas02 +// +// Created by Jimmy Fan on 2017/4/27. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef Point_h +#define Point_h + +#include "Shape.h" + +class Point: public Shape{ +protected: + int x,y; +public: + Point(int = 0, int = 0); + double area(); + void show(); +}; + +#endif /* Point_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..c800fe87 --- /dev/null +++ b/practices/cpp/level1/p05_Canvas/Rect.cpp @@ -0,0 +1,30 @@ +// +// Rect.cpp +// p05_Canvas02 +// +// Created by Jimmy Fan on 2017/4/27. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include +#include "Rect.h" +using namespace std; + +int __abs(int x) { + return x < 0 ? -x:x; +} + +Rect::Rect(int x1, int y1, int x2, int y2):Point(min(x1,x2),min(y1,y2)) { + width = __abs(x1 - x2); + height = __abs(y1 - y2); +} + +double Rect::area() { + return width * height; +} + +void Rect::show() { + printf("矩形左下角坐标为(%d,%d)\n",x,y); + printf("宽度为%d 高度为%d\n",width,height); +} diff --git a/practices/cpp/level1/p05_Canvas/Rect.h b/practices/cpp/level1/p05_Canvas/Rect.h new file mode 100644 index 00000000..b1c911ef --- /dev/null +++ b/practices/cpp/level1/p05_Canvas/Rect.h @@ -0,0 +1,23 @@ +// +// Rect.h +// p05_Canvas02 +// +// Created by Jimmy Fan on 2017/4/27. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef Rect_h +#define Rect_h + +#include "Point.h" + +class Rect: public Point{ +private: + int width,height; +public: + Rect(int = 0, int = 0, int = 0, int = 0); + double area(); + void show(); +}; + +#endif /* Rect_h */ diff --git a/practices/cpp/level1/p05_Canvas/Shape.h b/practices/cpp/level1/p05_Canvas/Shape.h new file mode 100644 index 00000000..e866f0dc --- /dev/null +++ b/practices/cpp/level1/p05_Canvas/Shape.h @@ -0,0 +1,19 @@ +// +// Shape.h +// p05_Canvas02 +// +// Created by Jimmy Fan on 2017/4/27. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef Shape_h +#define Shape_h + +class Shape { +public: + virtual double area() = 0; + virtual void show() = 0; +}; + + +#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..67d01386 --- /dev/null +++ b/practices/cpp/level1/p05_Canvas/main.cpp @@ -0,0 +1,60 @@ +// +// main.cpp +// p05_Canvas02 +// +// Created by Jimmy Fan on 2017/4/27. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include "Canvas.h" +using namespace std; + +int main(int argc, const char * argv[]) { + Canvas canvas; + bool flag = 1; + while (flag) { + printf("请输入所需操作编号:\n 1:添加图形\n 2:展示画布\n 3:清空画布\n 0:退出程序\n"); + int k; + scanf("%d",&k); + switch (k) { + case 0: + flag = 0; + break; + case 1: { + printf("请输入图形种类编号:\n 1:圆\n 2:矩形\n"); + int kk; + scanf("%d",&kk); + switch (kk) { + case 1: { + int x,y; double r; + printf("圆心: "); + scanf("%d %d",&x,&y); + printf("半径: "); + scanf("%lf",&r); + Circle circle(x,y,r); + canvas.addShape(&circle); + break; + } + case 2: { + int x1,y1,x2,y2; + printf("输入位于对角线上的两个点的坐标: "); + scanf("%d %d %d %d",&x1,&y1,&x2,&y2); + Rect rect(x1,y1,x2,y2); + canvas.addShape(&rect); + break; + } + } + break; + } + case 2: + canvas.show(); + break; + case 3: + canvas.clear(); + break; + } + } + + 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..be579fa4 --- /dev/null +++ b/practices/cpp/level1/p06_CircleAndPoint/Circle.cpp @@ -0,0 +1,34 @@ +// +// Circle.cpp +// p06_CircleAndPoint +// +// Created by Jimmy Fan on 2017/4/18. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include "Circle.h" +#define PI 3.1415926 + +Circle::Circle(double x,double y,double R) { + this -> centrePoint = Point(x,y); + this -> R = R; +} + +void Circle::move(double xx, double yy) { + centrePoint.move(xx, yy); +} + +void Circle::showCircle() { + printf("圆心坐标为:"); + centrePoint.showPoint(); + printf("半径为:%lf\n",this -> R); +} + +double Circle::area() { + return PI * R * R; +} + +void Circle::changeR(int R) { + this -> R = R; +} diff --git a/practices/cpp/level1/p06_CircleAndPoint/Circle.h b/practices/cpp/level1/p06_CircleAndPoint/Circle.h new file mode 100644 index 00000000..631a86e0 --- /dev/null +++ b/practices/cpp/level1/p06_CircleAndPoint/Circle.h @@ -0,0 +1,27 @@ +// +// Circle.h +// p06_CircleAndPoint +// +// Created by Jimmy Fan on 2017/4/18. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef Circle_h +#define Circle_h + +#include "Point.h" + +class Circle { +private: + Point centrePoint; + double R; +public: + Circle(double = 0,double = 0,double = 0); + void move(double xx,double yy); + void showCircle(); + double area(); + void changeR(int R); +}; + + +#endif /* Circle_h */ diff --git a/practices/cpp/level1/p06_CircleAndPoint/Point.cpp b/practices/cpp/level1/p06_CircleAndPoint/Point.cpp new file mode 100644 index 00000000..69a3d5de --- /dev/null +++ b/practices/cpp/level1/p06_CircleAndPoint/Point.cpp @@ -0,0 +1,24 @@ +// +// Point.cpp +// p06_CircleAndPoint +// +// Created by Jimmy Fan on 2017/4/18. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include "Point.h" + +Point::Point(double x,double y) { + this -> x = x; + this -> y = y; +} + +void Point::move(double x, double y) { + this -> x += x; + this -> y += y; +} + +void Point::showPoint() { + printf("%.3lf %.3lf\n",this -> x, this -> 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..923792b9 --- /dev/null +++ b/practices/cpp/level1/p06_CircleAndPoint/Point.h @@ -0,0 +1,22 @@ +// +// Point.h +// p06_CircleAndPoint +// +// Created by Jimmy Fan on 2017/4/18. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef Point_h +#define Point_h + +class Point { +private: + double x,y; +public: + Point(double = 0,double = 0); + void move(double x,double y); + void showPoint(); +}; + + +#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..bc139f51 --- /dev/null +++ b/practices/cpp/level1/p06_CircleAndPoint/main.cpp @@ -0,0 +1,55 @@ +// +// main.cpp +// p06_CircleAndPoint +// +// Created by Jimmy Fan on 2017/4/18. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include "Circle.h" + +int main(int argc, const char * argv[]) { + printf("请输入圆心坐标:(以逗号隔开)\n"); + double x,y; + scanf("%lf,%lf",&x,&y); + printf("请输入半径: "); + double R; + scanf("%lf",&R); + Circle C(x,y,R); + + bool flag = 1; + while (flag) { + printf("\n请输入要进行的操作编号:\n"); + printf(" 1:移动圆\n 2:求面积\n 3:改变半径\n 4:输出当前圆的信息\n 0:退出程序\n"); + int k; + scanf("%d",&k); + switch (k) { + case 0: + flag = 0; + break; + case 1: { + printf("输入要移动的偏移量:\n"); + double xx,yy; + scanf("%lf,%lf",&xx,&yy); + C.move(xx, yy); + break; + } + case 2: + printf("面积大小为:%.3lf\n",C.area()); + break; + case 3: { + printf("请输入新的半径大小: "); + double R; + scanf("%lf",&R); + C.changeR(R); + break; + } + case 4: + C.showCircle(); + break; + } + } + + return 0; +} diff --git a/practices/cpp/level1/p07_Circuit/Circuit.cpp b/practices/cpp/level1/p07_Circuit/Circuit.cpp new file mode 100644 index 00000000..1ea446d1 --- /dev/null +++ b/practices/cpp/level1/p07_Circuit/Circuit.cpp @@ -0,0 +1,34 @@ +// +// Circuit.cpp +// p07_Circuit +// +// Created by Jimmy Fan on 2017/6/23. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include "Circuit.h" + +Circuit::Circuit() { + k = 0; +} + +void Circuit::addDevice(Device *device) { + devices[k++] = device; +} + +void Circuit::on() { + for (int i = 0; i < k; i++) { + devices[i] -> on(); + } +} + +void Circuit::off() { + for (int i = 0; i < k; i++) { + devices[i] -> off(); + } +} + +int Circuit::getNum() { + return k; +} diff --git a/practices/cpp/level1/p07_Circuit/Circuit.h b/practices/cpp/level1/p07_Circuit/Circuit.h new file mode 100644 index 00000000..5cdd0ae6 --- /dev/null +++ b/practices/cpp/level1/p07_Circuit/Circuit.h @@ -0,0 +1,28 @@ +// +// Circuit.h +// p07_Circuit +// +// Created by Jimmy Fan on 2017/5/2. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef Circuit_h +#define Circuit_h + +#include "Device.h" +#define N 100 + +class Circuit { +private: + Device* devices[N]; + int k; +public: + Circuit(); + void addDevice(Device* device); + void on(); + void off(); + int getNum(); +}; + + +#endif /* Circuit_h */ diff --git a/practices/cpp/level1/p07_Circuit/Device.h b/practices/cpp/level1/p07_Circuit/Device.h new file mode 100644 index 00000000..c848d403 --- /dev/null +++ b/practices/cpp/level1/p07_Circuit/Device.h @@ -0,0 +1,19 @@ +// +// Device.h +// p07_Circuit +// +// Created by Jimmy Fan on 2017/5/2. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef Device_h +#define Device_h + +class Device { +public: + virtual void on() = 0; + virtual void off() = 0; +}; + + +#endif /* Device_h */ diff --git a/practices/cpp/level1/p07_Circuit/Fan.cpp b/practices/cpp/level1/p07_Circuit/Fan.cpp new file mode 100644 index 00000000..cfb2d1f1 --- /dev/null +++ b/practices/cpp/level1/p07_Circuit/Fan.cpp @@ -0,0 +1,22 @@ +// +// Fan.cpp +// p07_Circuit +// +// Created by Jimmy Fan on 2017/5/2. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include "Fan.h" + +Fan::Fan(int k) { + this -> k = k; +} + +void Fan::on() { + printf("风扇%d在转\n",k); +} + +void Fan::off() { + printf("风扇%d停了\n",k); +} diff --git a/practices/cpp/level1/p07_Circuit/Fan.h b/practices/cpp/level1/p07_Circuit/Fan.h new file mode 100644 index 00000000..0dbf0743 --- /dev/null +++ b/practices/cpp/level1/p07_Circuit/Fan.h @@ -0,0 +1,23 @@ +// +// Fan.h +// p07_Circuit +// +// Created by Jimmy Fan on 2017/5/2. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef Fan_h +#define Fan_h + +#include "Device.h" + +class Fan:public Device { +private: + int k; +public: + Fan(int k); + void on(); + void off(); +}; + +#endif /* Fan_h */ diff --git a/practices/cpp/level1/p07_Circuit/Lamp.cpp b/practices/cpp/level1/p07_Circuit/Lamp.cpp new file mode 100644 index 00000000..ee37691e --- /dev/null +++ b/practices/cpp/level1/p07_Circuit/Lamp.cpp @@ -0,0 +1,22 @@ +// +// Lamp.cpp +// p07_Circuit +// +// Created by Jimmy Fan on 2017/5/2. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include "Lamp.h" + +Lamp::Lamp(int k) { + this -> k = k; +} + +void Lamp::on() { + printf("灯泡%d亮了\n",k); +} + +void Lamp::off() { + printf("灯泡%d灭了\n",k); +} diff --git a/practices/cpp/level1/p07_Circuit/Lamp.h b/practices/cpp/level1/p07_Circuit/Lamp.h new file mode 100644 index 00000000..0f11ec39 --- /dev/null +++ b/practices/cpp/level1/p07_Circuit/Lamp.h @@ -0,0 +1,23 @@ +// +// Lamp.h +// p07_Circuit +// +// Created by Jimmy Fan on 2017/5/2. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef Lamp_h +#define Lamp_h + +#include "Device.h" + +class Lamp:public Device { +private: + int k; +public: + Lamp(int k); + void on(); + void off(); +}; + +#endif /* Lamp_h */ diff --git a/practices/cpp/level1/p07_Circuit/main.cpp b/practices/cpp/level1/p07_Circuit/main.cpp new file mode 100644 index 00000000..b3cd05ce --- /dev/null +++ b/practices/cpp/level1/p07_Circuit/main.cpp @@ -0,0 +1,44 @@ +// +// main.cpp +// p07_Circuit +// +// Created by Jimmy Fan on 2017/5/2. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include "Circuit.h" +#include "Lamp.h" +#include "Fan.h" + +int main(int argc, const char * argv[]) { + Circuit myCircuit; + bool flag = 1; + while (flag) { + printf("请输入所需操作编号:\n 1:添加灯泡\n 2:添加风扇\n 3:开关开\n 4:开关关\n 0:退出程序\n"); + int k; + scanf("%d",&k); + switch (k) { + case 0: + flag = 0; + break; + case 1: { + Lamp lamp(myCircuit.getNum()); + myCircuit.addDevice(&lamp); + break; + } + case 2: { + Fan fan(myCircuit.getNum()); + myCircuit.addDevice(&fan); + break; + } + case 3: + myCircuit.on(); + break; + case 4: + myCircuit.off(); + break; + } + } + return 0; +} diff --git a/practices/cpp/level1/p08_EmployeeAndSales/Employee.cpp b/practices/cpp/level1/p08_EmployeeAndSales/Employee.cpp new file mode 100644 index 00000000..30e33451 --- /dev/null +++ b/practices/cpp/level1/p08_EmployeeAndSales/Employee.cpp @@ -0,0 +1,21 @@ +// +// Employee.cpp +// p08_EmployeeAndSales +// +// Created by Jimmy Fan on 2017/6/23. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include "Employee.h" +using namespace std; + +Employee::Employee(char *name, int age, int level) { + this -> name = name; + this -> age = age; + this -> level = level; +} + +int Employee::getSalary() { + return 1000 * level; +} diff --git a/practices/cpp/level1/p08_EmployeeAndSales/Employee.h b/practices/cpp/level1/p08_EmployeeAndSales/Employee.h new file mode 100644 index 00000000..0db5f6b5 --- /dev/null +++ b/practices/cpp/level1/p08_EmployeeAndSales/Employee.h @@ -0,0 +1,23 @@ +// +// Employee.h +// p08_EmployeeAndSales +// +// Created by Jimmy Fan on 2017/6/23. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef Employee_h +#define Employee_h + +class Employee { +private: + char *name; + int age; + int level; +public: + Employee(char *name, int age, int level); + int getSalary(); +}; + + +#endif /* Employee_h */ diff --git a/practices/cpp/level1/p08_EmployeeAndSales/Salesman.cpp b/practices/cpp/level1/p08_EmployeeAndSales/Salesman.cpp new file mode 100644 index 00000000..0bc28d18 --- /dev/null +++ b/practices/cpp/level1/p08_EmployeeAndSales/Salesman.cpp @@ -0,0 +1,21 @@ +// +// Salesman.cpp +// p08_EmployeeAndSales +// +// Created by Jimmy Fan on 2017/6/23. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include "Salesman.h" +using namespace std; + +Salesman::Salesman(char *name, int age, int level, int sales): Employee(name, age, level) { + this -> sales = sales; +} + +int Salesman::getSalary() { + int salary = Employee::getSalary(); + salary += sales * 2 / 10; + return salary; +} diff --git a/practices/cpp/level1/p08_EmployeeAndSales/Salesman.h b/practices/cpp/level1/p08_EmployeeAndSales/Salesman.h new file mode 100644 index 00000000..37cb0364 --- /dev/null +++ b/practices/cpp/level1/p08_EmployeeAndSales/Salesman.h @@ -0,0 +1,22 @@ +// +// Salesman.h +// p08_EmployeeAndSales +// +// Created by Jimmy Fan on 2017/6/23. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef Salesman_h +#define Salesman_h + +#include "Employee.h" + +class Salesman: public Employee { +private: + int sales; +public: + Salesman(char *name, int age, int level, int sales); + int getSalary(); +}; + +#endif /* Salesman_h */ diff --git a/practices/cpp/level1/p09_Tree/Node.cpp b/practices/cpp/level1/p09_Tree/Node.cpp new file mode 100644 index 00000000..43a14a5f --- /dev/null +++ b/practices/cpp/level1/p09_Tree/Node.cpp @@ -0,0 +1,29 @@ +// +// Node.cpp +// p09_Tree +// +// Created by Jimmy Fan on 2017/6/23. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include "Node.h" +using namespace std; + +Node::Node(int data, int ID, int parentID) { + this -> data = data; + this -> ID = ID; + this -> parentID = parentID; +} + +void Node::append(Node node) { + son.push_back(node); +} + +int Node::getNumOfSon() { + return son.size(); +} + +int Node::getParentID() { + return parentID; +} diff --git a/practices/cpp/level1/p09_Tree/Node.h b/practices/cpp/level1/p09_Tree/Node.h new file mode 100644 index 00000000..05476567 --- /dev/null +++ b/practices/cpp/level1/p09_Tree/Node.h @@ -0,0 +1,28 @@ +// +// Node.h +// p09_Tree +// +// Created by Jimmy Fan on 2017/6/23. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef Node_h +#define Node_h + +#include +using namespace std; + +class Node { +private: + int data; + int ID; + int parentID; + vector son; +public: + Node(int = 0, int = 0, int = 0); + void append(Node node); + int getNumOfSon(); + int getParentID(); +}; + +#endif /* Node_h */ diff --git a/practices/cpp/level1/p09_Tree/Tree.cpp b/practices/cpp/level1/p09_Tree/Tree.cpp new file mode 100644 index 00000000..aa4f6adf --- /dev/null +++ b/practices/cpp/level1/p09_Tree/Tree.cpp @@ -0,0 +1,29 @@ +// +// Tree.cpp +// p09_Tree +// +// Created by Jimmy Fan on 2017/6/23. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include "Tree.h" +using namespace std; + +Tree::Tree() { + numOfNode = 0; + nodes = new Node(N); +} + +void Tree::append(int data, int k) { + Node node(data, ++numOfNode, k); + nodes[k].append(node); +} + +int Tree::getNumOfSon(int k) { + return nodes[k].getNumOfSon(); +} + +int Tree::getParentID(int k) { + return nodes[k].getParentID(); +} diff --git a/practices/cpp/level1/p09_Tree/Tree.h b/practices/cpp/level1/p09_Tree/Tree.h new file mode 100644 index 00000000..fdbb3efa --- /dev/null +++ b/practices/cpp/level1/p09_Tree/Tree.h @@ -0,0 +1,27 @@ +// +// Tree.h +// p09_Tree +// +// Created by Jimmy Fan on 2017/6/23. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef Tree_h +#define Tree_h + +#include "Node.h" +#define N 100 + +class Tree { +private: + int numOfNode; + Node *nodes; +public: + Tree(); + void append(int data, int k); + int getNumOfSon(int k); + int getParentID(int k); +}; + + +#endif /* Tree_h */ diff --git a/practices/cpp/level1/p09_Tree/main.cpp b/practices/cpp/level1/p09_Tree/main.cpp new file mode 100644 index 00000000..f74d3f78 --- /dev/null +++ b/practices/cpp/level1/p09_Tree/main.cpp @@ -0,0 +1,52 @@ +// +// main.cpp +// p09_Tree +// +// Created by Jimmy Fan on 2017/6/23. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include "Tree.h" +using namespace std; + +int main(int argc, const char * argv[]) { + Tree mytree; + bool flag = 1; + while (flag) { + printf("请输入所需操作编号:\n 1:添加结点\n 2:求节点的父节点\n 3:求节点的子节点个数\n 0:退出程序\n"); + int k; + scanf("%d",&k); + switch (k) { + case 0: + flag = 0; + break; + case 1: { + printf("请输入在几号节点下添加子节点:\n"); + int kk; + scanf("%d",&kk); + printf("请输入子节点的data值:\n"); + int x; + scanf("%d",&x); + mytree.append(x, kk); + break; + } + case 2: { + printf("请输入求几号节点的父节点:\n"); + int kk; + scanf("%d",&kk); + printf("%d号节点的父节点编号为%d\n",kk,mytree.getParentID(kk)); + break; + } + case 3: { + printf("请输入求几号节点的子节点个数:\n"); + int kk; + scanf("%d",&kk); + printf("%d号节点的子节点个数为%d\n",kk,mytree.getNumOfSon(kk)); + break; + } + } + } + + return 0; +} diff --git a/practices/cpp/level1/p11_Fighters/Fighters.xcodeproj/project.pbxproj b/practices/cpp/level1/p11_Fighters/Fighters.xcodeproj/project.pbxproj new file mode 100644 index 00000000..b679f0d5 --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters.xcodeproj/project.pbxproj @@ -0,0 +1,480 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 142924D91EC41059000BCA4B /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 142924D81EC41059000BCA4B /* main.cpp */; }; + 142924EF1EC41184000BCA4B /* libsfml-audio.2.4.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 142924E01EC41184000BCA4B /* libsfml-audio.2.4.2.dylib */; }; + 142924F01EC41184000BCA4B /* libsfml-audio.2.4.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 142924E11EC41184000BCA4B /* libsfml-audio.2.4.2.dylib */; }; + 142924F11EC41184000BCA4B /* libsfml-audio.2.4.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 142924E21EC41184000BCA4B /* libsfml-audio.2.4.2.dylib */; }; + 142924F21EC41184000BCA4B /* libsfml-graphics.2.4.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 142924E31EC41184000BCA4B /* libsfml-graphics.2.4.2.dylib */; }; + 142924F31EC41184000BCA4B /* libsfml-graphics.2.4.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 142924E41EC41184000BCA4B /* libsfml-graphics.2.4.2.dylib */; }; + 142924F41EC41184000BCA4B /* libsfml-graphics.2.4.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 142924E51EC41184000BCA4B /* libsfml-graphics.2.4.2.dylib */; }; + 142924F51EC41184000BCA4B /* libsfml-network.2.4.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 142924E61EC41184000BCA4B /* libsfml-network.2.4.2.dylib */; }; + 142924F61EC41184000BCA4B /* libsfml-network.2.4.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 142924E71EC41184000BCA4B /* libsfml-network.2.4.2.dylib */; }; + 142924F71EC41184000BCA4B /* libsfml-network.2.4.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 142924E81EC41184000BCA4B /* libsfml-network.2.4.2.dylib */; }; + 142924F81EC41184000BCA4B /* libsfml-system.2.4.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 142924E91EC41184000BCA4B /* libsfml-system.2.4.2.dylib */; }; + 142924F91EC41184000BCA4B /* libsfml-system.2.4.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 142924EA1EC41184000BCA4B /* libsfml-system.2.4.2.dylib */; }; + 142924FA1EC41184000BCA4B /* libsfml-system.2.4.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 142924EB1EC41184000BCA4B /* libsfml-system.2.4.2.dylib */; }; + 142924FB1EC41184000BCA4B /* libsfml-window.2.4.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 142924EC1EC41184000BCA4B /* libsfml-window.2.4.2.dylib */; }; + 142924FC1EC41184000BCA4B /* libsfml-window.2.4.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 142924ED1EC41184000BCA4B /* libsfml-window.2.4.2.dylib */; }; + 142924FD1EC41184000BCA4B /* libsfml-window.2.4.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 142924EE1EC41184000BCA4B /* libsfml-window.2.4.2.dylib */; }; + 149720171EEEAC0E00CF0321 /* Background.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 149720161EEEAC0E00CF0321 /* Background.cpp */; }; + 1497201C1EEEBF0800CF0321 /* Menu.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1497201B1EEEBF0800CF0321 /* Menu.cpp */; }; + 149720221EEEDAAB00CF0321 /* Reward.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 149720211EEEDAAB00CF0321 /* Reward.cpp */; }; + 14B6B2E91ED3C2D2000ED50B /* Score.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14B6B2E81ED3C2D2000ED50B /* Score.cpp */; }; + 14D3B1AA1EE63DE500ED2639 /* Boss.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14D3B1A91EE63DE500ED2639 /* Boss.cpp */; }; + 14E745A71EF20BE2005BDC7B /* GameMenu.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14E745A61EF20BE2005BDC7B /* GameMenu.cpp */; }; + 14F563DD1ECA85E9002BB1E0 /* Shot.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14F563DC1ECA85E9002BB1E0 /* Shot.cpp */; }; + 14F5EEEE1ECBD48C003D4EB6 /* Enemys.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14F5EEED1ECBD48C003D4EB6 /* Enemys.cpp */; }; + 14FA1FB61ED68AD000E12981 /* Heart.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14FA1FB51ED68AD000E12981 /* Heart.cpp */; }; + 14FB25AF1EC9C62E00E53C35 /* Game.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14FB25AE1EC9C62E00E53C35 /* Game.cpp */; }; + 14FB25B21EC9CA7E00E53C35 /* Player.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14FB25B11EC9CA7E00E53C35 /* Player.cpp */; }; + 14FB25B51EC9D2BC00E53C35 /* Enemy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14FB25B41EC9D2BC00E53C35 /* Enemy.cpp */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 142924D31EC41059000BCA4B /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 142924D51EC41059000BCA4B /* Fighters */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Fighters; sourceTree = BUILT_PRODUCTS_DIR; }; + 142924D81EC41059000BCA4B /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = ""; }; + 142924E01EC41184000BCA4B /* libsfml-audio.2.4.2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libsfml-audio.2.4.2.dylib"; path = "../SFML-2.4.2-osx-clang/lib/libsfml-audio.2.4.2.dylib"; sourceTree = ""; }; + 142924E11EC41184000BCA4B /* libsfml-audio.2.4.2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libsfml-audio.2.4.2.dylib"; path = "../SFML-2.4.2-osx-clang/lib/libsfml-audio.2.4.2.dylib"; sourceTree = ""; }; + 142924E21EC41184000BCA4B /* libsfml-audio.2.4.2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libsfml-audio.2.4.2.dylib"; path = "../SFML-2.4.2-osx-clang/lib/libsfml-audio.2.4.2.dylib"; sourceTree = ""; }; + 142924E31EC41184000BCA4B /* libsfml-graphics.2.4.2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libsfml-graphics.2.4.2.dylib"; path = "../SFML-2.4.2-osx-clang/lib/libsfml-graphics.2.4.2.dylib"; sourceTree = ""; }; + 142924E41EC41184000BCA4B /* libsfml-graphics.2.4.2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libsfml-graphics.2.4.2.dylib"; path = "../SFML-2.4.2-osx-clang/lib/libsfml-graphics.2.4.2.dylib"; sourceTree = ""; }; + 142924E51EC41184000BCA4B /* libsfml-graphics.2.4.2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libsfml-graphics.2.4.2.dylib"; path = "../SFML-2.4.2-osx-clang/lib/libsfml-graphics.2.4.2.dylib"; sourceTree = ""; }; + 142924E61EC41184000BCA4B /* libsfml-network.2.4.2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libsfml-network.2.4.2.dylib"; path = "../SFML-2.4.2-osx-clang/lib/libsfml-network.2.4.2.dylib"; sourceTree = ""; }; + 142924E71EC41184000BCA4B /* libsfml-network.2.4.2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libsfml-network.2.4.2.dylib"; path = "../SFML-2.4.2-osx-clang/lib/libsfml-network.2.4.2.dylib"; sourceTree = ""; }; + 142924E81EC41184000BCA4B /* libsfml-network.2.4.2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libsfml-network.2.4.2.dylib"; path = "../SFML-2.4.2-osx-clang/lib/libsfml-network.2.4.2.dylib"; sourceTree = ""; }; + 142924E91EC41184000BCA4B /* libsfml-system.2.4.2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libsfml-system.2.4.2.dylib"; path = "../SFML-2.4.2-osx-clang/lib/libsfml-system.2.4.2.dylib"; sourceTree = ""; }; + 142924EA1EC41184000BCA4B /* libsfml-system.2.4.2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libsfml-system.2.4.2.dylib"; path = "../SFML-2.4.2-osx-clang/lib/libsfml-system.2.4.2.dylib"; sourceTree = ""; }; + 142924EB1EC41184000BCA4B /* libsfml-system.2.4.2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libsfml-system.2.4.2.dylib"; path = "../SFML-2.4.2-osx-clang/lib/libsfml-system.2.4.2.dylib"; sourceTree = ""; }; + 142924EC1EC41184000BCA4B /* libsfml-window.2.4.2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libsfml-window.2.4.2.dylib"; path = "../SFML-2.4.2-osx-clang/lib/libsfml-window.2.4.2.dylib"; sourceTree = ""; }; + 142924ED1EC41184000BCA4B /* libsfml-window.2.4.2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libsfml-window.2.4.2.dylib"; path = "../SFML-2.4.2-osx-clang/lib/libsfml-window.2.4.2.dylib"; sourceTree = ""; }; + 142924EE1EC41184000BCA4B /* libsfml-window.2.4.2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libsfml-window.2.4.2.dylib"; path = "../SFML-2.4.2-osx-clang/lib/libsfml-window.2.4.2.dylib"; sourceTree = ""; }; + 149720151EEEAC0100CF0321 /* Background.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Background.h; sourceTree = ""; }; + 149720161EEEAC0E00CF0321 /* Background.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Background.cpp; sourceTree = ""; }; + 149720181EEEAD4800CF0321 /* background.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = background.png; path = Resources/background.png; sourceTree = ""; }; + 149720191EEEB5AC00CF0321 /* background_long.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = background_long.png; path = Resources/background_long.png; sourceTree = ""; }; + 1497201A1EEEBEFD00CF0321 /* Menu.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Menu.h; sourceTree = ""; }; + 1497201B1EEEBF0800CF0321 /* Menu.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Menu.cpp; sourceTree = ""; }; + 1497201D1EEEDA8800CF0321 /* reward_damage.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = reward_damage.png; path = Resources/reward_damage.png; sourceTree = ""; }; + 1497201E1EEEDA8800CF0321 /* reward_life.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = reward_life.png; path = Resources/reward_life.png; sourceTree = ""; }; + 1497201F1EEEDA8800CF0321 /* reward_speed.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = reward_speed.png; path = Resources/reward_speed.png; sourceTree = ""; }; + 149720211EEEDAAB00CF0321 /* Reward.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Reward.cpp; sourceTree = ""; }; + 14B6B2E21ED3BEC9000ED50B /* bullet.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = bullet.png; path = Resources/bullet.png; sourceTree = ""; }; + 14B6B2E31ED3BEC9000ED50B /* enemy0.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = enemy0.png; path = Resources/enemy0.png; sourceTree = ""; }; + 14B6B2E51ED3BEC9000ED50B /* plane.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = plane.png; path = Resources/plane.png; sourceTree = ""; }; + 14B6B2E61ED3C1F9000ED50B /* Arial Black.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = "Arial Black.ttf"; path = "Resources/Arial Black.ttf"; sourceTree = ""; }; + 14B6B2E71ED3C2C5000ED50B /* Score.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Score.h; sourceTree = ""; }; + 14B6B2E81ED3C2D2000ED50B /* Score.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Score.cpp; sourceTree = ""; }; + 14B6B2EA1ED3C749000ED50B /* enemy0_down1.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = enemy0_down1.png; path = Resources/enemy0_down1.png; sourceTree = ""; }; + 14B6B2EB1ED3C749000ED50B /* enemy0_down2.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = enemy0_down2.png; path = Resources/enemy0_down2.png; sourceTree = ""; }; + 14B6B2EC1ED3C749000ED50B /* enemy0_down3.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = enemy0_down3.png; path = Resources/enemy0_down3.png; sourceTree = ""; }; + 14B6B2ED1ED3C749000ED50B /* enemy0_down4.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = enemy0_down4.png; path = Resources/enemy0_down4.png; sourceTree = ""; }; + 14D3B1A01EE63DC100ED2639 /* boss_down1.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = boss_down1.png; path = Resources/boss_down1.png; sourceTree = ""; }; + 14D3B1A11EE63DC100ED2639 /* boss_down2.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = boss_down2.png; path = Resources/boss_down2.png; sourceTree = ""; }; + 14D3B1A21EE63DC100ED2639 /* boss_down3.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = boss_down3.png; path = Resources/boss_down3.png; sourceTree = ""; }; + 14D3B1A31EE63DC100ED2639 /* boss_down4.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = boss_down4.png; path = Resources/boss_down4.png; sourceTree = ""; }; + 14D3B1A41EE63DC100ED2639 /* boss_down5.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = boss_down5.png; path = Resources/boss_down5.png; sourceTree = ""; }; + 14D3B1A51EE63DC100ED2639 /* boss_down6.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = boss_down6.png; path = Resources/boss_down6.png; sourceTree = ""; }; + 14D3B1A61EE63DC100ED2639 /* boss_hit.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = boss_hit.png; path = Resources/boss_hit.png; sourceTree = ""; }; + 14D3B1A71EE63DC100ED2639 /* boss.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = boss.png; path = Resources/boss.png; sourceTree = ""; }; + 14D3B1A81EE63DDA00ED2639 /* Boss.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Boss.h; sourceTree = ""; }; + 14D3B1A91EE63DE500ED2639 /* Boss.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Boss.cpp; sourceTree = ""; }; + 14E745A51EF20BD6005BDC7B /* GameMenu.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GameMenu.h; sourceTree = ""; }; + 14E745A61EF20BE2005BDC7B /* GameMenu.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GameMenu.cpp; sourceTree = ""; }; + 14E745A81EF21745005BDC7B /* selector.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = selector.png; path = Resources/selector.png; sourceTree = ""; }; + 14E9EEF11EF65DA200610949 /* Reward.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Reward.h; sourceTree = ""; }; + 14F563DB1ECA85D9002BB1E0 /* Shot.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Shot.h; sourceTree = ""; }; + 14F563DC1ECA85E9002BB1E0 /* Shot.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Shot.cpp; sourceTree = ""; }; + 14F5EEEC1ECBD47F003D4EB6 /* Enemys.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Enemys.h; sourceTree = ""; }; + 14F5EEED1ECBD48C003D4EB6 /* Enemys.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Enemys.cpp; sourceTree = ""; }; + 14F8DCD31EDFB730006F3CF2 /* game_music.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; name = game_music.wav; path = Resources/game_music.wav; sourceTree = ""; }; + 14F8DCD41EDFB8B6006F3CF2 /* enemy0_down.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; name = enemy0_down.wav; path = Resources/enemy0_down.wav; sourceTree = ""; }; + 14F8DCD61EDFBB95006F3CF2 /* bullet.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; name = bullet.wav; path = Resources/bullet.wav; sourceTree = ""; }; + 14F8DCD81EDFBC8F006F3CF2 /* player_down.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; name = player_down.wav; path = Resources/player_down.wav; sourceTree = ""; }; + 14F8DCD91EDFBCFC006F3CF2 /* game_over.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; name = game_over.wav; path = Resources/game_over.wav; sourceTree = ""; }; + 14FA1FAD1ED67A3800E12981 /* bulletEnemy.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = bulletEnemy.png; path = Resources/bulletEnemy.png; sourceTree = ""; }; + 14FA1FAE1ED67ACB00E12981 /* bullet1.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = bullet1.png; path = Resources/bullet1.png; sourceTree = ""; }; + 14FA1FAF1ED6816400E12981 /* plane_down1.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = plane_down1.png; path = Resources/plane_down1.png; sourceTree = ""; }; + 14FA1FB01ED6816400E12981 /* plane_down2.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = plane_down2.png; path = Resources/plane_down2.png; sourceTree = ""; }; + 14FA1FB11ED6816400E12981 /* plane_down3.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = plane_down3.png; path = Resources/plane_down3.png; sourceTree = ""; }; + 14FA1FB21ED6816400E12981 /* plane_down4.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = plane_down4.png; path = Resources/plane_down4.png; sourceTree = ""; }; + 14FA1FB41ED689EE00E12981 /* Heart.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Heart.h; sourceTree = ""; }; + 14FA1FB51ED68AD000E12981 /* Heart.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Heart.cpp; sourceTree = ""; }; + 14FA1FB91ED6CEC500E12981 /* heart.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = heart.png; path = Resources/heart.png; sourceTree = ""; }; + 14FB25AD1EC9C62100E53C35 /* Game.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Game.h; sourceTree = ""; }; + 14FB25AE1EC9C62E00E53C35 /* Game.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Game.cpp; sourceTree = ""; }; + 14FB25B01EC9CA6800E53C35 /* Player.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Player.h; sourceTree = ""; }; + 14FB25B11EC9CA7E00E53C35 /* Player.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Player.cpp; sourceTree = ""; }; + 14FB25B31EC9D2B200E53C35 /* Enemy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Enemy.h; sourceTree = ""; }; + 14FB25B41EC9D2BC00E53C35 /* Enemy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Enemy.cpp; sourceTree = ""; }; + 14FB25B61EC9D35300E53C35 /* Sprite.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Sprite.h; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 142924D21EC41059000BCA4B /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 142924EF1EC41184000BCA4B /* libsfml-audio.2.4.2.dylib in Frameworks */, + 142924F01EC41184000BCA4B /* libsfml-audio.2.4.2.dylib in Frameworks */, + 142924F11EC41184000BCA4B /* libsfml-audio.2.4.2.dylib in Frameworks */, + 142924F21EC41184000BCA4B /* libsfml-graphics.2.4.2.dylib in Frameworks */, + 142924F31EC41184000BCA4B /* libsfml-graphics.2.4.2.dylib in Frameworks */, + 142924F41EC41184000BCA4B /* libsfml-graphics.2.4.2.dylib in Frameworks */, + 142924F51EC41184000BCA4B /* libsfml-network.2.4.2.dylib in Frameworks */, + 142924F61EC41184000BCA4B /* libsfml-network.2.4.2.dylib in Frameworks */, + 142924F71EC41184000BCA4B /* libsfml-network.2.4.2.dylib in Frameworks */, + 142924F81EC41184000BCA4B /* libsfml-system.2.4.2.dylib in Frameworks */, + 142924F91EC41184000BCA4B /* libsfml-system.2.4.2.dylib in Frameworks */, + 142924FA1EC41184000BCA4B /* libsfml-system.2.4.2.dylib in Frameworks */, + 142924FB1EC41184000BCA4B /* libsfml-window.2.4.2.dylib in Frameworks */, + 142924FC1EC41184000BCA4B /* libsfml-window.2.4.2.dylib in Frameworks */, + 142924FD1EC41184000BCA4B /* libsfml-window.2.4.2.dylib in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 142924CC1EC41059000BCA4B = { + isa = PBXGroup; + children = ( + 142924FF1EC412B6000BCA4B /* Resources */, + 142924D71EC41059000BCA4B /* Fighters */, + 142924D61EC41059000BCA4B /* Products */, + 142924DF1EC41184000BCA4B /* Frameworks */, + ); + sourceTree = ""; + }; + 142924D61EC41059000BCA4B /* Products */ = { + isa = PBXGroup; + children = ( + 142924D51EC41059000BCA4B /* Fighters */, + ); + name = Products; + sourceTree = ""; + }; + 142924D71EC41059000BCA4B /* Fighters */ = { + isa = PBXGroup; + children = ( + 142924D81EC41059000BCA4B /* main.cpp */, + 14FB25AD1EC9C62100E53C35 /* Game.h */, + 14FB25AE1EC9C62E00E53C35 /* Game.cpp */, + 14E745A51EF20BD6005BDC7B /* GameMenu.h */, + 14E745A61EF20BE2005BDC7B /* GameMenu.cpp */, + 1497201A1EEEBEFD00CF0321 /* Menu.h */, + 1497201B1EEEBF0800CF0321 /* Menu.cpp */, + 14E9EEF11EF65DA200610949 /* Reward.h */, + 149720211EEEDAAB00CF0321 /* Reward.cpp */, + 14FB25B61EC9D35300E53C35 /* Sprite.h */, + 14FB25B01EC9CA6800E53C35 /* Player.h */, + 14FB25B11EC9CA7E00E53C35 /* Player.cpp */, + 149720151EEEAC0100CF0321 /* Background.h */, + 149720161EEEAC0E00CF0321 /* Background.cpp */, + 14D3B1A81EE63DDA00ED2639 /* Boss.h */, + 14D3B1A91EE63DE500ED2639 /* Boss.cpp */, + 14FB25B31EC9D2B200E53C35 /* Enemy.h */, + 14FB25B41EC9D2BC00E53C35 /* Enemy.cpp */, + 14F5EEEC1ECBD47F003D4EB6 /* Enemys.h */, + 14F5EEED1ECBD48C003D4EB6 /* Enemys.cpp */, + 14F563DB1ECA85D9002BB1E0 /* Shot.h */, + 14F563DC1ECA85E9002BB1E0 /* Shot.cpp */, + 14B6B2E71ED3C2C5000ED50B /* Score.h */, + 14B6B2E81ED3C2D2000ED50B /* Score.cpp */, + 14FA1FB41ED689EE00E12981 /* Heart.h */, + 14FA1FB51ED68AD000E12981 /* Heart.cpp */, + ); + path = Fighters; + sourceTree = ""; + }; + 142924DF1EC41184000BCA4B /* Frameworks */ = { + isa = PBXGroup; + children = ( + 142924E01EC41184000BCA4B /* libsfml-audio.2.4.2.dylib */, + 142924E11EC41184000BCA4B /* libsfml-audio.2.4.2.dylib */, + 142924E21EC41184000BCA4B /* libsfml-audio.2.4.2.dylib */, + 142924E31EC41184000BCA4B /* libsfml-graphics.2.4.2.dylib */, + 142924E41EC41184000BCA4B /* libsfml-graphics.2.4.2.dylib */, + 142924E51EC41184000BCA4B /* libsfml-graphics.2.4.2.dylib */, + 142924E61EC41184000BCA4B /* libsfml-network.2.4.2.dylib */, + 142924E71EC41184000BCA4B /* libsfml-network.2.4.2.dylib */, + 142924E81EC41184000BCA4B /* libsfml-network.2.4.2.dylib */, + 142924E91EC41184000BCA4B /* libsfml-system.2.4.2.dylib */, + 142924EA1EC41184000BCA4B /* libsfml-system.2.4.2.dylib */, + 142924EB1EC41184000BCA4B /* libsfml-system.2.4.2.dylib */, + 142924EC1EC41184000BCA4B /* libsfml-window.2.4.2.dylib */, + 142924ED1EC41184000BCA4B /* libsfml-window.2.4.2.dylib */, + 142924EE1EC41184000BCA4B /* libsfml-window.2.4.2.dylib */, + ); + name = Frameworks; + sourceTree = ""; + }; + 142924FF1EC412B6000BCA4B /* Resources */ = { + isa = PBXGroup; + children = ( + 149720181EEEAD4800CF0321 /* background.png */, + 149720191EEEB5AC00CF0321 /* background_long.png */, + 14D3B1A01EE63DC100ED2639 /* boss_down1.png */, + 14D3B1A11EE63DC100ED2639 /* boss_down2.png */, + 14D3B1A21EE63DC100ED2639 /* boss_down3.png */, + 14D3B1A31EE63DC100ED2639 /* boss_down4.png */, + 14D3B1A41EE63DC100ED2639 /* boss_down5.png */, + 14D3B1A51EE63DC100ED2639 /* boss_down6.png */, + 14D3B1A61EE63DC100ED2639 /* boss_hit.png */, + 14D3B1A71EE63DC100ED2639 /* boss.png */, + 14F8DCD91EDFBCFC006F3CF2 /* game_over.wav */, + 14F8DCD31EDFB730006F3CF2 /* game_music.wav */, + 14F8DCD81EDFBC8F006F3CF2 /* player_down.wav */, + 14F8DCD41EDFB8B6006F3CF2 /* enemy0_down.wav */, + 14F8DCD61EDFBB95006F3CF2 /* bullet.wav */, + 14FA1FB91ED6CEC500E12981 /* heart.png */, + 14B6B2E21ED3BEC9000ED50B /* bullet.png */, + 14FA1FAD1ED67A3800E12981 /* bulletEnemy.png */, + 14FA1FAE1ED67ACB00E12981 /* bullet1.png */, + 14B6B2E31ED3BEC9000ED50B /* enemy0.png */, + 14B6B2EA1ED3C749000ED50B /* enemy0_down1.png */, + 14B6B2EB1ED3C749000ED50B /* enemy0_down2.png */, + 14B6B2EC1ED3C749000ED50B /* enemy0_down3.png */, + 14B6B2ED1ED3C749000ED50B /* enemy0_down4.png */, + 14B6B2E61ED3C1F9000ED50B /* Arial Black.ttf */, + 14E745A81EF21745005BDC7B /* selector.png */, + 14B6B2E51ED3BEC9000ED50B /* plane.png */, + 14FA1FAF1ED6816400E12981 /* plane_down1.png */, + 14FA1FB01ED6816400E12981 /* plane_down2.png */, + 14FA1FB11ED6816400E12981 /* plane_down3.png */, + 14FA1FB21ED6816400E12981 /* plane_down4.png */, + 1497201D1EEEDA8800CF0321 /* reward_damage.png */, + 1497201E1EEEDA8800CF0321 /* reward_life.png */, + 1497201F1EEEDA8800CF0321 /* reward_speed.png */, + ); + name = Resources; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 142924D41EC41059000BCA4B /* Fighters */ = { + isa = PBXNativeTarget; + buildConfigurationList = 142924DC1EC41059000BCA4B /* Build configuration list for PBXNativeTarget "Fighters" */; + buildPhases = ( + 142924D11EC41059000BCA4B /* Sources */, + 142924D21EC41059000BCA4B /* Frameworks */, + 142924D31EC41059000BCA4B /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Fighters; + productName = Fighters; + productReference = 142924D51EC41059000BCA4B /* Fighters */; + productType = "com.apple.product-type.tool"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 142924CD1EC41059000BCA4B /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0820; + ORGANIZATIONNAME = "Jimmy Fan"; + TargetAttributes = { + 142924D41EC41059000BCA4B = { + CreatedOnToolsVersion = 8.2.1; + ProvisioningStyle = Automatic; + }; + }; + }; + buildConfigurationList = 142924D01EC41059000BCA4B /* Build configuration list for PBXProject "Fighters" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 142924CC1EC41059000BCA4B; + productRefGroup = 142924D61EC41059000BCA4B /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 142924D41EC41059000BCA4B /* Fighters */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 142924D11EC41059000BCA4B /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 149720221EEEDAAB00CF0321 /* Reward.cpp in Sources */, + 14D3B1AA1EE63DE500ED2639 /* Boss.cpp in Sources */, + 14E745A71EF20BE2005BDC7B /* GameMenu.cpp in Sources */, + 14FB25B51EC9D2BC00E53C35 /* Enemy.cpp in Sources */, + 142924D91EC41059000BCA4B /* main.cpp in Sources */, + 14FB25AF1EC9C62E00E53C35 /* Game.cpp in Sources */, + 14FB25B21EC9CA7E00E53C35 /* Player.cpp in Sources */, + 1497201C1EEEBF0800CF0321 /* Menu.cpp in Sources */, + 14F5EEEE1ECBD48C003D4EB6 /* Enemys.cpp in Sources */, + 14F563DD1ECA85E9002BB1E0 /* Shot.cpp in Sources */, + 149720171EEEAC0E00CF0321 /* Background.cpp in Sources */, + 14FA1FB61ED68AD000E12981 /* Heart.cpp in Sources */, + 14B6B2E91ED3C2D2000ED50B /* Score.cpp in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 142924DA1EC41059000BCA4B /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = /usr/local/include; + LIBRARY_SEARCH_PATHS = /usr/local/lib; + MACOSX_DEPLOYMENT_TARGET = 10.12; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + }; + name = Debug; + }; + 142924DB1EC41059000BCA4B /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = /usr/local/include; + LIBRARY_SEARCH_PATHS = /usr/local/lib; + MACOSX_DEPLOYMENT_TARGET = 10.12; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = macosx; + }; + name = Release; + }; + 142924DD1EC41059000BCA4B /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + HEADER_SEARCH_PATHS = /usr/local/include; + LIBRARY_SEARCH_PATHS = /usr/local/lib; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 142924DE1EC41059000BCA4B /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + HEADER_SEARCH_PATHS = /usr/local/include; + LIBRARY_SEARCH_PATHS = /usr/local/lib; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 142924D01EC41059000BCA4B /* Build configuration list for PBXProject "Fighters" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 142924DA1EC41059000BCA4B /* Debug */, + 142924DB1EC41059000BCA4B /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 142924DC1EC41059000BCA4B /* Build configuration list for PBXNativeTarget "Fighters" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 142924DD1EC41059000BCA4B /* Debug */, + 142924DE1EC41059000BCA4B /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 142924CD1EC41059000BCA4B /* Project object */; +} diff --git a/practices/cpp/level1/p11_Fighters/Fighters.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/practices/cpp/level1/p11_Fighters/Fighters.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..e22b781a --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/practices/cpp/level1/p11_Fighters/Fighters.xcodeproj/project.xcworkspace/xcuserdata/fjm.xcuserdatad/UserInterfaceState.xcuserstate b/practices/cpp/level1/p11_Fighters/Fighters.xcodeproj/project.xcworkspace/xcuserdata/fjm.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 00000000..d4864b87 Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Fighters.xcodeproj/project.xcworkspace/xcuserdata/fjm.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/practices/cpp/level1/p11_Fighters/Fighters.xcodeproj/xcuserdata/fjm.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/practices/cpp/level1/p11_Fighters/Fighters.xcodeproj/xcuserdata/fjm.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 00000000..53cdecad --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters.xcodeproj/xcuserdata/fjm.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,39 @@ + + + + + + + + + + + + + diff --git a/practices/cpp/level1/p11_Fighters/Fighters.xcodeproj/xcuserdata/fjm.xcuserdatad/xcschemes/Fighters.xcscheme b/practices/cpp/level1/p11_Fighters/Fighters.xcodeproj/xcuserdata/fjm.xcuserdatad/xcschemes/Fighters.xcscheme new file mode 100644 index 00000000..83d95282 --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters.xcodeproj/xcuserdata/fjm.xcuserdatad/xcschemes/Fighters.xcscheme @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/practices/cpp/level1/p11_Fighters/Fighters.xcodeproj/xcuserdata/fjm.xcuserdatad/xcschemes/xcschememanagement.plist b/practices/cpp/level1/p11_Fighters/Fighters.xcodeproj/xcuserdata/fjm.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 00000000..ff4027cb --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters.xcodeproj/xcuserdata/fjm.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,22 @@ + + + + + SchemeUserState + + Fighters.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + 142924D41EC41059000BCA4B + + primary + + + + + diff --git a/practices/cpp/level1/p11_Fighters/Fighters/Background.cpp b/practices/cpp/level1/p11_Fighters/Fighters/Background.cpp new file mode 100644 index 00000000..968072b4 --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters/Background.cpp @@ -0,0 +1,34 @@ +// +// Background.cpp +// Fighters +// +// Created by Jimmy Fan on 2017/6/12. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include +#include "Background.h" +using namespace std; +#define EPS 1e-5 + +Background::Background() { + texture.loadFromFile("/Users/fjm/Git/Fighters/Resources/background.png"); + rect = texture.getSize(); + background[0].setTexture(texture); + background[1].setTexture(texture); + background[0].setPosition(0, 0); + background[1].setPosition(0, rect.y); + t = 1; + speed = -40; +} + +void Background::move(sf::Time time) { + background[0].move(0, speed * time.asSeconds()); + background[1].move(0, speed * time.asSeconds()); + sf::Vector2f pos = background[t].getPosition(); + if (pos.y <= 0) { + t = (t+1) & 1; + background[t].setPosition(0, rect.y + pos.y); + } +} diff --git a/practices/cpp/level1/p11_Fighters/Fighters/Background.h b/practices/cpp/level1/p11_Fighters/Fighters/Background.h new file mode 100644 index 00000000..74eae28e --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters/Background.h @@ -0,0 +1,23 @@ +// +// Background.h +// Fighters +// +// Created by Jimmy Fan on 2017/6/12. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef Background_h +#define Background_h + +#include "Sprite.h" + +class Background: public Sprite { +private: + int t; +public: + sf::Sprite background[2]; + Background(); + void move(sf::Time time); +}; + +#endif /* Background_h */ diff --git a/practices/cpp/level1/p11_Fighters/Fighters/Boss.cpp b/practices/cpp/level1/p11_Fighters/Fighters/Boss.cpp new file mode 100644 index 00000000..fa450441 --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters/Boss.cpp @@ -0,0 +1,124 @@ + +// +// Boss.cpp +// Fighters +// +// Created by Jimmy Fan on 2017/6/6. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include "Boss.h" +#include +#include +using namespace std; + +Boss::Boss() { + texture.loadFromFile("/Users/fjm/Git/Fighters/Resources/boss.png"); + rect = texture.getSize(); + Plane.setTexture(texture); + Plane.setPosition((windowWidth - rect.x)/2, 0); + speed = 150; + HP = 30; + aliveCondition = 1; + stay = 0; + bossTime = 0; + bossComing = 0; + WIN = 0; + direction = 1; + timee = 1; + for (int i = 0; i < numOfBossShots; i++) shots[i].isAlive = 0; +} + +void Boss::reStart() { + texture.loadFromFile("/Users/fjm/Git/Fighters/Resources/boss.png"); + rect = texture.getSize(); + Plane.setTexture(texture); + Plane.setPosition((windowWidth - rect.x)/2, 0); + HP = 40; + aliveCondition = 1; + stay = 0; + WIN = 0; + bossTime = 0; + bossComing = 0; + direction = 1; + timee = 1; + for (int i = 0; i < numOfBossShots; i++) shots[i].isAlive = 0; +} + +void Boss::move(sf::Time time) { + for (int i = 0; i < numOfBossShots; i++) { + if (shots[i].isAlive) { + shots[i].move(time); + } + } + if (aliveCondition && aliveCondition != 1) { + down(aliveCondition); + return; + } + if (HP < 10) { + texture.loadFromFile("/Users/fjm/Git/Fighters/Resources/boss_hit.png"); + rect = texture.getSize(); + Plane.setTexture(texture); + } + sf::Vector2f pos = Plane.getPosition(); + if (!stay) { + int yNow = pos.y + rect.y; + int dy = speed * time.asSeconds(); + if (yNow + dy > 300) { + dy = 300 - yNow; + stay = 1; + } + Plane.move(sf::Vector2f(0, dy)); + } + else { + int xNow = pos.x + rect.x; + int dx = speed * time.asSeconds() * direction; + if (xNow + dx >= windowWidth) { + dx = windowWidth - xNow; + direction = -direction; + } + else if (pos.x + dx <= 0) { + dx = -pos.x; + direction = -direction; + } + Plane.move(sf::Vector2f(dx,0)); + } +} + +void Boss::shoot(sf::Time time, Player player) { + if (time.asMilliseconds() > timeInterval * timee) { + timee ++; + for (int i = 0; i < numOfBossShots; i++) { + if (!shots[i].isAlive) { + sf::Vector2f posBoss = Plane.getPosition(); + sf::Vector2f posPlane = player.Plane.getPosition(); + int dx = (posPlane.x + player.rect.x / 2) - (posBoss.x + rect.x / 2); + int dy = (posPlane.y + player.rect.y / 2) - (posBoss.y + rect.y); + int dxy = sqrt(dx*dx + dy*dy); + shots[i].setSpeed(200); + shots[i].setDirection(sf::Vector2f((double)dx/(double)dxy, -(double)dy/(double)dxy)); + shots[i].setPicture(-1); + shots[i].isAlive = 1; + shots[i].shot.setPosition(posBoss.x + rect.x / 2, posBoss.y + rect.y); + break; + } + } + } +} + + +void Boss::down(int k) { + int t = 7; + if (k == 6*t + 15) { + bossTime = 0; + bossComing = 0; + WIN = 1; + return; + } + if (k % t == 1 && k/t < 6) { + texture.loadFromFile("/Users/fjm/Git/Fighters/Resources/boss_down" + to_string(k/t+1) + ".png"); + Plane.setTexture(texture); + rect = texture.getSize(); + } + aliveCondition = k + 1; +} diff --git a/practices/cpp/level1/p11_Fighters/Fighters/Boss.h b/practices/cpp/level1/p11_Fighters/Fighters/Boss.h new file mode 100644 index 00000000..ddaaecaa --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters/Boss.h @@ -0,0 +1,39 @@ +// +// Boss.h +// Fighters +// +// Created by Jimmy Fan on 2017/6/6. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef Boss_h +#define Boss_h + +#include "Sprite.h" +#include "Shot.h" +#include "Player.h" +#define timeInterval 1000 +#define numOfBossShots 10 + +class Boss: public Sprite { +private: + bool stay; + int direction; + int timee; +public: + bool WIN; + int HP; + bool bossTime; + bool bossComing; + int aliveCondition; + Shot shots[10]; + Boss(); + sf::Sprite Plane; + void move(sf::Time time); + void shoot(sf::Time time, Player player); + void down(int k); + void reStart(); +}; + + +#endif /* Boss_h */ diff --git a/practices/cpp/level1/p11_Fighters/Fighters/Enemy.cpp b/practices/cpp/level1/p11_Fighters/Fighters/Enemy.cpp new file mode 100644 index 00000000..a398176c --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters/Enemy.cpp @@ -0,0 +1,65 @@ +// +// Enemy.cpp +// Fighters +// +// Created by Jimmy Fan on 2017/5/15. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include +#include +#include +#include "Enemy.h" +using namespace std; +#define PI 3.1415926 + +Enemy::Enemy() { + texture.loadFromFile("/Users/fjm/Git/Fighters/Resources/enemy0.png"); + rect = texture.getSize(); + enemyPlane.setTexture(texture); + speed = 100; + aliveCondition = 0; + isShoot = 0; + key = rand() % 10; +} + +void Enemy::move(sf::Time time) { + enemyPlane.move(sf::Vector2f(0,speed * time.asSeconds())); + sf::Vector2f pos = enemyPlane.getPosition(); + if (pos.y >= windowHeight) { + aliveCondition = 0; + isShoot = 0; + } +} + +void Enemy::down(int k) { + int t = 3; + if (k == 4*t + 1) { + texture.loadFromFile("/Users/fjm/Git/Fighters/Resources/enemy0.png"); + enemyPlane.setTexture(texture); + rect = texture.getSize(); + aliveCondition = 0; + isShoot = 0; + return; + } + if (k % t == 1) { + texture.loadFromFile("/Users/fjm/Git/Fighters/Resources/enemy0_down" + to_string(k/t+1) + ".png"); + enemyPlane.setTexture(texture); + rect = texture.getSize(); + } + aliveCondition = k + 1; +} + +void Enemy::shoot(sf::Time totTime) { + if (((totTime.asMilliseconds()) % 5000) / 500 == key && !isShoot) { + isShoot = 1; + int alpha = rand() % 60 + 60; + shot.setDirection(sf::Vector2f(cos((double)alpha*PI / 180.0),-sin((double)alpha*PI /180.0))); + shot.setSpeed(200); + shot.setPicture(-1); + shot.isAlive = 1; + sf::Vector2f pos = enemyPlane.getPosition(); + shot.shot.setPosition(pos.x + rect.x / 2, pos.y + rect.y / 2); + } +} diff --git a/practices/cpp/level1/p11_Fighters/Fighters/Enemy.h b/practices/cpp/level1/p11_Fighters/Fighters/Enemy.h new file mode 100644 index 00000000..930d4596 --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters/Enemy.h @@ -0,0 +1,31 @@ +// +// Enemy.h +// Fighters +// +// Created by Jimmy Fan on 2017/5/15. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef Enemy_h +#define Enemy_h + +#include "Sprite.h" +#include "Shot.h" +#include + +class Enemy: public Sprite { +private: + bool isShoot; + int key; +public: + int HP; + sf::Sprite enemyPlane; + Enemy(); + void move(sf::Time time); + int aliveCondition; + void down(int k); + void shoot(sf::Time totTime); + Shot shot; +}; + +#endif /* Enemy_h */ diff --git a/practices/cpp/level1/p11_Fighters/Fighters/Enemys.cpp b/practices/cpp/level1/p11_Fighters/Fighters/Enemys.cpp new file mode 100644 index 00000000..0e68df54 --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters/Enemys.cpp @@ -0,0 +1,67 @@ +// +// Enemys.cpp +// Fighters +// +// Created by Jimmy Fan on 2017/5/17. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include +#include +#include "Enemys.h" +using namespace std; + +Enemys::Enemys(int numOfEnemys, int timeInterval) { + this -> numOfEnemys = numOfEnemys; + this -> timeInterval = timeInterval; + srand((unsigned)time(NULL)); + timee = 0; +} + +void Enemys::reStart() { + for (int i = 0; i < numOfEnemys; i++) { + enemys[i].aliveCondition = 0; + enemys[i].shot.isAlive = 0; + } + timee = 0; +} + +void Enemys::creatEnemy(sf::Time totTime) { + if (totTime.asMilliseconds() > timeInterval * timee) { + timee ++; + for (int i = 0; i < numOfEnemys; i++) { + if (!enemys[i].aliveCondition) { + enemys[i].aliveCondition = 1; + enemys[i].HP = 2; + int x = rand() % (windowWidth - enemys[i].rect.x); + enemys[i].enemyPlane.setPosition(x, 0); + break; + } + } + } +} + +void Enemys::move(sf::Time time) { + for (int i = 0; i < numOfEnemys; i++) { + if (enemys[i].aliveCondition == 1) { + enemys[i].move(time); + } + if (enemys[i].aliveCondition && enemys[i].aliveCondition != 1) { + enemys[i].down(enemys[i].aliveCondition); + } + } + for (int i = 0; i < numOfEnemys; i++) { + if (enemys[i].shot.isAlive) { + enemys[i].shot.move(time); + } + } +} + +void Enemys::shoot(sf::Time totTime) { + for (int i = 0; i < numOfEnemys; i++) { + if (enemys[i].aliveCondition == 1) { + enemys[i].shoot(totTime); + } + } +} diff --git a/practices/cpp/level1/p11_Fighters/Fighters/Enemys.h b/practices/cpp/level1/p11_Fighters/Fighters/Enemys.h new file mode 100644 index 00000000..879a14af --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters/Enemys.h @@ -0,0 +1,29 @@ +// +// Enemys.h +// Fighters +// +// Created by Jimmy Fan on 2017/5/17. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef Enemys_h +#define Enemys_h + +#include "Enemy.h" +#define N 20 + +class Enemys { +private: + int timeInterval; + int timee; +public: + Enemy enemys[N]; + int numOfEnemys; + Enemys(int = 10,int = 1000); + void creatEnemy(sf::Time totTime); + void move(sf::Time time); + void shoot(sf::Time totTime); + void reStart(); +}; + +#endif /* Enemys_h */ diff --git a/practices/cpp/level1/p11_Fighters/Fighters/Game.cpp b/practices/cpp/level1/p11_Fighters/Fighters/Game.cpp new file mode 100644 index 00000000..f3d92bd6 --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters/Game.cpp @@ -0,0 +1,383 @@ +// +// Game.cpp +// Fighters +// +// Created by Jimmy Fan on 2017/5/15. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include +#include "Game.h" +using namespace std; + +Game::Game() { + mWindow.create(sf::VideoMode(windowWidth,windowHeight), "Fighters"); + mWindow.setFramerateLimit(60); + gameTime = sf::Time::Zero; + bossTime = sf::Time::Zero; + font.loadFromFile("/Users/fjm/Git/Fighters/Resources/Arial Black.ttf"); + gameMusic.openFromFile("/Users/fjm/Git/Fighters/Resources/game_music.wav"); + gameOverMusic.openFromFile("/Users/fjm/Git/Fighters/Resources/game_over.wav"); + enemyDownBuffer.loadFromFile("/Users/fjm/Git/Fighters/Resources/enemy0_down.wav"); + enemyDownSound.setBuffer(enemyDownBuffer); + playerDownBuffer.loadFromFile("/Users/fjm/Git/Fighters/Resources/player_down.wav"); + playerDownSound.setBuffer(playerDownBuffer); + pause = 0; + timee = 1; + gameMenu.inMenu = 1; +} + +void Game::run() { + sf::Clock clock; + sf::Time time = sf::Time::Zero; + sf::Time Time = sf::seconds(1.f/60.f); + sf::Time dTime; + gameMusic.play(); +// boss.bossComing = 1; + while (mWindow.isOpen()) { + processEvents(); + dTime = clock.getElapsedTime(); + if (!pause && !boss.WIN && !player.GameOver && !gameMenu.inMenu) gameTime += dTime; + if (boss.bossTime) bossTime += dTime; + time += clock.restart(); + while (time > Time) { + time -= Time; + processEvents(); + update(Time); + } + render(); + } + gameOverMusic.stop(); +} + +void Game::processEvents() { + sf::Event event; + while (mWindow.pollEvent(event)) { + if (event.type == sf::Event::Closed) { + mWindow.close(); + } + if (event.type == sf::Event::KeyPressed) { + handlePlayerInput(event.key.code, 1); + } + if (event.type == sf::Event::KeyReleased) { + handlePlayerInput(event.key.code, 0); + } + } +} + +void Game::update(sf::Time time) { + background.move(time); + if (boss.WIN || player.GameOver || pause) return; + player.move(time); + if (reward.alive) reward.move(time); + if (!boss.bossComing) { + enemy.creatEnemy(gameTime); + if (gameTime.asMilliseconds() > rewardTimeInterval * timee) { + timee ++; + reward.setKind(); + } + } + enemy.shoot(gameTime); + enemy.move(time); + checkCrash(); + if (boss.bossTime) { + boss.move(time); + boss.shoot(bossTime, player); + } + else { + if (boss.bossComing) { + bool flag = 1; + for (int i = 0; i < enemy.numOfEnemys; i++) { + if (enemy.enemys[i].aliveCondition || enemy.enemys[i].shot.isAlive) { + flag = 0; + break; + } + } + if (flag) { + boss.bossTime = 1; + } + } + } +} + +void Game::render() { + mWindow.clear(); + mWindow.draw(background.background[0]); + mWindow.draw(background.background[1]); + if (gameMenu.inMenu) { + mWindow.draw(gameMenu.getTitleText()); + mWindow.draw(gameMenu.getSelector()); + mWindow.draw(gameMenu.getStartText()); + mWindow.draw(gameMenu.getRankText()); + mWindow.draw(gameMenu.getQuitText()); + mWindow.display(); + return; + } + if (pause) { + player.menu.setData(player.damage, player.speed, player.life); + mWindow.draw(player.menu.getDamageText()); + mWindow.draw(player.menu.getSpeedText()); + mWindow.draw(player.menu.getLifeText()); + mWindow.draw(player.menu.getTitleText()); + mWindow.display(); + return; + } + if (player.GameOver) { + gameMusic.stop(); + gameOverMusic.play(); + sf::Text over,toMenu; + over.setFont(font); + over.setCharacterSize(45); + over.setString("Game Over"); + over.setPosition((windowWidth - over.getLocalBounds().width)/2, (windowHeight - over.getLocalBounds().height)/2 - 50); + mWindow.draw(over); + toMenu.setFont(font); + toMenu.setString("ENTER to Menu"); + toMenu.setCharacterSize(25); + toMenu.setPosition((windowWidth - toMenu.getLocalBounds().width)/2, (windowHeight - toMenu.getLocalBounds().height)/2 + 50); + mWindow.draw(toMenu); + mWindow.display(); + return; + } + if (boss.WIN) { + sf::Text win,toMenu; + win.setFont(font); + win.setString("YOU WIN!!"); + win.setCharacterSize(45); + win.setPosition((windowWidth - win.getLocalBounds().width)/2, (windowHeight - win.getLocalBounds().height)/2 - 50); + mWindow.draw(win); + toMenu.setFont(font); + toMenu.setString("ENTER to Menu"); + toMenu.setCharacterSize(25); + toMenu.setPosition((windowWidth - toMenu.getLocalBounds().width)/2, (windowHeight - toMenu.getLocalBounds().height)/2 + 50); + mWindow.draw(toMenu); + mWindow.display(); + return; + } + mWindow.draw(score.score); + if (damageUP) { + damageUP --; + sf::Text damageUp; + damageUp.setFont(font); + damageUp.setCharacterSize(20); + damageUp.setString("damage up"); + damageUp.setFillColor(sf::Color::Black); + sf::Vector2f posPlayer = player.Plane.getPosition(); + damageUp.setPosition(posPlayer.x + player.rect.x / 2 - damageUp.getLocalBounds().width / 2, posPlayer.y - 50); + mWindow.draw(damageUp); + } + if (speedUP) { + speedUP --; + sf::Text speedUp; + speedUp.setFont(font); + speedUp.setCharacterSize(20); + speedUp.setString("speed up"); + speedUp.setFillColor(sf::Color::Black); + sf::Vector2f posPlayer = player.Plane.getPosition(); + speedUp.setPosition(posPlayer.x + player.rect.x / 2 - speedUp.getLocalBounds().width / 2, posPlayer.y - 50); + mWindow.draw(speedUp); + } + if (lifeUP) { + lifeUP --; + sf::Text lifeUp; + lifeUp.setFont(font); + lifeUp.setCharacterSize(20); + lifeUp.setString("life up"); + lifeUp.setFillColor(sf::Color::Black); + sf::Vector2f posPlayer = player.Plane.getPosition(); + lifeUp.setPosition(posPlayer.x + player.rect.x / 2 - lifeUp.getLocalBounds().width / 2, posPlayer.y - 50); + mWindow.draw(lifeUp); + } + if (player.aliveCondition) { + if ((player.inviolable && (player.inviolable/8) % 2) || !player.inviolable) mWindow.draw(player.Plane); + if (player.inviolable) player.inviolable --; + } + if (reward.alive) mWindow.draw(reward.reward); + for (int i = 0; i < numOfShots; i++) { + if (player.shots[i].isAlive) { + mWindow.draw(player.shots[i].shot); + } + } + for (int i = 0; i < enemy.numOfEnemys; i++) { + if (enemy.enemys[i].aliveCondition) { + mWindow.draw(enemy.enemys[i].enemyPlane); + } + } + for (int i = 0; i < enemy.numOfEnemys; i++) { + if (enemy.enemys[i].shot.isAlive) { + mWindow.draw(enemy.enemys[i].shot.shot); + } + } + for (int i = 1; i <= player.life; i++) { + heart.heart.setPosition(windowWidth - i * (20 + heart.getRect().x), 20); + mWindow.draw(heart.heart); + } + if (boss.bossTime) { + mWindow.draw(boss.Plane); + for (int i = 0; i < numOfBossShots; i++) { + if (boss.shots[i].isAlive) { + mWindow.draw(boss.shots[i].shot); + } + } + } + mWindow.display(); +} + +void Game::reStart() { + gameTime = sf::Time::Zero; + bossTime = sf::Time::Zero; + score.updateScore(0); + player.reStart(); + enemy.reStart(); + boss.reStart(); + gameMusic.play(); + timee = 1; + pause = 0; + gameMenu.inMenu = 1; +} + +void Game::handlePlayerInput(sf::Keyboard::Key key, bool isPressed) { + if (gameMenu.inMenu) { + if (key == sf::Keyboard::Up || key == sf::Keyboard::Down || key == sf::Keyboard::Return) { + if (isPressed) { + int k = gameMenu.setEvent(key); + if (k == 1) gameMenu.inMenu = 0; + if (k == 2) {}//输出排行榜 + if (k == 3) mWindow.close(); + } + } + return; + } + if (key == sf::Keyboard::Up || key == sf::Keyboard::Down || key == sf::Keyboard::Left || key == sf::Keyboard::Right) { + player.setMove(key,isPressed); + } + if (key == sf::Keyboard::Space) { + player.shoot(isPressed); + } + if (key == sf::Keyboard::Return) { + if (player.GameOver || boss.WIN) { + reStart(); + } + } + if (key == sf::Keyboard::Tab) { + if (isPressed) pause = !pause; + } +} + +bool Game::isCollsion(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2) { + if (x1 >= x2 && x1 >= x2 + w2) return 0; + if (x1 <= x2 && x1 + w1 <= x2) return 0; + if (y1 >= y2 && y1 >= y2 + h2) return 0; + if (y1 <= y2 && y1 + h1 <= y2) return 0; + return 1; +} + +void Game::checkCrash() { + for (int i = 0; i < enemy.numOfEnemys; i++) { + if (enemy.enemys[i].aliveCondition != 1) continue; + for (int j = 0; j < numOfShots; j++) { + if (!player.shots[j].isAlive) continue; + sf::Vector2f posEnemy = enemy.enemys[i].enemyPlane.getPosition(); + sf::Vector2f posShot = player.shots[j].shot.getPosition(); + if (isCollsion(posEnemy.x, posEnemy.y, enemy.enemys[i].rect.x, enemy.enemys[i].rect.y, posShot.x, posShot.y, player.shots[j].rect.x, player.shots[j].rect.y)) { + enemy.enemys[i].HP -= player.damage; + if (enemy.enemys[i].HP <= 0) { + enemy.enemys[i].down(1); + enemyDownSound.play(); + score.updateScore(10); + } + player.shots[j].isAlive = 0; + if (score.getScore() > scoreBossComing) { + boss.bossComing = 1; + } + break; + } + } + } + if (boss.bossTime) { + if (boss.aliveCondition == 1) { + for (int i = 0; i < numOfShots; i++) { + if (!player.shots[i].isAlive) continue; + sf::Vector2f posBoss = boss.Plane.getPosition(); + sf::Vector2f posShot = player.shots[i].shot.getPosition(); + if (isCollsion(posBoss.x, posBoss.y, boss.rect.x, boss.rect.y, posShot.x, posShot.y, player.shots[i].rect.x, player.shots[i].rect.y)) { + boss.HP -= player.damage; + if (boss.HP <= 0) { + boss.down(1); + } + player.shots[i].isAlive = 0; + break; + } + } + } + } + if (player.aliveCondition != 1) return; + if (reward.alive) { + sf::Vector2f posPlayer = player.Plane.getPosition(); + sf::Vector2f posReward = reward.reward.getPosition(); + if (isCollsion(posPlayer.x, posPlayer.y, player.rect.x, player.rect.y, posReward.x, posReward.y, reward.rect.x, reward.rect.y)) { + reward.alive = 0; + if (reward.getKind() == 0) { + player.damage ++; + damageUP = 10; + } + if (reward.getKind() == 1) { + player.life ++; + lifeUP = 10; + } + if (reward.getKind() == 2) { + player.speed += 50; + speedUP = 10; + } + } + } + if (player.inviolable) return; + if (player.aliveCondition != 1) return; + for (int i = 0; i < enemy.numOfEnemys; i++) { + if (enemy.enemys[i].aliveCondition != 1) continue; + sf::Vector2f posPlayer = player.Plane.getPosition(); + sf::Vector2f posEnemy = enemy.enemys[i].enemyPlane.getPosition(); + if (isCollsion(posPlayer.x, posPlayer.y, player.rect.x, player.rect.y, posEnemy.x, posEnemy.y, enemy.enemys[i].rect.x, enemy.enemys[i].rect.y)) { + enemy.enemys[i].down(1); + playerDownSound.play(); + player.down(1); + break; + } + } + if (player.aliveCondition != 1) return; + for (int i = 0; i < enemy.numOfEnemys; i++) { + if (enemy.enemys[i].shot.isAlive) { + sf::Vector2f posPlayer = player.Plane.getPosition(); + sf::Vector2f posShot = enemy.enemys[i].shot.shot.getPosition(); + if (isCollsion(posPlayer.x, posPlayer.y, player.rect.x, player.rect.y, posShot.x, posShot.y, enemy.enemys[i].shot.rect.x, enemy.enemys[i].shot.rect.y)) { + enemy.enemys[i].shot.isAlive = 0; + playerDownSound.play(); + player.down(1); + break; + } + } + } + if (player.aliveCondition != 1) return; + for (int i = 0; i < numOfBossShots; i++) { + if (boss.shots[i].isAlive) { + sf::Vector2f posPlayer = player.Plane.getPosition(); + sf::Vector2f posShot = boss.shots[i].shot.getPosition(); + if (isCollsion(posPlayer.x, posPlayer.y, player.rect.x, player.rect.y, posShot.x, posShot.y, boss.shots[i].rect.x, boss.shots[i].rect.y)) { + boss.shots[i].isAlive = 0; + playerDownSound.play(); + player.down(1); + break; + } + } + } + if (player.aliveCondition != 1) return; + if (boss.bossTime) { + sf::Vector2f posBoss = boss.Plane.getPosition(); + sf::Vector2f posPlayer = player.Plane.getPosition(); + if (isCollsion(posPlayer.x, posPlayer.y, player.rect.x, player.rect.y, posBoss.x, posBoss.y, boss.rect.x, boss.rect.y)) { + playerDownSound.play(); + player.down(1); + } + } +} diff --git a/practices/cpp/level1/p11_Fighters/Fighters/Game.h b/practices/cpp/level1/p11_Fighters/Fighters/Game.h new file mode 100644 index 00000000..596c4e8f --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters/Game.h @@ -0,0 +1,61 @@ +// +// Game.h +// Fighters +// +// Created by Jimmy Fan on 2017/5/15. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef Game_h +#define Game_h + +#include +#include +#include "Player.h" +#include "Enemys.h" +#include "Score.h" +#include "Heart.h" +#include "Boss.h" +#include "Reward.h" +#include "Background.h" +#include "GameMenu.h" +#define rewardTimeInterval 8000 +#define scoreBossComing 200 + +class Game { +private: + sf::Music gameMusic; + sf::Music gameOverMusic; + sf::SoundBuffer enemyDownBuffer; + sf::Sound enemyDownSound; + sf::SoundBuffer playerDownBuffer; + sf::Sound playerDownSound; + sf::Font font; + sf::RenderWindow mWindow; + sf::Time gameTime; + sf::Time bossTime; + Score score; + Player player; + Enemys enemy; + Heart heart; + Boss boss; + Background background; + Reward reward; + GameMenu gameMenu; + int damageUP, speedUP, lifeUP; + int timee; + bool pause; + void processEvents(); + void update(sf::Time time); + void render(); + void handlePlayerInput(sf::Keyboard::Key key, bool isPressed); + void checkCrash(); + void reStart(); + bool isCollsion(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2); +public: + Game(); + void run(); +}; + + +#endif /* Game_h */ diff --git a/practices/cpp/level1/p11_Fighters/Fighters/GameMenu.cpp b/practices/cpp/level1/p11_Fighters/Fighters/GameMenu.cpp new file mode 100644 index 00000000..99145b8e --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters/GameMenu.cpp @@ -0,0 +1,76 @@ +// +// GameMenu.cpp +// Fighters +// +// Created by Jimmy Fan on 2017/6/15. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include "GameMenu.h" +using namespace std; + +GameMenu::GameMenu() { + font.loadFromFile("/Users/fjm/Git/Fighters/Resources/Arial Black.ttf"); + title.setFont(font); + title.setStyle(sf::Text::Bold); + title.setString("Fighters"); + title.setCharacterSize(80); + sf::FloatRect rect = title.getLocalBounds(); + title.setPosition((windowWidth - rect.width)/2, 50); + + start.setFont(font); + start.setString("Start Game"); + start.setCharacterSize(35); + rect = start.getLocalBounds(); + start.setPosition((windowWidth - rect.width)/2, 200); + + rank.setFont(font); + rank.setString("Rank"); + rank.setCharacterSize(35); + rect = rank.getLocalBounds(); + rank.setPosition((windowWidth - rect.width)/2, 300); + + quit.setFont(font); + quit.setString("Quit Game"); + quit.setCharacterSize(35); + rect = quit.getLocalBounds(); + quit.setPosition((windowWidth - rect.width)/2, 400); + + texture.loadFromFile("/Users/fjm/Git/Fighters/Resources/selector.png"); + selector.setTexture(texture); +} + +int GameMenu::setEvent(sf::Keyboard::Key key) { + if (key == sf::Keyboard::Up) { + index = index==1?1:index-1; + } + if (key == sf::Keyboard::Down) { + index = index==3?3:index+1; + } + if (key == sf::Keyboard::Return) { + return index; + } + return 0; +} + +sf::Text GameMenu::getTitleText() { + return title; +} + +sf::Text GameMenu::getStartText() { + return start; +} + +sf::Text GameMenu::getRankText() { + return rank; +} + +sf::Text GameMenu::getQuitText() { + return quit; +} + +sf::Sprite GameMenu::getSelector() { + selector.setPosition(60, (index+1) * 100 + 5); + return selector; +} diff --git a/practices/cpp/level1/p11_Fighters/Fighters/GameMenu.h b/practices/cpp/level1/p11_Fighters/Fighters/GameMenu.h new file mode 100644 index 00000000..7f0ae867 --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters/GameMenu.h @@ -0,0 +1,37 @@ +// +// GameMenu.h +// Fighters +// +// Created by Jimmy Fan on 2017/6/15. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef GameMenu_h +#define GameMenu_h + +#include +#define windowWidth 480 + +class GameMenu { +private: + sf::Font font; + sf::Text title; + sf::Text start; + sf::Text rank; + sf::Text quit; + sf::Sprite selector; + sf::Texture texture; + int index = 1; +public: + bool inMenu; + GameMenu(); + int setEvent(sf::Keyboard::Key key); + sf::Text getTitleText(); + sf::Text getStartText(); + sf::Text getRankText(); + sf::Text getQuitText(); + sf::Sprite getSelector(); +}; + + +#endif /* GameMenu_h */ diff --git a/practices/cpp/level1/p11_Fighters/Fighters/Heart.cpp b/practices/cpp/level1/p11_Fighters/Fighters/Heart.cpp new file mode 100644 index 00000000..7206f941 --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters/Heart.cpp @@ -0,0 +1,22 @@ +// +// Heart.cpp +// Fighters +// +// Created by Jimmy Fan on 2017/5/25. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include "Heart.h" +using namespace std; + +Heart::Heart() { + texture.loadFromFile("/Users/fjm/Git/Fighters/Resources/heart.png"); + rect = texture.getSize(); + heart.setTexture(texture); +} + +sf::Vector2u Heart::getRect() { + return rect; +} + diff --git a/practices/cpp/level1/p11_Fighters/Fighters/Heart.h b/practices/cpp/level1/p11_Fighters/Fighters/Heart.h new file mode 100644 index 00000000..c86da8ff --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters/Heart.h @@ -0,0 +1,25 @@ +// +// Heart.h +// Fighters +// +// Created by Jimmy Fan on 2017/5/25. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef Heart_h +#define Heart_h + +#include + +class Heart { +private: + sf::Texture texture; + sf::Vector2u rect; +public: + sf::Sprite heart; + Heart(); + sf::Vector2u getRect(); +}; + + +#endif /* Heart_h */ diff --git a/practices/cpp/level1/p11_Fighters/Fighters/Menu.cpp b/practices/cpp/level1/p11_Fighters/Fighters/Menu.cpp new file mode 100644 index 00000000..542373d1 --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters/Menu.cpp @@ -0,0 +1,48 @@ +// +// Menu.cpp +// Fighters +// +// Created by Jimmy Fan on 2017/6/12. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include "Menu.h" +#include +using namespace std; + +Menu::Menu() { + font.loadFromFile("/Users/fjm/Git/Fighters/Resources/Arial Black.ttf"); + Damage.setFont(font); + Speed.setFont(font); + Life.setFont(font); + Title.setFont(font); + Title.setString("Ability"); + Title.setCharacterSize(40); + Title.setPosition((windowWidth - Title.getLocalBounds().width) / 2, 50); + Damage.setPosition(120, 150); + Speed.setPosition(120, 220); + Life.setPosition(120, 290); + +} + +void Menu::setData(int damage, int speed, int life) { + Damage.setString("Damamge: " + to_string(damage)); + Speed.setString( "Speed: " + to_string(speed/50)); + Life.setString( "Life: " + to_string(life)); +} + +sf::Text Menu::getDamageText() { + return Damage; +} + +sf::Text Menu::getSpeedText() { + return Speed; +} + +sf::Text Menu::getLifeText() { + return Life; +} + +sf::Text Menu::getTitleText() { + return Title; +} diff --git a/practices/cpp/level1/p11_Fighters/Fighters/Menu.h b/practices/cpp/level1/p11_Fighters/Fighters/Menu.h new file mode 100644 index 00000000..a2e3821f --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters/Menu.h @@ -0,0 +1,31 @@ +// +// Menu.h +// Fighters +// +// Created by Jimmy Fan on 2017/6/12. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef Menu_h +#define Menu_h + +#include +#define windowWidth 480 + +class Menu { +private: + sf::Font font; + sf::Text Damage; + sf::Text Speed; + sf::Text Life; + sf::Text Title; +public: + Menu(); + void setData(int damage, int speed, int life); + sf::Text getDamageText(); + sf::Text getSpeedText(); + sf::Text getLifeText(); + sf::Text getTitleText(); +}; + +#endif /* Menu_h */ diff --git a/practices/cpp/level1/p11_Fighters/Fighters/Player.cpp b/practices/cpp/level1/p11_Fighters/Fighters/Player.cpp new file mode 100644 index 00000000..f54879ec --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters/Player.cpp @@ -0,0 +1,140 @@ +// +// Player.cpp +// Fighters +// +// Created by Jimmy Fan on 2017/5/15. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include "Player.h" +using namespace std; + +Player::Player() { + texture.loadFromFile("/Users/fjm/Git/Fighters/Resources/plane.png"); + rect = texture.getSize(); + Plane.setTexture(texture); + Plane.setPosition((windowWidth - rect.x)/2, windowHeight - rect.y - 10); + speed = 200; + damage = 1; + aliveCondition = 1; + moveUp = 0; + moveRight = 0; + moveLeft = 0; + moveDown = 0; + life = 3; + GameOver = 0; + shotBuffer.loadFromFile("/Users/fjm/Git/Fighters/Resources/bullet.wav"); + shotSound.setBuffer(shotBuffer); + for (int i = 0; i < numOfShots; i++) shots[i].setSpeed(150); + inviolable = 0; +} + +void Player::reStart() { + Plane.setPosition((windowWidth - rect.x)/2, windowHeight - rect.y - 10); + aliveCondition = 1; + moveUp = 0; + moveRight = 0; + moveLeft = 0; + moveDown = 0; + life = 3; + speed = 200; + damage = 1; + GameOver = 0; + for (int i = 0; i < numOfShots; i++) shots[i].isAlive = 0; + inviolable = 0; +} + +void Player::setMove(sf::Keyboard::Key key, bool isPressed) { + if (key == sf::Keyboard::Up) { + moveUp = isPressed; + } + if (key == sf::Keyboard::Down) { + moveDown = isPressed; + } + if (key == sf::Keyboard::Left) { + moveLeft = isPressed; + } + if (key == sf::Keyboard::Right) { + moveRight = isPressed; + } +} + +void Player::move(sf::Time time) { + for (int i = 0; i < numOfShots; i++) { + if (shots[i].isAlive) { + shots[i].move(time); + } + } + if (!aliveCondition) { + life --; + if (life) { + Plane.setPosition((windowWidth - rect.x)/2, windowHeight - rect.y - 10); + aliveCondition = 1; + inviolable = 120; + return; + } + else { + GameOver = 1; + return; + } + } + if (aliveCondition != 1) { + down(aliveCondition); + return; + } + sf::Vector2f movement(0,0); + sf::Vector2f pos = Plane.getPosition(); + if (!(moveUp && moveDown)) { + if (moveUp && pos.y >= 0) { + movement.y -= speed; + } + if (moveDown && pos.y <= windowHeight - rect.y) { + movement.y += speed; + } + } + if (!(moveLeft && moveRight)) { + if (moveLeft && pos.x >= 0) { + movement.x -= speed; + } + if (moveRight && pos.x <= windowWidth - rect.x) { + movement.x += speed; + } + } + Plane.move(movement * time.asSeconds()); +} + +void Player::shoot(bool isPressed) { + if (!isPressed) return; + shotSound.play(); + if (aliveCondition != 1) return; + sf::Vector2f pos = Plane.getPosition(); + for (int i = 0; i < numOfShots; i++) { + if (!shots[i].isAlive) { + shots[i].isAlive = 1; + shots[i].setPicture(1); + shots[i].shot.setPosition(pos.x + rect.x / 2 - shots[i].rect.x / 2, pos.y - 50); + break; + } + } +} + + +void Player::down(int k) { + int t = 3; + if (k == 4*t + 1) { + texture.loadFromFile("/Users/fjm/Git/Fighters/Resources/plane.png"); + Plane.setTexture(texture); + rect = texture.getSize(); + aliveCondition = 0; + return; + } + if (k % t == 1) { + texture.loadFromFile("/Users/fjm/Git/Fighters/Resources/plane_down" + to_string(k/t+1) + ".png"); + Plane.setTexture(texture); + rect = texture.getSize(); + } + aliveCondition = k + 1; +} + + diff --git a/practices/cpp/level1/p11_Fighters/Fighters/Player.h b/practices/cpp/level1/p11_Fighters/Fighters/Player.h new file mode 100644 index 00000000..f182b891 --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters/Player.h @@ -0,0 +1,41 @@ +// +// Player.h +// Fighters +// +// Created by Jimmy Fan on 2017/5/15. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef Player_h +#define Player_h + +#include "Sprite.h" +#include "Shot.h" +#include +#include "Menu.h" +#define numOfShots 20 + +class Player: public Sprite { +private: + bool moveUp,moveDown,moveLeft,moveRight; + sf::SoundBuffer shotBuffer; + sf::Sound shotSound; +public: + int damage; + int life; + sf::Sprite Plane; + int aliveCondition; + Shot shots[numOfShots]; + Player(); + Menu menu; + int inviolable; + bool GameOver; + void setMove(sf::Keyboard::Key key, bool isPressed); + void move(sf::Time time); + void shoot(bool isPressed); + void down(int k); + void reStart(); +}; + + +#endif /* Player_h */ diff --git a/practices/cpp/level1/p11_Fighters/Fighters/Reward.cpp b/practices/cpp/level1/p11_Fighters/Fighters/Reward.cpp new file mode 100644 index 00000000..0d1d1b58 --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters/Reward.cpp @@ -0,0 +1,41 @@ +// +// Reward.cpp +// Fighters +// +// Created by Jimmy Fan on 2017/6/12. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include +#include "Reward.h" +using namespace std; + +Reward::Reward() { + speed = 200; + alive = 0; +} + +void Reward::move(sf::Time time) { + reward.move(0, speed * time.asSeconds()); + sf::Vector2f pos = reward.getPosition(); + if (pos.y >= windowHeight) { + alive = 0; + } +} + +void Reward::setKind() { + kind = rand() % 3; + if (kind == 0) texture.loadFromFile("/Users/fjm/Git/Fighters/Resources/reward_damage.png"); + if (kind == 1) texture.loadFromFile("/Users/fjm/Git/Fighters/Resources/reward_life.png"); + if (kind == 2) texture.loadFromFile("/Users/fjm/Git/Fighters/Resources/reward_speed.png"); + rect = texture.getSize(); + reward.setTexture(texture); + int x = rand() % (windowWidth - rect.x); + reward.setPosition(x, 0); + alive = 1; +} + +int Reward::getKind() { + return kind; +} diff --git a/practices/cpp/level1/p11_Fighters/Fighters/Reward.h b/practices/cpp/level1/p11_Fighters/Fighters/Reward.h new file mode 100644 index 00000000..f32cdb6d --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters/Reward.h @@ -0,0 +1,27 @@ +// +// Reward.h +// Fighters +// +// Created by Jimmy Fan on 2017/6/12. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef Reward_h +#define Reward_h + +#include "Sprite.h" + +class Reward: public Sprite { +private: + int kind; +public: + Reward(); + bool alive; + void move(sf::Time time); + void setKind(); + int getKind(); + sf::Sprite reward; +}; + + +#endif /* Reward_h */ diff --git a/practices/cpp/level1/p11_Fighters/Fighters/Score.cpp b/practices/cpp/level1/p11_Fighters/Fighters/Score.cpp new file mode 100644 index 00000000..7dd05a84 --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters/Score.cpp @@ -0,0 +1,32 @@ +// +// Score.cpp +// Fighters +// +// Created by Jimmy Fan on 2017/5/23. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include +#include "Score.h" +using namespace std; + +Score::Score() { + scoreNow = 0; + font.loadFromFile("/Users/fjm/Git/Fighters/Resources/Arial Black.ttf"); + score.setFont(font); + score.setCharacterSize(30); + score.setFillColor(sf::Color::White); + score.setPosition(20, 20); + score.setString("Score: " + to_string(scoreNow)); + score.setStyle(sf::Text::Bold); +} + +void Score::updateScore(int x) { + if (x == 0) scoreNow = 0; + else scoreNow += x; + score.setString("Score: " + to_string(scoreNow)); +} + +int Score::getScore() { + return scoreNow; +} diff --git a/practices/cpp/level1/p11_Fighters/Fighters/Score.h b/practices/cpp/level1/p11_Fighters/Fighters/Score.h new file mode 100644 index 00000000..5db8352a --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters/Score.h @@ -0,0 +1,26 @@ +// +// Score.h +// Fighters +// +// Created by Jimmy Fan on 2017/5/23. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef Score_h +#define Score_h + +#include + +class Score { +private: + sf::Font font; + int scoreNow; +public: + sf::Text score; + Score(); + void updateScore(int x); + int getScore(); +}; + + +#endif /* Score_h */ diff --git a/practices/cpp/level1/p11_Fighters/Fighters/Shot.cpp b/practices/cpp/level1/p11_Fighters/Fighters/Shot.cpp new file mode 100644 index 00000000..da815fe6 --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters/Shot.cpp @@ -0,0 +1,42 @@ +// +// Shot.cpp +// Fighters +// +// Created by Jimmy Fan on 2017/5/16. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include "Shot.h" + +Shot::Shot(sf::Vector2f direction) { + this -> direction = direction; + speed = 100; + isAlive = 0; +} + +void Shot::move(sf::Time time) { + sf::Vector2f pos = shot.getPosition(); + if (pos.y < 0 || pos.y > windowHeight || pos.x < 0 || pos.x > windowWidth) isAlive = 0; + else shot.move(sf::Vector2f(direction.x * speed * time.asSeconds(), -direction.y * speed * time.asSeconds())); +} + +void Shot::setDirection(sf::Vector2f direction) { + this -> direction = direction; +} + +void Shot::setSpeed(int speed) { + this -> speed = speed; +} + +void Shot::setPicture(int k) { + if (k == 1) { + texture.loadFromFile("/Users/fjm/Git/Fighters/Resources/bullet.png"); + rect = texture.getSize(); + shot.setTexture(texture); + } + if (k == -1) { + texture.loadFromFile("/Users/fjm/Git/Fighters/Resources/bullet1.png"); + rect = texture.getSize(); + shot.setTexture(texture); + } +} diff --git a/practices/cpp/level1/p11_Fighters/Fighters/Shot.h b/practices/cpp/level1/p11_Fighters/Fighters/Shot.h new file mode 100644 index 00000000..d7dbe47a --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters/Shot.h @@ -0,0 +1,27 @@ +// +// Shot.h +// Fighters +// +// Created by Jimmy Fan on 2017/5/16. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef Shot_h +#define Shot_h + +#include "Sprite.h" + +class Shot: public Sprite { +private: + sf::Vector2f direction; +public: + sf::Sprite shot; + Shot(sf::Vector2f = sf::Vector2f(0.0,1.0)); + void move(sf::Time time); + bool isAlive; + void setDirection(sf::Vector2f direction); + void setSpeed(int speed); + void setPicture(int k); +}; + +#endif /* Shot_h */ diff --git a/practices/cpp/level1/p11_Fighters/Fighters/Sprite.h b/practices/cpp/level1/p11_Fighters/Fighters/Sprite.h new file mode 100644 index 00000000..9927059e --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters/Sprite.h @@ -0,0 +1,25 @@ +// +// Sprite.h +// Fighters +// +// Created by Jimmy Fan on 2017/5/15. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#ifndef Sprite_h +#define Sprite_h + + +#include +#define windowWidth 480 +#define windowHeight 600 + +class Sprite { +public: + sf::Vector2u rect; + sf::Texture texture; + virtual void move(sf::Time time) = 0; + int speed; +}; + +#endif /* Sprite_h */ diff --git a/practices/cpp/level1/p11_Fighters/Fighters/main.cpp b/practices/cpp/level1/p11_Fighters/Fighters/main.cpp new file mode 100644 index 00000000..3e04e1b0 --- /dev/null +++ b/practices/cpp/level1/p11_Fighters/Fighters/main.cpp @@ -0,0 +1,15 @@ +// +// main.cpp +// Fighters +// +// Created by Jimmy Fan on 2017/5/11. +// Copyright © 2017年 Jimmy Fan. All rights reserved. +// + +#include "Game.h" + +int main() { + Game game; + game.run(); + return 0; +} diff --git a/practices/cpp/level1/p11_Fighters/README.md b/practices/cpp/level1/p11_Fighters/README.md old mode 100755 new mode 100644 index 58761a68..98fd7e5d --- a/practices/cpp/level1/p11_Fighters/README.md +++ b/practices/cpp/level1/p11_Fighters/README.md @@ -1,5 +1,2 @@ -### 题目:打飞机小游戏 - -### 功能要求: - -随心所欲!!! \ No newline at end of file +# Fighters +My Fighters Game diff --git a/practices/cpp/level1/p11_Fighters/Resources/Arial Black.ttf b/practices/cpp/level1/p11_Fighters/Resources/Arial Black.ttf new file mode 100644 index 00000000..88772774 Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/Arial Black.ttf differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/background.png b/practices/cpp/level1/p11_Fighters/Resources/background.png new file mode 100755 index 00000000..08a1831d Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/background.png differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/background_long.png b/practices/cpp/level1/p11_Fighters/Resources/background_long.png new file mode 100644 index 00000000..3383e784 Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/background_long.png differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/boss.png b/practices/cpp/level1/p11_Fighters/Resources/boss.png new file mode 100755 index 00000000..b842d562 Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/boss.png differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/boss_down1.png b/practices/cpp/level1/p11_Fighters/Resources/boss_down1.png new file mode 100755 index 00000000..bfe9ae03 Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/boss_down1.png differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/boss_down2.png b/practices/cpp/level1/p11_Fighters/Resources/boss_down2.png new file mode 100755 index 00000000..27178481 Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/boss_down2.png differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/boss_down3.png b/practices/cpp/level1/p11_Fighters/Resources/boss_down3.png new file mode 100755 index 00000000..bb0e8679 Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/boss_down3.png differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/boss_down4.png b/practices/cpp/level1/p11_Fighters/Resources/boss_down4.png new file mode 100755 index 00000000..663ef9fa Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/boss_down4.png differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/boss_down5.png b/practices/cpp/level1/p11_Fighters/Resources/boss_down5.png new file mode 100755 index 00000000..15ed0bea Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/boss_down5.png differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/boss_down6.png b/practices/cpp/level1/p11_Fighters/Resources/boss_down6.png new file mode 100755 index 00000000..951d61cc Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/boss_down6.png differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/boss_hit.png b/practices/cpp/level1/p11_Fighters/Resources/boss_hit.png new file mode 100755 index 00000000..692f7771 Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/boss_hit.png differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/bullet.png b/practices/cpp/level1/p11_Fighters/Resources/bullet.png new file mode 100755 index 00000000..b7fe3296 Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/bullet.png differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/bullet.wav b/practices/cpp/level1/p11_Fighters/Resources/bullet.wav new file mode 100644 index 00000000..8c3c2906 Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/bullet.wav differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/bullet1.png b/practices/cpp/level1/p11_Fighters/Resources/bullet1.png new file mode 100755 index 00000000..a456edc7 Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/bullet1.png differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/bulletEnemy.png b/practices/cpp/level1/p11_Fighters/Resources/bulletEnemy.png new file mode 100755 index 00000000..8523378e Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/bulletEnemy.png differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/enemy0.png b/practices/cpp/level1/p11_Fighters/Resources/enemy0.png new file mode 100755 index 00000000..4188de5b Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/enemy0.png differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/enemy0_down.wav b/practices/cpp/level1/p11_Fighters/Resources/enemy0_down.wav new file mode 100644 index 00000000..620b53d9 Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/enemy0_down.wav differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/enemy0_down1.png b/practices/cpp/level1/p11_Fighters/Resources/enemy0_down1.png new file mode 100755 index 00000000..d067a0ba Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/enemy0_down1.png differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/enemy0_down2.png b/practices/cpp/level1/p11_Fighters/Resources/enemy0_down2.png new file mode 100755 index 00000000..7b9f8560 Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/enemy0_down2.png differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/enemy0_down3.png b/practices/cpp/level1/p11_Fighters/Resources/enemy0_down3.png new file mode 100755 index 00000000..1ea338e0 Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/enemy0_down3.png differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/enemy0_down4.png b/practices/cpp/level1/p11_Fighters/Resources/enemy0_down4.png new file mode 100755 index 00000000..b41e8dd5 Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/enemy0_down4.png differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/game_music.wav b/practices/cpp/level1/p11_Fighters/Resources/game_music.wav new file mode 100644 index 00000000..b1d2054f Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/game_music.wav differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/game_over.wav b/practices/cpp/level1/p11_Fighters/Resources/game_over.wav new file mode 100644 index 00000000..a52d6565 Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/game_over.wav differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/heart.png b/practices/cpp/level1/p11_Fighters/Resources/heart.png new file mode 100644 index 00000000..c38d11de Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/heart.png differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/plane.png b/practices/cpp/level1/p11_Fighters/Resources/plane.png new file mode 100644 index 00000000..4b03a780 Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/plane.png differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/plane_down1.png b/practices/cpp/level1/p11_Fighters/Resources/plane_down1.png new file mode 100755 index 00000000..bb2a98ac Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/plane_down1.png differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/plane_down2.png b/practices/cpp/level1/p11_Fighters/Resources/plane_down2.png new file mode 100755 index 00000000..e16fc028 Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/plane_down2.png differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/plane_down3.png b/practices/cpp/level1/p11_Fighters/Resources/plane_down3.png new file mode 100755 index 00000000..c84df96f Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/plane_down3.png differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/plane_down4.png b/practices/cpp/level1/p11_Fighters/Resources/plane_down4.png new file mode 100755 index 00000000..b9b5b63c Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/plane_down4.png differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/player_down.wav b/practices/cpp/level1/p11_Fighters/Resources/player_down.wav new file mode 100644 index 00000000..c1251571 Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/player_down.wav differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/reward_damage.png b/practices/cpp/level1/p11_Fighters/Resources/reward_damage.png new file mode 100644 index 00000000..5e267b12 Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/reward_damage.png differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/reward_life.png b/practices/cpp/level1/p11_Fighters/Resources/reward_life.png new file mode 100644 index 00000000..8f69b292 Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/reward_life.png differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/reward_speed.png b/practices/cpp/level1/p11_Fighters/Resources/reward_speed.png new file mode 100644 index 00000000..22fabe20 Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/reward_speed.png differ diff --git a/practices/cpp/level1/p11_Fighters/Resources/selector.png b/practices/cpp/level1/p11_Fighters/Resources/selector.png new file mode 100755 index 00000000..3ecbb1ee Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/Resources/selector.png differ diff --git a/practices/cpp/level1/p11_Fighters/TodoList.md b/practices/cpp/level1/p11_Fighters/TodoList.md index 497725f5..26fcee75 100755 --- a/practices/cpp/level1/p11_Fighters/TodoList.md +++ b/practices/cpp/level1/p11_Fighters/TodoList.md @@ -1,25 +1,22 @@ | 任务(功能) | Value | Effort | 是否已完成 -----|-------------------------------|-----------|-----------|------------| -1 | 完成SFML配置,显示“SFML works” | 0 | | | -2 | 显示一架静止的飞机于屏幕底部 | 5 | | | -3 | 背景音乐 | 1 | | | -4 | 左右键,控制移动飞机 | 10 | | | -5 | 限制左右边界 | 1 | | | -6 | 空格键开炮,显示运动的炮弹 | 5 | | | -7 | 炮弹飞出边界处理 | 2 | | | -8 | 随机产生敌机,并向下运动 | 10 | | | -9 | 敌机飞出边界处理 | 2 | | | -10 | 碰撞处理(敌机与炮弹碰撞) | 10 | | | -11 | 显示敌机爆炸过程 | 10 | | | -12 | 爆炸声音 | 2 | | | -13 | 计分及显示 | 5 | | | -14 | 敌机炮弹处理 | 10 | | | -15 | 被敌机击中处理(炸毁、3条命) | 10 | | | -16 | 过关控制(过关需要计分、游戏速度控制)| 20 | | | -17 | | | | | -18 | | | | | -19 | | | | | -20 | | | | | -合计 | | | | | - - +1 | 完成SFML配置,显示“SFML works” | 0 | | V | +2 | 显示一架静止的飞机于屏幕底部 | 5 | | V | +3 | 背景音乐 | 1 | | V | +4 | 左右键,控制移动飞机 | 10 | | V | +5 | 限制左右边界 | 1 | | V | +6 | 空格键开炮,显示运动的炮弹 | 5 | |V | +7 | 炮弹飞出边界处理 | 2 | | V| +8 | 随机产生敌机,并向下运动 | 10 | | V | +9 | 敌机飞出边界处理 | 2 | |V | +10 | 碰撞处理(敌机与炮弹碰撞) | 10 | | V | +11 | 显示敌机爆炸过程 | 10 | |V | +12 | 爆炸声音 | 2 | |V | +13 | 计分及显示 | 5 | |V | +14 | 敌机炮弹处理 | 10 | |V | +15 | 被敌机击中处理(炸毁、3条命) | 10 | |V | +16 | 过关控制(过关需要计分、游戏速度控制)| 20 | |V | +17 | 主菜单功能 |5 | | V | +18 | 游戏中显示属性菜单功能 |5 | | V | +19 | 添加掉落道具(攻击力,生命,速度),获得道具后的提醒 | 10 | | V | +20 | 重生后短暂无敌以及闪烁特效 | 10 | | V | \ No newline at end of file diff --git a/practices/cpp/level1/p11_Fighters/UML.png b/practices/cpp/level1/p11_Fighters/UML.png new file mode 100644 index 00000000..381bd680 Binary files /dev/null and b/practices/cpp/level1/p11_Fighters/UML.png differ