跳到正文

MAC_001

2033515

威龙

在洛谷打开
资料、奖项与版本

资料

编号
2033515
抓取

陶片放逐

无权限变更

查看记录

//▞
#include <bits/stdc++.h>
#include <windows.h>
using namespace std;
struct bodyXY{
    int x;
    int y;
}bodyxy[401],temp1,temp2;
bool timeflag[21][21];
char temp='w';
int snakex=10,snakey=10,foodx,foody,snakelen=1;
void move(int x,int y){
    COORD coord={x,y};
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
int main(){
	srand(time(0));
	foodx=rand()%20+1;
	foody=rand()%20+1;
	while(1){
		printf("#####################\n");
		for(int i=1;i<=20;i++){
			printf("#                   #\n");
		}
		printf("#####################\n");
		if(snakex==foodx&&snakey==foody){
			snakelen++;
			foodx=rand()%19+1;
			foody=rand()%19+1;
		}else{
			move(foodx,foody);
			printf("@");
		}
		for(int i=1;i<=snakelen;i++){
			move(bodyxy[i].x,bodyxy[i].y);
			if(i==1){
				printf("0");
			}else{
				printf("+");
			}
		}
		for(int i=1;i<=300-snakelen*5;i++){
			if (GetKeyState('W') & 0x8000) {
	        	temp='W';
		    }
			if (GetKeyState('S') & 0x8000) {
			    temp='S';
			}
			if (GetKeyState('A') & 0x8000) {
		        temp='A';
	        }
	        if (GetKeyState('D') & 0x8000) {
	            temp='D';
	        }
	        Sleep(1);
    	}
        switch (temp){
			case 'W':
				snakey--;
				break;
			case 'S':
				snakey++;
				break;
			case 'A':
				snakex--;
				break;
			case 'D':
				snakex++;
				break;
		}
		if(snakex==0||snakex==20||snakey==0||snakey==20){
			system("cls");
			printf("game over! your score is %d",snakelen*10);
			return 0;
		}
		temp1=bodyxy[1],temp2;
		bodyxy[1]={snakex,snakey};
		for(int i=2;i<=snakelen+1;i++){
        	temp2=bodyxy[i],bodyxy[i]=temp1,temp1=temp2;
    	}
    	for(int i=1;i<=snakelen;i++){
        	move(bodyxy[i].x,bodyxy[i].y);
        	printf("+");
    	}
    	move(0,22);
		printf("score:%d",snakelen*10);
        system("cls");
	}
}
C++
#include <bits/stdc++.h>
#include <windows.h>
using namespace std;
void go(int x,int y){
	COORD coord={x,y};
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
int main(){
	int playerX=7,EmenySpawnTimer=5,EmenyMoveTimer=250,bulletX[13],bulletY[13],emenyX[13],emenyY[13],emenyTemp=1;
	memset(bulletY,0,sizeof(bulletY));
	memset(emenyY,0,sizeof(emenyY));
	srand(time(0));
	for(int i=1;;i++){
		cout<<"---------------\n";
		for(int j=1;j<=13;j++){
			cout<<"|             |\n";
		}
		cout<<"---------------\n";
		if((GetKeyState('A')&0x8000||GetKeyState('a')&0x8000)&&playerX>1){
			playerX--;
		}if((GetKeyState('D')&0x8000||GetKeyState('d')&0x8000)&&playerX<13){
			playerX++;
		}
		go(playerX,13);
		cout<<"A";
		bulletX[i%13]=playerX,bulletY[i%13]=12;
		for(int j=0;j<13;j++){
			if(bulletY[j]>0){
				go(bulletX[j],bulletY[j]);
				cout<<"^";
				bulletY[j]--;
			}
		}
		if(i%25==0&&EmenySpawnTimer>1){
			EmenySpawnTimer--;
		}
		if(i%EmenySpawnTimer==0){
			if(emenyTemp==13/EmenySpawnTimer){
				emenyTemp=0;
			}
			emenyX[emenyTemp]=rand()%13+1;
			emenyY[emenyTemp]=1;
			emenyTemp++;
		}
		for(int j=0;j<13;j++){
			if(emenyY[j]>0){
				if(emenyY[j]==13){
					system("cls");
					cout<<"游戏结束!得分:"<<i;
					system("pause");
					return 0;
				}
				for(int k=0;k<13;k++){
					if(bulletX[k]==emenyX[j]&&bulletY[k]==emenyY[j]){
						emenyY[j]=0;
					}
				}
				go(emenyX[j],emenyY[j]);
				cout<<"V"; 
				emenyY[j]++;
			}
		}
		go(0,15);
		cout<<"得分:"<<i;
		Sleep(EmenyMoveTimer);
		system("cls");
	}
	return 0;
}
代码
共 1 篇
  1. 休闲·娱乐

    打卡

    MAC_001 的运势\ § 中吉 §\ 宜:放假\ 自由自在的一个假期\ 宜:吃饭\ 人是铁饭是钢忌:去食堂\ 爱吃的菜刚被打完\ 忌:重构代码\ 越改越乱 \ 你已经在洛谷连续打卡了 404 天

    1 赞