小游戏-贪吃蛇C#控制台项目


C#或U3D初学者必做游戏。 该项目由vs2015编译,C#开发,已测试可以编译运行。 游戏功能:单人游戏、双人游戏,有背景音乐和提示音,可改变地图大小,游戏速度。 附带游戏说明及视频。
资源截图
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Media;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.IO;

namespace Snake
{
    /// 
    /// 二维坐标
    /// 

    class Vector2
    {
        int x;
        int y;
        public Vector2(int x int y)
        {
            this.x = x;
            this.y = y;
        }

        public int X
        {
            get
            {
                return x;
            }
        }

        public int Y
        {
            get
            {
                return y;
            }
        }
    }

    /// 
    /// 配置信息
    /// 

    class Map
    {
        public static int X = 20;
        public static int Y = 20;
    }
    /// 
    /// 配置信息
    /// 

    class Option
    {
        public static SoundPlayer s = new SoundPlayer(Directory.GetCurrentDirectory() + @“snake.wav“);
        public static bool music = true;
        public static bool sound = true;
        public static int speed = 500;
    }

    /// 
    /// 蛇头方向枚举
    /// 

    enum SnakeDirect
    {
        up down left right
    }

    /// 
    /// 蛇类
    /// 

    class SnakeAll
    {
        int score;
        bool isDead;
        ConsoleColor color;
        Vector2 head tail node judge;
        SnakeDirect sd;
        Queue sall = new Queue();

        //构造函数——初始化
        public SnakeAll()
        {
            score = 0;
            isDead = false;
            color = ConsoleColor.Red;
            //初始方向往上
            sd = SnakeDirect.down;
            node = new Vector2(0 0);
            sall.Enqueue(node);
            node = new Vector2(0 1);
            sall.Enqueue(node);
            //初始蛇头蛇尾
            //tail = sall.Peek();
            head = node;
        }
        public SnakeAll(int no)
        {
            score = 0;
            isDead = false;
            color = ConsoleColor.Blue;
            //初始方向往上
            sd = SnakeDirect.up;
            node = new Vector2(Map.X-1 Map.Y-1);
            sall.Enqueue(node);
            node = new Vector2(Map.X-1 Map.Y-1-1);
            sall.Enqueue(node);
            //初始蛇头蛇尾
            //tail = sall.Peek();
            head = node;
        }

        //蛇头方向改变
        public void DirectChange(ConsoleKeyInfo info)
        {
            if (sd == SnakeDirect.up)
            {
                if (info.Key != ConsoleKey.UpArrow || info.Key != ConsoleKey.DownArrow || info.Key != ConsoleKey.W || info.Key != ConsoleKey.S)
                {
                    switch (info.Key)
                    {
                        case ConsoleKey.A:
                        case ConsoleKey.LeftArrow:
                            sd = SnakeDirect.left;
                

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-06-02 18:19  Snake
     文件    93214958  2018-06-02 19:05  Snake.mp4
     文件         189  2018-05-30 08:37  SnakeApp.config
     目录           0  2018-06-02 18:19  Snakein
     目录           0  2018-06-02 18:19  SnakeinDebug
     文件       20480  2018-06-02 18:18  SnakeinDebugSnake.exe
     文件         189  2018-05-30 08:37  SnakeinDebugSnake.exe.config
     文件       36352  2018-06-02 18:18  SnakeinDebugSnake.pdb
     文件       22696  2018-06-02 18:18  SnakeinDebugSnake.vshost.exe
     文件         189  2018-05-30 08:37  SnakeinDebugSnake.vshost.exe.config
     文件         490  2013-03-18 17:00  SnakeinDebugSnake.vshost.exe.manifest
     文件     7835692  2018-06-01 16:23  SnakeinDebugSnake.wav
     目录           0  2018-06-02 20:00  SnakeinRelease
     目录           0  2018-06-02 18:19  Snakeobj
     目录           0  2018-06-02 18:19  SnakeobjDebug
     文件         725  2018-06-01 15:04  SnakeobjDebugDesignTimeResolveAssemblyReferences.cache
     文件        6758  2018-06-02 15:30  SnakeobjDebugDesignTimeResolveAssemblyReferencesInput.cache
     文件         430  2018-06-02 18:18  SnakeobjDebugSnake.csproj.FileListAbsolute.txt
     文件        1922  2018-05-30 13:45  SnakeobjDebugSnake.csprojResolveAssemblyReference.cache
     文件       20480  2018-06-02 18:18  SnakeobjDebugSnake.exe
     文件       36352  2018-06-02 18:18  SnakeobjDebugSnake.pdb
     文件           0  2018-05-30 08:37  SnakeobjDebugTemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
     文件           0  2018-05-30 08:37  SnakeobjDebugTemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
     文件           0  2018-05-30 08:37  SnakeobjDebugTemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
     目录           0  2018-06-02 18:19  SnakeobjDebugTempPE
     文件        3072  2018-06-01 15:34  SnakeobjDebugTempPEProperties.Resources.Designer.cs.dll
     文件       49080  2018-06-04 15:26  SnakeProgram.cs
     目录           0  2018-06-02 18:19  SnakeProperties
     文件        1336  2018-05-30 08:37  SnakePropertiesAssemblyInfo.cs
     文件        2670  2018-06-01 15:34  SnakeSnake.csproj
     文件         226  2018-06-01 15:43  SnakeSnake.csproj.user
............此处省略1个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)