SnakeBody.cs
上传用户:cljx11
上传日期:2022-08-09
资源大小:49k
文件大小:1k
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Collections;
- namespace Snake_v2
- {
- static class SnakeBody
- {
- public static ArrayList BodyX = new ArrayList();
- public static ArrayList BodyY = new ArrayList();
- public static void BodyClear() //清空
- {
- BodyX.Clear();
- BodyY.Clear();
- SnakeMap.MapClear();
- }
- public static void BodyAdd(int x,int y) //加蛇头
- {
- BodyX.Insert(0,x);
- BodyY.Insert(0,y);
- SnakeMap.Map[x, y] = 1;
- }
- public static void BodyDel() //删蛇尾
- {
- SnakeMap.Map[(int)BodyX[BodyX.Count - 1],(int)BodyY[BodyY.Count - 1]] = 0;
- BodyX.RemoveAt(BodyX.Count - 1);
- BodyY.RemoveAt(BodyY.Count - 1);
- }
- public static void NewSnake(int l) //产生一条蛇长为 l 的新蛇
- {
- BodyClear();
- for (int i = 0; i <l; i++)
- {
- BodyAdd(i,0);
- SnakeMap.Map[i,0] = 1;
- }
- }
- public static int GetSnakeHeadX()
- {
- return (int)BodyX[0];
- }
- public static int GetSnakeHeadY()
- {
- return (int)BodyY[0];
- }
- }
- }