资深光能
#include<iostream>
#include<windows.h>
#include<conio.h>
using namespace std;
int a[1000][1000],fs=0;
void mp(int x,int y)
{
int x1=x-9,x2=x+9,y1=y-9,y2=y+9;
if(x1<1)
{
x2+=(1-x1);
x1=1;
}
if(y1<1)
{
y2+=(1-y1);
y1=1;
}
if(x2>20)
{
x1-=(x2-20);
x2=20;
}
if(y2>20)
{
y1-=(y2-20);
y2=20;
}
cout<<"你有";
cout<<fs<<"分\n";
cout<<" ";
for(int i=x1;i<=x2;i++)
if(i<10)
cout<<' '<<i;
else
cout<<i;
cout<<"\n ______________________________________\n";
for(int i=y1;i<=y2;i++)
{
if(i<10)cout<<" "<<i<<'|';
else cout<<i<<'|';
for(int j=x1;j<=x2;j++)
{
if(a[j][i]==1)cout<<"你";
else if(a[j][i]==2)cout<<"■";
else if(a[j][i]==3)cout<<"☆";
else cout<<" ";
}
if(i<10)cout<<'|'<<" "<<i;
else cout<<'|'<<i;
cout<<endl;
}
cout<<" ______________________________________\n";
cout<<" ";
for(int i=x1;i<=x2;i++)
if(i<10)
cout<<' '<<i;
else
cout<<i;
}
int main()
{
int x,y;
cin>>x>>y;
a[x][y]=1;
for(int i=1;i<=20;i++)
for(int j=1;j<=20;j++)
if(rand()%8<2)
a[i][j]=2;
else if(rand()%3==1)
a[i][j]=3;
while(1)
{
system("cls");
mp(x,y);
char c;
c=getche();
if(c=='A'&&x-1>0&&a[x-1][y]!=2)
{
if(a[x-1][y]==3)fs++;
a[x][y]=0;
a[x-1][y]=1;
x-=1;
}
if(c=='W'&&y-1>0&&a[x][y-1]!=2)
{
if(a[x][y-1]==3)fs++;
a[x][y]=0;
a[x][y-1]=1;
y-=1;
}
if(c=='D'&&x+1<=20&&a[x+1][y]!=2)
{
if(a[x+1][y]==3)fs++;
a[x][y]=0;
a[x+1][y]=1;
x+=1;
}
if(c=='S'&&y+1<=20&&a[x][y+1]!=2)
{
if(a[x][y+1]==3)fs++;
a[x][y]=0;
a[x][y+1]=1;
y+=1;
}
}
}
陈室战争马上就要改成二维了
初级守护
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <windows.h>
#include <conio.h>
using namespace std;
#define R 10
#define C 10
int map[R][C] = { 0 };
int map1[10][10] = {
{0,0,1,1,1,0,0,0,0,0},
{0,0,1,3,1,0,0,0,0,0},
{0,0,1,0,1,1,1,1,0,0},
{1,1,1,0,0,4,3,1,0,0},
{1,3,4,4,0,1,1,1,0,0},
{1,1,1,5,4,1,0,0,0,0},
{0,0,0,1,3,1,0,0,0,0},
{0,0,0,1,1,1,0,0,0,0}
};
int map2[R][C]={
{1,1,1,1,1,0,0,0,0,0},
{1,5,0,0,1,0,0,0,0,0},
{1,0,4,4,1,0,1,1,1,0},
{1,0,4,0,1,0,1,3,1,0},
{1,1,1,0,1,1,1,3,1,0},
{0,1,1,0,0,0,0,3,1,0},
{0,1,0,0,0,1,0,0,1,0},
{0,1,0,0,0,1,1,1,1,0},
{0,1,1,1,1,1,0,0,0,0}
};
int map3[R][C]={
{0,0,0,1,1,1,1,1,1,1},
{0,0,1,1,0,0,1,0,5,1},
{0,0,1,0,0,0,1,0,0,1},
{0,0,1,4,0,4,0,4,0,1},
{0,0,1,0,4,1,1,0,0,1},
{1,1,1,0,4,0,1,0,1,1},
{1,3,3,3,3,3,0,0,1,0},
{1,1,1,1,1,1,1,1,1,0},
};
int map4[R][C]={
{1,1,1,1,1,1,1,1,0,0},
{1,5,0,0,0,0,0,1,0,0},
{1,0,0,4,0,4,0,1,0,0},
{1,0,0,0,0,0,0,0,1,0},
{1,0,0,1,0,0,0,0,1,1},
{1,0,0,1,0,4,0,0,0,1},
{1,3,0,1,3,0,0,0,3,1},
{1,1,1,1,1,1,1,1,1,1},
};
int map5[R][C]={
{0,0,0,1,1,1,1,1,0,0},
{0,0,0,1,5,0,0,1,0,0},
{1,1,1,1,0,4,3,1,0,0},
{1,3,0,0,0,0,1,1,1,0},
{1,1,1,1,0,0,0,0,1,0},
{0,0,0,1,0,4,1,4,1,1},
{0,0,0,1,0,0,0,0,3,1},
{0,0,0,1,1,1,1,1,1,1},
};
void Game_Menu();
void Game_description();
int DrawMap();
void Move();
int finish();
void setmap(int n);
void color(int m);
BOOL flag = true;
int pass=1;
void Game_Menu(){
system("cls");
cout<<"/**********我是猪才怪公司-出品*********\\\n";
cout<<"*|------------------------------------|*\n";
cout<<"*| 经 典 小 游 戏 |*\n";
cout<<"*| 推 箱 子 |*\n";
cout<<"*| 1.按 S 或 s 键 开 始 |*\n";
cout<<"*| 2.按 Q 或 q 键 退 出 |*\n";
cout<<"*|------------------------------------|*\n";
cout<<"\\**************************************/\n";
_getch();
}
void Game_description(){/*初始化模块,显示游戏操作说明*/
cout<<"/***********我是猪才怪公司-提示*******\\\n";
cout<<"*------------------------------------*\n";
cout<<"* 操 作 提 示 *\n";
cout<<"* 操作上移: W w ↑ *\n";
cout<<"* 操作下移: S s ↓ *\n";
cout<<"* 操作左移: A a ← *\n";
cout<<"* 操作右移: D d → *\n";
cout<<"* *\n";
cout<<"* 退 出: Q q *\n";
cout<<"* ■:表示墙体 *\n";
cout<<"* ☆:表示目的地 *\n";
cout<<"* □:表示箱子 *\n";
cout<<"* ♀:表示人 *\n";
cout<<"* 由于是编程游戏,画面会很闪,请原谅 *\n";
cout<<"*------------------------------------*\n";
cout<<"\\***********************************/\n";
}
int DrawMap(){
cout<<"您正处于关卡第:"<<pass<<"关"<<endl;
for (int i = 0; i < R; i++){
for (int j = 0; j < C; j++){
switch (map[i][j]){
case 0:
color(0xF);
cout << " ";
break;
case 1:
color(8);
cout << "■";
break;
case 3:
color(0xE);
cout << "☆";
break;
case 4:
color(4);
cout << "□";
break;
case 5:
color(3);
cout << "♀";
break;
case 7:
color(6);
cout << "★";
break;
case 8:
color(3);
cout << "♀";
break;
default:
break;
}
}
cout <<endl;
}
return 0;
}
void Move(){
int r,c;
for(int i=0;i<R;i++){
for(int j=0;j<C;j++){
if(map[i][j]==5||map[i][j]==8){
r=i;
c=j;
}
}
}
cout<<"玩家,您当前的坐标是:("<<r<<","<<c<<")"<<endl;
int ch;
ch=_getch();
switch(ch){
case 'W':
case 'w':
case 72:
if(map[r-1][c]==0||map[r-1][c]==3){
map[r-1][c]+=5;
map[r][c]-=5;
}
else if(map[r-1][c]==4||map[r-1][c]==7){
if(map[r-2][c]==0||map[r-2][c]==3){
map[r-2][c]+=4;
map[r-1][c]+=1;
map[r][c]-=5;
}
}
break;
case 'S':
case 's':
case 80:
if(map[r+1][c]==0||map[r+1][c]==3){
map[r+1][c]+=5;
map[r][c]-=5;
}
else if(map[r+1][c]==4||map[r+1][c]==7){
if(map[r+2][c]==0||map[r+2][c]==3){
map[r+2][c]+=4;
map[r+1][c]+=1;
map[r][c]-=5;
}
}
break;
case 'A':
case 'a':
case 75:
if(map[r][c-1]==0||map[r][c-1]==3){
map[r][c-1]+=5;
map[r][c]-=5;
}
else if(map[r][c-1]==4||map[r][c-1]==7){
if(map[r][c-2]==0||map[r][c-2]==3){
map[r][c-2]+=4;
map[r][c-1]+=1;
map[r][c]-=5;
}
}
break;
case 'D':
case 'd':
case 77:
if(map[r][c+1]==0||map[r][c+1]==3){
map[r][c+1]+=5;
map[r][c]-=5;
}
else if(map[r][c+1]==4||map[r][c+1]==7){
if(map[r][c+2]==0||map[r][c+2]==3){
map[r][c+2]+=4;
map[r][c+1]+=1;
map[r][c]-=5;
}
}
break;
case 'Q':
case 'q':
flag=false;
default:
break;
}
return ;
}
int finish(){
for (int i=0;i<R;i++){
for (int j=0;j<C;j++){
if (map[i][j] == 4){
return 0;
}
}
}
return 1;
}
void setmap(int n){
if (n == 1){
memcpy(map, map1, sizeof(map1));
}
if (n == 2){
memcpy(map, map2, sizeof(map2));
}
if (n == 3){
memcpy(map, map3, sizeof(map3));
}
if (n == 4){
memcpy(map, map4, sizeof(map4));
}
if (n == 5){
memcpy(map, map5, sizeof(map5));
}
return ;
}
void color(int m){
HANDLE consolehend;
consolehend = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(consolehend, m);
return ;
}
int main(){
char c;
Game_Menu();
c = getch();
setmap(pass);
switch(c){
case 'Q':
case 'q':
return 0;
case 'S':
case 's':
while (flag){
system("cls");
Game_description();
DrawMap();
Move();
if(finish()){
system("cls");
DrawMap();
printf("恭喜你!游戏胜利!,如进行下一关,请按"Enter"键\n");
system("pause");
pass++;
setmap(pass);
}
}
break;
}
return 0;
}
//我也来!!只为娱乐,请勿举报~~