using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Collections.Generic;
namespace 飞机大战__20180827__1
{
public class PlantWar
{
//地图
public void Map()
{
int[,] MapStr = new int[,]
{
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },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机生成
Plants PlayerPlant = new Plants();
PlayerPlant = RandomPlants(MapStr,"Player");
for (int i = 0; i < PlayerPlant.PlantVection2.Count; i++)
{
MapStr[PlayerPlant.PlantVection2[i].x, PlayerPlant.PlantVection2[i].y] = 3;
}
//敌机
List<Plants> EnemyList = new List<Plants>();
List<Plants> Play = new List<Plants>();
Play.Add(PlayerPlant);
//玩家子弹
Bullets PlayerBullet = new Bullets();
//敌机子弹
Bullets EnemyBullets = new Bullets();
int PlayerNum = 0;
int EnemyNum = 0;
while (true)
{
Console.SetCursorPosition(0, 0);//设置光标位置
Console.CursorVisible = false;//隐藏光标
Thread.Sleep(10);
if (EnemyList.Count<2)
{
Plants Enemy = new Plants();
Enemy = RandomPlants(MapStr, "Enemy");
EnemyList.Add(Enemy);
}
if (EnemyNum%20==0)
{
for (int i = 0; i < EnemyList.Count; i++)
{
EnemyBullets = CreatBullet(EnemyBullets, EnemyList[i], 'f');
}
}
EnemyBullets = BulletRemove(EnemyBullets,EnemyList[0]);
Play[0] = PlayerPlant;
RefreshBullet(EnemyList[0], ref EnemyBullets, ref Play, ref MapStr, 3);
EnemyNum++;
if (EnemyNum%4==0)
{
for (int i = 0; i < EnemyList.Count; i++)
{
for (int j = 0; j < EnemyList[i].PlantVection2.Count; j++)
{
MapStr[EnemyList[i].PlantVection2[j].x, EnemyList[i].PlantVection2[j].y] = 0;
}
}
EnemyList = RemovePlant(EnemyList, MapStr);
for (int i = 0; i < EnemyList.Count; i++)
{
for (int j = 0; j < EnemyList[i].PlantVection2.Count; j++)
{
if (EnemyList[i].PlantVection2[0].x == MapStr.GetLength(0) - 2)
{
for (int k = 0; k < EnemyList[i].PlantVection2.Count; k++)
{
MapStr[EnemyList[i].PlantVection2[k].x, EnemyList[i].PlantVection2[k].y] = 0;
}
EnemyList.RemoveAt(i);
i--;
break;
}
else
{
MapStr[EnemyList[i].PlantVection2[j].x, EnemyList[i].PlantVection2[j].y] = 2;
}
}
}
}
int rpgX = 0;//控制人物上下
int rpgY = 0;//控制人物左右
bool bo = false;
//控制移动
char ch = ' ';
if (Console.KeyAvailable)
{
ConsoleKeyInfo info = Console.ReadKey(true);
if (info.Key == ConsoleKey.W)
{
ch = 'w';
}
if (info.Key == ConsoleKey.S)
{
ch = 's';
}
if (info.Key == ConsoleKey.A)
{
ch = 'a';
}
if (info.Key == ConsoleKey.D)
{
ch = 'd';
}
if (info.Key == ConsoleKey.F)
{
ch = 'f';
}
if (info.Key==ConsoleKey.G)
{
ch = 'g';
}
bo = true;
}
if (bo==true)
{
PlayerBullet = CreatBullet(PlayerBullet, PlayerPlant, ch);
}
PlayerBullet = BulletRemove(PlayerBullet,PlayerPlant);
int a = EnemyList.Count;
RefreshBullet(PlayerPlant,ref PlayerBullet,ref EnemyList, ref MapStr,2);
int b = EnemyList.Count;
if (b<a)
{
PlayerNum++;
}
#region 判断移动方向
if (ch == 'w' || ch == 'W')
{
rpgX = -1;
}
if (ch == 's' || ch == 'S')
{
rpgX = 1;
}
if (ch == 'a' || ch == 'A')
{
rpgY = -1;
}
if (ch == 'd' || ch == 'D')
{
rpgY = 1;
}
#endregion
if (MapStr[PlayerPlant.PlantVection2[0].x+rpgX, PlayerPlant.PlantVection2[0].y+rpgY] == 1|| MapStr[PlayerPlant.PlantVection2[1].x + rpgX, PlayerPlant.PlantVection2[1].y + rpgY] == 1 || MapStr[PlayerPlant.PlantVection2[5].x + rpgX, PlayerPlant.PlantVection2[5].y + rpgY] == 1 || MapStr[PlayerPlant.PlantVection2[8].x + rpgX, PlayerPlant.PlantVection2[8].y + rpgY] == 1)
{
continue;
}
else
{
for (int i = 0; i < PlayerPlant.PlantVection2.Count; i++)
{
MapStr[PlayerPlant.PlantVection2[i].x, PlayerPlant.PlantVection2[i].y] = 0;
PlayerPlant.PlantVection2[i] = new Vection2() {x= PlayerPlant.PlantVection2[i].x+rpgX, y=PlayerPlant.PlantVection2[i].y+rpgY };
MapStr[PlayerPlant.PlantVection2[i].x, PlayerPlant.PlantVection2[i].y] = 3;
}
MapreFresh(MapStr);
bo = true;
}
Console.WriteLine("摧毁敌机数:{0}", PlayerNum);
if (Play.Count == 0)
{
Console.WriteLine("Game Over");
Quit();
}
}
}
//地图刷新
public void MapreFresh(int[,] MapStr)
{
for (int i = 0; i < MapStr.GetLength(0); i++)
{
for (int j = 0; j < MapStr.GetLength(1); j++)
{
if (MapStr[i, j] == 0)
{
Console.Write(" ");
}
if (MapStr[i, j] == 1)
{
Console.Write("■");
}
if (MapStr[i, j] == 2)
{
Console.Write("※");
}
if (MapStr[i, j] == 3)
{
Console.Write("★");
}
if (MapStr[i, j] == 4)
{
Console.Write("◆");
}
if (MapStr[i, j] == 5)
{
Console.Write("◇");
}
}
Console.WriteLine();
}
}
//随机生成飞机
public Plants RandomPlants(int[,] MapStr,string str)
{
Plants Plant = new Plants();
Random rd = new Random();
while (true)
{
int rdNum = rd.Next(3,MapStr.GetLength(1)-4);
if (str =="Enemy")
{
if (MapStr[4, rdNum] == 0 && MapStr[3, rdNum - 2] == 0 && MapStr[3, rdNum - 1] == 0 && MapStr[3, rdNum] == 0 && MapStr[3, rdNum + 1] == 0 && MapStr[3, rdNum + 2] == 0 && MapStr[2, rdNum] == 0 && MapStr[1, rdNum - 1] == 0 && MapStr[1, rdNum] == 0 && MapStr[1, rdNum + 1] == 0)
{
Plant.PlantVection2.Add(new Vection2() { x = 4, y = rdNum });
Plant.PlantVection2.Add(new Vection2() { x = 3, y = rdNum - 2 });
Plant.PlantVection2.Add(new Vection2() { x = 3, y = rdNum - 1 });
Plant.PlantVection2.Add(new Vection2() { x = 3, y = rdNum });
Plant.PlantVection2.Add(new Vection2() { x = 3, y = rdNum + 1 });
Plant.PlantVection2.Add(new Vection2() { x = 3, y = rdNum + 2 });
Plant.PlantVection2.Add(new Vection2() { x = 2, y = rdNum });
Plant.PlantVection2.Add(new Vection2() { x = 1, y = rdNum - 1 });
Plant.PlantVection2.Add(new Vection2() { x = 1, y = rdNum });
Plant.PlantVection2.Add(new Vection2() { x = 1, y = rdNum + 1 });
}
}
if (str == "Player")
{
if (MapStr[4, rdNum] == 0 && MapStr[3, rdNum - 2] == 0 && MapStr[3, rdNum - 1] == 0 && MapStr[3, rdNum] == 0 && MapStr[3, rdNum + 1] == 0 && MapStr[3, rdNum + 2] == 0 && MapStr[2, rdNum] == 0 && MapStr[1, rdNum - 1] == 0 && MapStr[1, rdNum] == 0 && MapStr[1, rdNum + 1] == 0)
{
Plant.PlantVection2.Add(new Vection2() { x = MapStr.GetLength(0) - 5, y = rdNum });
Plant.PlantVection2.Add(new Vection2() { x = MapStr.GetLength(0) - 4, y = rdNum - 2 });
Plant.PlantVection2.Add(new Vection2() { x = MapStr.GetLength(0) - 4, y = rdNum - 1 });
Plant.PlantVection2.Add(new Vection2() { x = MapStr.GetLength(0) - 4, y = rdNum });
Plant.PlantVection2.Add(new Vection2() { x = MapStr.GetLength(0) - 4, y = rdNum + 1 });
Plant.PlantVection2.Add(new Vection2() { x = MapStr.GetLength(0) - 4, y = rdNum + 2 });
Plant.PlantVection2.Add(new Vection2() { x = MapStr.GetLength(0) - 3, y = rdNum });
Plant.PlantVection2.Add(new Vection2() { x = MapStr.GetLength(0) - 2, y = rdNum - 1 });
Plant.PlantVection2.Add(new Vection2() { x = MapStr.GetLength(0) - 2, y = rdNum });
Plant.PlantVection2.Add(new Vection2() { x = MapStr.GetLength(0) - 2, y = rdNum + 1 });
}
}
return Plant;
}
}
Random rd = new Random();
//飞机自动巡航
public List<Plants> RemovePlant(List<Plants> Plant,int[,] MapStr)
{
while (true)
{
for (int i = 0; i < Plant.Count; i++)
{
int rdPlant = rd.Next(1, 3);//1左 2右
if (rdPlant == 1)
{
if (MapStr[Plant[i].PlantVection2[1].x + 1, Plant[i].PlantVection2[1].y - 1] == 0)
{
for (int j = 0; j < Plant[i].PlantVection2.Count; j++)
{
if (MapStr[Plant[i].PlantVection2[j].x + 1, Plant[i].PlantVection2[j].y - 1] == 4 || MapStr[Plant[i].PlantVection2[j].x + 1, Plant[i].PlantVection2[j].y - 1] == 5)
{
Plant.RemoveAt(i);
i--;
break;
}
if (j == Plant[i].PlantVection2.Count - 1)
{
for (int k = 0; k < Plant[i].PlantVection2.Count; k++)
{
Plant[i].PlantVection2[k] = new Vection2() { x = Plant[i].PlantVection2[k].x + 1, y = Plant[i].PlantVection2[k].y - 1 };
}
}
}
}
}
if (rdPlant == 2)
{
if (MapStr[Plant[i].PlantVection2[5].x + 1, Plant[i].PlantVection2[5].y + 1] == 0)
{
for (int j = 0; j < Plant[i].PlantVection2.Count; j++)
{
if (MapStr[Plant[i].PlantVection2[j].x + 1, Plant[i].PlantVection2[j].y + 1] == 4 || MapStr[Plant[i].PlantVection2[j].x + 1, Plant[i].PlantVection2[j].y + 1] == 5)
{
Plant.RemoveAt(i);
i--;
break;
}
if (j == Plant[i].PlantVection2.Count - 1)
{
for (int k = 0; k < Plant[i].PlantVection2.Count; k++)
{
Plant[i].PlantVection2[k] = new Vection2() { x = Plant[i].PlantVection2[k].x + 1, y = Plant[i].PlantVection2[k].y + 1 };
}
}
}
}
}
}
return Plant;
}
}
//生成子弹
public Bullets CreatBullet(Bullets bullet,Plants plant,char ch)
{
int num = plant.PlantVection2[0].x - plant.PlantVection2[3].x;
if (ch=='f')
{
bullet.OneBullet.Add(new Vection2() {x=plant.PlantVection2[0].x+num,y=plant.PlantVection2[0].y});
}
if (ch=='g')
{
bullet.MoreBullets.Add(new Vection2() { x = plant.PlantVection2[1].x + num, y = plant.PlantVection2[1].y });
}
return bullet;
}
//子弹移动
public Bullets BulletRemove(Bullets bullet,Plants plant)
{
int num = plant.PlantVection2[0].x - plant.PlantVection2[3].x;
for (int i = 0; i < bullet.OneBullet.Count; i++)
{
bullet.OneBullet[i] = new Vection2() {x=bullet.OneBullet[i].x+num,y=bullet.OneBullet[i].y };
}
for (int i = 0; i < bullet.MoreBullets.Count; i++)
{
bullet.MoreBullets[i] = new Vection2() { x = bullet.MoreBullets[i].x + num, y = bullet.MoreBullets[i].y };
}
return bullet;
}
//移动后刷新判断
public void RefreshBullet(Plants plant, ref Bullets bullet,ref List<Plants> hostilePlant, ref int[,] MapStr,int plantNum)
{
int num = plant.PlantVection2[0].x - plant.PlantVection2[3].x;
for (int i = 0; i < bullet.OneBullet.Count; i++)
{
MapStr[bullet.OneBullet[i].x-num, bullet.OneBullet[i].y] = 0;
if (MapStr[bullet.OneBullet[i].x,bullet.OneBullet[i].y]==0)
{
MapStr[bullet.OneBullet[i].x, bullet.OneBullet[i].y] = 4;
}
else if (MapStr[bullet.OneBullet[i].x, bullet.OneBullet[i].y] == 1|| MapStr[bullet.OneBullet[i].x, bullet.OneBullet[i].y] == plantNum-1)
{
bullet.OneBullet.RemoveAt(i);
i--;
}
else if (MapStr[bullet.OneBullet[i].x, bullet.OneBullet[i].y] == plantNum)
{
for (int j = 0; j < hostilePlant.Count; j++)
{
bool boPlant = false;
for (int m = 0; m < hostilePlant[j].PlantVection2.Count; m++)
{
if (hostilePlant[j].PlantVection2[m].x== bullet.OneBullet[i].x&& hostilePlant[j].PlantVection2[m].y == bullet.OneBullet[i].y)
{
for (int k = 0; k < hostilePlant[j].PlantVection2.Count; k++)
{
MapStr[hostilePlant[j].PlantVection2[k].x, hostilePlant[j].PlantVection2[k].y] = 0;
}
hostilePlant.RemoveAt(j);
bullet.OneBullet.RemoveAt(i);
i--;
j--;
boPlant = true;
break;
}
}
if (boPlant==true)
{
break;
}
}
}
}
for (int i = 0; i < bullet.MoreBullets.Count; i++)
{
MapStr[bullet.MoreBullets[i].x - num, bullet.MoreBullets[i].y] = 0;
MapStr[bullet.MoreBullets[i].x - num, bullet.MoreBullets[i].y+4] = 0;
if (MapStr[bullet.MoreBullets[i].x, bullet.MoreBullets[i].y] == 0)
{
MapStr[bullet.MoreBullets[i].x, bullet.MoreBullets[i].y] = 5;
MapStr[bullet.MoreBullets[i].x, bullet.MoreBullets[i].y+4] = 5;
}
else if (MapStr[bullet.MoreBullets[i].x, bullet.MoreBullets[i].y] == 1 || MapStr[bullet.MoreBullets[i].x, bullet.MoreBullets[i].y] == plantNum - 1)
{
bullet.MoreBullets.RemoveAt(i);
i--;
}
else if (MapStr[bullet.MoreBullets[i].x, bullet.MoreBullets[i].y] == plantNum)
{
for (int j = 0; j < hostilePlant.Count; j++)
{
bool boPlant = false;
for (int m = 0; m < hostilePlant[j].PlantVection2.Count; m++)
{
if ((hostilePlant[j].PlantVection2[m].x == bullet.MoreBullets[i].x && hostilePlant[j].PlantVection2[m].y == bullet.MoreBullets[i].y)||(hostilePlant[j].PlantVection2[m].x == bullet.MoreBullets[i].x && hostilePlant[j].PlantVection2[m].y == bullet.MoreBullets[i].y+4))
{
for (int k = 0; k < hostilePlant[j].PlantVection2.Count; k++)
{
MapStr[hostilePlant[j].PlantVection2[k].x, hostilePlant[j].PlantVection2[k].y] = 0;
}
hostilePlant.RemoveAt(j);
bullet.MoreBullets.RemoveAt(i);
i--;
j--;
boPlant = true;
break;
}
}
if (boPlant == true)
{
break;
}
}
}
}
}
//tuichu
public void Quit()
{
Thread.Sleep(2000);
Environment.Exit(0);
}
}
//飞机类
public class Plants
{
public List<Vection2> PlantVection2;
public Plants()
{
PlantVection2 = new List<Vection2>();
}
}
//子弹类
public class Bullets
{
public List<Vection2> OneBullet;//单发子弹
public List<Vection2> MoreBullets;//多发子弹
public Bullets()
{
OneBullet = new List<Vection2>();
MoreBullets = new List<Vection2>();
}
}
//二维坐标
public struct Vection2
{
public int x;
public int y;
public Vection2(int x,int y)
{
this.x = x;
this.y = y;
}
}
class Program
{
static void Main(string[] args)
{
new PlantWar().Map();
Console.ReadKey();
}
}
}