社区讨论
自制神奇躲陨石小游戏Astroids
灌水区参与者 8已保存回复 11
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 11 条
- 当前快照
- 1 份
- 快照标识符
- @m09gc5ny
- 此快照首次捕获于
- 2024/08/25 18:54 2 年前
- 此快照最后确认于
- 2025/11/05 00:34 4 个月前
CPP
/* Copyright Flintmall, 2px Stuido. All rights reserved.*/
/* Astroids */
#include <iostream>
#include <conio.h>
#include <windows.h>
#include <ctime>
#include <algorithm>
using namespace std;
void setColor(int color){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),color);
return ;
}
int waitKey(){
int sum = 75;
while(sum--){
if(_kbhit()){
return getch();
}
_sleep(1);
}
}
int random(int x){
srand(time(0));
int m = rand() % x + 1;
return m;
}
void cls(){
system("cls");
return ;
}
char map[5][10] = {
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'}
};
int y = 2;
int turn;
int score;
bool flag = true;
int bullet = 1;
int canShoot;
int main(){
while(flag){
system("color F");
cout<<"Astroids - 躲避陨石罢!"<<endl;
cout<<"2px Games Studio"<<endl;
cout<<"W,S/I,J控制我方飞船,E/U发射子弹。"<<endl;
cout<<"分数:"<<score<<endl;
cout<<"子弹数:"<<bullet<<endl;
for(int i = 0;i < 5;i++){
for(int j = 0;j < 10;j++){
if(i == y && j == 0){
setColor(3);
cout<<'Y';
}
else{
if(map[i][j] == '.'){
setColor(8);
}
else if(map[i][j] == '-'){
setColor(4);
}
else{
setColor(7);
}
cout<<map[i][j];
}
}
cout<<endl;
}
int ch = waitKey();
if((char(ch) == 'w' || char(ch) == 'W' || char(ch) == 'i' || char(ch) == 'I') && y > 0){
y -= 1;
}
else if((char(ch) == 's' || char(ch) == 'S' || char(ch) == 'j' || char(ch) == 'J') && y < 4){
y += 1;
}
else if((char(ch) == 'e' || char(ch) == 'E' || char(ch) == 'u' || char(ch) == 'U') && bullet){
map[y][0] = '-';
bullet--;
}
if(!(turn)){
int ny = random(5);
map[ny - 1][9] = '@';
turn = 4;
if(score > 20){
int nx = random(random(5));
map[nx - 1][9] = '@';
if(score > 40){
int nz = random(random(random(5)));
map[nz - 1][8] = '@';
if(score > 60){
int nt = random(random(random(random(5))));
map[nt - 1][8] = '@';
if(score > 80){
int na = random(nt);
map[na - 1][7] = '@';
if(score > 100){
int nb = random(na);
map[nb - 1][7] = '@';
if(score > 120){
int nc = random(nb);
map[nc - 1][6] = '@';
if(score > 140){
int nd = random(nc);
map[nd - 1][6] = '@';
if(score >= 150){
break;
}
}
}
}
}
}
}
}
}
turn--;
canShoot++;
if(!(canShoot % 42) && bullet < 3){
bullet++;
}
for(int i = 0;i < 5;i++){
for(int j = 0;j < 10;j++){
if(map[i][j] == '@'){
if(j - 1 < 0){
map[i][j] = '.';
continue;
}
else if(i == y && j - 1 == 0){
flag = false;
break;
}
else if(map[i][j - 1] == '-'){
map[i][j] = '.';
map[i][j - 1] = '.';
}
swap(map[i][j],map[i][j - 1]);
}
else if(map[i][j] == '-'){
if(map[i][j + 1] == '@'){
map[i][j] = '.';
map[i][j + 1] = '.';
}
else if(j + 1 == 10){
map[i][j] = '.';
}
swap(map[i][j],map[i][j + 1]);
j++;
}
}
}
if(!(turn % 3) && turn){
score++;
}
cls();
}
cls();
system("color F");
if(score >= 150){
cout<<"你赢力!:D"<<endl;
}
else{
cout<<"你输辣!X("<<endl;
}
cout<<"最终得分:"<<score;
return score;
}
回复
共 11 条回复,欢迎继续交流。
正在加载回复...