最近没事,做了个街头篮球游戏,只要138行,还不算多(我的狼人杀1000多行)
实现效果:
按任意键开始
游戏界面(小写ad移动,小写w闪现,小写s投篮)
结束界面
#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;
//kbhit()
//shuru=getch();
int first() {
system("color F0");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);
cout<<" 街头篮球"<<endl;
cout<<"规则:w闪现,ad移动,s投篮。(请打开英文输入法)"<<endl;
while(true) {
if(kbhit()) {
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;
}
int out() {
system("color F0");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
g_map[3][my]=6;
g_map[3][my]=6;
for(int i=0; i<4; i++) {
for(int j=0; j<10; 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{
cout<<0;
}
}
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'&&my<9-5) {
my+=5;
}
if(ch=='a'&&my>0) {
my--;
}
if(ch=='d'&&my<9) {
my++;
}
if(ch=='s') {
if(my>=5) {
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[3][my]=6;
g_map[3][my]=6;
}
int main() {
first();
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<<"球被抢了,失败";
return 0;
}
if(in==1) {
system("cls");
system("color F0");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN);
cout<<"上篮成功,胜利";
return 0;
}
}
}