用AHK实现水木社区一C++程序

/*

发信人: kevin820601 (noname), 信区: CPlusPlus

标  题: 请问这个程序怎么实现啊

发信站: 水木社区 (Tue Oct  5 04:05:02 2010), 站内

 

Please input a number:10

 

    1    2    6    7   15   16   28   29   45   46

 

    3    5    8   14   17   27   30   44   47   64

 

    4    9   13   18   26   31   43   48   63   65

 

   10   12   19   25   32   42   49   62   66   79

 

   11   20   24   33   41   50   61   67   78   80

 

   21   23   34   40   51   60   68   77   81   90

 

   22   35   39   52   59   69   76   82   89   91

 

   36   38   53   58   70   75   83   88   92   97

 

   37   54   57   71   74   84   87   93   96   98

 

   55   56   72   73   85   86   94   95   99  100

 

--

 

※ 来源:·水木社区 http://newsmth.net·[FROM: 202.106.149.*]

 

*/

 

/*

用Ahk实现了这个算法。

 

运行方式:打开一个excel,鼠标点中某单元格,按win+t即可输出上述方阵。

*/

#Persistent

#SingleInstance force

;~ run excel

Return

 

#t::

InputBox, num, INPUT, Please input a number,,280,130,,,,,10

if ErrorLevel

return

else

loop_num:=num*num

 

x:=1

y:=1

direction:=9 ;ru

 

 

loop,%loop_num%

{

 

test(x,y,direction,num)

;~ send %x%,%y%,%direction%; %a_index%

send  %a_index%

if (direction=9) ;ru

ru()

if (direction=6) ;r

r()

if (direction=1) ;ld

ld()

if (direction=2) ;d

d()

 

if (direction=6)

{

direction:=nextDirection

}

if (direction=2)

{

direction:=nextDirection

}

}

 

Return

 

 

 

test(_x,_y,_direction,num)

{

 

 

if(_direction=9)

{

_x+=1

_y-=1

}

if(_direction=6)

{

_x+=1

}

if(_direction=1)

{

_x-=1

_y+=1

}

if(_direction=2)

{

_y+=1

}

 

 

If _y<1

{

;~ MsgBox 上边

global direction:=6

global nextDirection:=1

}

 

;上下两段不可更换次序

 

;~ MsgBox %_x%,%_y%

if _x>%num%

{

;~ msgbox 右边

global direction:=2

global nextDirection:=1

}

 

 

 

if _x<1

{

;~ MsgBox 左边

global direction:=2

global nextDirection:=9

}

 

If _y>%num%

{

;~ MsgBox 下边

global direction:=6

global nextDirection:=9

}

}

 

u(){

global

y-=1

send {Up} ;主键盘上的向上的箭头键

Return

}

d(){

global

y+=1

send {Down}

Return

}

 

l(){

global

x-=1

send {Left} ;主键盘上的向左的箭头键

Return

}

 

r(){

global

x+=1

send {Right}

Return

}

 

ru(){

r()

u()

Return

}

rd(){

r()

d()

Return

}

ld(){

l()

d()

Return

}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值