• 大小: 309KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-02
  • 语言: C#
  • 标签: C#  小游戏  源码  

资源简介

自己做的C#贪吃蛇,基于winForms,希望对大家有用,入门级代码。

资源截图

代码片段和文件信息

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


namespace SnakeGT
{
    public class Bean : Block
    {
        public Bean()
        {
            this.CurrentColor = Color.Black;
            this.LeftTopPosition = new Point(Program.BeanOffset Program.BeanOffset);
            this.SideLength = Program.SideLength;
        }
        public override void Paint(Graphics g)
        {
            SolidBrush brush = new SolidBrush(this.CurrentColor);
            g.FillRectangle(brush this.LeftTopPosition.X this.LeftTopPosition.Y this.SideLength this.SideLength);
        }
        public void RandomPosition(Floor floor)
        {
            Point floorLeftTopPosition = floor.LeftTopPosition;
            Random r = new Random();

            int randomX = this.SideLength * r.Next((floorLeftTopPosition.X + this.SideLength) / this.SideLength
            (floorLeftTopPosition.X + floor.SideLength - 2 * this.SideLength) / this.SideLength);
            int randomY = this.SideLength * r.Next((floorLeftTopPosition.Y + this.SideLength) / this.SideLength
            (floorLeftTopPosition.Y + floor.Height - 2 * this.SideLength) / this.SideLength);

            this.LeftTopPosition = new Point(randomX randomY);

        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-10-29 10:05  SnakeGT\
     目录           0  2018-10-29 10:05  SnakeGT\.vs\
     目录           0  2018-10-29 10:05  SnakeGT\.vs\SnakeGT\
     目录           0  2018-10-29 10:06  SnakeGT\.vs\SnakeGT\v15\
     文件       71168  2018-11-06 19:25  SnakeGT\.vs\SnakeGT\v15\.suo
     目录           0  2018-10-29 10:06  SnakeGT\.vs\SnakeGT\v15\Server\
     目录           0  2018-11-02 11:00  SnakeGT\.vs\SnakeGT\v15\Server\sqlite3\
     文件           0  2018-10-29 10:06  SnakeGT\.vs\SnakeGT\v15\Server\sqlite3\db.lock
     文件      606208  2018-11-02 13:26  SnakeGT\.vs\SnakeGT\v15\Server\sqlite3\storage.ide
     文件       32768  2018-11-06 19:19  SnakeGT\.vs\SnakeGT\v15\Server\sqlite3\storage.ide-shm
     文件     4120032  2018-11-06 19:25  SnakeGT\.vs\SnakeGT\v15\Server\sqlite3\storage.ide-wal
     目录           0  2018-11-06 19:24  SnakeGT\SnakeGT\
     文件         189  2018-10-29 10:05  SnakeGT\SnakeGT\App.config
     文件        1373  2018-11-02 13:41  SnakeGT\SnakeGT\Bean.cs
     文件         461  2018-11-01 20:41  SnakeGT\SnakeGT\Block.cs
     文件         220  2018-11-01 22:32  SnakeGT\SnakeGT\Direction.cs
     文件         668  2018-11-01 22:06  SnakeGT\SnakeGT\Floor.cs
     文件        1954  2018-11-02 15:56  SnakeGT\SnakeGT\Form1.Designer.cs
     文件        2834  2018-11-02 15:56  SnakeGT\SnakeGT\Form1.cs
     文件        6011  2018-11-02 13:40  SnakeGT\SnakeGT\Form1.resx
     文件        1268  2018-11-01 20:41  SnakeGT\SnakeGT\Program.cs
     目录           0  2018-10-29 10:05  SnakeGT\SnakeGT\Properties\
     文件        1312  2018-10-29 10:05  SnakeGT\SnakeGT\Properties\AssemblyInfo.cs
     文件        2827  2018-10-29 10:05  SnakeGT\SnakeGT\Properties\Resources.Designer.cs
     文件        5612  2018-10-29 10:05  SnakeGT\SnakeGT\Properties\Resources.resx
     文件        1094  2018-10-29 10:05  SnakeGT\SnakeGT\Properties\Settings.Designer.cs
     文件         249  2018-10-29 10:05  SnakeGT\SnakeGT\Properties\Settings.settings
     文件        4792  2018-11-06 19:24  SnakeGT\SnakeGT\Snake.cs
     文件        1514  2018-11-02 15:12  SnakeGT\SnakeGT\SnakeBlock.cs
     文件        3826  2018-11-01 22:32  SnakeGT\SnakeGT\SnakeGT.csproj
     目录           0  2018-10-29 10:05  SnakeGT\SnakeGT\bin\
............此处省略21个文件信息

评论

共有 条评论