c#写的贪食蛇游戏(源码)

本文分享了一款使用C#编程语言编写的贪食蛇游戏完整源码,可供下载学习。
摘要由CSDN通过智能技术生成

 这是一个用c#写的贪食蛇游戏源码,分享一下:

下载地址(含源码)

using  System;
using
 System.Collections.Generic;
using
 System.Text;
using
 System.Drawing;
using
 System.Windows;
using
 System.Windows.Forms;
namespace
 Snake

{
    
//面板初时数据

    public class Map
    
{
        
public  static int NodeWidth = 20
;
        
public static  int MapWidth = 300
;
        
public static int MapHeight = 300
;
        
public static int NodeRowCount = MapWidth /
 NodeWidth;
        
public static int NodeColumCount = MapWidth /
 NodeWidth;
    }

    
//用来绘制snake节点
   public  class DrawNode
    
{
       
public
  Bitmap LocalMap;
       
public static
 Graphics g;
       
public
 DrawNode(Color color)
       
{
           
int
 x, y;
           LocalMap 
= new
 Bitmap(Map.NodeWidth, Map.NodeWidth);
           
for (x = 0; x < LocalMap.Width; x++
)
           
{
               
for (y = 0; y < LocalMap.Height; y++
)
               
{
                   Color pixelColor 
=
 LocalMap.GetPixel(x, y);
                   Color newColor 
=
 color;
                   LocalMap.SetPixel(x, y, newColor);
               }

           }
          
       }
       
       
//在指定的行列处画蛇节点

       public void DrawIn(int n, int m)
       
{
           g.DrawImage(LocalMap, m 
* Map.NodeWidth, n *
 Map.NodeWidth);
       }

       
//按蛇的节点位置画蛇节点
       public void DrawInNode(Node node)
       
{
           DrawIn(node.Row, node.Column); 
       }

        
    }
   
    
//node节点当前方向

    public  enum Direction
    
{
        Up,
        Down,
        Left,
        Right
    }

    
//sanke 节点
    public class Node
    
{
        
public int Row;//行数

        public int Column;//列数
        public  Direction NodeDirection;//方向
        public Node(int Row, int Column, Direction NodeDirection)
        
{
            
this.Row =
 Row;
            
this.Column =
 Column;
            
this.NodeDirection =
 NodeDirection;
        }

        
public bool IsEqual(Node node) //判断2节点位置是否相等
        {
            
if (this.Column == node.Column && this.Row ==
 node.Row)
            
{
                
return
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值