• 大小: 785KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-11
  • 语言: C#
  • 标签: 贪吃蛇  C#  控制台  

资源简介

C#控制台编写的贪吃蛇,欢迎大家一起探讨学习,要积分是为了下其它东西,我也是被逼的!

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Text;

namespace GluttonousSnake
{
    class Map
    {
        Random ran = new Random();
        public int length = 25;
        public int wide = 25;
        public char[] maps;
        public int[] food;
        /// 
        /// 绘制出地图边界
        /// 

        public void DrawMap()
        {
            maps = new char[length wide];
            for (int i = 0; i < maps.GetLength(0); i++)
            {
                for (int j = 0; j < maps.GetLength(1); j++)
                {
                    if (i == 0|| j == 0 || j == maps.GetLength(1) - 1|| i == maps.GetLength(0) - 1)
                    {
                        maps[i j] = ‘▓‘;
                    }
                    else
                    {
                        maps[i j] = ‘ ‘;
                    }

                }
            }
        }
        /// 
        /// 打印地图
        /// 

        public void PrintMap()
        {
            Console.Clear();
            for (int i = 0; i < maps.GetLength(0); i++)
            {
                for (int j = 0; j < maps.GetLength(1); j++)
                {
                    Console.SetCursorPosition(j * 2 i);
                    Console.Write(maps[i j]);
                }
            }
            Console.CursorVisible = false;
        }
        /// 
        /// 随机生成一个蛇
        /// 

        public void RandomSnake(Snake sn)
        {
            sn.snakeList = new List();
            int x =ran.Next(1 length - 1);
            int y =ran.Next(1 wide - 1);
            for (int i = 0; i < sn.lenght; i++)
            {
                int[] xy = new int[2];
                xy[0] = x;
                xy[1] = y - i;
                sn.snakeList.Add(xy);
                //maps[xy[0] xy[1]] = “♀“;
                maps[xy[0] xy[1]] = ‘♀‘;
                Console.SetCursorPosition(xy[1]*2 xy[0]);
                Console.Write(maps[xy[0] xy[1]]);
            }
        }
        /// 
        /// 随机一个食物
        /// 

        public void RandomFood(List snkeList)
        {
            int x=1;
            int y=1;
            bool bl = true;
            while (bl)
            {
                x = ran.Next(1 length - 1);
                y = ran.Next(1 wide - 1);
                int i=0;
                foreach (var item in snkeList)
                {
                    if (item[0] == x && item[1] == y)
                    {
                        i++;
                    }
                }
                if (i==0)
                {
                    bl = false;
                }
            }

            food = new int[2];
            food[0] = x;
            food[1] = y;
            maps[x y] = ‘〇‘;
            Console.SetCursorPosition(y*2 x);
            Console.Write(maps[x 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-05-28 20:15  GluttonousSnake\
     目录           0  2018-05-28 20:15  GluttonousSnake\.vs\
     目录           0  2018-05-28 20:15  GluttonousSnake\.vs\GluttonousSnake\
     目录           0  2018-05-28 20:15  GluttonousSnake\.vs\GluttonousSnake\DesignTimeBuild\
     文件      368916  2018-05-29 00:34  GluttonousSnake\.vs\GluttonousSnake\DesignTimeBuild\.dtbcache
     目录           0  2018-05-28 20:15  GluttonousSnake\.vs\GluttonousSnake\v15\
     文件       32256  2018-05-29 00:39  GluttonousSnake\.vs\GluttonousSnake\v15\.suo
     目录           0  2018-05-28 20:15  GluttonousSnake\.vs\GluttonousSnake\v15\Server\
     目录           0  2018-05-28 20:15  GluttonousSnake\.vs\GluttonousSnake\v15\Server\sqlite3\
     文件           0  2018-05-27 10:34  GluttonousSnake\.vs\GluttonousSnake\v15\Server\sqlite3\db.lock
     文件      634880  2018-05-29 00:19  GluttonousSnake\.vs\GluttonousSnake\v15\Server\sqlite3\storage.ide
     文件       32768  2018-05-29 00:36  GluttonousSnake\.vs\GluttonousSnake\v15\Server\sqlite3\storage.ide-shm
     文件     4144752  2018-05-29 00:34  GluttonousSnake\.vs\GluttonousSnake\v15\Server\sqlite3\storage.ide-wal
     目录           0  2018-05-29 00:32  GluttonousSnake\GluttonousSnake\
     文件         178  2018-05-27 10:33  GluttonousSnake\GluttonousSnake\GluttonousSnake.csproj
     文件        3090  2018-05-28 23:35  GluttonousSnake\GluttonousSnake\Map.cs
     文件        2186  2018-05-29 00:32  GluttonousSnake\GluttonousSnake\Program.cs
     文件        9722  2018-05-28 23:38  GluttonousSnake\GluttonousSnake\Snake.cs
     目录           0  2018-05-28 20:15  GluttonousSnake\GluttonousSnake\bin\
     目录           0  2018-05-28 20:15  GluttonousSnake\GluttonousSnake\bin\Debug\
     目录           0  2018-05-28 20:15  GluttonousSnake\GluttonousSnake\bin\Debug\netcoreapp2.0\
     文件         477  2018-05-29 00:34  GluttonousSnake\GluttonousSnake\bin\Debug\netcoreapp2.0\GluttonousSnake.deps.json
     文件       10752  2018-05-29 00:34  GluttonousSnake\GluttonousSnake\bin\Debug\netcoreapp2.0\GluttonousSnake.dll
     文件        3804  2018-05-29 00:34  GluttonousSnake\GluttonousSnake\bin\Debug\netcoreapp2.0\GluttonousSnake.pdb
     文件         248  2018-05-29 00:34  GluttonousSnake\GluttonousSnake\bin\Debug\netcoreapp2.0\GluttonousSnake.runtimeconfig.dev.json
     文件         154  2018-05-29 00:34  GluttonousSnake\GluttonousSnake\bin\Debug\netcoreapp2.0\GluttonousSnake.runtimeconfig.json
     目录           0  2018-05-29 00:34  GluttonousSnake\GluttonousSnake\obj\
     目录           0  2018-05-28 20:15  GluttonousSnake\GluttonousSnake\obj\Debug\
     目录           0  2018-05-28 20:15  GluttonousSnake\GluttonousSnake\obj\Debug\netcoreapp2.0\
     文件        1028  2018-05-27 10:34  GluttonousSnake\GluttonousSnake\obj\Debug\netcoreapp2.0\GluttonousSnake.AssemblyInfo.cs
     文件          42  2018-05-27 10:34  GluttonousSnake\GluttonousSnake\obj\Debug\netcoreapp2.0\GluttonousSnake.AssemblyInfoInputs.cache
............此处省略10个文件信息

评论

共有 条评论