static private int nextPosition; //移动后的蛇头位置 static public int MoveNextPosition(string direction) //移动后的蛇头位置 { int[] coordinate = SNAKE.ChangeToCD(SNAKE.SnakeStart); //coordinate[0]是行-X坐标,coordinate[1]是列-Y坐标 switch (direction) { case "↑": coordinate[0] += -1; break; case "↓": coordinate[0] += 1; break; case "←": coordinate[1] += -1; break; case "→": coordinate[1] += 1; break; default: break; } int i = SNAKE.SnakeCoorID(coordinate[0], coordinate[1]); nextPosition = i; SNAKE.SnakeMoveCoordinate.Add(i); //记录到SNAKE.SnakeMoveCoordinate数组 return(i); }
public void RandomFoodCoor()//随机给出食物的位置 { string id = "pictureBox" + SNAKE.RandomFoodCoor(); object control = this.GetType().GetField(id, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.IgnoreCase).GetValue(this); ((PictureBox)control).Visible = false; int[] asd = SNAKE.ChangeToCD(Convert.ToInt32(SNAKE.FoodCoor)); label4.Text = "食物位置:(" + asd[0] + "," + asd[1] + ")"; label2.Text = "长度:" + SNAKE.SnakeLength; }
public void MoveToDo()//移动 { int move = MOVE.MoveNextPosition(SNAKE.Direction); ((PictureBox)IdControl(move)).Visible = false; if (MOVE.MoveDisappear != 0) { ((PictureBox)IdControl(MOVE.MoveDisappear)).Visible = true; } else { RandomFoodCoor(); } int[] asd = SNAKE.ChangeToCD(SNAKE.SnakeStart); label3.Text = "蛇头位置:(" + asd[0] + "," + asd[1] + ")"; }