diff --git a/Bullet.cpp b/Bullet.cpp new file mode 100644 index 00000000..1d71cd45 --- /dev/null +++ b/Bullet.cpp @@ -0,0 +1,42 @@ +#include "stdafx.h" +#include "Bullet.h" +#include "game.h" +//extern int head; +//extern int tail; +//extern bool empty; +extern sf::RenderWindow mainWindow; +Bullet::Bullet() +{ + if (image.loadFromFile("images/bullet1.png") != true) + { + return; + } + +} + +void Bullet::draw() +{ + sf::Sprite sprite(image); + sprite.setOrigin(BulletPointX, BulletPointY); + mainWindow.draw(sprite); +} + +void Bullet::move(float timeDelta) +{ + + if (BulletPointY < 0) + { + BulletPointY = BulletPointY + 100*timeDelta; + } + else + { + Game::tail = (Game::tail + 1) % bulnumber; + Game::empty = true; + } +} + +void Bullet::UseBullet() +{ + BulletPointX = Plane::pointX - 30; + BulletPointY = Plane::pointY + 50; +} \ No newline at end of file diff --git a/Bullet.h b/Bullet.h new file mode 100644 index 00000000..76f8c6fb --- /dev/null +++ b/Bullet.h @@ -0,0 +1,16 @@ +#pragma once +#include "stdafx.h" +#include "Plane.h" +class Bullet +{ +public: + sf::Texture image; + float BulletPointX; + float BulletPointY; + Bullet::Bullet(); + void draw(); + void move(float timeDelta); + void UseBullet(); +}; + + \ No newline at end of file diff --git a/Cpp level1 1/1 b/Cpp level1 1/1 new file mode 100644 index 00000000..371a5ec0 --- /dev/null +++ b/Cpp level1 1/1 @@ -0,0 +1 @@ +闃熷垪聽 diff --git a/Cpp level1 1/mainqueue.cpp b/Cpp level1 1/mainqueue.cpp new file mode 100644 index 00000000..8580e7b3 --- /dev/null +++ b/Cpp level1 1/mainqueue.cpp @@ -0,0 +1,50 @@ +// Queue.cpp : 定义控制台应用程序的入口点。 +// + +#include "stdafx.h" +#include "queue.h" +#include "iostream" +#include "stdio.h" +#define _CRT_SECURE_NO_WARNINGS +using namespace std; + + + + +int main() +{ + int number; + int flag = 0; + std::cout << "input the size of the queue" <queue(number); + printf("make a choice 'a number'(append a number) or 'b'(pop)\n"); + while (1) + { + if (flag == 0) + { + queue.show(); + printf("\n"); + } + flag = 0; + + char ch = getchar(); + switch (ch) + { + case 'a': + queue.append(); + break; + case 'b': + queue.pop(); + break; + default: + { + flag = 1; + break; + } + } + } + +} + + diff --git a/Cpp level1 1/queue.h b/Cpp level1 1/queue.h new file mode 100644 index 00000000..144b7aec --- /dev/null +++ b/Cpp level1 1/queue.h @@ -0,0 +1,126 @@ +#pragma once +#include "stdafx.h" +#include +#include +//逻辑上的始终,不必是物理上的始终 +using namespace std; +template +class Queue +{ + +private: + T* qu; + int tail = 0; + int num; + int head = 0; + int mark = 0; + int flag = 0; +public: + + Queue(int num) + { + qu = new T[num]; + this->num = num; + } + + ~Queue() + { + delete[]qu; + } + + void append(); + void pop(); + void show(); + bool isEmpty(); + bool isFull(); + bool judge(int i); +}; + + +template +void Queue::pop() +{ + if (!isEmpty()) + { + head=(head+1)%num; + while (getchar() != '\n') + { + continue; + } + mark = 0; + } + else + { + printf("the queue is empty"); + } +} + +template +void Queue::append() +{ + if (!isFull()) + { + + cin >> qu[tail]; + tail = (tail + 1) % num; + while (getchar() != '\n') + { + continue; + } + mark = 1; + } + else + { + printf("the queue is full\n"); + } +} + + +template +bool Queue::isEmpty() +{ + if (tail == head&&mark == 0) + { + return true; + } + else + { + return false; + } +} + +template +bool Queue::isFull() +{ + if (tail ==head&&mark==1) + { + return true; + } + else + { + return false; + } +} + +template +void Queue::show() +{ + for (int i = head;judge(i); i=(i+1)%num,flag=1) + { + cout << qu[i] << " "; + } + flag = 0; +} + +template +bool Queue::judge(int i) +{ + if (i == tail&&isFull() && flag == 0||i!=tail) + { + return true; + } + else + { + return false; + } +} \ No newline at end of file diff --git a/Cpp level1 2/2 b/Cpp level1 2/2 new file mode 100644 index 00000000..99432dcf --- /dev/null +++ b/Cpp level1 2/2 @@ -0,0 +1 @@ +鏍埪 diff --git a/Cpp level1 2/stack.h b/Cpp level1 2/stack.h new file mode 100644 index 00000000..e87ccef3 --- /dev/null +++ b/Cpp level1 2/stack.h @@ -0,0 +1,106 @@ +#pragma once +#include "stdafx.h" +#include +#include +#include "stack.h" +using namespace std; +template +class Stack +{ + +private: + T* st; + int index = 0; + int num; +public: + + Stack(int num) + { + st = new T[num]; + this->num = num; + } + + ~Stack() + { + delete[]st; + } + + void push(); + void pop(); + void show(); + bool isEmpty(); + bool isFull(); +}; + + +template +void Stack::pop() +{ + if (!isEmpty()) + { + index--; + while (getchar() != '\n') + { + continue; + } + } + else + { + printf("the stack is empty"); + } +} + +template +void Stack::push() +{ + if (!isFull()) + { + + cin >> st[index]; + index++; + while (getchar() != '\n') + { + continue; + } + } + else + { + printf("the stack is full\n"); + } +} + + +template +bool Stack::isEmpty() +{ + if (index == 0) + { + return true; + } + else + { + return false; + } +} + +template +bool Stack::isFull() +{ + if (index >= num) + { + return true; + } + else + { + return false; + } +} + +template +void Stack::show() +{ + for (int i = 0; i < index; i++) + { + cout << st[i] << " "; + } +} \ No newline at end of file diff --git a/Cpp level1 2/stackmain.cpp b/Cpp level1 2/stackmain.cpp new file mode 100644 index 00000000..d89ba436 --- /dev/null +++ b/Cpp level1 2/stackmain.cpp @@ -0,0 +1,50 @@ +// stack.cpp : 定义控制台应用程序的入口点。 +// + +#include "stdafx.h" +#include "stack.h" +#include +#include +#define _CRT_SECURE_NO_WARNINGS +using namespace std; + + + + +int main() +{ + int number; + int flag = 0; + std::cout << "input the size of the stack" <stack(number); + printf("make a choice 'a number'(push a number) or 'b'(pop)\n"); + while (1) + { + if (flag == 0) + { + stack.show(); + printf("\n"); + } + flag = 0; + + char ch = getchar(); + switch (ch) + { + case 'a': + stack.push(); + break; + case 'b': + stack.pop(); + break; + default: + { + flag = 1; + break; + } + } + } + +} + + diff --git a/Cpp level1 2/stdafx.cpp b/Cpp level1 2/stdafx.cpp new file mode 100644 index 00000000..2d697797 --- /dev/null +++ b/Cpp level1 2/stdafx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : 只包括标准包含文件的源文件 +// stack.pch 将作为预编译头 +// stdafx.obj 将包含预编译类型信息 + +#include "stdafx.h" + +// TODO: 在 STDAFX.H 中引用任何所需的附加头文件, +//而不是在此文件中引用 diff --git a/Cpp level1 2/stdafx.h b/Cpp level1 2/stdafx.h new file mode 100644 index 00000000..baa4bbc6 --- /dev/null +++ b/Cpp level1 2/stdafx.h @@ -0,0 +1,15 @@ +// stdafx.h : 标准系统包含文件的包含文件, +// 或是经常使用但不常更改的 +// 特定于项目的包含文件 +// + +#pragma once + +#include "targetver.h" + +#include +#include + + + +// TODO: 在此处引用程序需要的其他头文件 diff --git a/Cpp level1 2/targetver.h b/Cpp level1 2/targetver.h new file mode 100644 index 00000000..416cebf8 --- /dev/null +++ b/Cpp level1 2/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。 + +// 如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并将 +// 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。 + +#include diff --git a/Cpp level1 3/3 b/Cpp level1 3/3 new file mode 100644 index 00000000..c193c489 --- /dev/null +++ b/Cpp level1 3/3 @@ -0,0 +1 @@ +瀹夊叏聽鏁扮粍 diff --git a/Cpp level1 3/c++ level1 3.cpp b/Cpp level1 3/c++ level1 3.cpp new file mode 100644 index 00000000..d89d60f6 --- /dev/null +++ b/Cpp level1 3/c++ level1 3.cpp @@ -0,0 +1,61 @@ +// c++ level1 3.cpp : 定义控制台应用程序的入口点。 +// + +#include "stdafx.h" +#include +#include +#include +using namespace std; +template +class ArrayList +{ + vector vec; +public: + template + class Ref { + ArrayList *array; + int position; + public: + Ref(ArrayList *a, int pos) :array(a), position(pos) {}; + T operator=(T v) { + if (array->vec.size() <= position) + array->vec.resize(position + 1); + array->vec[position] = v; + return array->vec[position]; + } + operator T() const { + if (array->vec.size() <= position) + throw exception(); + return array->vec[position]; + } + T operator =(Ref v) + { + if (array->vec.size() <=v.position) + throw exception(); + return array->vec[position]; + } + }; + Ref operator[](int p) { return Ref(this, p); }; +}; + + +int main() +{ + ArrayList array; + int num = 5; + array[1] = num; + cout << array[1] << endl; + try { + num = array[3]; + } + catch (std::exception &e) { + cout << "array bounds" < +#include +#include +#include +#include +#include "resource.h" +#include +#include + +using namespace std; +HDC hdc; +const class Point +{ +public: + int x; + int y; + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int version) + { + ar & BOOST_SERIALIZATION_NVP(x); + ar & BOOST_SERIALIZATION_NVP(y); + }; +}; +class Index +{ +public: + int index; + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int version) + { + ar & BOOST_SERIALIZATION_NVP(index); + }; +}; + class Shape { + public : + virtual void LButtonDown() = 0; + virtual void LButtonUp() = 0; + virtual void MouseMove() = 0; + virtual void Paint() = 0; + virtual void Begin() = 0; + virtual void End() = 0; + virtual void GetHwnd(HWND hwnd)=0; + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int version) + {}; + }; + BOOST_SERIALIZATION_ASSUME_ABSTRACT(Shape) + class Line :public Shape + { + protected: + int mark; + Point pt[100]; + int *ptrx, *ptry; + HWND hwnd; + PAINTSTRUCT ps; + int flag = 0; + public: + Line() {}; + + + Line(static int &x,static int &y,HWND hwnd) + { + ptrx = &x; + ptry = &y; + this->hwnd= hwnd; + mark = 0; + } + void LButtonDown() + { + pt[mark].x = *ptrx; + pt[mark].y = *ptry; + } + void MouseMove() + { + if (flag == 0) + { + pt[mark].x = *ptrx; + pt[mark].y = *ptry; + } + } + void LButtonUp() + { + if(flag==0) + mark++; + } + void Paint() + { + + HPEN hPen; + RECT rect; + GetClientRect(hwnd, &rect); + hPen = CreatePen(PS_SOLID, 2, RGB(0, 0, 255)); + SelectObject(hdc, hPen); + if (flag == 0) + { + for (int i = 0; i < mark; i++) + { + + MoveToEx(hdc, pt[i].x, pt[i].y, 0); + LineTo(hdc, pt[i + 1].x, pt[i + 1].y); + } + } + if (mark >= 2 && (pt[mark-1].x - pt[0].x)*(pt[mark-1].x - pt[0].x) + (pt[mark-1].y - pt[0].y)*(pt[mark-1].y - pt[0].y)<145) + { + flag = 1; + Polygon(hdc, (const POINT*)pt, mark); + } + } + void Begin() + { + hdc = BeginPaint(hwnd, &ps); + } + void End() + { + EndPaint(hwnd, &ps); + } + void GetHwnd(HWND hwnd) + { + this->hwnd = hwnd; + } + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int version) + { + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Shape); + ar & BOOST_SERIALIZATION_NVP(pt); + ar & BOOST_SERIALIZATION_NVP(mark); + } + virtual ~Line(){}; + }; + BOOST_CLASS_EXPORT(Line) + + class Tri :public Shape + { + protected: + int mark; + Point pt[3]; + int *ptrx, *ptry; + HWND hwnd; + PAINTSTRUCT ps; + public: + Tri() {}; + Tri(static int &x, static int &y, HWND hwnd) + { + ptrx = &x; + ptry = &y; + this->hwnd = hwnd; + mark = 0; + } + void LButtonDown() + { + if (mark <= 2) + { + pt[mark].x = *ptrx; + pt[mark].y = *ptry; + } + } + void MouseMove() + { + if (mark <= 2) + { + pt[mark].x = *ptrx; + pt[mark].y = *ptry; + } + } + void LButtonUp() + { + if(mark<=2) + mark++; + } + void Paint() + { + + HPEN hPen; + hPen = CreatePen(PS_SOLID, 2, RGB(0, 0, 255)); + SelectObject(hdc, hPen); + for (int i = 0; i < mark&&mark<3; i++) + { + MoveToEx(hdc, pt[i].x, pt[i].y, 0); + LineTo(hdc, pt[i + 1].x, pt[i + 1].y); + + } + if (mark == 3) + { + Polygon(hdc, (const POINT*)pt, 3); + } + + } + void Begin() + { + hdc = BeginPaint(hwnd, &ps); + } + void End() + { + EndPaint(hwnd, &ps); + } + void GetHwnd(HWND hwnd) + { + this->hwnd = hwnd; + } + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int version) + { + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Shape); + ar & BOOST_SERIALIZATION_NVP(pt); + ar & BOOST_SERIALIZATION_NVP(mark); + } + virtual ~Tri() {}; + }; + BOOST_CLASS_EXPORT(Tri) + + class Round :public Shape + { + protected: + int mark; + int flag = 0; + Point pt[2]; + int *ptrx, *ptry; + HWND hwnd; + PAINTSTRUCT ps; + int tempX = 0; + int tempY = 0; + public: + Round() {}; + Round(static int &x, static int &y, HWND hwnd) + { + ptrx = &x; + ptry = &y; + this->hwnd = hwnd; + mark = 0; + } + void LButtonDown() + { + if (mark <=1) + { + pt[mark].x = *ptrx; + pt[mark].y = *ptry; + } + if (mark == 2&&(*ptrx>pt[0].x)&&(*ptrxpt[0].y)&&(*ptryhwnd = hwnd; + } + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int version) + { + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Shape); + ar & BOOST_SERIALIZATION_NVP(pt); + ar & BOOST_SERIALIZATION_NVP(mark); + } + virtual ~Round() {}; + }; + BOOST_CLASS_EXPORT(Round) + + class Rect :public Shape + { + protected: + int mark; + Point pt[2]; + int *ptrx, *ptry; + HWND hwnd; + PAINTSTRUCT ps; + public: + Rect() {}; + Rect(static int &x, static int &y, HWND hwnd) + { + ptrx = &x; + ptry = &y; + this->hwnd = hwnd; + mark = 0; + + } + void LButtonDown() + { + if (mark <= 1) + { + pt[mark].x = *ptrx; + pt[mark].y = *ptry; + } + } + void MouseMove() + { + if (mark == 1) + { + pt[mark].x = *ptrx; + pt[mark].y = *ptry; + } + } + void LButtonUp() + { + if (mark <= 1) + mark++; + } + void Paint() + { + HPEN hPen; + hPen = CreatePen(PS_SOLID, 2, RGB(0, 0, 255)); + SelectObject(hdc, hPen); + Rectangle(hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y); + } + void Begin() + { + hdc = BeginPaint(hwnd, &ps); + } + void End() + { + EndPaint(hwnd, &ps); + } + void GetHwnd(HWND hwnd) + { + this->hwnd = hwnd; + } + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int version) + { + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Shape); + ar & BOOST_SERIALIZATION_NVP(pt); + ar & BOOST_SERIALIZATION_NVP(mark); + } + virtual ~Rect() {}; + }; + BOOST_CLASS_EXPORT(Rect) + + class Creator { + public: + virtual Shape* factory() = 0; + }; + + class LineCreator :public Creator + { + protected: + int *ptrx, *ptry; + HWND hwnd; + public: + LineCreator( int &x, int &y,HWND hwnd) { + ptrx = &x; + ptry = &y; + this->hwnd = hwnd; + + } + Shape* factory() + { + return new Line(*ptrx,*ptry,hwnd); + } + }; + + class TriCreator :public Creator + { + protected: + int *ptrx, *ptry; + HWND hwnd; + + public: + TriCreator(int &x, int &y, HWND hwnd) { + ptrx = &x; + ptry = &y; + this->hwnd = hwnd; + } + Shape* factory() + { + return new Tri(*ptrx, *ptry, hwnd); + } + }; + + class RectCreator :public Creator + { + protected: + int *ptrx, *ptry; + HWND hwnd; + public: + RectCreator(int &x, int &y, HWND hwnd) { + ptrx = &x; + ptry = &y; + this->hwnd = hwnd; + } + Shape* factory() + { + return new Rect(*ptrx, *ptry, hwnd); + } + }; + + class RoundCreator :public Creator + { + protected: + int *ptrx, *ptry; + HWND hwnd; + public: + RoundCreator(int &x, int &y, HWND hwnd) { + ptrx = &x; + ptry = &y; + this->hwnd = hwnd; + } + Shape* factory() + { + return new Round(*ptrx, *ptry, hwnd); + } + }; + + +LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { + TCHAR SoftName[] = TEXT("画板"); + HWND hwnd; + WNDCLASS wndclass; + wndclass.style = CS_HREDRAW | CS_VREDRAW; + wndclass.lpfnWndProc = WndProc; + wndclass.cbClsExtra = 0; + wndclass.cbWndExtra = 0; + wndclass.hInstance = hInstance; + wndclass.hIcon = LoadIcon(hInstance, SoftName); + wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); + wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); + wndclass.lpszMenuName = "MenuDemo"; + wndclass.lpszClassName = SoftName; + if (!RegisterClass(&wndclass)) { + MessageBox(NULL, TEXT("This program requires Windows NT!"), SoftName, MB_ICONERROR); + return 0; + } + + hwnd = CreateWindow(SoftName, SoftName,WS_OVERLAPPEDWINDOW,GetSystemMetrics(SM_CXSCREEN) / 4, GetSystemMetrics(SM_CYSCREEN) / 4, GetSystemMetrics(SM_CXSCREEN) / 2, GetSystemMetrics(SM_CYSCREEN) / 2, NULL, NULL, hInstance, NULL); + ShowWindow(hwnd, iCmdShow); + UpdateWindow(hwnd); + + MSG msg; + while (GetMessage(&msg, NULL, 0, 0)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + return msg.wParam; +} +LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + static int mark = 0,flag=0; + static int x=100, y=100; + HMENU hMenu; + static int index = 0; + static vector creator(2); + static vector shape(2); + static bool judge = true; + switch(message) + { + case WM_LBUTTONDOWN: + { + if (shape[0] != NULL) + { + x = LOWORD(lParam); + y = HIWORD(lParam); + shape[index-1]->LButtonDown(); + } + + break; + } + + case WM_MOUSEMOVE: + { + if (shape[0] != NULL) + { + x = LOWORD(lParam); + y = HIWORD(lParam); + shape[index-1]->MouseMove(); + InvalidateRect(hwnd, NULL, TRUE); + + } + break; + } + case WM_PAINT: + { + for (int i = index - 1; i >= 0; i--) + { + if (i == index - 1) + shape[i]->Begin(); + + shape[i]->Paint(); + + if (i == 0) + shape[i]->End(); + } + } + break; + case WM_LBUTTONUP: + + if (shape[0] != NULL) + { + shape[index-1]->LButtonUp(); + + } + break; + + case WM_COMMAND: + { + hMenu = GetMenu(hwnd); + switch (LOWORD(wParam)) { + + case DRAW_LINE: + { + creator.push_back(NULL); + shape.push_back(NULL); + creator[index] = new LineCreator(x, y, hwnd); + shape[index] = creator[index]->factory(); + index++; + + break; + } + case DRAW_ROUND: + { + creator.push_back(NULL); + shape.push_back(NULL); + creator[index] = new RoundCreator(x, y, hwnd); + shape[index] = creator[index]->factory(); + index++; + break; + } + + case DRAW_TRI: + { + creator.push_back(NULL); + shape.push_back(NULL); + creator[index] = new TriCreator(x, y, hwnd); + shape[index] = creator[index]->factory(); + index++; + break; + } + + case DRAW_RECT: + { + creator.push_back(NULL); + shape.push_back(NULL); + creator[index] = new RectCreator(x, y, hwnd); + shape[index] = creator[index]->factory(); + index++; + break; + } + case OPEN: + { + Index in; + std::ifstream ifs("d:\\paint", std::ios::binary); + boost::archive::text_iarchive ia(ifs); + ia >> BOOST_SERIALIZATION_NVP(in); + creator.resize(in.index); + shape.resize(in.index); + while (index < in.index) + { + ia >> BOOST_SERIALIZATION_NVP(shape[index++]); + + } + shape[index - 1]->GetHwnd(hwnd); + break; + } + case SAVE: + { + Index in; + in.index = index; + std::ofstream ofs("d:\\paint", std::ios::binary); + boost::archive::text_oarchive oa(ofs); + oa << BOOST_SERIALIZATION_NVP(in); + for(int i=0;i +using namespace std; +class Device +{ +public: + virtual void on() = 0; + virtual void off() = 0; +}; + +class Circuit +{ +private: + Device *device[100]; + int index=0; +public: + void add(Device* device) + { + this->device[index] = device; + index++; + } + void on() + { + for (int i = 0; i < index; i++) + { + device[i]->on(); + } + } + + void off() + { + for (int i = 0; i < index; i++) + { + device[i]->off(); + } + } + +}; + + +class Fan :public Device +{ +public: + + void on() + { + cout << "fan ran" << endl; + } + void off() + { + cout << "fan close" << endl; + } +}; +class Light:public Device +{ +public: + void on() + { + cout << "light ran" << endl; + } + void off() + { + cout << "light close" << endl; + } +}; + +int main() +{ + Circuit circuit; + Fan fan; + Light light; + circuit.add(&fan); + circuit.add(&light); + circuit.on(); + circuit.off(); + return 0; +} + diff --git a/README.md b/README.md deleted file mode 100755 index 96b5fdd9..00000000 --- a/README.md +++ /dev/null @@ -1,67 +0,0 @@ -# CCpp2017 - -## 鍩烘湰鎿嶄綔娴佺▼ - -1. 浠 [https://github.com/luckymark/CCpp2017](https://github.com/luckymark/CCpp2017) fork 鍒颁綘鑷繁鐨刧ithub涓 -2. 鍒涘缓鏈湴浠撳簱锛(濡傛灉鐢ㄦ満鎴跨殑鐢佃剳锛屽垯寤鸿clone鍒癠鐩橈紝渚夸簬鎼哄甫) - - ``` - git clone https://github.com/ **YourGithubAccount** /CCpp2017 - cd CCpp2017 - ls - - git config user.name=??? - git config user.email=??? - - git remote -v - git remote add upstream https://github.com/luckymark/CCpp2017 - ``` - -3. 淇敼銆佹彁浜や唬鐮侊細 - - ``` - git status - git add . - git commit -m "瀹屾垚浜唕unning letter" - git push - ``` - -4. 浠 https://github.com/luckymark/CCpp2017 鑾峰彇鏇存柊 - - ``` - git fetch upstream - git merge upstream/master - ``` - [鍦╣ithub缃戦〉涓婃洿鏂扮殑鏂规硶](https://www.zhihu.com/question/20393785/answer/30725725) - - [fork鍚庡浣曞悓姝ユ簮鐨勬柊鏇存柊](https://segmentfault.com/q/1010000002590371) - -5. 璇锋眰鑰佸笀review浠g爜鐨勬柟娉曪細鍦╣ithub缃戦〉涓婂彂璧蜂竴涓狿R锛坧ull request锛夊嵆鍙 - -## [浣滀笟](https://github.com/luckymark/CCpp2017/tree/master/practices) - -1. level0 鍙夛紝鐢ㄤ簬杩樹笉澶熺啛缁冪殑鍚屽缁冩墜锛堝珜棰樼洰澶皯鐨勫悓瀛︼紝閭e氨鍒峰埛鍜盵绁炴妧澶у鐨凮J](http://acm.uestc.edu.cn/#/)鍚э紝浠庝綆鍒伴珮鍦板埛鍝堬級 -2. level1 蹇呭仛锛岃鍫傦紜璇惧悗缁冧範 -3. level2 鍙夛紝渚涚簿鍔涙椇鐩涘埌鍙樻佺殑澶х浠彂娉勪箣鐢 - -## 鍙傝 - -### GIT - -[鍙蹭笂鏈娴呮樉鏄撴噦鐨凣it鏁欑▼锛 寤栭洩宄癩(http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000) - -[Pro Git锛堜腑鏂囩増锛塢(http://git.oschina.net/progit/) - -[鎾歌瀛 鍔ㄦ墜瀛it 涓撴不鑿滈笩](http://igit.linuxtoy.org/contents.html) - -[Git杩滅▼鎿嶄綔璇﹁В 闃竴宄癩(http://www.ruanyifeng.com/blog/2014/06/git_remote.html) - -[fork鍚庡浣曡窡涓婃簮repo鐨勫彉鍖朷(https://segmentfault.com/q/1010000002590371) - -### Markdown - -[Markdown鍏ラ棬鎸囧崡](http://www.jianshu.com/p/1e402922ee32) - -### 鍏朵粬 - -[鍏嶈垂鐨勮绠楁満缂栫▼绫讳腑鏂囦功绫峕(https://github.com/wwj718/free-programming-books-zh_CN) diff --git a/cpp level1 11/AgainMenu.cpp b/cpp level1 11/AgainMenu.cpp new file mode 100644 index 00000000..f44f49e8 --- /dev/null +++ b/cpp level1 11/AgainMenu.cpp @@ -0,0 +1,44 @@ +#include "stdafx.h" +#include "AgainMenu.h" +#include "StartMenu.h" +#include "StrUpdate.h" +extern sf::RenderWindow mainWindow; +AgainMenu::AgainMenu() +{ + if (image.loadFromFile("images/end.png") != true) + { + return; + } +} + +void AgainMenu::Draw() +{ + sf::Sprite sprite(image); + sprite.setOrigin(0, 0); + mainWindow.draw(sprite); +} +void AgainMenu::Choose() +{ + sf::Event event; + while (1) + { + mainWindow.pollEvent(event); + if (event.type == sf::Event::MouseButtonPressed) + { + int x = event.mouseButton.x; + int y = event.mouseButton.y; + if (x > 334 && x < 900 && y>308 && y<442) + { + StartMenu::number = 0; + StrUpdate::life = 40; + StrUpdate::score = 0; + return; + } + else if ((x > 530 && x <744 && y>500 && y<600)) + { + StartMenu::number = 2; + return; + } + } + } +} \ No newline at end of file diff --git a/cpp level1 11/AgainMenu.h b/cpp level1 11/AgainMenu.h new file mode 100644 index 00000000..a9f50161 --- /dev/null +++ b/cpp level1 11/AgainMenu.h @@ -0,0 +1,11 @@ +#pragma once +#include "stdafx.h" +#include "Menu.h" +class AgainMenu :public Menu +{ +public: + sf::Texture image; + AgainMenu(); + void Draw(); + void Choose(); +}; diff --git a/cpp level1 11/Boss.cpp b/cpp level1 11/Boss.cpp new file mode 100644 index 00000000..c1573eb0 --- /dev/null +++ b/cpp level1 11/Boss.cpp @@ -0,0 +1,82 @@ +#include "stdafx.h" +#include "Boss.h" +#include "game.h" +#include "ctime" + +extern sf::RenderWindow mainWindow; +Boss::Boss() +{ + enebullet = new BossBullet(this); + + if (image.loadFromFile("images/boss.png") != true) + { + return; + } + if (images[0].loadFromFile("images/bossExplode3.png") != true) + { + return; + } + if (images[1].loadFromFile("images/bossExplode2.png") != true) + { + return; + } + if (images[2].loadFromFile("images/bossExplode1.png") != true) + { + return; + } + if (images[3].loadFromFile("images/bossExplode0.png") != true) + { + return; + } +} + +void Boss::draw() +{ + if (bosslife/3>=3) + { + sf::Sprite sprite(image); + sprite.setOrigin(EnemyPointX, EnemyPointY); + mainWindow.draw(sprite); + + } + else + { + sf::Sprite sprite(images[bosslife/3]); + sprite.setOrigin(EnemyPointX, EnemyPointY); + mainWindow.draw(sprite); + } + + +} + + + +void Boss::move(float timeDelta) +{ + + if (EnemyPointY >-height) + { + EnemyPointY = EnemyPointY - 30 * timeDelta; + } + else + { + Game::btail = right[Game::btail]; + Game::bempty = true; + } +} + +void Boss::UseEnemy() +{ + static int mark = 0; + if (mark == 0) + { + srand((unsigned)time(NULL)); + mark = 1; + } + EnemyPointX = -rand() % (width - 70); + EnemyPointY = 300; +} + +int Boss::right[bossnumber] = { 0 }; +int Boss::left[bossnumber] = { 0 }; +int Boss::efflag = 0; \ No newline at end of file diff --git a/cpp level1 11/Boss.h b/cpp level1 11/Boss.h new file mode 100644 index 00000000..e08e2c05 --- /dev/null +++ b/cpp level1 11/Boss.h @@ -0,0 +1,24 @@ +#pragma once +#include "stdafx.h" +#include "Plane.h" +#include "BossBullet.h" +class BossBullet; +class Boss +{ +public: + + BossBullet *enebullet; + sf::Texture image; + sf::Texture images[4]; + float EnemyPointX; + float EnemyPointY; + int bosslife = 12; + static int efflag; + Boss(); + void draw(); + void move(float timeDelta); + void UseEnemy(); + static int right[bossnumber]; + static int left[bossnumber]; + +}; \ No newline at end of file diff --git a/cpp level1 11/BossBullet.cpp b/cpp level1 11/BossBullet.cpp new file mode 100644 index 00000000..bb4bd2a9 --- /dev/null +++ b/cpp level1 11/BossBullet.cpp @@ -0,0 +1,109 @@ +#include "stdafx.h" +#include "BossBullet.h" +#include "game.h" +#include "math.h" +#include "Boss.h" +#include "LevelControl.h" +#define pi 3.14 +extern sf::RenderWindow mainWindow; +BossBullet::BossBullet(Boss *boss) +{ + this->boss = boss; + if (image.loadFromFile("images/bullet3.png") != true) + { + return; + } + + for (int i = 0; i < bossonce*bossbulnumber - 1; i++) + { + right[i] = i + 1; + } + right[bossonce*bossbulnumber - 1] = 0; + for (int i = 1; i < bossonce*bossbulnumber; i++) + { + left[i] = i - 1; + } + left[0] = bossonce*bossbulnumber - 1; +} + +void BossBullet::draw() +{ + for (int i =tail; ObjectManager::FullOrEmpty(i, head, empty, efflag); i = right[i]) + { + sf::Sprite sprite(image); + sprite.setOrigin(BulletPointX[i], BulletPointY[i]); + mainWindow.draw(sprite); + } + +} + +void BossBullet::move(float timeDelta) +{ + + if (mark == 0) + { + float timeDelta3 = clock3.restart().asSeconds(); + mark = 1; + } + sf::Time time1 = clock3.getElapsedTime(); + if (time1.asSeconds() > LevelControl::bossBulletAppearTime&&enemyExist == 1 && totalEnemyPointX +10- 30*j; + BulletPointY[i] = boss->EnemyPointY - 150; + head =right[head]; + if (head ==tail) + { + empty = false; + } + + float deltaX = BulletPointX[i] - Plane::pointX; + float deltaY = BulletPointY[i] - Plane::pointY; + float delta = sqrt(deltaX*deltaX + deltaY*deltaY); + float rateX = deltaX / delta; + float rateY = deltaY / delta; + this->rateX[i] = rateX; + this->rateY[i] = rateY; + } + + mark = 0; + if (boss->EnemyPointX > Plane::pointX) + { + boss->EnemyPointX = boss->EnemyPointX - 15; + } + else if (boss->EnemyPointX < Plane::pointX) + { + boss->EnemyPointX = boss->EnemyPointX + 15; + } + } + + for (int num = tail; ObjectManager::FullOrEmpty(num, head, empty, efflag); num = right[num]) + { + + if (BulletPointY[num] >-height&& BulletPointY[num]<=150&&BulletPointX[num]<0&&BulletPointX[num]>-width)//没有必要flag[num]!=0,击中我方飞机,不打印就行了,这里无需判断 + { + BulletPointY[num] = BulletPointY[num] - 130 * timeDelta*rateY[num]; + BulletPointX[num] = BulletPointX[num] - 130 * timeDelta*rateX[num]; + } + else + { + if (num == tail) + { + tail = right[tail]; + } + + right[left[num]] = right[num]; + left[right[num]] = left[num]; + right[left[tail]] = num; + left[num] = left[tail]; + left[tail] = num; + right[num] =tail; + empty = true; + } + + + } +} + diff --git a/cpp level1 11/BossBullet.h b/cpp level1 11/BossBullet.h new file mode 100644 index 00000000..8625433a --- /dev/null +++ b/cpp level1 11/BossBullet.h @@ -0,0 +1,33 @@ +#pragma once +#include "stdafx.h" +#include "NormalBullet.h" + +#define bossonce 4 +#define bossbulnumber 20//每辆敌机发射子弹的批次 +class Boss; +class BossBullet +{ +public: + sf::Texture image; + float BulletPointX[bossonce*bossbulnumber]; + float BulletPointY[bossonce*bossbulnumber]; + int flag[bossonce*bossbulnumber] = { 0 }; + float rateX[bossonce*bossbulnumber] = { 0 }; + float rateY[bossonce*bossbulnumber] = { 0 }; + int right[bossonce*bossbulnumber] = { 0 }; + int left[bossonce*bossbulnumber] = { 0 }; + int enemyExist = 0; + int begin = 0; + int total = 0; + int mark = 0; + int head = 0; + int tail = 0; + bool empty = true; + int efflag = 0; + sf::Clock clock3; + BossBullet(Boss *boss); + Boss *boss; + + void draw(); + void move(float timeDelta); +}; \ No newline at end of file diff --git a/cpp level1 11/BossBurst.cpp b/cpp level1 11/BossBurst.cpp new file mode 100644 index 00000000..8080859a --- /dev/null +++ b/cpp level1 11/BossBurst.cpp @@ -0,0 +1,213 @@ +#include "stdafx.h" +#include "BossBurst.h" +#include "game.h" +#include "StrUpdate.h" + +extern sf::RenderWindow mainWindow; +extern MusicPlay musicPlay; +void BossBurst::crash(NormalBullet *bullet, Boss *boss, BossBurst *burst,int &tail, int &head, int &efflag, bool &empty, int *right, int *left) +{ + int flag = 0; + for (int i = tail; ObjectManager::FullOrEmpty(i,head,empty,efflag); i = right[i]) + { + for (int j = Game::btail; ObjectManager::FullOrEmpty(j,Game::bhead,Game::bempty,Boss::efflag); j = Boss::right[j]) + { + if (fabs(bullet[i].BulletPointX + 50 - boss[j].EnemyPointX) <50 && fabs(bullet[i].BulletPointY - boss[j].EnemyPointY) < 50) + { + + + StrUpdate::score=StrUpdate::score+3; + boss[j].bosslife=boss[j].bosslife-3; + //printf(" %d ", boss[j].bosslife); + if (i == tail) + { + tail =right[i]; + } + right[left[i]] =right[i]; + left[right[i]] = left[i]; + right[left[tail]] = i; + left[i] = left[tail]; + left[tail] = i; + right[i] = tail; + + if (head == tail&&empty == false) + { + head = i; + } + + if (boss[j].bosslife > 0) + { + break; + } + musicPlay.BurstMusic(); + burst[j].pointX = boss[j].EnemyPointX; + burst[j].pointY = boss[j].EnemyPointY; + burst[j].times = 0; + boss[j].enebullet->enemyExist = 0; + + if (j == Game::btail) + { + Game::btail = Boss::right[j]; + } + //调整模拟双向链表,连接当前项前后两项,把当前项插入tail左侧的位置,当处理项不是tail时,tail和head都不变 + + Boss::right[Boss::left[j]] = Boss::right[j]; + Boss::left[Boss::right[j]] = Boss::left[j]; + Boss::right[Boss::left[Game::btail]] = j; + Boss::left[j] = Boss::left[Game::btail]; + Boss::left[Game::btail] = j; + Boss::right[j] = Game::btail; + + + if (Game::bhead == Game::btail&&Game::bempty == false) + { + Game::bhead = j; + } + + + flag = 1; + } + if (flag == 1) + { + break; + } + } + if (flag == 1) + { + flag = 0; + continue; + } + } +} + +void BossBurst::crash(MultiBullet *bullet, Boss *boss, BossBurst *burst, int &tail, int &head, int &efflag, bool &empty, int *right, int *left) +{ + int flag = 0; + for (int i = tail; ObjectManager::FullOrEmpty(i, head, empty, efflag); i = right[i]) + { + for (int j = Game::btail; ObjectManager::FullOrEmpty(j, Game::bhead, Game::bempty, Boss::efflag); j = Boss::right[j]) + { + if (fabs(bullet[i].BulletPointX + 50 - boss[j].EnemyPointX) <50 && fabs(bullet[i].BulletPointY - boss[j].EnemyPointY) < 50) + { + + + StrUpdate::score++; + boss[j].bosslife--; + if (i == tail) + { + tail = right[i]; + } + right[left[i]] = right[i]; + left[right[i]] = left[i]; + right[left[tail]] = i; + left[i] = left[tail]; + left[tail] = i; + right[i] = tail; + + if (head == tail&&empty == false) + { + head = i; + } + + if (boss[j].bosslife > 0) + { + flag = 1; + break; + } + musicPlay.BurstMusic(); + burst[j].pointX = boss[j].EnemyPointX; + burst[j].pointY = boss[j].EnemyPointY; + burst[j].times = 0; + boss[j].enebullet->enemyExist = 0; + + if (j == Game::btail) + { + Game::btail = Boss::right[j]; + } + //调整模拟双向链表,连接当前项前后两项,把当前项插入tail左侧的位置,当处理项不是tail时,tail和head都不变 + + Boss::right[Boss::left[j]] = Boss::right[j]; + Boss::left[Boss::right[j]] = Boss::left[j]; + + + + Boss::right[Boss::left[Game::btail]] = j; + Boss::left[j] = Boss::left[Game::btail]; + Boss::left[Game::btail] = j; + Boss::right[j] = Game::btail; + + if (Game::bhead == Game::btail&&Game::bempty == false) + { + Game::bhead = j; + } + + + flag = 1; + } + if (flag == 1) + { + break; + } + } + if (flag == 1) + { + flag = 0; + continue; + } + } +} + +void BossBurst::explode() +{ + static sf::Clock clock4; + static int mark = 0; + + if (mark == 0) + { + float timeDelta4 = clock4.restart().asSeconds(); + mark = 1; + } + sf::Time time1 = clock4.getElapsedTime(); + + if (times == 0) + { + + sf::Sprite sprite(image0); + sprite.setOrigin(pointX, pointY); + mainWindow.draw(sprite); + + } + else if (times == 1) + { + + sf::Sprite sprite(image1); + sprite.setOrigin(pointX, pointY); + mainWindow.draw(sprite); + + } + else if (times == 2) + { + times = -1; + + } + + if (time1.asSeconds() > 0.5) + { + times++; + mark = 0; + } + +} + +BossBurst::BossBurst() +{ + if (image0.loadFromFile("images/bossExplode3.png") != true) + { + return; + } + if (image1.loadFromFile("images/bossExplode4.png") != true) + { + return; + } + +} \ No newline at end of file diff --git a/cpp level1 11/BossBurst.h b/cpp level1 11/BossBurst.h new file mode 100644 index 00000000..19b70fa5 --- /dev/null +++ b/cpp level1 11/BossBurst.h @@ -0,0 +1,17 @@ +#pragma once +#include "stdafx.h" +#include "NormalBullet.h" +#include "Boss.h" +#include "ObjectManager.h" +class BossBurst +{ +public: + int pointX; + int pointY; + int times = -1; + sf::Texture image0, image1, image2; + BossBurst(); + static void crash(NormalBullet *bullet, Boss *boss, BossBurst *burst,int &tail, int &head, int &efflag, bool &empty, int *right, int *left); + static void crash(MultiBullet *bullet, Boss *boss, BossBurst *burst, int &tail, int &head, int &efflag, bool &empty, int *right, int *left); + void explode(); +}; \ No newline at end of file diff --git a/cpp level1 11/BossCauseBurst.cpp b/cpp level1 11/BossCauseBurst.cpp new file mode 100644 index 00000000..51778a10 --- /dev/null +++ b/cpp level1 11/BossCauseBurst.cpp @@ -0,0 +1,42 @@ +#include "stdafx.h" +#include "BossCauseBurst.h" +#include "BossBullet.h" +#include "Plane.h" +#include "math.h" +#include "StrUpdate.h" +extern MusicPlay musicPlay; +void BossCauseBurst::crash(Boss *boss) +{ + for (int i = Game::btail; ObjectManager::FullOrEmpty(i, Game::bhead, Game::bempty, Boss::efflag); i = Boss::right[i]) + { + int &tail = boss[i].enebullet->tail; + int &head = boss[i].enebullet->head; + bool &empty= boss[i].enebullet->empty; + for (int j = tail; ObjectManager::FullOrEmpty(j, head, empty, boss[i].enebullet->efflag); j = boss[i].enebullet->right[j]) + { + + if (fabs(boss[i].enebullet->BulletPointX[j] + 15 - Plane::pointX) < 30 && fabs(boss[i].enebullet->BulletPointY[j] - Plane::pointY + 15)<30) + { + + if (j == tail) + { + tail = boss[i].enebullet->right[j]; + } + boss[i].enebullet->right[boss[i].enebullet->left[j]] = boss[i].enebullet->right[j]; + boss[i].enebullet->left[boss[i].enebullet->right[j]] = boss[i].enebullet->left[j]; + boss[i].enebullet->right[boss[i].enebullet->left[tail]] = j; + boss[i].enebullet->left[j] = boss[i].enebullet->left[tail]; + boss[i].enebullet->left[tail] = j; + boss[i].enebullet->right[j] = tail; + + if (head == tail&&empty == false) + { + head = j; + } + StrUpdate::life--; + + } + + } + } +} \ No newline at end of file diff --git a/cpp level1 11/BossCauseBurst.h b/cpp level1 11/BossCauseBurst.h new file mode 100644 index 00000000..e9845277 --- /dev/null +++ b/cpp level1 11/BossCauseBurst.h @@ -0,0 +1,8 @@ +#pragma once +#include "stdafx.h" +#include "Boss.h" +class BossCauseBurst +{ +public: + static void crash(Boss *boss); +}; \ No newline at end of file diff --git a/cpp level1 11/Enemy.cpp b/cpp level1 11/Enemy.cpp new file mode 100644 index 00000000..bb3562a2 --- /dev/null +++ b/cpp level1 11/Enemy.cpp @@ -0,0 +1,53 @@ +#include "stdafx.h" +#include "Enemy.h" +#include "game.h" +#include "ctime" + +extern sf::RenderWindow mainWindow; +Enemy::Enemy() +{ + enebullet=new EnemyBullet(this); + if (image.loadFromFile("images/plane2.png") != true) + { + return; + } + +} + +void Enemy::draw() +{ + sf::Sprite sprite(image); + sprite.setOrigin(EnemyPointX, EnemyPointY); + mainWindow.draw(sprite); +} + +void Enemy::move(float timeDelta) +{ + + if (EnemyPointY >-height) + { + EnemyPointY = EnemyPointY - LevelControl::enemyMoveSpeed * timeDelta; + } + else + { + Game::etail = right[Game::etail]; + Game::eempty = true; + } +} + +void Enemy::UseEnemy() +{ + static int mark = 0; + if (mark == 0) + { + srand((unsigned)time(NULL)); + mark = 1; + } + + EnemyPointX = -rand()%(width-70); + EnemyPointY = 120; +} + +int Enemy::right[enenumber] = { 0 }; +int Enemy::left[enenumber] = { 0 }; +int Enemy::efflag = 0; diff --git a/cpp level1 11/Enemy.h b/cpp level1 11/Enemy.h new file mode 100644 index 00000000..36376cd2 --- /dev/null +++ b/cpp level1 11/Enemy.h @@ -0,0 +1,23 @@ +#pragma once +#include "stdafx.h" +#include "Plane.h" +#include "EnemyBullet.h" +class EnemyBullet; +class Enemy +{ +public: + EnemyBullet *enebullet; + sf::Texture image; + float EnemyPointX; + float EnemyPointY; + int life = 6; + static int right[enenumber]; + static int left[enenumber]; + static int efflag ; + Enemy(); + void draw(); + void move(float timeDelta); + void UseEnemy(); + + +}; \ No newline at end of file diff --git a/cpp level1 11/EnemyBullet.cpp b/cpp level1 11/EnemyBullet.cpp new file mode 100644 index 00000000..6b17937b --- /dev/null +++ b/cpp level1 11/EnemyBullet.cpp @@ -0,0 +1,101 @@ +#include "stdafx.h" +#include "EnemyBullet.h" +#include "game.h" +#include "math.h" +#include "LevelControl.h" +#define pi 3.14 +extern sf::RenderWindow mainWindow; +EnemyBullet::EnemyBullet(Enemy *enemy) +{ + this->enemy = enemy; + if (image.loadFromFile("images/bullet3.png") != true) + { + return; + } + +} + +void EnemyBullet::draw() +{ + + for (int i = 0; i < eneonce*enebulnumber; i++) + { + if (flag[i] != 0) + { + sf::Sprite sprite(image); + sprite.setOrigin(BulletPointX[i], BulletPointY[i]); + mainWindow.draw(sprite); + } + } + +} + +void EnemyBullet::move(float timeDelta) +{ + + if (mark == 0) + { + float timeDelta3 = clock3.restart().asSeconds(); + mark = 1; + } + sf::Time time1 = clock3.getElapsedTime(); + if (time1.asSeconds() >LevelControl::enemyBulletAppearTime&&enemyExist==1&&totalEnemyPointX-10; + BulletPointY[i] = enemy->EnemyPointY-100; + + } + flag[total] = flag[total + 1] = flag[total + 2] = 1; + total = total + 3; + mark = 0; + } + //printf(" %d ", total); + for (int num = 0; num < total;) + { + //if(enemyExist) + //printf(" num:%d %f ",num, BulletPointY[num]); + if (BulletPointY[num] >-height)//没有必要flag[num]!=0,击中我方飞机,不打印就行了,这里无需判断 + { + + if (num % 3 == 0) + { + BulletPointY[num] = BulletPointY[num] - 155 * timeDelta; + + } + else if (num % 3 == 1) + { + BulletPointY[num] = BulletPointY[num] - 155 * timeDelta*0.7; + BulletPointX[num] = BulletPointX[num] + 130 * timeDelta*0.7; + } + else if (num % 3 == 2) + { + BulletPointY[num] = BulletPointY[num] - 155 * timeDelta*0.7; + BulletPointX[num] = BulletPointX[num] - 130 * timeDelta*0.7; + } + num++; + + } + else//(BulletPointY[num] <=-height) //6.3 bug1:因为同一个不存在的子弹增加了多次begin; + { + if (flag[num] == 1) + { + begin++; + flag[num] = 0; + } + num++; + + //if(enemyExist==1) + //printf("no"); + if (begin == total&&begin!=0) + { + total = 0; + begin = 0; + } + + } + } +} + + diff --git a/cpp level1 11/EnemyBullet.h b/cpp level1 11/EnemyBullet.h new file mode 100644 index 00000000..db7c1b40 --- /dev/null +++ b/cpp level1 11/EnemyBullet.h @@ -0,0 +1,24 @@ +#pragma once +#include "stdafx.h" +#include "NormalBullet.h" + +#define eneonce 3 +#define enebulnumber 10//每辆敌机发射子弹的批次 +class Enemy; +class EnemyBullet +{ +public: + sf::Texture image; + float BulletPointX[eneonce*enebulnumber]; + float BulletPointY[eneonce*enebulnumber]; + int flag[eneonce*enebulnumber] = { 0 }; + int total = 0;//炮弹总数 + int mark = 0; + int enemyExist = 0;//判断对应的敌机是否存在,如果不存在则不生成新子弹 + int begin = 0; + sf::Clock clock3; + EnemyBullet(Enemy *enemy); + Enemy *enemy; + void draw(); + void move(float timeDelta); +}; diff --git a/cpp level1 11/EnemyBurst.cpp b/cpp level1 11/EnemyBurst.cpp new file mode 100644 index 00000000..16187c22 --- /dev/null +++ b/cpp level1 11/EnemyBurst.cpp @@ -0,0 +1,214 @@ +#include "stdafx.h" +#include "EnemyBurst.h" +#include "game.h" +#include "StrUpdate.h" + +extern sf::RenderWindow mainWindow; +extern MusicPlay musicPlay; +void EnemyBurst::crash(NormalBullet *bullet, Enemy *enemy,EnemyBurst *burst,int &tail,int &head,int &efflag,bool &empty,int *right,int *left) +{ + + int flag = 0; + for (int i = tail; ObjectManager::FullOrEmpty(i,head,empty,efflag); i = right[i])//tail,head,empty,efflag,right + { + + for (int j = Game::etail; ObjectManager::FullOrEmpty(j,Game::ehead,Game::eempty,Enemy::efflag); j = Enemy::right[j]) + { + + if (fabs(bullet[i].BulletPointX + 15 - enemy[j].EnemyPointX) < 30 && fabs(bullet[i].BulletPointY - enemy[j].EnemyPointY) < 30) + { + flag = 1; + musicPlay.BurstMusic(); + StrUpdate::score=StrUpdate::score+6; + burst[j].pointX = enemy[j].EnemyPointX; + burst[j].pointY = enemy[j].EnemyPointY; + burst[j].times = 0;//这一句暂时搁置 + enemy[j].enebullet->enemyExist = 0; + if (i == tail) + { + tail = right[i]; + } + + //调整模拟双向链表,连接当前项前后两项,把当前项插入tail左侧的位置,当处理项不是tail时,tail和head都不变 + right[left[i]] = right[i]; + left[right[i]] = left[i]; + right[left[tail]] = i; + left[i] = left[tail]; + left[tail] = i; + right[i] = tail; + + if (head == tail&&empty == false) + { + head = i; + } + + + if (j == Game::etail) + { + Game::etail = Enemy::right[j]; + } + Enemy::right[Enemy::left[j]] = Enemy::right[j]; + Enemy::left[Enemy::right[j]] = Enemy::left[j]; + Enemy::right[Enemy::left[Game::etail]] = j; + Enemy::left[j] = Enemy::left[Game::etail]; + Enemy::left[Game::etail] = j; + Enemy::right[j] = Game::etail; + //bug 5:ehead==etail满了时,不管插到哪里都插到了ehead,etail之间,还会打印,故插到etail之前,改变ehead + //ehead==etail为空时,不管插到哪里都没插到了ehead,etail之间,不调整ehead,etail + if (Game::ehead == Game::etail&&Game::eempty == false) + { + Game::ehead = j; + } + + + } + if (flag == 1) + { + break; + } + } + if (flag == 1) + { + flag = 0; + continue; + } + } +} + +void EnemyBurst::crash(MultiBullet *bullet, Enemy *enemy, EnemyBurst *burst, int &tail, int &head, int &efflag, bool &empty, int *right, int *left) +{ + + int flag = 0; + for (int i = tail; ObjectManager::FullOrEmpty(i, head, empty, efflag); i = right[i])//tail,head,empty,efflag,right + { + + for (int j = Game::etail; ObjectManager::FullOrEmpty(j, Game::ehead, Game::eempty, Enemy::efflag); j = Enemy::right[j]) + { + + if ((bullet[i].BulletPointX -enemy[j].EnemyPointX-8.5)*(bullet[i].BulletPointX - enemy[j].EnemyPointX - 8.5) + + (bullet[i].BulletPointY - enemy[j].EnemyPointY - 20.5)*(bullet[i].BulletPointY - enemy[j].EnemyPointY - 20.5)<10000) + { + flag = 1; + StrUpdate::score++; + + enemy[j].life--; + if (i == tail) + { + tail = right[i]; + } + + + + right[left[i]] = right[i]; + left[right[i]] = left[i]; + right[left[tail]] = i; + left[i] = left[tail]; + left[tail] = i; + right[i] = tail; + if (head == tail&&empty == false) + { + head = i; + } + + if (enemy[j].life> 0) + { + break; + } + musicPlay.BurstMusic(); + burst[j].pointX = enemy[j].EnemyPointX; + burst[j].pointY = enemy[j].EnemyPointY; + burst[j].times = 0;//这一句暂时搁置 + enemy[j].enebullet->enemyExist = 0; + if (j == Game::etail) + { + Game::etail = Enemy::right[j]; + } + Enemy::right[Enemy::left[j]] = Enemy::right[j]; + Enemy::left[Enemy::right[j]] = Enemy::left[j]; + Enemy::right[Enemy::left[Game::etail]] = j; + Enemy::left[j] = Enemy::left[Game::etail]; + Enemy::left[Game::etail] = j; + Enemy::right[j] = Game::etail; + //bug 5:ehead==etail满了时,不管插到哪里都插到了ehead,etail之间,还会打印,故插到etail之前,改变ehead + //ehead==etail为空时,不管插到哪里都没插到了ehead,etail之间,不调整ehead,etail + if (Game::ehead == Game::etail&&Game::eempty == false) + { + Game::ehead = j; + } + } + if (flag == 1) + { + break; + } + } + if (flag == 1) + { + flag = 0; + continue; + } + } +} +void EnemyBurst::explode() +{ + static sf::Clock clock4; + static int mark = 0; + + if (mark == 0) + { + float timeDelta4 = clock4.restart().asSeconds(); + mark = 1; + } + sf::Time time1 = clock4.getElapsedTime(); + + if (times == 0) + { + + sf::Sprite sprite(image0); + sprite.setOrigin(pointX, pointY); + mainWindow.draw(sprite); + + } + else if (times ==1) + { + + sf::Sprite sprite(image1); + sprite.setOrigin(pointX, pointY); + mainWindow.draw(sprite); + + } + else if (times == 2) + { + + sf::Sprite sprite(image2); + sprite.setOrigin(pointX, pointY); + mainWindow.draw(sprite); + + } + else if (times == 3) + { + times = -1; + } + if (time1.asSeconds() > 0.5) + { + times++; + mark = 0; + } + +} + +EnemyBurst::EnemyBurst() +{ + if (image0.loadFromFile("images/enemyExplode0.png") != true) + { + return; + } + if (image1.loadFromFile("images/enemyExplode1.png") != true) + { + return; + } + if (image2.loadFromFile("images/enemyExplode2.png") != true) + { + return; + } +} + diff --git a/cpp level1 11/EnemyBurst.h b/cpp level1 11/EnemyBurst.h new file mode 100644 index 00000000..9d9b4995 --- /dev/null +++ b/cpp level1 11/EnemyBurst.h @@ -0,0 +1,17 @@ +#pragma once +#include "stdafx.h" +#include "NormalBullet.h" +#include "Enemy.h" +#include "ObjectManager.h" +class EnemyBurst +{ +public: + int pointX; + int pointY; + int times = -1; + sf::Texture image0, image1, image2; + EnemyBurst(); + static void crash(NormalBullet *bullet, Enemy *enemy,EnemyBurst *burst, int &tail, int &head, int &efflag, bool &empty,int *right,int *left); + static void crash(MultiBullet *bullet, Enemy *enemy, EnemyBurst *burst, int &tail, int &head, int &efflag, bool &empty, int *right, int *left); + void explode(); +}; \ No newline at end of file diff --git a/cpp level1 11/EnemyCauseBurst.cpp b/cpp level1 11/EnemyCauseBurst.cpp new file mode 100644 index 00000000..cfc9d11b --- /dev/null +++ b/cpp level1 11/EnemyCauseBurst.cpp @@ -0,0 +1,27 @@ +#include "stdafx.h" +#include "EnemyCauseBurst.h" +#include "EnemyBullet.h" +#include "Plane.h" +#include "math.h" +#include "StrUpdate.h" +extern MusicPlay musicPlay; +void EnemyCauseBurst::crash(Enemy *enemy) +{ + for (int i = 0; i < enenumber; i++) + { + for (int j = 0; j < eneonce*enebulnumber; j++) + { + if (enemy[i].enebullet->flag[j] != 0) + { + if (fabs(enemy[i].enebullet->BulletPointX[j] + 15 - Plane::pointX) < 30 && fabs(enemy[i].enebullet->BulletPointY[j] - Plane::pointY+15)<30) + { + + enemy[i].enebullet->flag[j] = 0; + enemy[i].enebullet->begin++; + StrUpdate::life--; + + } + } + } + } +} \ No newline at end of file diff --git a/cpp level1 11/EnemyCauseBurst.h b/cpp level1 11/EnemyCauseBurst.h new file mode 100644 index 00000000..7f930c61 --- /dev/null +++ b/cpp level1 11/EnemyCauseBurst.h @@ -0,0 +1,8 @@ +#pragma once +#include "stdafx.h" +#include "Enemy.h" +class EnemyCauseBurst +{ +public: + static void crash(Enemy *enemy); +}; \ No newline at end of file diff --git a/cpp level1 11/HelpMenu.cpp b/cpp level1 11/HelpMenu.cpp new file mode 100644 index 00000000..4eea5b8f --- /dev/null +++ b/cpp level1 11/HelpMenu.cpp @@ -0,0 +1,36 @@ +#include "stdafx.h" +#include "HelpMenu.h" +#include "StartMenu.h" +extern sf::RenderWindow mainWindow; +HelpMenu::HelpMenu() +{ + if (image.loadFromFile("images/help.png") != true) + { + return; + } +} + +void HelpMenu::Draw() +{ + sf::Sprite sprite(image); + sprite.setOrigin(0, 0); + mainWindow.draw(sprite); +} +void HelpMenu::Choose() +{ + sf::Event event; + while (1) + { + mainWindow.pollEvent(event); + if (event.type == sf::Event::MouseButtonPressed) + { + int x = event.mouseButton.x; + int y = event.mouseButton.y; + if (x > 475 && x < 777&&y>548&&y<623) + { + StartMenu::number = 0; + return; + } + } + } +} \ No newline at end of file diff --git a/cpp level1 11/HelpMenu.h b/cpp level1 11/HelpMenu.h new file mode 100644 index 00000000..044cccd3 --- /dev/null +++ b/cpp level1 11/HelpMenu.h @@ -0,0 +1,11 @@ +#pragma once +#include "stdafx.h" +#include "Menu.h" +class HelpMenu:public Menu +{ +public: + sf::Texture image; + HelpMenu(); + void Draw(); + void Choose(); +}; diff --git a/cpp level1 11/LevelControl.cpp b/cpp level1 11/LevelControl.cpp new file mode 100644 index 00000000..010bfd77 --- /dev/null +++ b/cpp level1 11/LevelControl.cpp @@ -0,0 +1,36 @@ +#include "stdafx.h" +#include "LevelControl.h" +#include "StrUpdate.h" + +void LevelControl::Change() +{ + if (StrUpdate::level > record) + { + record++; + //够用十关 + if (enemyAppearTime > 0.5) + { + enemyAppearTime= enemyAppearTime-0.25; + } + if (enemyBulletAppearTime > 0.7) + { + enemyBulletAppearTime = enemyBulletAppearTime - 0.2; + } + if (bossAppearTime > 5) + { + bossAppearTime = bossAppearTime - 3; + } + if (bossBulletAppearTime > 0.5) + { + bossBulletAppearTime = bossBulletAppearTime - 0.35; + } + } +} + +float LevelControl::enemyAppearTime = 3.0; +float LevelControl::enemyBulletAppearTime=2.7; +float LevelControl::enemyMoveSpeed = 85; +float LevelControl::bossAppearTime=35.0; +float LevelControl::bossBulletAppearTime=4.0; + +int LevelControl::record = 1; \ No newline at end of file diff --git a/cpp level1 11/LevelControl.h b/cpp level1 11/LevelControl.h new file mode 100644 index 00000000..da7ca86f --- /dev/null +++ b/cpp level1 11/LevelControl.h @@ -0,0 +1,13 @@ +#pragma once +#include "stdafx.h" +class LevelControl +{ +public: + static float enemyAppearTime; + static float enemyBulletAppearTime; + static float bossAppearTime; + static float bossBulletAppearTime; + static float enemyMoveSpeed; + static int record; + static void Change(); +}; \ No newline at end of file diff --git a/cpp level1 11/Menu.h b/cpp level1 11/Menu.h new file mode 100644 index 00000000..8a2dcb15 --- /dev/null +++ b/cpp level1 11/Menu.h @@ -0,0 +1,8 @@ +#pragma once +#include "stdafx.h" + +class Menu +{ + virtual void Draw() = 0; + virtual void Choose() = 0; +}; \ No newline at end of file diff --git a/cpp level1 11/MultiBullet.cpp b/cpp level1 11/MultiBullet.cpp new file mode 100644 index 00000000..77110cf5 --- /dev/null +++ b/cpp level1 11/MultiBullet.cpp @@ -0,0 +1,99 @@ +#include "stdafx.h" +#include "MultiBullet.h" +#include "game.h" +#include "math.h" + +extern sf::RenderWindow mainWindow; +MultiBullet::MultiBullet() +{ + + if (image.loadFromFile("images/bullet2.png") != true) + { + return; + } +} + +void MultiBullet::draw() +{ + + sf::Sprite sprite(image); + sprite.setOrigin(BulletPointX, BulletPointY); + mainWindow.draw(sprite); + +} + +void MultiBullet::move(float timeDelta,int num) +{ + + if (BulletPointY <0&&BulletPointX<0&&BulletPointX>-width) + { + + if(MultiBullet::direction[num]==0) + { + BulletPointY = BulletPointY + 200 * timeDelta; + + } + else if (MultiBullet::direction[num] == 1) + { + BulletPointY = BulletPointY + 200 * timeDelta*0.86; + BulletPointX = BulletPointX + 200 * timeDelta*0.5; + } + else if (MultiBullet::direction[num] == 2) + { + BulletPointY = BulletPointY + 200 * timeDelta*0.86; + BulletPointX = BulletPointX - 200 * timeDelta*0.5; + } + else if (MultiBullet::direction[num] == 3) + { + BulletPointY = BulletPointY + 200 * timeDelta*0.5; + BulletPointX = BulletPointX + 200 * timeDelta*0.86; + } + else if (MultiBullet::direction[num] == 4) + { + BulletPointY = BulletPointY + 200 * timeDelta*0.5; + BulletPointX = BulletPointX - 200 * timeDelta*0.86; + } + + + } + else + { + if (num == Game::mtail) + { + Game::mtail = right[Game::mtail]; + } + //逻辑严密性有待检验 + right[left[num]] = right[num]; + left[right[num]] = left[num]; + right[left[Game::mtail]] = num; + left[num] = left[Game::mtail]; + left[Game::mtail] = num; + right[num] = Game::mtail; + + Game::mempty = true; + } + +} + +bool MultiBullet::Judge() +{ + int sub = Game::mtail - Game::mhead; + if (sub == 0&&Game::mempty==true) + { + return true; + } + else if ((Game::mtail + multi - Game::mhead) % (multinumber*multionce) >= 5) + { + return true; + } + + else + { + return false; + } + +} +int MultiBullet::right[multinumber*multionce] = { 0 }; +int MultiBullet::left[multinumber*multionce] = { 0 }; +int MultiBullet::direction[multi] = { 0 }; +int flag[multionce*multinumber] = { 0 }; \ No newline at end of file diff --git a/cpp level1 11/MultiBullet.h b/cpp level1 11/MultiBullet.h new file mode 100644 index 00000000..f688b697 --- /dev/null +++ b/cpp level1 11/MultiBullet.h @@ -0,0 +1,29 @@ +#pragma once +#include "stdafx.h" +#include "Plane.h" +#include "Enemy.h" +#include "MyBullet.h" +#define multionce 5 +#define multinumber 12 +#define multi multionce*multinumber +class MultiBullet :public MyBullet +{ +public: + sf::Clock clock3; + sf::Texture image; + int mark = 0; + int total = 0; + int begin = 0; + int addtotal = 0; + + static int flag[multionce*multinumber] ; + static int right[multinumber*multionce]; + static int left[multinumber*multionce]; + static int direction[multi]; + MultiBullet(); + void draw(); + void move(float timeDelta,int num); + static bool Judge(); + + +}; \ No newline at end of file diff --git a/cpp level1 11/MusicPlay.cpp b/cpp level1 11/MusicPlay.cpp new file mode 100644 index 00000000..2e789361 --- /dev/null +++ b/cpp level1 11/MusicPlay.cpp @@ -0,0 +1,43 @@ +#include "stdafx.h" +#include "MusicPlay.h" + +void MusicPlay::GameMusic() +{ + if (!gameMusic.openFromFile("sound/game_music.ogg")) + { + return; + } + if (useMusic) + { + gameMusic.setLoop(true); + gameMusic.play(); + } +} + +void MusicPlay::BurstMusic() +{ + if (!burstMusic.openFromFile("sound/explode.ogg")) + { + return; + } + if (MusicPlay::useMusic) + { + burstMusic.play(); + } +} + +void MusicPlay::AgainMusic() +{ + gameMusic.stop(); + if (!againMusic.openFromFile("sound/gameover.ogg")) + { + return; + } + if (MusicPlay::useMusic) + { + againMusic.play(); + } +} + + +int MusicPlay::useMusic = 1; \ No newline at end of file diff --git a/cpp level1 11/MusicPlay.h b/cpp level1 11/MusicPlay.h new file mode 100644 index 00000000..86c99e21 --- /dev/null +++ b/cpp level1 11/MusicPlay.h @@ -0,0 +1,13 @@ +#pragma once +#include "stdafx.h" +class MusicPlay +{ +public: + static int useMusic; + sf::Music gameMusic; + sf::Music burstMusic; + sf::Music againMusic; + void GameMusic(); + void BurstMusic(); + void AgainMusic(); +}; \ No newline at end of file diff --git a/cpp level1 11/MyBullet.h b/cpp level1 11/MyBullet.h new file mode 100644 index 00000000..12d6881b --- /dev/null +++ b/cpp level1 11/MyBullet.h @@ -0,0 +1,7 @@ +#pragma once +class MyBullet +{ +public: + float BulletPointX; + float BulletPointY; +}; \ No newline at end of file diff --git a/cpp level1 11/NormalBullet.cpp b/cpp level1 11/NormalBullet.cpp new file mode 100644 index 00000000..76123bdc --- /dev/null +++ b/cpp level1 11/NormalBullet.cpp @@ -0,0 +1,45 @@ +#include "stdafx.h" +#include "NormalBullet.h" +#include "game.h" +#include "math.h" + +extern sf::RenderWindow mainWindow; +NormalBullet::NormalBullet() +{ + if (image.loadFromFile("images/bullet1.png") != true) + { + return; + } + +} + +void NormalBullet::draw() +{ + sf::Sprite sprite(image); + sprite.setOrigin(BulletPointX, BulletPointY); + mainWindow.draw(sprite); +} + +void NormalBullet::move(float timeDelta) +{ + + if (BulletPointY < 0) + { + BulletPointY = BulletPointY + 150*timeDelta; + } + else + { + Game::tail = right[Game::tail]; + Game::empty = true; + } +} + +void NormalBullet::UseBullet() +{ + BulletPointX = Plane::pointX - 30; + BulletPointY = Plane::pointY + 50; +} + + +int NormalBullet::right[bulnumber] = { 0 }; +int NormalBullet::left[bulnumber] = { 0 }; diff --git a/cpp level1 11/NormalBullet.h b/cpp level1 11/NormalBullet.h new file mode 100644 index 00000000..859e9168 --- /dev/null +++ b/cpp level1 11/NormalBullet.h @@ -0,0 +1,19 @@ +#pragma once +#include "stdafx.h" +#include "Plane.h" +#include "Enemy.h" +#include "MyBullet.h" +class NormalBullet :public MyBullet +{ +public: + + sf::Texture image; + NormalBullet(); + void draw(); + void move(float timeDelta); + void UseBullet(); + static int right[bulnumber]; + static int left[bulnumber]; +}; + + \ No newline at end of file diff --git a/cpp level1 11/ObjectManager.cpp b/cpp level1 11/ObjectManager.cpp new file mode 100644 index 00000000..e9e0016c --- /dev/null +++ b/cpp level1 11/ObjectManager.cpp @@ -0,0 +1,368 @@ +#include "stdafx.h" +#include "ObjectManager.h" +#include "Plane.h" +#include "game.h" +#include "windows.h" + + +extern sf::RenderWindow mainWindow; +void ObjectManager::PlaneUpdate(Plane &plane) +{ + static sf::Clock clock0; + float timeDelta = clock0.restart().asSeconds(); + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) + { + plane.MoveLeft(timeDelta); + } + else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) + { + plane.MoveRight(timeDelta); + } + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) + { + plane.MoveUp(timeDelta); + } + else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) + { + plane.MoveDown(timeDelta); + } + if(sf::Keyboard::isKeyPressed(sf::Keyboard::Tab)) + { + plane.WeaponChange(); + } + plane.draw(); +} + +void ObjectManager::BulletUpdate(NormalBullet *bullet) +{ + + static int mark = 0; + if (mark == 0) + { + for (int i = 0; i < bulnumber-1; i++) + { + NormalBullet::right[i] = i + 1; + } + NormalBullet::right[bulnumber - 1] = 0; + for (int i = 1; i < bulnumber ; i++) + { + NormalBullet::left[i] = i- 1; + } + NormalBullet::left[0] = bulnumber - 1; + mark = 1; + } + + static sf::Clock clock1; + float timeDelta = clock1.restart().asSeconds(); + for (int i = Game::tail; FullOrEmpty(i,Game::head,Game::empty,Plane::efflag); i = NormalBullet::right[i]) + { + + bullet[i].move(timeDelta); + bullet[i].draw(); + } + + sf::Event event; + mainWindow.pollEvent(event); + + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space) && flag == 1) + { + if (Plane::weaponStatus == 0) + { + if (Game::head != Game::tail || (Game::head == Game::tail&&Game::empty == true)) + { + bullet[Game::head].UseBullet(); + Game::head = NormalBullet::right[Game::head]; + if (Game::head == Game::tail) + { + Game::empty = false; + } + flag = 0;//bug 3:如果发不出子弹,就不必改变flag + } + } + } + else if (!sf::Keyboard::isKeyPressed(sf::Keyboard::Space))//bug 4:release没有用,改成现在的做法 + { + flag = 1; + } + +} + +void ObjectManager::EnemyUpdate(Enemy *enemy) +{ + static int emark = 0; + if (emark == 0) + { + for (int i = 0; i < enenumber - 1; i++) + { + Enemy::right[i] = i + 1; + } + Enemy::right[enenumber - 1] = 0; + for (int i = 1; i < enenumber; i++) + { + Enemy::left[i] = i - 1; + } + Enemy::left[0] = enenumber - 1; + emark = 1; + } + static sf::Clock clock2; + float timeDelta = clock2.restart().asSeconds(); + for (int i = Game::etail; FullOrEmpty(i,Game::ehead,Game::eempty,Enemy::efflag); i = Enemy::right[i]) + { + enemy[i].move(timeDelta); + enemy[i].draw(); + + } + //打印敌机子弹 + for (int i = 0; i < enenumber; i++) + { + enemy[i].enebullet->move(timeDelta); + enemy[i].enebullet->draw(); + } + static sf::Clock clock3; + static int mark = 0; + if (mark == 0) + { + float timeDelta3 = clock3.restart().asSeconds(); + mark = 1; + } + sf::Time time1 = clock3.getElapsedTime(); + if (time1.asSeconds() >LevelControl::enemyAppearTime) + { + if (Game::ehead != Game::etail || (Game::ehead == Game::etail&&Game::eempty == true)) + { + enemy[Game::ehead].life = 6; + enemy[Game::ehead].UseEnemy(); + enemy[Game::ehead].enebullet->enemyExist = 1; + Game::ehead = Enemy::right[Game::ehead]; + if (Game::ehead == Game::etail) + { + Game::eempty = false; + } + + } + mark = 0;//bug 5:两个mark不能合并,必须分开 + } +} + +bool ObjectManager::FullOrEmpty(int i,int head,bool empty,int &flag) +{ + if (empty == true && i != head) + { + return true; + } + else if (empty == false && flag == 0)//when empty == false,i==tail==head + { + flag = 1; + return true; + } + //deal with empty==true && i==head and empty==false + else if (flag == 1) + { + if (i == head)//i should meet head twice + { + flag = 0; + return false; + } + else + { + return true; + } + } + else + { + return false; + } +} + + +void ObjectManager::EnemyBurstUpdate(EnemyBurst *burst,NormalBullet *bullet,MultiBullet *multiBullet,Enemy *enemy) +{ + + //6.17 bug1:把派生类指针赋给基类指针,而两者加1的效果不同 + //不能用基类指针处理派生类数组 + EnemyBurst::crash(bullet, enemy,burst,Game::tail,Game::head,Plane::efflag,Game::empty,NormalBullet::right,NormalBullet::left); + EnemyBurst::crash(multiBullet, enemy, burst, Game::mtail, Game::mhead, Plane::mefflag, Game::mempty, MultiBullet::right, MultiBullet::left); + static sf::Clock clock3; + static int mark = 0; + + if (mark == 0) + { + float timeDelta3 = clock3.restart().asSeconds(); + mark = 1; + } + + + EnemyCauseBurst::crash(enemy); + mark = 0; + + for (int i = 0; i < enenumber; i++) + { + if (burst[i].times != -1) + { + burst[i].explode(); + } + } +} + +void ObjectManager::BackgroundUpdate() +{ + sf::Texture image; + if (image.loadFromFile("images/Background.jpg") != true) + { + return; + } + sf::Sprite sprite(image); + sprite.setOrigin(0,0); + mainWindow.draw(sprite); +} + + + +void ObjectManager::BossBurstUpdate(BossBurst *burst, NormalBullet *bullet, MultiBullet *multiBullet,Boss *boss) +{ + BossBurst::crash(bullet, boss, burst, Game::tail, Game::head, Plane::efflag, Game::empty, NormalBullet::right, NormalBullet::left); + BossBurst::crash(multiBullet, boss, burst, Game::mtail, Game::mhead, Plane::mefflag, Game::mempty, MultiBullet::right, MultiBullet::left); + static sf::Clock clock3; + static int mark = 0; + + if (mark == 0) + { + float timeDelta3 = clock3.restart().asSeconds(); + mark = 1; + } + + + BossCauseBurst::crash(boss); + mark = 0; + + for (int i = 0; i < bossnumber; i++) + { + if (burst[i].times != -1) + { + burst[i].explode(); + } + } +} + +void ObjectManager::BossUpdate(Boss *boss) +{ + static int bmark = 0; + if (bmark == 0) + { + for (int i = 0; i < bossnumber - 1; i++) + { + Boss::right[i] = i + 1; + } + Boss::right[bossnumber - 1] = 0; + for (int i = 1; i < bossnumber; i++) + { + Boss::left[i] = i - 1; + } + Boss::left[0] = bossnumber - 1; + bmark = 1; + } + static sf::Clock clock2; + float timeDelta = clock2.restart().asSeconds(); + for (int i = Game::btail; FullOrEmpty(i,Game::bhead,Game::bempty,Boss::efflag); i = Boss::right[i]) + { + boss[i].move(timeDelta); + boss[i].draw(); + + } + //打印敌机子弹 + for (int i = 0; i < bossnumber; i++) + { + boss[i].enebullet->move(timeDelta); + boss[i].enebullet->draw(); + } + static sf::Clock clock3; + static int mark = 0; + if (mark == 0) + { + float timeDelta3 = clock3.restart().asSeconds(); + mark = 1; + } + sf::Time time1 = clock3.getElapsedTime(); + if (time1.asSeconds() > LevelControl::bossAppearTime) + { + if (Game::bhead != Game::btail || (Game::bhead == Game::btail&&Game::bempty == true)) + { + boss[Game::bhead].UseEnemy(); + + boss[Game::bhead].enebullet->enemyExist = 1; + boss[Game::bhead].bosslife = 12; + Game::bhead = Boss::right[Game::bhead]; + if (Game::bhead == Game::btail) + { + Game::bempty = false; + } + + } + mark = 0;//bug 5:两个mark不能合并,必须分开 + } +} + +void ObjectManager::MultiBulletUpdate(MultiBullet *bullet) +{ + static int mark = 0; + if (mark == 0) + { + for (int i = 0; i < multinumber*multionce - 1; i++) + { + MultiBullet::right[i] = i + 1; + } + MultiBullet::right[multinumber*multionce - 1] = 0; + for (int i = 1; i < multinumber*multionce; i++) + { + MultiBullet::left[i] = i - 1; + } + MultiBullet::left[0] = multinumber*multionce - 1; + mark = 1; + for (int i = 0; i < multi; i++) + { + MultiBullet::direction[i] = i%multionce; + } + } + + static sf::Clock clock1; + float timeDelta = clock1.restart().asSeconds(); + for (int i = Game::mtail; FullOrEmpty(i, Game::mhead, Game::mempty, Plane::mefflag); i = MultiBullet::right[i]) + { + + bullet[i].move(timeDelta,i); + bullet[i].draw(); + } + + sf::Event event; + mainWindow.pollEvent(event); + static int timemark = 1; + static sf::Clock clock4; + + if (timemark == 1) + { + float timeDelta3 = clock4.restart().asSeconds(); + timemark = 2; + } + sf::Time time2 = clock4.getElapsedTime(); + + static bool empty = true; + + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space) && time2.asSeconds() > 0.7 && Plane::weaponStatus == 1&&MultiBullet::Judge()) + { + //head的调整,大于五个发射下一轮的调整 + for (int i = Game::mhead, j = 0; j<5; i = MultiBullet::right[i], j++) + { + bullet[i].BulletPointX = Plane::pointX - 30; + bullet[i].BulletPointY = Plane::pointY; + MultiBullet::direction[i] = j; + Game::mhead = MultiBullet::right[Game::mhead]; + if (Game::mhead == Game::mtail) + { + Game::mempty = false; + } + } + timemark = 1; + } + + +} diff --git a/cpp level1 11/ObjectManager.h b/cpp level1 11/ObjectManager.h new file mode 100644 index 00000000..d1ab0558 --- /dev/null +++ b/cpp level1 11/ObjectManager.h @@ -0,0 +1,41 @@ +#pragma once +#include "stdafx.h" +#include "Plane.h" +#include "NormalBullet.h" +#include "MultiBullet.h" + +#include "Enemy.h" +#include "EnemyBurst.h" +#include "EnemyBullet.h" +#include "EnemyCauseBurst.h" + +#include "Boss.h" +#include "BossBurst.h" +#include "BossBullet.h" +#include "BossCauseBurst.h" +#include "LevelControl.h" +class EnemyBurst; +class BossBurst; +class ObjectManager +{ +private: + int flag = 1; + int eflag = 0; + +public: + void BackgroundUpdate(); + void PlaneUpdate(Plane &plane); + void BulletUpdate(NormalBullet *bullet); + void MultiBulletUpdate(MultiBullet *bullet); + + + + void EnemyUpdate(Enemy *enemy); + void EnemyBurstUpdate(EnemyBurst *burst, NormalBullet *bullet,MultiBullet *multiBullet,Enemy *enemy); + + + void BossUpdate(Boss *boss); + void BossBurstUpdate(BossBurst *burst, NormalBullet *bullet,MultiBullet *multiBullet, Boss *boss); + bool static FullOrEmpty(int i, int head, bool empty, int &flag); +}; + diff --git a/cpp level1 11/Plane.cpp b/cpp level1 11/Plane.cpp new file mode 100644 index 00000000..f817fd8b --- /dev/null +++ b/cpp level1 11/Plane.cpp @@ -0,0 +1,77 @@ +#include "stdafx.h" +#include "Plane.h" +extern sf::RenderWindow mainWindow; + + Plane::Plane(int width,int height) + { + if (image.loadFromFile("images/plane1.png") != true) + { + return ; + } + pointX = -width / 2; + pointY = -height + 100; + this->width = width; + this->height = height; + draw(); + } + + + + void Plane::MoveLeft(float timeDelta) + { + if (pointX<0) + { + pointX = pointX +300*timeDelta; + draw(); + } + + } + void Plane::MoveRight(float timeDelta) + { + if (pointX>-width+80) + { + pointX = pointX -300* timeDelta; + draw(); + } + + } + + void Plane::MoveUp(float timeDelta) + { + if (pointY<0) + { + pointY = pointY +600*timeDelta; + draw(); + + } + + } + + void Plane::MoveDown(float timeDelta) + { + if (pointY>-height + 80) + { + pointY = pointY -600*timeDelta; + draw(); + + } + + } + void Plane::draw() + { + sf::Sprite sprite(image); + sprite.setOrigin(pointX, pointY); + mainWindow.draw(sprite); + } + + void Plane::WeaponChange() + { + weaponStatus = (weaponStatus + 1) % weaponnumber; + } + float Plane::pointX = 0; + float Plane::pointY = 0; + float Plane::width = 0; + float Plane::height = 0; + int Plane::weaponStatus = 0; + int Plane::efflag = 0; + int Plane::mefflag = 0; \ No newline at end of file diff --git a/cpp level1 11/Plane.h b/cpp level1 11/Plane.h new file mode 100644 index 00000000..700970ac --- /dev/null +++ b/cpp level1 11/Plane.h @@ -0,0 +1,26 @@ +#pragma once +#include "stdafx.h" +#define weaponnumber 2 +class Plane +{ +public: + static float pointX; + static float pointY; + static float width; + static float height; + static int weaponStatus; + static int efflag; + static int mefflag; + sf::Texture image; + + + Plane(int width, int height); + void MoveLeft(float timeDelta); + void MoveRight(float timeDelta); + void MoveUp(float timeDelta); + void MoveDown(float timeDelta); + void WeaponChange(); + void draw(); + friend class NormalBullet; +}; + diff --git a/cpp level1 11/ReadMe.txt b/cpp level1 11/ReadMe.txt new file mode 100644 index 00000000..2b6be0ec --- /dev/null +++ b/cpp level1 11/ReadMe.txt @@ -0,0 +1,30 @@ +锘======================================================================== + 鎺у埗鍙板簲鐢ㄧ▼搴忥細椋炴満 椤圭洰姒傝堪 +======================================================================== + +搴旂敤绋嬪簭鍚戝宸蹭负鎮ㄥ垱寤轰簡姝 椋炴満 搴旂敤绋嬪簭銆 + +鏈枃浠舵瑕佷粙缁嶇粍鎴 椋炴満 搴旂敤绋嬪簭鐨勬瘡涓枃浠剁殑鍐呭銆 + + +椋炴満.vcxproj + 杩欐槸浣跨敤搴旂敤绋嬪簭鍚戝鐢熸垚鐨 VC++ 椤圭洰鐨勪富椤圭洰鏂囦欢锛屽叾涓寘鍚敓鎴愯鏂囦欢鐨 Visual C++ 鐨勭増鏈俊鎭紝浠ュ強鏈夊叧浣跨敤搴旂敤绋嬪簭鍚戝閫夋嫨鐨勫钩鍙般侀厤缃拰椤圭洰鍔熻兘鐨勪俊鎭 + +椋炴満.vcxproj.filters + 杩欐槸浣跨敤鈥滃簲鐢ㄧ▼搴忓悜瀵尖濈敓鎴愮殑 VC++ 椤圭洰绛涢夊櫒鏂囦欢銆傚畠鍖呭惈鏈夊叧椤圭洰鏂囦欢涓庣瓫閫夊櫒涔嬮棿鐨勫叧鑱斾俊鎭傚湪 IDE 涓紝閫氳繃杩欑鍏宠仈锛屽湪鐗瑰畾鑺傜偣涓嬩互鍒嗙粍褰㈠紡鏄剧ず鍏锋湁鐩镐技鎵╁睍鍚嶇殑鏂囦欢銆備緥濡傦紝鈥.cpp鈥濇枃浠朵笌鈥滄簮鏂囦欢鈥濈瓫閫夊櫒鍏宠仈銆 + +椋炴満.cpp + 杩欐槸涓诲簲鐢ㄧ▼搴忔簮鏂囦欢銆 + +///////////////////////////////////////////////////////////////////////////// +鍏朵粬鏍囧噯鏂囦欢: + +StdAfx.h, StdAfx.cpp + 杩欎簺鏂囦欢鐢ㄤ簬鐢熸垚鍚嶄负 椋炴満.pch 鐨勯缂栬瘧澶 (PCH) 鏂囦欢鍜屽悕涓 StdAfx.obj 鐨勯缂栬瘧绫诲瀷鏂囦欢銆 + +///////////////////////////////////////////////////////////////////////////// +鍏朵粬娉ㄩ噴: + +搴旂敤绋嬪簭鍚戝浣跨敤鈥淭ODO:鈥濇敞閲婃潵鎸囩ず搴旀坊鍔犳垨鑷畾涔夌殑婧愪唬鐮侀儴鍒嗐 + +///////////////////////////////////////////////////////////////////////////// diff --git a/cpp level1 11/StartMenu.cpp b/cpp level1 11/StartMenu.cpp new file mode 100644 index 00000000..aab73a42 --- /dev/null +++ b/cpp level1 11/StartMenu.cpp @@ -0,0 +1,52 @@ +#include "stdafx.h" +#include "StartMenu.h" +extern sf::RenderWindow mainWindow; +StartMenu::StartMenu() +{ + if (image.loadFromFile("images/start.png") != true) + { + return; + } +} + +void StartMenu::Draw() +{ + sf::Sprite sprite(image); + sprite.setOrigin(0, 0); + mainWindow.draw(sprite); +} + +void StartMenu::Choose() +{ + sf::Event event; + while (1) + { + mainWindow.pollEvent(event); + if (event.type == sf::Event::MouseButtonPressed) + { + int x = event.mouseButton.x; + int y =event.mouseButton.y; + if (x > 575 && x < 740) + { + if (y>470 && y < 550) + { + number = 0; + break; + } + else if (y>580 && y < 670) + { + number = 1; + break; + } + else if (y>670 && y < 800) + { + number = 2; + break; + } + } + } + } + +} + +int StartMenu::number = -1; \ No newline at end of file diff --git a/cpp level1 11/StartMenu.h b/cpp level1 11/StartMenu.h new file mode 100644 index 00000000..dd3fa053 --- /dev/null +++ b/cpp level1 11/StartMenu.h @@ -0,0 +1,12 @@ +#pragma once +#include "stdafx.h" +#include "Menu.h" +class StartMenu:public Menu +{ +public: + static int number; + sf::Texture image; + StartMenu(); + void Draw(); + void Choose(); +}; diff --git a/cpp level1 11/StrUpdate.cpp b/cpp level1 11/StrUpdate.cpp new file mode 100644 index 00000000..f6ee25ba --- /dev/null +++ b/cpp level1 11/StrUpdate.cpp @@ -0,0 +1,48 @@ +#include "stdafx.h" +#include "StrUpdate.h" +#define section 50 + +int StrUpdate::life = 40; +int StrUpdate::score = 0; + +extern sf::RenderWindow mainWindow; +void StrUpdate::update() +{ + + sf::Font font; + font.loadFromFile("D:\\SFML-2.4.2-windows-vc14-32-bit\\SFML-2.4.2\\Sansation.ttf"); + + if (score > upper) + { + level++; + range = range + section; + upper = upper + range; + + } + std::string s1 = NumToStr(life); + std::string s2 = NumToStr(score); + std::string s3 = NumToStr(level); + std::string s; + if (Plane::weaponStatus == 0) + { + s = "life:" + s1 + " " + "score:" +s2+" "+"weapon:"+" "+"missile"+" level: "+ s3; + } + else if (Plane::weaponStatus == 1) + { + s = "life:" + s1 + " " + "score:" +s2+" "+"weapon:"+" "+"shot" + " level: " + s3; + } + sf::Text text(s, font, 30); + mainWindow.draw(text); + +} + +std::string StrUpdate::NumToStr(int i) +{ + std::stringstream ss; + ss << i; + return ss.str(); +} + +int StrUpdate::level = 1; +int StrUpdate::range = section; +int StrUpdate::upper = section; \ No newline at end of file diff --git a/cpp level1 11/StrUpdate.h b/cpp level1 11/StrUpdate.h new file mode 100644 index 00000000..18bd65e5 --- /dev/null +++ b/cpp level1 11/StrUpdate.h @@ -0,0 +1,17 @@ +#pragma once +#include "stdafx.h" +#include "game.h" +#include "string" +#include "sstream" + +class StrUpdate +{ +public: + static int life; + static int score; + static int upper; + static int range; + static void update(); + static std::string NumToStr(int i); + static int level; +}; \ No newline at end of file diff --git a/cpp level1 11/TodoList.md b/cpp level1 11/TodoList.md new file mode 100644 index 00000000..6c6d57f4 --- /dev/null +++ b/cpp level1 11/TodoList.md @@ -0,0 +1,25 @@ +锘 缂栧彿 | 浠诲姟 | value |effort|鏄惁宸插畬鎴恷 + -----|-----|-----|------|-----| + 1 | 瀹屾垚SFML閰嶇疆锛屾樉绀衡淪FML works鈥 | 0 | 1 | 宸插畬鎴 | + 2 | 鏄剧ず涓鏋堕潤姝㈢殑椋炴満浜庡睆骞曞簳閮 | 5 | 1 | 宸插畬鎴 | +3 | 鑳屾櫙闊充箰 | 1 | 1 | 宸插畬鎴 | +4 | 宸﹀彸閿紝鎺у埗绉诲姩椋炴満 | 10 | 5 | 宸插畬鎴 | +5 | 闄愬埗宸﹀彸杈圭晫 | 1 | 1 | 宸插畬鎴 | +6 | 绌烘牸閿紑鐐紝鏄剧ず杩愬姩鐨勭偖寮 | 5 | 10 | 宸插畬鎴 | +7 | 鐐脊椋炲嚭杈圭晫澶勭悊 | 2 | 1 | 宸插畬鎴 | +8 | 闅忔満浜х敓鏁屾満锛屽苟鍚戜笅杩愬姩 | 10 | 5 | 宸插畬鎴 | +9 | 鏁屾満椋炲嚭杈圭晫澶勭悊 | 2 | 1 | 宸插畬鎴 | +10 | 纰版挒澶勭悊锛堟晫鏈轰笌鐐脊纰版挒锛 | 10 | 10 | 宸插畬鎴 | +11 | 鏄剧ず鏁屾満鐖嗙偢杩囩▼ | 10 | 2 | 宸插畬鎴 | +12 | 鐖嗙偢澹伴煶 | 2 | 2 | 宸插畬鎴 | +13 | 璁″垎鍙婃樉绀 | 5 | 2 | 宸插畬鎴 | +14 | 鏁屾満鐐脊澶勭悊 | 10 | 10 | 宸插畬鎴 | +15 | 琚晫鏈哄嚮涓鐞嗭紙鐐告瘉銆3鏉″懡锛 | 10 | 5 | 宸插畬鎴 | +16 | 杩囧叧鎺у埗锛堣繃鍏抽渶瑕佽鍒嗐佹父鎴忛熷害鎺у埗锛墊 20 | 5 | 宸插畬鎴 | +17 | 鍑虹幇boss | 5 | 10 | 宸插畬鎴 | +18 | 閫夋嫨瀛愬脊 | 2 | 10 | 宸插畬鎴 | +19 | 涓婁笅绉诲姩 | 2 | 1 | 宸插畬鎴 | +20 |娣诲姞鑳屾櫙鍜屾姞鍥 | 5 | 5 | 宸插畬鎴 | +鍚堣 | | 117 | 88 | 宸插畬鎴 | + + diff --git a/cpp level1 11/game.cpp b/cpp level1 11/game.cpp new file mode 100644 index 00000000..c335b5aa --- /dev/null +++ b/cpp level1 11/game.cpp @@ -0,0 +1,108 @@ + #include "stdafx.h" + #include "Plane.h" + #include "game.h" + #include "EnemyBurst.h" + #include "StrUpdate.h" + #include "StartMenu.h" + #include "HelpMenu.h" + #include "AgainMenu.h" + #include "BossBurst.h" +sf::RenderWindow mainWindow; + +MusicPlay musicPlay; + +void Game::play() +{ + + Plane plane(width, height); + NormalBullet bullet[bulnumber]; + MultiBullet multiBullet[multionce*multinumber]; + Enemy enemy[enenumber]; + EnemyBurst enemyBurst[enenumber]; + Boss boss[bossnumber]; + BossBurst bossBurst[bossnumber]; + ObjectManager manager; + + musicPlay.GameMusic(); + //第一处声音 + + while (StartMenu::number==0&&StrUpdate::life>0) + { + + mainWindow.clear(); + manager.BackgroundUpdate(); + manager.PlaneUpdate(plane); + + manager.BulletUpdate(bullet); + manager.MultiBulletUpdate(multiBullet); + manager.EnemyUpdate(enemy); + manager.EnemyBurstUpdate(enemyBurst,bullet,multiBullet,enemy); + manager.BossUpdate(boss); + manager.BossBurstUpdate(bossBurst,bullet,multiBullet,boss); + StrUpdate::update(); + LevelControl::Change(); + mainWindow.display(); + } +} + +void Game::start() +{ + if (StartMenu::number == -1) + { + mainWindow.create(sf::VideoMode(width, height, 32), "PlaneGame!"); + StartMenu start; + start.Draw(); + mainWindow.display(); + start.Choose(); + } +} + +void Game::help() +{ + if (StartMenu::number == 1) + { + HelpMenu help; + help.Draw(); + mainWindow.display(); + help.Choose(); + } +} + +void Game::again() +{ + if (StartMenu::number != 2) + { + AgainMenu again; + again.Draw(); + mainWindow.display(); + musicPlay.AgainMusic(); + again.Choose(); + + } +} + +int Game::head = 0; +int Game::tail = 0; +int Game::flag = 1; +bool Game::empty = true; + +int Game::mhead = 0; +int Game::mtail = 0; +int Game::mflag = 1; +bool Game::mempty = true; + +int Game::ehead = 0; +int Game::etail = 0; +bool Game::eempty = true; + +int Game::ebhead = 0; +int Game::ebtail = 0; +bool Game::ebempty = true; + +int Game::bhead = 0; +int Game::btail = 0; +bool Game::bempty = true; + +int Game::bbhead = 0; +int Game::bbtail = 0; +bool Game::bbempty = true; diff --git a/cpp level1 11/game.h b/cpp level1 11/game.h new file mode 100644 index 00000000..d3c8ad4b --- /dev/null +++ b/cpp level1 11/game.h @@ -0,0 +1,50 @@ +#pragma once +#include "stdafx.h" +#include 。 +#include "Plane.h" +#include "NormalBullet.h" +#include "ObjectManager.h" +#include "EnemyBullet.h" +#include "MusicPlay.h" +#define width 1224 +#define height 800 + +class Game +{ +public: + static int head ; + static int tail ; + static int flag ; + static bool empty; + + static int mhead; + static int mtail; + static int mflag; + static bool mempty; + + static int ehead; + static int etail; + static bool eempty; + + static int ebhead; + static int ebtail; + static bool ebempty; + + static int bhead; + static int btail; + static bool bempty; + + static int bbhead; + static int bbtail; + static bool bbempty; + + sf::Clock clock1; + + float time = 0; + float timeDelta = 0; + int menuMark = 0; + void play(); + void start(); + void help(); + void again(); +}; diff --git a/cpp level1 11/images/BossExplode1.png b/cpp level1 11/images/BossExplode1.png new file mode 100644 index 00000000..60517fb6 Binary files /dev/null and b/cpp level1 11/images/BossExplode1.png differ diff --git a/cpp level1 11/images/BossExplode2.png b/cpp level1 11/images/BossExplode2.png new file mode 100644 index 00000000..908afba9 Binary files /dev/null and b/cpp level1 11/images/BossExplode2.png differ diff --git a/cpp level1 11/images/BossExplode3.png b/cpp level1 11/images/BossExplode3.png new file mode 100644 index 00000000..7f1b1db5 Binary files /dev/null and b/cpp level1 11/images/BossExplode3.png differ diff --git a/cpp level1 11/images/BossExplode4.png b/cpp level1 11/images/BossExplode4.png new file mode 100644 index 00000000..669b5a51 Binary files /dev/null and b/cpp level1 11/images/BossExplode4.png differ diff --git a/cpp level1 11/images/MainMenu.png b/cpp level1 11/images/MainMenu.png new file mode 100644 index 00000000..4742f463 Binary files /dev/null and b/cpp level1 11/images/MainMenu.png differ diff --git a/cpp level1 11/images/background.jpg b/cpp level1 11/images/background.jpg new file mode 100644 index 00000000..1c2409d0 Binary files /dev/null and b/cpp level1 11/images/background.jpg differ diff --git a/cpp level1 11/images/boss.png b/cpp level1 11/images/boss.png new file mode 100644 index 00000000..f680c11a Binary files /dev/null and b/cpp level1 11/images/boss.png differ diff --git a/cpp level1 11/images/bossExplode0.png b/cpp level1 11/images/bossExplode0.png new file mode 100644 index 00000000..a7590e5b Binary files /dev/null and b/cpp level1 11/images/bossExplode0.png differ diff --git a/cpp level1 11/images/bullet1.png b/cpp level1 11/images/bullet1.png new file mode 100644 index 00000000..ec451c58 Binary files /dev/null and b/cpp level1 11/images/bullet1.png differ diff --git a/cpp level1 11/images/bullet2.png b/cpp level1 11/images/bullet2.png new file mode 100644 index 00000000..6a1a8c6c Binary files /dev/null and b/cpp level1 11/images/bullet2.png differ diff --git a/cpp level1 11/images/bullet3.png b/cpp level1 11/images/bullet3.png new file mode 100644 index 00000000..cb71da75 Binary files /dev/null and b/cpp level1 11/images/bullet3.png differ diff --git a/cpp level1 11/images/end.png b/cpp level1 11/images/end.png new file mode 100644 index 00000000..e7a07af1 Binary files /dev/null and b/cpp level1 11/images/end.png differ diff --git a/cpp level1 11/images/enemyExplode0.PNG b/cpp level1 11/images/enemyExplode0.PNG new file mode 100644 index 00000000..824c139e Binary files /dev/null and b/cpp level1 11/images/enemyExplode0.PNG differ diff --git a/cpp level1 11/images/enemyExplode1.PNG b/cpp level1 11/images/enemyExplode1.PNG new file mode 100644 index 00000000..b1487e84 Binary files /dev/null and b/cpp level1 11/images/enemyExplode1.PNG differ diff --git a/cpp level1 11/images/enemyExplode2.PNG b/cpp level1 11/images/enemyExplode2.PNG new file mode 100644 index 00000000..f1d4809a Binary files /dev/null and b/cpp level1 11/images/enemyExplode2.PNG differ diff --git a/cpp level1 11/images/help.png b/cpp level1 11/images/help.png new file mode 100644 index 00000000..17fa05bc Binary files /dev/null and b/cpp level1 11/images/help.png differ diff --git a/cpp level1 11/images/plane1.png b/cpp level1 11/images/plane1.png new file mode 100644 index 00000000..a94f02e2 Binary files /dev/null and b/cpp level1 11/images/plane1.png differ diff --git a/cpp level1 11/images/plane2.png b/cpp level1 11/images/plane2.png new file mode 100644 index 00000000..bc9abf2f Binary files /dev/null and b/cpp level1 11/images/plane2.png differ diff --git a/cpp level1 11/images/start.png b/cpp level1 11/images/start.png new file mode 100644 index 00000000..7ce1fdeb Binary files /dev/null and b/cpp level1 11/images/start.png differ diff --git a/cpp level1 11/main.cpp b/cpp level1 11/main.cpp new file mode 100644 index 00000000..b1a587e2 --- /dev/null +++ b/cpp level1 11/main.cpp @@ -0,0 +1,22 @@ +// 飞机.cpp : 定义控制台应用程序的入口点。 +// +#include "stdafx.h" +#include "game.h" +#include "StartMenu.h" + + + + +int main() +{ + Game game; + game.start(); + game.help(); + while (StartMenu::number != 2) + { + game.play(); + game.again(); + } + return 0; +} + diff --git a/cpp level1 11/sound/achievement.ogg b/cpp level1 11/sound/achievement.ogg new file mode 100644 index 00000000..1d459c28 Binary files /dev/null and b/cpp level1 11/sound/achievement.ogg differ diff --git a/cpp level1 11/sound/big_spaceship_flying.ogg b/cpp level1 11/sound/big_spaceship_flying.ogg new file mode 100644 index 00000000..98cc00cd Binary files /dev/null and b/cpp level1 11/sound/big_spaceship_flying.ogg differ diff --git a/cpp level1 11/sound/bullet.ogg b/cpp level1 11/sound/bullet.ogg new file mode 100644 index 00000000..175f5b01 Binary files /dev/null and b/cpp level1 11/sound/bullet.ogg differ diff --git a/cpp level1 11/sound/button.ogg b/cpp level1 11/sound/button.ogg new file mode 100644 index 00000000..87de5ddf Binary files /dev/null and b/cpp level1 11/sound/button.ogg differ diff --git a/cpp level1 11/sound/enemy1_down.ogg b/cpp level1 11/sound/enemy1_down.ogg new file mode 100644 index 00000000..7023b908 Binary files /dev/null and b/cpp level1 11/sound/enemy1_down.ogg differ diff --git a/cpp level1 11/sound/enemy2_down.ogg b/cpp level1 11/sound/enemy2_down.ogg new file mode 100644 index 00000000..725c0847 Binary files /dev/null and b/cpp level1 11/sound/enemy2_down.ogg differ diff --git a/cpp level1 11/sound/enemy3_down.ogg b/cpp level1 11/sound/enemy3_down.ogg new file mode 100644 index 00000000..d7e982c8 Binary files /dev/null and b/cpp level1 11/sound/enemy3_down.ogg differ diff --git a/cpp level1 11/sound/explode.OGG b/cpp level1 11/sound/explode.OGG new file mode 100644 index 00000000..bf7e12d7 Binary files /dev/null and b/cpp level1 11/sound/explode.OGG differ diff --git a/cpp level1 11/sound/game_music.ogg b/cpp level1 11/sound/game_music.ogg new file mode 100644 index 00000000..9ef2e180 Binary files /dev/null and b/cpp level1 11/sound/game_music.ogg differ diff --git a/cpp level1 11/sound/gameover.OGG b/cpp level1 11/sound/gameover.OGG new file mode 100644 index 00000000..df3ec59a Binary files /dev/null and b/cpp level1 11/sound/gameover.OGG differ diff --git a/cpp level1 11/sound/get_bomb.ogg b/cpp level1 11/sound/get_bomb.ogg new file mode 100644 index 00000000..336a4c6c Binary files /dev/null and b/cpp level1 11/sound/get_bomb.ogg differ diff --git a/cpp level1 11/sound/get_double_laser.ogg b/cpp level1 11/sound/get_double_laser.ogg new file mode 100644 index 00000000..50d4a404 Binary files /dev/null and b/cpp level1 11/sound/get_double_laser.ogg differ diff --git a/cpp level1 11/sound/out_porp.ogg b/cpp level1 11/sound/out_porp.ogg new file mode 100644 index 00000000..1e20b584 Binary files /dev/null and b/cpp level1 11/sound/out_porp.ogg differ diff --git a/cpp level1 11/sound/use_bomb.ogg b/cpp level1 11/sound/use_bomb.ogg new file mode 100644 index 00000000..2e2adc77 Binary files /dev/null and b/cpp level1 11/sound/use_bomb.ogg differ diff --git a/cpp level1 11/stdafx.cpp b/cpp level1 11/stdafx.cpp new file mode 100644 index 00000000..1747da69 --- /dev/null +++ b/cpp level1 11/stdafx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : 只包括标准包含文件的源文件 +// 飞机.pch 将作为预编译头 +// stdafx.obj 将包含预编译类型信息 + +#include "stdafx.h" + +// TODO: 在 STDAFX.H 中引用任何所需的附加头文件, +//而不是在此文件中引用 diff --git a/cpp level1 11/stdafx.h b/cpp level1 11/stdafx.h new file mode 100644 index 00000000..1d95a19a --- /dev/null +++ b/cpp level1 11/stdafx.h @@ -0,0 +1,34 @@ +// stdafx.h : 标准系统包含文件的包含文件, +// 或是经常使用但不常更改的 +// 特定于项目的包含文件 +// + +#pragma once + +#include "targetver.h" + +#include +#include + + + +// TODO: 在此处引用程序需要的其他头文件 + + #include + #include + #include + #include + + #include + #include + #include + #include "windows.h" + #include "time.h" + + + +#define bulnumber 10 +#define enenumber 5 +#define bossnumber 10 + + \ No newline at end of file diff --git a/cpp level1 11/targetver.h b/cpp level1 11/targetver.h new file mode 100644 index 00000000..416cebf8 --- /dev/null +++ b/cpp level1 11/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。 + +// 如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并将 +// 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。 + +#include diff --git a/game.cpp b/game.cpp new file mode 100644 index 00000000..8c4e9ce4 --- /dev/null +++ b/game.cpp @@ -0,0 +1,25 @@ + #include "stdafx.h" + #include "Plane.h" + #include "game.h" +sf::RenderWindow mainWindow; +void Game::play() +{ + mainWindow.create(sf::VideoMode(width, height, 32), "PlaneGame!"); + Plane plane(width, height); + Bullet bullet[bulnumber]; + ObjectManager manager; + while (1) + { + mainWindow.clear(); + manager.PlaneUpdate(plane); + manager.BulletUpdate(bullet); + mainWindow.display(); + } +} + + + +int Game::head = 0; +int Game::tail = 0; +int Game::flag = 1; +bool Game::empty = true; \ No newline at end of file diff --git a/game.h b/game.h new file mode 100644 index 00000000..e789f0f8 --- /dev/null +++ b/game.h @@ -0,0 +1,24 @@ +#pragma once +#include 。 +#include "Plane.h" +#include "Bullet.h" +#include "ObjectManager.h" +#include "stdafx.h" +#define width 1024 +#define height 770 + +class Game +{ +public: + static int head ; + static int tail ; + static int flag ; + static bool empty ; + sf::Clock clock1; + + float time = 0; + float timeDelta = 0; + + void play(); + bool FullOrEmpty(int i); +}; diff --git a/level1 1.c b/level1 1.c new file mode 100644 index 00000000..54485129 --- /dev/null +++ b/level1 1.c @@ -0,0 +1,29 @@ +#include +#include +#include + + +int main() { + system("mode con cols=80 lines=20"); + int x = 0, y = 0, mark = 0; + while (1) + { + int i; + for (i = 0; i < x; i++) + { + printf(" "); + } + printf("r"); + (mark % 2 == 0) ? x++ : x--; + if (x == 0 || x == 80) + { + mark++; + } + Sleep(30); + system("cls"); + + } + system("pause"); + return 0; +} + diff --git a/level1 10.c b/level1 10.c new file mode 100644 index 00000000..ac425053 --- /dev/null +++ b/level1 10.c @@ -0,0 +1,256 @@ +#include +#include +#include +#include +#define length1 9*13 +int judge_cho(char* judge,char**map); +int judge_star(char* judge, char**map); +void output_map(); +void game(); + +int main() +{ +# if 0 + output_map(); +# endif + game(); + system("pause"); + return 0; +} + +int judge_cho(char* judge,char **map) +{ + if (*judge == '1'&&(map[1][5] != 'o' || map[4][4] != 'o' || map[6][5] != 'o')) + { + return 1; + } + if (*judge == '2' && (map[2][2] != 'o' || map[3][3] != 'o')) + { + return 1; + } + return 0; + +} + +void output_map() { + + char map1[9][13] = { "############", + "#####* #####", + "##### #####", + "### o ###", + "### * So ###", + "### o ###", + "#####*######", + "##### ######", + "############" }; + + char map2[7][9] = { " ###### ", + " # ##", + "##*##o #", + "# *o #", + "# # #", + "# S ###", + "###### " }; + + FILE *wmap = fopen("E:\\map.dat", "w+b"); + if (!wmap) + { + printf("can't open the file"); + exit(1); + } + rewind(wmap); + fwrite(map1, sizeof(map1), 1, wmap); + fwrite(map2, sizeof(map2), 1, wmap); + fclose(wmap); + +} +int judge_star(char* judge, char **map) +{ + if (*judge == '1' ) + { + if (map[1][5] == ' ') + map[1][5] = '*'; + if (map[4][4] == ' ') + map[4][4] = '*'; + if (map[6][5] == ' ') + map[6][5] = '*'; + + } + if (*judge == '2') + { + if (map[2][2] == ' ') + { + + map[2][2] = '*'; + } + if (map[3][3] == ' ') + map[3][3] = '*'; + return 1; + } + return 0; +} +void game() +{ + FILE *rmap = fopen("E:\\map.dat", "r+b"); + if (!rmap) + { + printf("can't open the file"); + exit(1); + } + printf("Please choose the stage,1 or 2\n"); + printf("After game begin,input q to quit\n"); + printf("Use w a s d to move\n"); + + char **map = NULL; + char cho; + int row = 0, column = 0, x, y, flag = 1; + + cho = getchar(); + switch (cho) + { + case '1': + { + row = 9; column = 13; x = 4; y = 6; + map = (char**)calloc(row, sizeof(char*)); + map[0] = (char*)calloc(column*row, sizeof(char)); + //memset(map[0], '\0', column*row*sizeof(char));(malloc) + for (int i = 1; i < row; i++) + map[i] = map[i - 1] + column; + fseek(rmap, 0L, SEEK_SET); + fread(map[0], column * sizeof(char), row, rmap); + flag = 0; + for (int i = 0; i < row; i++) + printf("%s", map[i]); + break; + } + + case '2': + { + row = 7; column = 9; x = 5; y = 3; + map = (char**)calloc(row, sizeof(char*)); + map[0] = (char*)calloc(column*row, sizeof(char)); + //memset(map[0], '\0', column*row * sizeof(char)); + for (int i = 1; i < row; i++) + map[i] = map[i - 1] + column; + + fseek(rmap, 1L * length1, SEEK_SET); + fread(map[0], column * sizeof(char), row, rmap); + flag = 0; + break; + } + default: + printf("1 or 2 haven't been chosen"); + exit(0); + } + fclose(rmap); + + //pushbox + int dir[4][2] = { { -1,0, },{ 1,0 },{ 0,-1 },{ 0,1 } }; + int change_x = 0, change_y = 0; + char score[] = "100"; + while (judge_cho(&cho, map)) + { + system("cls"); + + + for (int i = 0; i < row; i++) + { + printf("%s\n", map[i]); + + } + printf("score:%s", score); + + + char ch = getch(); + switch (ch) { + case 'w': + change_x = dir[0][0]; + change_y = dir[0][1]; + break; + case 's': + change_x = dir[1][0]; + change_y = dir[1][1]; + break; + case 'a': + change_x = dir[2][0]; + change_y = dir[2][1]; + break; + case'd': + change_x = dir[3][0]; + change_y = dir[3][1]; + break; + case'q': + exit(0); + + } + if (map[x + change_x][y + change_y] == 'o'&&map[x + change_x * 2][y + change_y * 2] == ' ') + { + map[x + change_x][y + change_y] = 'S'; + map[x + change_x * 2][y + change_y * 2] = 'o'; + } + else if (map[x + change_x][y + change_y] == ' ') + { + map[x + change_x][y + change_y] = 'S'; + } + else if (map[x + change_x][y + change_y] == '*') + { + map[x + change_x][y + change_y] = 'S'; + } + else if (map[x + change_x][y + change_y] == 'o'&&map[x + change_x * 2][y + change_y * 2] == '*') + { + map[x + change_x][y + change_y] = 'S'; + map[x + change_x * 2][y + change_y * 2] = 'o'; + } + else + { + continue; + } + map[x][y] = ' '; + judge_star(&cho, map); + x = x + change_x; + y = y + change_y; + if (score[2] != '0') + { + score[2]--; + } + else if (score[2] == '0'&&score[1] != '0') + { + score[2] = '9'; + score[1]--; + } + else if (score[0] != '0') + { + score[2] = '9'; + score[1] = '9'; + score[0]--; + } + else + { + printf("game over"); + exit(0); + } + } + system("cls"); + + for (int i = 0; i < row; i++) + { + printf("%s\n", map[i]); + + } + //output result and send score into document + printf("score:%s\n", score); + printf("you win!!"); + FILE *pmap = fopen("E:\\map.dat", "a+b"); + if (!pmap) + { + printf("can't open the file"); + exit(1); + } + fseek(pmap, 0L, SEEK_END); + fwrite(score,sizeof(score), 1, pmap); + fclose(pmap); + + free(map[0]); + free(map); + +} diff --git a/level1 11.c b/level1 11.c new file mode 100644 index 00000000..652718de --- /dev/null +++ b/level1 11.c @@ -0,0 +1,112 @@ +#include +#include +typedef struct node{ + int value = 0; + node* next=NULL; +}node; +void print_list(node*head,int num); +void input_list(node*head, int num); +node* reverse(node*head, int num); +int find_five(node*head,int num,int flag); +int main() +{ + node *head=NULL, *p, *q,*tail; + int num; + scanf("%d", &num); + for (int i = 0; i < num; i++) + { + p = (node*)malloc(sizeof(node)); + if (head == NULL) + { + head = p; + } + else + { + q->next = p; + } + q = p; + } + + node *seek = head; + input_list(head, num); + print_list(head, num); + head=reverse(head, num); + print_list(head, num); + + int position1=find_five(head, num,0); + printf("position:%d\n", position1); + + int position2 = find_five(head, num, 1); + printf("position:%d\n", position2); + system("pause"); + return 0; +} + +void init_list(node*head, int num) +{ + +} +int find_five(node*head,int num,int flag) +{ + + node *seek = head; + int mark = 0; + for (int i = 0; i < num; i++) + { + if (seek->value == 5 ) + { + if (mark == flag) + { + return i; + } + mark++; + } + seek = seek->next; + } + return -1; +} + +void print_list(node*head, int num) +{ + node *seek = head; + for (int i = 0; i < num; i++) + { + printf("%d ", seek->value); + seek = seek->next; + } + printf("\n"); +} + +void input_list(node*head, int num) +{ + node *seek = head; + for (int i = 0; i < num; i++) + { + scanf("%d", &(seek->value)); + seek = seek->next; + } +} + +node* reverse(node*head, int num) +{ + node *seek = head; + node *former = head, *latter; + for (int i = 0;; i++) + { + if (seek == head) + { + seek = seek->next; + continue; + } + latter = seek->next; + seek->next = former; + former = seek; + seek = latter; + if (i == num - 1) + { + head = former; + break; + } + } + return head; +} diff --git a/level1 12.c b/level1 12.c new file mode 100644 index 00000000..60e08171 --- /dev/null +++ b/level1 12.c @@ -0,0 +1,160 @@ +#include +#include +#include +#include +#define MAX 5 +typedef struct Good { + char size[101] = ""; + int num = 0; +}good; +int mark_del(int*book); +void printf_goodlist(int *ptr,good* temp_good); +void del_goodlist(int *ptr, good* temp_good); +void add_goodlist(int *ptr, good* temp_good); +int main() +{ + int index = 0; + good temp_good[MAX]; + int *ptr = &index; + + printf_goodlist(ptr, temp_good); + + printf("input 1,2 or 3\n"); + printf("1:printf goodlist\n"); + printf("2:add goods size and number into the warehouse\n"); + printf("3:delete from the warehouse\n"); + printf("q to quit\n"); + + while (1) + { + printf("go ahead!\n"); + char ch = getchar(); + system("cls"); + switch (ch) + { + case '1': + { + printf("printf goodlist\n"); + printf_goodlist(ptr, temp_good); + getchar(); + break; + } + case '2': + { + + printf("add goods size and number into the warehouse\n"); + printf("click enter(once)+ctrl+z + enter(twice) to finish \n"); + add_goodlist(ptr, temp_good); + break; + } + case'3': + { + printf("delete from the warehouse\n"); + printf("input the index of goods you want to delete add ctrl+z(before enter) at last"); + del_goodlist(ptr, temp_good); + break; + } + case 'q': exit(0); + default: { + printf("you should input 1,2 or 3\n"); + } + + } + } + system("pause"); + return 0; +} + +void printf_goodlist(int *ptr, good* temp_good) +{ + *ptr = 0; + FILE *rgood = fopen("E:\\good.dat", "r+b"); + if (!rgood) + { + printf("can't open the file"); + exit(1); + } + + char c; + fseek(rgood, 0, SEEK_SET); + while (!feof(rgood)) { + if ((c = fgetc(rgood)) == EOF) + { + break; + } + fread(temp_good, sizeof(good), 1, rgood); + (*ptr)++; + } + fseek(rgood, 0, SEEK_SET); + fread(temp_good, sizeof(good), *ptr, rgood); + int temp_index = *ptr; + fclose(rgood); + for (int i = 0; i < *ptr; i++) + { + printf("%s %d\n", temp_good[i].size, temp_good[i].num); + } +} + +int mark_del(int*book) +{ + int j,sum = 0; + fflush(stdin); + while (scanf("%d", &j) == 1) + { + book[j] = 1; + sum++; + } + return sum; +} + + + +void del_goodlist(int *ptr, good* temp_good) +{ + int book[MAX] = { 0 }; + int total = (*ptr) - mark_del(book); + good change_good[MAX]; + for (int i = 0, j = 0; i < total; ) + { + if (book[j] == 0) + { + change_good[i++] = temp_good[j++]; + } + else + { + j++; + } + } + FILE *rwgood = fopen("E:\\good.dat", "w+b"); + if (!rwgood) + { + printf("can't open the file"); + exit(1); + } + fseek(rwgood, 0, SEEK_SET); + fwrite(change_good, sizeof(good), total, rwgood); + fclose(rwgood); + getchar(); +} + +void add_goodlist(int *ptr, good* temp_good) +{ + FILE *wgood = fopen("E:\\good.dat", "w+b"); + if (!wgood) + { + printf("can't open the file"); + exit(1); + } + while (*ptr < MAX && 2 == scanf("%s %d", &temp_good[*ptr].size, &temp_good[*ptr].num) ) + { + (*ptr)++; + } + if (*ptr == MAX ) + { + printf("the warehouse is full\n"); + } + fseek(wgood, 0, SEEK_SET); + fwrite(temp_good, sizeof(good), *ptr, wgood); + fclose(wgood); + getchar(); +} diff --git a/level1 2.c b/level1 2.c new file mode 100644 index 00000000..5299fd88 --- /dev/null +++ b/level1 2.c @@ -0,0 +1,24 @@ +#include +#include +int main() +{ + int num, mark = 0, i; + printf("input a integer bigger than 2"); + scanf("%d", &num); + for (i = 2; i +#include +int main() +{ + for (float i = 0; i < 100; i++) + { + float as_child = i / 6; + float as_tee = i / 12; + float live_alone = i / 7; + float get_son = 5; + float son_live = i / 2; + if (as_child + as_tee + live_alone + get_son + son_live + 4 == i) + printf("%f", i); + } + system("pause"); + return 0; +} diff --git a/level1 4.c b/level1 4.c new file mode 100644 index 00000000..ecfe1eac --- /dev/null +++ b/level1 4.c @@ -0,0 +1,16 @@ +#include +#include +int main() +{ + int units, tens, hundreds; + for (int i = 100; i < 999; i++) + { + hundreds = i / 100; + tens = i / 10 %10; + units = i % 100 %10; + if (i == hundreds*hundreds*hundreds + tens*tens*tens + units*units*units) + printf("%d ", i); + } + system("pause"); + return 0; +} diff --git a/level1 5.c b/level1 5.c new file mode 100644 index 00000000..865f31a7 --- /dev/null +++ b/level1 5.c @@ -0,0 +1,26 @@ +#include +#include +#include +#include +int main(){ + printf("2 3 "); + double start, finish; + start = clock(); + for (int j = 2; j <= 1000; j++) + for (int i = 2; i <= sqrt(j); i++) + { + + if (j%i == 0) + { + break; + } + if (i == (int)sqrt(j)) + { + printf("%d ",j); + } + } + finish = clock(); + printf(" %f seconds\n", (finish - start) / CLOCKS_PER_SEC); + system("pause"); + return 0; +} diff --git a/level1 6.c b/level1 6.c new file mode 100644 index 00000000..53e84c80 --- /dev/null +++ b/level1 6.c @@ -0,0 +1,47 @@ +#include +#include +#include +void Goldbach(); + +int main() +{ + Goldbach(); + system("pause"); + return 0; +} + +void Goldbach() { + int mark_prime1 = 0, mark_prime2 = 0; + for (int i = 2; i <= 100; i = i + 2) + for (int j = 2; j < i; j++) + { + for (int k = 2; k <= sqrt(j); k++) + { + mark_prime1 = 0; + if (j%k == 0) + { + mark_prime1 = 1; + break; + } + + } + if (mark_prime1 == 0) + { + int ano_pri = i - j; + for (int k = 2; k <= sqrt(ano_pri); k++) + { + mark_prime2 = 0; + if (ano_pri%k == 0) + { + mark_prime2 = 1; + break; + } + } + if (mark_prime2 == 0) + { + printf("%d+%d=%d ", j, ano_pri, i); + } + + } + } +} diff --git a/level1 7.c b/level1 7.c new file mode 100644 index 00000000..b5195f05 --- /dev/null +++ b/level1 7.c @@ -0,0 +1,120 @@ +//vigenere cipher +#include +#include +#include +#include +#define x "plaintext" +#define y "key" +#define z "ciphertext" +char select(); +void encryption(); +void decryption(); +int main() +{ + + + while (1) + { + char ch = select(); + + switch (ch) + { + case'a':printf("let's go to encryption\n"); + { + encryption(); + break; + } + case'b':printf("let's go to decryption\n"); + { + decryption(); + break; + } + case'q':return 0; + default: + { + printf("try again\n"); + continue; + } + + + } + } + system("pause"); + return 0; +} +char select() +{ + int ch; + printf("make a choice\n" + "a encryption b decryption\n" + "q quit\n"); + ch = getchar(); + while (getchar() != '\n') + continue; + return ch; +} + +void encryption() +{ + char text[101] = "\0", key[101]; + printf("please input %s:", x); + gets(text); + for (int i = 0; i < strlen(text); i++)//input a b,change into lower case + { + text[i] = tolower(text[i]); + } + + printf("please input %s:", y); + gets(key); + for (int i = 0; i < strlen(key); i++) + { + key[i] = tolower(key[i]); + } + if (strlen(text) < strlen(key)) + { + printf("key is longer than plaintext\n"); + return ; + } + + for (int i = 0,j = 0; text[i]; i++) + { + if (text[i] >= 'a'&&text[i] <= 'z') + { + text[i] = 'a' + (text[i] + (key[j%strlen(key)] - 'a') - 'a') % 26; + j++; + } + } + + printf("ciphertext"); + puts(text); + +} +void decryption() +{ + char text[101] = "\0", key[101]; + printf("please input %s:", z); + gets(text); + for (int i = 0; i= 'a'&&text[i] <= 'z') + { + text[i] = 'a' + (text[i] - (key[j%strlen(key)] - 'a') + 26-'a') % 26; + j++; + } + } + printf("plaintext"); + puts(text); +} diff --git a/level1 8.c b/level1 8.c new file mode 100644 index 00000000..350997a4 --- /dev/null +++ b/level1 8.c @@ -0,0 +1,75 @@ +#include +#include +#include +int main() +{ + int n; + scanf("%d",&n); + char** result = ((char**)calloc((int)pow(2, n),sizeof(char*))); + for (int i = 0; i <(int)pow(2,n); i++) + { + result[i] = (char*)calloc(2, sizeof(char)); + } + result[1][0] = 'a'; + result[1][1] = 'c'; + for (int i = 2; i <= n ; i++) + { + int x = (int)pow(2, i - 1) ; + result[x][0] = 'a'; + result[x][1] = 'c'; + for (int j = 1; j < x; j++) //a b c ->a c b + { + if (result[j][0] == 'c') + { + result[j][0] = 'b'; + } + else if (result[j][0] == 'b') + { + result[j][0] = 'c'; + } + if (result[j][1] == 'b') + { + result[j][1] = 'c'; + } + else if (result[j][1] == 'c') + { + result[j][1] = ' b'; + } + } + for (int j = x + 1; j <= 2 * x-1; j++)//a c b ->b a c + { + if (result[j - x][0] == 'a') + { + result[j][0] = 'b'; + } + else if (result[j - x][0] == 'b') + { + result[j][0] = 'c'; + } + else + { + result[j][0] = ' a'; + } + if (result[j - x][1] == 'a') + { + result[j][1] = ' b'; + } + else if (result[j - x][1] == 'b') + { + result[j][1] = ' c'; + } + else + { + result[j][1] = ' a'; + } + } + } + for (int i = 1; i < (int)pow(2, n); i++) + { + printf("%c->%c\n", result[i][0], result[i][1]); + free(result[i]); + } + free(result); + system("pause"); + return 0; +} diff --git a/level1 9.c b/level1 9.c new file mode 100644 index 00000000..0ed550c9 --- /dev/null +++ b/level1 9.c @@ -0,0 +1,62 @@ +#include +#include +#include +int main() +{ + char map[9][13] = { "############", + "S ## ###", + "# #######", + "## #########", + "## #### ", + "## #### ####", + "## #### ####", + "## ####", + "############" }; + + + int dir[4][2] = { { -1,0, },{ 1,0 },{ 0,-1 },{ 0,1 } }; + int x = 1, y = 0, change_x = 0, change_y = 0; + while (map[4][11] != 'S') + { + system("cls"); + for (int i = 0; i < 9; i++) + { + printf("%s\n", map[i]); + } + char ch = getch(); + switch (ch) { + case 'w': + change_x = dir[0][0]; + change_y = dir[0][1]; + break; + case 's': + change_x = dir[1][0]; + change_y = dir[1][1]; + break; + case 'a': + change_x = dir[2][0]; + change_y = dir[2][1]; + break; + case'd': + change_x = dir[3][0]; + change_y = dir[3][1]; + break; + } + + if (map[x + change_x][y + change_y] == ' ') + { + map[x + change_x][y + change_y] = 'S'; + map[x][y] = ' '; + x = x + change_x; + y = y + change_y; + } + } + system("cls"); + for (int i = 0; i < 9; i++) + { + printf("%s\n", map[i]); + } + printf("you win!!"); + system("pause"); + return 0; +} diff --git a/practices/c/level1/p10_pushBoxes/README.md b/practices/c/level1/p10_pushBoxes/README.md index 4419d7ad..e8de0368 100755 --- a/practices/c/level1/p10_pushBoxes/README.md +++ b/practices/c/level1/p10_pushBoxes/README.md @@ -1,4 +1,4 @@ -### 棰樼洰锛氭帹绠卞瓙灏忔父鎴忥紙鍩轰簬console锛 +锘### 棰樼洰锛氭帹绠卞瓙灏忔父鎴忥紙鍩轰簬console锛 ### 鍔熻兘瑕佹眰锛 @@ -6,4 +6,6 @@ 2. 鍦ㄥ湴鍥句腑澧炲姞绠卞瓙銆佺瀛愮洰鏍囦綅缃瓑鍥惧舰锛 3. 褰撶帺瀹跺皢鎵鏈夌瀛愬綊浣嶏紝鍒欐樉绀虹帺瀹惰耽寰椾簡娓告垙锛 4. 鎸夌帺瀹惰蛋鍔ㄦ鏁拌鍒嗭紱 -5. 璁捐澶氫釜鍏冲崱锛屾瘡涓鍏崇殑鍦板浘浠庢枃浠朵腑璇诲彇锛岀帺瀹舵瘡鍏崇殑鍒嗘暟璁板綍鍒版枃浠朵腑锛 \ No newline at end of file +5. 璁捐澶氫釜鍏冲崱锛屾瘡涓鍏崇殑鍦板浘浠庢枃浠朵腑璇诲彇锛岀帺瀹舵瘡鍏崇殑鍒嗘暟璁板綍鍒版枃浠朵腑锛 + +