//版本:1.03
#include<algorithm>
#include<iostream>
#include<stdio.h>
#include<iostream>
#include<windows.h>
#include<conio.h>
#include <time.h>
#include <stdlib.h>
int a=1;
int in=0;
using namespace std;
int g_map[5][10];
int mx;
int my;
int dx;
int dy;
char ms;
//kbhit()
//shuru=getch();
int out() {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
g_map[3][my]=6;
g_map[3][my]=6;
for(int i=-1; i<5; i++) {
for(int j=-1; j<11; j++) {
if(i==dx&&j==dy){
cout<<9;
}
else if(i==mx&&j==my){
cout<<6;
}
else if(i==1&&j==9){
cout<<1;
}
else if(i==-1||i==4){
cout<<"*";
}
else if(j==-1||j==10){
cout<<"*";
}
else{
cout<<" ";
}
}
cout<<endl;
}
}
int wl(){
if(mx<3&&my!=dy){
mx++;
}
}
int out2() {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
g_map[3][my]=6;
g_map[3][my]=6;
for(int i=-1; i<5; i++) {
for(int j=-1; j<11; j++) {
if(i==dx&&j==dy){
cout<<" ";
}
else if(i==mx&&j==my){
cout<<6;
}
else if(i==1&&j==9){
cout<<1;
}
else if(i==-1||i==4){
cout<<"*";
}
else if(j==-1||j==10){
cout<<"*";
}
else{
cout<<" ";
}
}
cout<<endl;
}
}
int robot() {
if(my>dy&&dy<9) {
dy++;
}
if(my<dy&&dy>0) {
dy--;
}
for(int i=0; i<5; i++) {
for(int j=0; j<5; j++) {
if(g_map[i][j]==9) {
g_map[i][j]=0;
}
}
}
g_map[3][dy]=9;
}
int play() {
char ch;
if(kbhit()) {
ch=getch();
if((ch=='w'||ch=='i')&&mx>2){
mx-=3;
}
if((ch=='e'||ch=='u')&&my<9-5) {
my+=5;
}
if((ch=='a'||ch=='j')&&my>0) {
my--;
}
if((ch=='d'||ch=='l')&&my<9) {
my++;
}
if(ch=='s'||ch=='k') {
in=1;
}
}
if(kbhit()) {
ch=getch();
if((ch=='w'||ch=='i')&&mx>2){
mx-=3;
}
if((ch=='e'||ch=='u')&&my<9-5) {
my+=5;
}
if((ch=='a'||ch=='j')&&my>0) {
my--;
}
if((ch=='d'||ch=='l')&&my<9) {
my++;
}
if(ch=='s'||ch=='k') {
in=1;
}
}
if(kbhit()) {
ch=getch();
if((ch=='w'||ch=='i')&&mx>2){
mx-=3;
}
if((ch=='e'||ch=='u')&&my<9-5) {
my+=5;
}
if((ch=='a'||ch=='j')&&my>0) {
my--;
}
if((ch=='d'||ch=='l')&&my<9) {
my++;
}
if(ch=='s'||ch=='k') {
in=1;
}
}
for(int i=0; i<5; i++) {
for(int j=0; j<5; j++) {
if(g_map[i][j]==6) {
g_map[i][j]=0;
}
}
}
g_map[mx][my]=6;
g_map[mx][my]=6;
}
int m(){
while(true) {
a++;
system("cls");
out();
robot();
play();
Sleep(500);
if(my==dy&&mx==dx) {
system("cls");
system("color F0");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED );
cout<<"球被抢了,失败";
Sleep(3000);
return 0;
}
if(in==1) {
system("cls");
system("color F0");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN);
cout<<"上篮成功,胜利";
Sleep(3000);
return 0;
}
wl();
}
}
int xl(){
while(true) {
a++;
system("cls");
out2();
robot();
play();
Sleep(500);
if(in==1) {
system("cls");
system("color F0");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN);
cout<<"上篮成功,胜利";
Sleep(3000);
return 0;
}
wl();
}
}
int first() {
system("color F0");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);
cout<<" 街头篮球"<<endl;
cout<<"规则:w(i)跳,e(u)闪现,a(j)d(l)移动,s(k)投篮。(请打开英文输入法)"<<endl;
cout<<"6玩家9对手1篮筐"<<endl;
cout<<"版本特性:更新训练模式,并增加灵敏度"<<endl;
cout<<"按g进入经典模式,按h进入训练模式"<<endl;
while(true) {
if(kbhit()) {
ms=getch();
break;
}
}
for(int i=0; i<5; i++) {
for(int j=0; j<10; j++) {
g_map[i][j]=0;
}
}
for(int i=0; i<10; i++) {
g_map[4][i]=8;
}
g_map[3][0]=6;
mx=3;
my=0;
g_map[3][5]=9;
dx=3;
dy=5;
g_map[1][9]=1;
if(ms=='g'){
m();
}
else if(ms=='h'){
xl();
}
else{
cout<<endl;
cout<<"你是朵拉吗?";
}
}
int main() {
first();
}
10-14
07-08