Project1

标题: 空心菱形问题 [打印本页]

作者: chd114    时间: 2013-10-19 18:38
标题: 空心菱形问题
RUBY 代码复制
  1. #环菱形
  2.     when 4
  3.       delete = []
  4.       p delete
  5.       for i in more_step
  6.         x = position[i][0]
  7.         y = position[i][1]
  8.         # 无视障碍物的场合
  9.         if through
  10.           # 下
  11.           if !position.include?([x, y + 1])
  12.             position.push([x, y + 1])
  13.             route.push(route[i] + [2])
  14.             if route[i].size + 1 < max
  15.               more_step.push(route.index(route[i] + [2]))
  16.               if route[i].size + 1 < max-1
  17.                 delete.push(position.push([x, y + 1]),route.index(route[i] + [2]))
  18.               end
  19.             end
  20.           end
  21.           # 左
  22.           if !position.include?([x - 1, y])
  23.             position.push([x - 1, y])
  24.             route.push(route[i] + [4])
  25.             if route[i].size + 1 < max
  26.               more_step.push(route.index(route[i] + [4]))
  27.               if route[i].size + 1 < max-1
  28.                 delete.push(position.push([x - 1, y]),route.index(route[i] + [4]))
  29.               end
  30.             end
  31.           end
  32.           # 右
  33.           if !position.include?([x + 1, y])
  34.             position.push([x + 1, y])
  35.             route.push(route[i] + [6])
  36.             if route[i].size + 1 < max
  37.               more_step.push(route.index(route[i] + [6]))
  38.               if route[i].size + 1 < max-1
  39.                 delete.push(position.push([x - 1, y]),route.index(route[i] + [6]))
  40.               end
  41.             end
  42.           end
  43.           # 上
  44.           if !position.include?([x, y - 1])
  45.             position.push([x, y - 1])
  46.             route.push(route[i] + [8])
  47.             if route[i].size + 1 < max
  48.               more_step.push(route.index(route[i] + [8]))
  49.               if route[i].size + 1 < max-1
  50.                 delete.push(position.push([x, y - 1]),route.index(route[i] + [8]))
  51.               end
  52.             end
  53.           end
  54.           p delete
  55.           for i in delete
  56.             position.delete(i)
  57.           end
  58.           return position
  59.  
  60.         # 非无视障碍物的场合
  61.         else
  62.           # 下
  63.           if !position.include?([x, y + 1]) and !on_area?(x, y, type) and
  64.             (@battler.passable?(x, y, 2) or (on_area?(x, y + 1, type) and type != 4))
  65.             position.push([x, y + 1])
  66.             route.push(route[i] + [2])
  67.             if route[i].size + 1 < max
  68.               more_step.push(route.index(route[i] + [2]))
  69.             end
  70.             end
  71.           # 左
  72.           if !position.include?([x - 1, y]) and !on_area?(x, y, type) and
  73.             (@battler.passable?(x, y, 4) or (on_area?(x - 1, y, type) and type != 4))
  74.             position.push([x - 1, y])
  75.             route.push(route[i] + [4])
  76.             if route[i].size + 1 < max
  77.               more_step.push(route.index(route[i] + [4]))
  78.             end
  79.           end
  80.           # 右
  81.           if !position.include?([x + 1, y]) and !on_area?(x, y, type) and
  82.             (@battler.passable?(x, y, 6) or (on_area?(x + 1, y, type) and type != 4))
  83.             position.push([x + 1, y])
  84.             route.push(route[i] + [6])
  85.             if route[i].size + 1 < max
  86.               more_step.push(route.index(route[i] + [6]))
  87.             end
  88.           end
  89.           # 上
  90.           if !position.include?([x, y - 1]) and !on_area?(x, y, type) and
  91.           (@battler.passable?(x, y, 8) or (on_area?(x, y - 1, type) and type != 4))
  92.             position.push([x, y - 1])
  93.             route.push(route[i] + [8])
  94.             if route[i].size + 1 < max
  95.               more_step.push(route.index(route[i] + [8]))
  96.             end
  97.           end
  98.         end
  99.       end


脚本是这样···正常效果是要获得一个空心的菱形,可是实际应用效果却是无论怎么定义都获得一个最小的菱形···




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1