C#控制台简单坦克大战

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Threading;

namespace 坦克大战__20180820__1
{
class BattleCity
{
int x;
int y;

    //首界面
    public void Inter()
    {
        Console.WriteLine("****************");
        Console.WriteLine("*  请选择操作  *");
        Console.WriteLine("*  1.开始游戏  *");
        Console.WriteLine("*  2.退出游戏  *");
        Console.WriteLine("****************");

        int n = int.Parse(Console.ReadLine());
        switch (n)
        {
            case 1: Map(); break;
            case 2: Quit(); break;
            default:
                Console.WriteLine("输入有误");
                break;
        }


    }

    //重新开始
    public void GameAgain()
    {
        Console.WriteLine("****************");
        Console.WriteLine("*  请选择操作  *");
        Console.WriteLine("*  1.重新开始  *");
        Console.WriteLine("*  2.退出游戏  *");
        Console.WriteLine("****************");

        int n = int.Parse(Console.ReadLine());
        switch (n)
        {
            case 1: Map(); break;
            case 2: Quit(); break;
            default:
                Console.WriteLine("输入有误");
                break;
        }
    }

    //地图
    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 },
            {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 },
            {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 },
            {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 },
            {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,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 }

        };         
        MapreFresh(MapStr);
        Remove(MapStr);
    }

    //移动
    public void Remove(int[,] MapStr)
    {
        List<Vection2> list = new List<Vection2>();
        list.Add(new Vection2() { x = 11, y = 4 });
        list.Add(new Vection2() { x = 12, y = 3 });
        list.Add(new Vection2() { x = 12, y = 5 });
        list.Add(new Vection2() { x = 13, y = 4 });
        list.Add(new Vection2() { x = 14, y = 3 });
        list.Add(new Vection2() { x = 14, y = 5 });
        for (int i = 0; i < list.Count; i++)
        {
            MapStr[list[i].x, list[i].y] = 3;
        }
        List<List<Vection2>> playerList = new List<List<Vection2>>();
        playerList.Add(list);//存玩家坦克

        //存子弹
        Bullets playerBullets = new Bullets();//玩家子弹
        List<Bullets> playerGather = new List<Bullets>();
        playerGather.Add(playerBullets);



        List<Vection2> list1 = RandomTank(MapStr);//随机生成敌人坦克1
        for (int i = 0; i < list1.Count; i++)
        {
            MapStr[list1[i].x, list1[i].y] = 2;
        }
        List<Vection2> list2 = RandomTank(MapStr);//随机生成敌人坦克2
        for (int i = 0; i < list2.Count ; i++)
        {
            MapStr[list2[i].x, list2[i].y] = 2;
        }

        List<List<Vection2>> listTank = new List<List<Vection2>>();//存坦克
        listTank.Add(list1);
        listTank.Add(list2);


        //存敌人子弹
        Bullets ForBullets1 = new Bullets();
        Bullets ForBullets2 = new Bullets();
        List<Bullets> TankGather = new List<Bullets>();//敌人发射子弹坦克集合
        TankGather.Add(ForBullets1);
        TankGather.Add(ForBullets2);

        bool ChangeBo = false;
        bool TankBo = true;
        int  ForNum = 5;
        while (true)
        {
            bool boSre = true;
            Console.SetCursorPosition(0, 0);//设置光标位置
            Console.CursorVisible=false;//隐藏光标


            for (int i = 0; i < listTank.Count; i++)
            {
                MapStr = RandomRemove(listTank[i], MapStr);
            }


            bool bo = false;
            int rpgX = 0;//控制人物上下
            int rpgY = 0;//控制人物左右

            Thread.Sleep(200);


            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';
                }

                boSre = false;
            }




            //玩家坦克开火
            if (ch == 'f')
            {
                playerGather = TankFire(playerList,playerGather,MapStr);

            }
            //玩家坦克子弹移动
            playerBullets = RemoveBullets(playerBullets);
            //玩家坦克子弹移动后判断
            MapStr = JudgeBullets(playerBullets,listTank,MapStr,4);




            //敌人坦克开火                
            if (ForNum==5)
            {
                if (listTank.Count>0)
                {
                    TankGather = TankFire(listTank,TankGather,MapStr);    //生成敌人坦克子弹                  
                }
                ForNum = 0;
            }
            ForNum++;

            //敌人子弹移动   
            for (int i = 0; i < TankGather.Count; i++)
            {
                TankGather[i] = RemoveBullets(TankGather[i]);
            }         


            //子弹移动后判断
            for (int i = 0; i < TankGather.Count; i++)
            {
                MapStr = JudgeBullets(TankGather[i], playerList, MapStr, 5);
            }








            #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[list[0].x + rpgX, list[0].y + rpgY] == 2)
            {
                Console.WriteLine("游戏结束");
                Quit();
            }

            if (MapStr[list[0].x + rpgX, list[0].y + rpgY]==1)
            {
                continue;
            }
            else
            {
                if (ch=='w')
                {
                    MapStr[list[0].x, list[0].y] = 0;
                    list[0] = new Vection2() {x=list[3].x-2,y=list[3].y };
                }

                if (ch == 's')
                {
                    MapStr[list[0].x, list[0].y] = 0;
                    list[0] = new Vection2() { x = list[3].x + 2, y = list[3].y };
                }
                if (ch == 'a')
                {
                    MapStr[list[0].x, list[0].y] = 0;
                    list[0] = new Vection2() { x = list[3].x , y = list[3].y-2 };
                }
                if (ch == 'd')
                {
                    MapStr[list[0].x, list[0].y] = 0;
                    list[0] = new Vection2() { x = list[3].x, y = list[3].y + 2 };
                }             

                for (int i = 0; i < list.Count; i++)
                {
                    MapStr[list[i].x, list[i].y] = 0;
                    MapStr[list[i].x + rpgX, list[i].y + rpgY] = 3;

                }                

                MapreFresh(MapStr);                 

                bo = true;
                boSre = true;

            }

            if (bo == true)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    list[i] = new Vection2() {x=list[i].x+rpgX,y=list[i].y+rpgY };
                }
                x += rpgX;
                y += rpgY;

            }

            Console.WriteLine("分數:{0}", 2 - listTank.Count);
        }


    }

    //地图刷新
    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 List<Vection2> RandomTank(int[,] num)
    {
        List<Vection2> list1 = new List<Vection2>();
        list1.Add(new Vection2() { x = 0, y = 0 });
        list1.Add(new Vection2() { x = 0, y = 0 });
        list1.Add(new Vection2() { x = 0, y = 0 });
        list1.Add(new Vection2() { x = 0, y = 0 });
        list1.Add(new Vection2() { x = 0, y = 0 });
        list1.Add(new Vection2() { x = 0, y = 0 });

        Random rd = new Random();
        while (true)
        {
            int rdNum1 = rd.Next(1,num.GetLength(0)-2);//x轴
            int rdNum2 = rd.Next(1, num.GetLength(1)-2);//y轴
            if (num[rdNum1, rdNum2] == 1 || num[rdNum1, rdNum2] == 2 || num[rdNum1, rdNum2] == 3)
            {
                continue;
            }
            else if (num[rdNum1+1, rdNum2-1] == 1 || num[rdNum1 + 1, rdNum2 - 1] == 2 || num[rdNum1 + 1, rdNum2 - 1] == 3)
            {
                continue;
            }
            else if (num[rdNum1 + 1, rdNum2 + 1] == 1 || num[rdNum1 + 1, rdNum2 + 1] == 2 || num[rdNum1 + 1, rdNum2 + 1] == 3)
            {
                continue;
            }
            else if (num[rdNum1 + 2, rdNum2 ] == 1 || num[rdNum1 + 2, rdNum2 ] == 2 || num[rdNum1 + 2, rdNum2 ] == 3)
            {
                continue;
            }
            else if (num[rdNum1 + 3, rdNum2 - 1] == 1 || num[rdNum1 + 3, rdNum2 - 1] == 2 || num[rdNum1 + 3, rdNum2 - 1] == 3)
            {
                continue;
            }
            else if (num[rdNum1 + 3, rdNum2 + 1] == 1 || num[rdNum1 + 3, rdNum2 + 1] == 2 || num[rdNum1 + 3, rdNum2 + 1] == 3)
            {
                continue;
            }
            else 
            {

                list1[0]=  (new Vection2() { x = rdNum1, y = rdNum2 });
                list1[1] = (new Vection2() { x = rdNum1 + 1, y = rdNum2 - 1 });
                list1[2] = (new Vection2() { x = rdNum1 + 1, y = rdNum2 + 1 });
                list1[3] = (new Vection2() { x = rdNum1 + 2, y = rdNum2 });
                list1[4] = (new Vection2() { x = rdNum1 + 3, y = rdNum2 - 1 });
                list1[5] = (new Vection2() { x = rdNum1 + 3, y = rdNum2 + 1 });

                return list1;
            }

        }





    }

    Random rdTank = new Random();
    //坦克随机移动
    public int[,] RandomRemove(List<Vection2> list,int[,]  num)
    {

        while (true)
        {             
            int rdfNum = rdTank.Next(1, 5);//1向上  2向下  3向左  4向右
            for (int i = 0; i < list.Count; i++)
            {
                num[list[i].x, list[i].y] = 0;
            }

            if (rdfNum == 1 && num[list[3].x - 3, list[3].y] == 0)
            {
                list[0] = new Vection2() { x = list[3].x - 2, y = list[3].y };

                for (int i = 0; i < list.Count; i++)
                {
                    list[i] = new Vection2() { x = list[i].x - 1, y = list[i].y };
                }
            }

            if (rdfNum == 2 && num[list[3].x + 3, list[3].y] == 0)
            {
               list[0] = new Vection2() { x = list[3].x + 2, y = list[3].y };
                for (int i = 0; i < list.Count; i++)
                {
                    list[i] = new Vection2() { x = list[i].x + 1, y = list[i].y };
                }
            }

            if (rdfNum == 3 && num[list[3].x , list[3].y-3] == 0)
            {
                list[0] = new Vection2() { x = list[3].x, y = list[3].y - 2 };
                for (int i = 0; i < list.Count; i++)
                {
                    list[i] = new Vection2() { x = list[i].x, y = list[i].y - 1 };
                }
            }

            if (rdfNum == 4 && num[list[3].x, list[3].y + 3] == 0 )
            {
                list[0] = new Vection2() { x = list[3].x, y = list[3].y + 2 };
                for (int i = 0; i < list.Count; i++)
                {
                    list[i] = new Vection2() { x = list[i].x, y = list[i].y + 1 };
                }
            }

            for (int i = 0; i < list.Count; i++)
            {
                num[list[i].x, list[i].y] = 2;
            }

            return num;




        }

   }

    //开火
    public List<Bullets> TankFire(List<List<Vection2>> listTank,List<Bullets> TankGather, int[,] MapStr)
    {
        for (int i = 0; i < listTank.Count; i++)
        {
            if (listTank[i][0].y == listTank[i][3].y)
            {
                if (listTank[i][0].x < listTank[i][3].x)
                {

                    if (MapStr[listTank[i][0].x - 1, listTank[i][0].y] == 0)
                    {
                        TankGather[i].BulletUp.Add(new Vection2() { x = listTank[i][0].x - 1, y = listTank[i][0].y });
                    }

                }
                if (listTank[i][0].x > listTank[i][3].x)
                {
                    if (MapStr[listTank[i][0].x + 1, listTank[i][0].y] == 0)
                    {
                        TankGather[i].BulletDown.Add(new Vection2() { x = listTank[i][0].x + 1, y = listTank[i][0].y });
                    }
                }

            }

            if (listTank[i][0].x == listTank[i][3].x)
            {
                if (listTank[i][0].y < listTank[i][3].y)
                {
                    if (MapStr[listTank[i][0].x, listTank[i][0].y - 1] == 0)
                    {
                        TankGather[i].BulletRinght.Add(new Vection2() { x = listTank[i][0].x, y = listTank[i][0].y - 1 });
                    }
                }
                if (listTank[i][0].y > listTank[i][3].y)
                {
                    if (MapStr[listTank[i][0].x, listTank[i][0].y + 1] == 0)
                    {
                        TankGather[i].BulletLift.Add(new Vection2() { x = listTank[i][0].x, y = listTank[i][0].y + 1 });
                    }
                }
            }
        }
        return TankGather;
    }

    //子弹移动
    public Bullets RemoveBullets(Bullets sendBullet)
    {
        for (int i = 0; i < sendBullet.BulletUp.Count; i++)
        {
            sendBullet.BulletUp[i] = new Vection2() { x = sendBullet.BulletUp[i].x - 1, y = sendBullet.BulletUp[i].y };
        }
        for (int i = 0; i <sendBullet.BulletDown.Count; i++)
        {
            sendBullet.BulletDown[i] = new Vection2() { x = sendBullet.BulletDown[i].x + 1, y = sendBullet.BulletDown[i].y };
        }

        for (int i = 0; i < sendBullet.BulletRinght.Count; i++)
        {
            sendBullet.BulletRinght[i] = new Vection2() { x = sendBullet.BulletRinght[i].x, y = sendBullet.BulletRinght[i].y - 1 };
        }

        for (int i = 0; i <sendBullet.BulletLift.Count; i++)
        {
            sendBullet.BulletLift[i] = new Vection2() { x = sendBullet.BulletLift[i].x, y = sendBullet.BulletLift[i].y + 1 };
        }

        return sendBullet;
    }

    //敌人子弹移动判断
    public int[,] JudgeBullets(Bullets sendBullet, List<List<Vection2>> listTank, int[,] MapStr,int num)
    {

        bool boTank = false;
        for (int i = 0; i < sendBullet.BulletUp.Count; i++)
        {
            MapStr[sendBullet.BulletUp[i].x+1, sendBullet.BulletUp[i].y ] = 0;

            if (MapStr[sendBullet.BulletUp[i].x , sendBullet.BulletUp[i].y] ==0 )
            {
                MapStr[sendBullet.BulletUp[i].x, sendBullet.BulletUp[i].y] = num;
            }
            else if (MapStr[sendBullet.BulletUp[i].x, sendBullet.BulletUp[i].y] == num-2)
            {
                if (num==5)
                {
                    Console.WriteLine("游戏结束!!!");
                    Quit();
                }
                if (num==4)
                {
                    for (int j = 0; j < listTank.Count; j++)
                    {
                        for (int k = 0; k < listTank[j].Count; k++)
                        {
                            if (listTank[j][k].x == sendBullet.BulletUp[i].x && listTank[j][k].y == sendBullet.BulletUp[i].y)
                            {
                                MapStr[listTank[j][0].x, listTank[j][0].y] = 0;
                                MapStr[listTank[j][1].x, listTank[j][1].y] = 0;
                                MapStr[listTank[j][2].x, listTank[j][2].y] = 0;
                                MapStr[listTank[j][3].x, listTank[j][3].y] = 0;
                                MapStr[listTank[j][4].x, listTank[j][4].y] = 0;
                                MapStr[listTank[j][5].x, listTank[j][5].y] = 0;

                                listTank.RemoveAt(j);
                                sendBullet.BulletUp.RemoveAt(i);
                                j--;
                                i--;
                                boTank = true;
                                break;
                            }
                        }
                        if (boTank==true)
                        {
                            break;
                        }
                    }

                }

            }
            else
            {
                sendBullet.BulletUp.RemoveAt(i);
                i--;
            }
        }

        for (int i = 0; i < sendBullet.BulletDown.Count; i++)
        {
            MapStr[sendBullet.BulletDown[i].x - 1, sendBullet.BulletDown[i].y] = 0;

            if (MapStr[sendBullet.BulletDown[i].x, sendBullet.BulletDown[i].y] == 0)
            {
                MapStr[sendBullet.BulletDown[i].x, sendBullet.BulletDown[i].y] = num;
            }
            else if (MapStr[sendBullet.BulletDown[i].x, sendBullet.BulletDown[i].y] == num - 2)
            {
                if (num == 5)
                {
                    Console.WriteLine("游戏结束!!!");
                    Quit();
                }
                if (num == 4)
                {
                    for (int j = 0; j < listTank.Count; j++)
                    {
                        for (int k = 0; k < listTank[j].Count; k++)
                        {
                            if (listTank[j][k].x == sendBullet.BulletDown[i].x && listTank[j][k].y == sendBullet.BulletDown[i].y)
                            {
                                MapStr[listTank[j][0].x, listTank[j][0].y] = 0;
                                MapStr[listTank[j][1].x, listTank[j][1].y] = 0;
                                MapStr[listTank[j][2].x, listTank[j][2].y] = 0;
                                MapStr[listTank[j][3].x, listTank[j][3].y] = 0;
                                MapStr[listTank[j][4].x, listTank[j][4].y] = 0;
                                MapStr[listTank[j][5].x, listTank[j][5].y] = 0;

                                listTank.RemoveAt(j);
                                sendBullet.BulletDown.RemoveAt(i);
                                j--;
                                i--;
                                boTank = true;
                                break;
                            }
                        }
                        if (boTank == true)
                        {
                            break;
                        }
                    }

                }
            }
            else
            {
                sendBullet.BulletDown.RemoveAt(i);
                i--;
            }
        }

        for (int i = 0; i < sendBullet.BulletRinght.Count; i++)
        {
            MapStr[sendBullet.BulletRinght[i].x , sendBullet.BulletRinght[i].y+1] = 0;

            if (MapStr[sendBullet.BulletRinght[i].x, sendBullet.BulletRinght[i].y] == 0)
            {
                MapStr[sendBullet.BulletRinght[i].x, sendBullet.BulletRinght[i].y] = num;
            }
            else if (MapStr[sendBullet.BulletRinght[i].x, sendBullet.BulletRinght[i].y] == num - 2)
            {
                if (num == 5)
                {
                    Console.WriteLine("游戏结束!!!");
                    Quit();
                }
                if (num == 4)
                {
                    for (int j = 0; j < listTank.Count; j++)
                    {
                        for (int k = 0; k < listTank[j].Count; k++)
                        {
                            if (listTank[j][k].x == sendBullet.BulletRinght[i].x && listTank[j][k].y == sendBullet.BulletRinght[i].y)
                            {
                                MapStr[listTank[j][0].x, listTank[j][0].y] = 0;
                                MapStr[listTank[j][1].x, listTank[j][1].y] = 0;
                                MapStr[listTank[j][2].x, listTank[j][2].y] = 0;
                                MapStr[listTank[j][3].x, listTank[j][3].y] = 0;
                                MapStr[listTank[j][4].x, listTank[j][4].y] = 0;
                                MapStr[listTank[j][5].x, listTank[j][5].y] = 0;

                                listTank.RemoveAt(j);
                                sendBullet.BulletRinght.RemoveAt(i);
                                j--;
                                i--;
                                boTank = true;
                                break;
                            }
                        }
                        if (boTank == true)
                        {
                            break;
                        }
                    }
                }
            }
            else
            {
                sendBullet.BulletRinght.RemoveAt(i);
                i--;
            }
        }

        for (int i = 0; i < sendBullet.BulletLift.Count; i++)
        {
            MapStr[sendBullet.BulletLift[i].x, sendBullet.BulletLift[i].y - 1] = 0;

            if (MapStr[sendBullet.BulletLift[i].x, sendBullet.BulletLift[i].y] == 0)
            {
                MapStr[sendBullet.BulletLift[i].x, sendBullet.BulletLift[i].y] = num;
            }
            else if (MapStr[sendBullet.BulletLift[i].x, sendBullet.BulletLift[i].y] == num-2)
            {
                if (num == 5)
                {
                    Console.WriteLine("游戏结束!!!");
                    Quit();
                }
                if (num == 4)
                {
                    for (int j = 0; j < listTank.Count; j++)
                    {
                        for (int k = 0; k < listTank[j].Count; k++)
                        {
                            if (listTank[j][k].x == sendBullet.BulletLift[i].x && listTank[j][k].y == sendBullet.BulletLift[i].y)
                            {
                                MapStr[listTank[j][0].x, listTank[j][0].y] = 0;
                                MapStr[listTank[j][1].x, listTank[j][1].y] = 0;
                                MapStr[listTank[j][2].x, listTank[j][2].y] = 0;
                                MapStr[listTank[j][3].x, listTank[j][3].y] = 0;
                                MapStr[listTank[j][4].x, listTank[j][4].y] = 0;
                                MapStr[listTank[j][5].x, listTank[j][5].y] = 0;

                                listTank.RemoveAt(j);
                                sendBullet.BulletLift.RemoveAt(i);
                                j--;
                                i--;
                                boTank = true;
                                break;
                            }
                        }
                        if (boTank == true)
                        {
                            break;
                        }
                    }

                }
            }
            else
            {
                sendBullet.BulletLift.RemoveAt(i);
                i--;
            }
        }





        return MapStr;
    }


    //退出
    public void Quit()
    {
        Thread.Sleep(2000);
        Environment.Exit(0);
    }

}

public class Bullets
{
    public List<Vection2> BulletUp;
    public List<Vection2> BulletDown;
    public List<Vection2> BulletRinght;
    public List<Vection2> BulletLift;

    public Bullets()
    {
        BulletUp = new List<Vection2>();
        BulletDown = new List<Vection2>();
        BulletRinght = new List<Vection2>();
        BulletLift = new List<Vection2>();
    }

}

public struct Vection2
{
   public  int x;
   public  int y;
}

class Program
{
    static void Main(string[] args)
    {
        new BattleCity().Map();


        Console.ReadKey();
    }
}

}

猜你喜欢

转载自blog.csdn.net/qq_42016542/article/details/82108066
今日推荐