Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

郭家瑞 打飞机游戏 完成 #7

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@ Generated\ Files/
.builds
*.pidb
*.svclog
*.scc
*.scc
*.sln
*.vcxproj
*.filters
*.user
3 changes: 3 additions & 0 deletions .vs/ProjectSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": null
}
6 changes: 6 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ExpandedNodes": [
""
],
"PreviewInSolutionExplorer": false
}
Binary file added .vs/shiyan/v16/.suo
Binary file not shown.
Binary file added .vs/slnx.sqlite
Binary file not shown.
53 changes: 53 additions & 0 deletions level1/homework/homework1/homework1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include<stdio.h>
#include<Windows.h>
//郭家瑞 2020080901015
int CurrentCursorPositionX()
{
int a = 0;
HANDLE hStdout;
CONSOLE_SCREEN_BUFFER_INFO pBuffer;
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hStdout, &pBuffer);
a = pBuffer.dwCursorPosition.X;
return a;
}
int CurrentCursorPositionY()
{
int b = 0;
HANDLE hStdout;
CONSOLE_SCREEN_BUFFER_INFO pBuffer;
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hStdout, &pBuffer);
b = pBuffer.dwCursorPosition.Y;
return b;
}
int main()
{
char a = 'a';
int i = 1, n = 1;
int x = 0, endX = 1, endY = 0;
bool b = true;
while (1)
{
if (b) n++;
else n--;
while (i < n)
{
i++;
printf(" ");
}
i = 1;
x = CurrentCursorPositionX();
printf("%c", a);
endX = CurrentCursorPositionX();
endY = CurrentCursorPositionY();
if (endX == x || endY >= 1) b = false;
if (endX == 1 && endY == 0) b = true;
Sleep(300);
system("cls");
}
return 0;
}



165 changes: 165 additions & 0 deletions level1/homework/homework10/homework10.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<Windows.h>
#include<conio.h>

int main()
{
FILE* fp = NULL;
short readKey, currentX = 0, currentY = 0, endX[10], endY[10], t, rept, score;
char x[29][100] = { 0 }, buff[100], scoreString[4] = { 0 };
unsigned char numberOfLevel;
short Y, X;
fp = fopen("pushBoxes.txt", "r+");
numberOfLevel = fgetc(fp);//读取关卡数
fgets(buff, 255, (FILE*)fp);//忽略回车
while (1) {
fscanf(fp, "%s", buff);//读取行数
if (strlen(buff) == 1) {
Y = buff[0] - 48;
}
else if (strlen(buff) == 2) {
Y = (buff[0] - 48) * 10 + buff[1] - 48;
}
else {
fclose(fp);
return 0;
}
fscanf(fp, "%s", buff);//读取列数
if (strlen(buff) == 1) {
X = buff[0] - 48;
}
else if (strlen(buff) == 2) {
X = (buff[0] - 48) * 10 + buff[1] - 48;
}
else {
fclose(fp);
return 0;
}
fgets(buff, 255, (FILE*)fp);//忽略回车
t = -1;
for (int i = 0;i < Y;i++) {
fgets(buff, 255, (FILE*)fp);
for (int j = 0;j < strlen(buff);j++) {
x[i][j] = buff[j];//读取关卡地图
if (x[i][j] == 'l') {//记录玩家初始位置
currentY = i;
currentX = j;
}
if (x[i][j] == 'P') {//记录箱子终点
t++;//记录箱子终点数目
endY[t] = i;
endX[t] = j;
}
}
}
rept = t;
score = t * 30 + 30;
while (1) {
system("cls");
t = rept;
while (t >= 0) {//如果终点显示为空格,则使其显示P
if (x[endY[t]][endX[t]] == ' ')
x[endY[t]][endX[t]] = 'P';
t--;
}
x[currentY][currentX] = 'l';
for (int i = 0;i < Y + 1;)
printf("%s", x[i++]);
t = rept;
while (t >= 0) {
if (x[endY[t]][endX[t]] == 'o') {
t--;
}
else break;
}
score--;
if (t == -1) {
if (score < 0)score = 0;
itoa(score, scoreString, 10);//将分数转为字符串的形式
fseek(fp, -(Y * (X + 2) + 5), SEEK_CUR);
fputs(scoreString,fp);//写入分数
if (score >= 10 && score < 99)
fseek(fp, (Y * (X + 2) + 3), SEEK_CUR);
else if (score >= 0 && score < 10)
fseek(fp, (Y * (X + 2) + 4), SEEK_CUR);
else if (score >= 100)
fseek(fp, (Y * (X + 2) + 2), SEEK_CUR);
numberOfLevel--;
if (numberOfLevel > 48) {
printf("You are win,and then you will enter next level.\n");
printf("And you can put down any key to enter next level.\n");
system("pause");
break;
}
else {
printf("You cross all levels!");
fclose(fp);
return 0;
}
}
do {//控制玩家移动
readKey = getch();
switch (readKey) {
case 72:
if (currentY > 0) {
if (x[currentY - 1][currentX] == ' ' || x[currentY - 1][currentX] == 'P') {
x[currentY][currentX] = ' ';
currentY--;
}
else if (x[currentY - 1][currentX] == 'o' && x[currentY - 2][currentX] != 'X') {
x[currentY - 2][currentX] = 'o';
x[currentY][currentX] = ' ';
currentY--;
}
else readKey = 0;
}
break;
case 80:
if (currentY < Y) {
if (x[currentY + 1][currentX] == ' ' || x[currentY + 1][currentX] == 'P') {
x[currentY][currentX] = ' ';
currentY++;
}
else if (x[currentY + 1][currentX] == 'o' && currentY < Y - 1 && x[currentY + 2][currentX] != 'X') {
x[currentY + 2][currentX] = 'o';
x[currentY][currentX] = ' ';
currentY++;
}
else readKey = 0;
}
break;
case 75:
if (currentX > 0) {
if (x[currentY][currentX - 1] == ' ' || x[currentY][currentX - 1] == 'P') {
x[currentY][currentX] = ' ';
currentX--;
}
else if (x[currentY][currentX - 1] == 'o' && currentX > 1 && x[currentY][currentX - 2] != 'X') {
x[currentY][currentX - 2] = 'o';
x[currentY][currentX] = ' ';
currentX--;
}
else readKey = 0;
}
break;
case 77:
if (currentX < X + 1) {
if (x[currentY][currentX + 1] == ' ' || x[currentY][currentX + 1] == 'P') {
x[currentY][currentX] = ' ';
currentX++;
}
else if (x[currentY][currentX + 1] == 'o' && currentX < X && x[currentY][currentX + 2] != 'X') {
x[currentY][currentX + 2] = 'o';
x[currentY][currentX] = ' ';
currentX++;
}
else readKey = 0;
}
break;
}
} while (readKey != 72 && readKey != 80 && readKey != 75 && readKey != 77);
}
}
}
16 changes: 16 additions & 0 deletions level1/homework/homework10/pushBoxes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
2
6 17 scores:34
XXXXXXXXXXXXXXXXX
XXl XPX XXXX
XX oXX X Xo XXXX
XXXPXX XXXX
XXXXXX XXXXX
XXXXXXXXXXXXXXXXX
7 17 scores:14
XXXXXXXXXXXXXXXXX
XXl XPX X
XX oXX X Xo X
XX PXX X
X X
X X
XXXXXXXXXXXXXXXXX
63 changes: 63 additions & 0 deletions level1/homework/homework11/homework11.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include<stdio.h>
#include<stdlib.h>

struct LinkedList {
int num;
struct LinkedList* nextP;
int value;
};
LinkedList* first = NULL;
LinkedList* end = NULL;

int Find(LinkedList* first, int a, int num) {//查找指定第几个5
LinkedList* temp = first;
while (temp != NULL) {
temp = temp->nextP;
if (temp->value == a) {
num--;
if (num == 0)
return temp->num;
}
}
return -1;
}

int main() {
for (int i = 0;i < 10;i++) {//创建链表
LinkedList* temp =(LinkedList *)malloc(sizeof(LinkedList));
temp->num = i + 1;
temp->nextP = NULL;
temp->value = rand() % 10;
if (first == NULL) first = temp;
else end->nextP = temp;
end = temp;
}

LinkedList* temp = first;//遍历链表,显示value
while (temp != NULL) {
printf("%d %d\n",temp->num, temp->value);
temp = temp->nextP;
}

LinkedList* nomarl = first, * x = first, *change = first;//反序
while (1) {
x = change;
if (nomarl == first) {
end = nomarl;
nomarl = nomarl->nextP;
change->nextP = NULL;
}
change = nomarl;
if (nomarl->nextP != NULL){
nomarl = nomarl->nextP;
change->nextP = x;
}
else {
change->nextP = x;
first = change;
break;
}
}

}

35 changes: 35 additions & 0 deletions level1/homework/homework12/homework12.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include<stdio.h>
#include<stdlib.h>
#include"warehouse.h"

int main() {
int control = -1;
char buff[256];
FILE* fp = NULL, * temp = NULL;
printf("Menu\n\n");
printf("1:显示存货列表\n\n");
printf("2:入库\n\n");
printf("3:出库\n\n");
printf("4:退出程序\n\n");
while (1) {
printf("\n按数字键继续\n");
scanf("%d", &control);
printf("\n");
switch (control) {
case 1:
PrintWareHouse(fp, "warehouse.txt", buff, 256);
break;
case 2:
printf("再次按“0”以结束入库\n");
RepeatEnterHouse(fp, "warehouse.txt", '0', buff, 256);
break;
case 3:
printf("再次按“0”以结束出库\n");
RepeatExitHouse(fp, "warehouse.txt", '0', buff, 256);
break;
case 4:return 0;
default:printf("请输入1~4的数字\n");
}
}

}
Loading