c语言桌面图标贪吃蛇,调用桌面图标玩贪吃蛇

http://bbs.aau.cn/forum.php?mod=viewthread&tid=12085

1.[代码][ AAuto ]代码

import win.ui;

import winex.desktop

/*DSG{{*/

var winform = ..win.form(text="AAuto Form";right=303;bottom=109;mode="popup";title=false)

winform.add(

about={cls="static";left=20;top=30;right=264;bottom=80;color=255;notify=1;transparent=1;z=1}

)

/*}}*/

var scrWidth, scrHeight = win.getScreen();

var tmpWidth = scrWidth * 15;

var tmpHeight = scrHeight * 15;

var iconTop = 2;

var iconLeft = 21;

var iconSize = 75;

var depHeight = math.floor(tmpHeight / (15 * iconSize));

var depWidth = math.floor(tmpWidth / (15 * iconSize));

var count = winex.desktop.listview.count; //桌面图标个数

var snakeLen; //贪吃蛇当前长度

var head; //贪吃蛇的头索引

tab = {};

class iconObj{

int i; //当前引号

int n; //下一个索引号

int x;//坐标 X

int y;//坐标 Y

}

// 创建每个图标的对象

for(i=1; count; 1){

table.insert(tab, iconObj(), i);

}

// 移动细节

moveTo = function(iconIndex){

winex.desktop.listview.setItemPos(iconIndex,

tab[iconIndex].x * iconSize + iconLeft,

tab[iconIndex].y * iconSize + iconTop);

}

//随机食物

showGem = function(num){

math.randomize();

var finded = false ;

while( !finded ){

tab[num].x = math.floor(math.random() * depWidth);

tab[num].y = math.floor(math.random() * depHeight);

finded = true;

for(i=1; snakeLen; 1){

if(tab[i].x == tab[num].x and

tab[i].y == tab[num].y) {

finded = false;

}

}

}

moveTo(num);

}

//游戏初始化

initGame = function(){

winex.desktop.listview.setExtended(0x80000/*_LVS_EX_SNAPTOGRID*/,false);

winex.desktop.listview.modifyStyle(0x100/*_LVS_AUTOARRANGE*/);

if(count< 2) {

win.msgboxErr("图标少于2个");

}

for(i=1;count;1){

var moveToX = -100;

var moveToY = 0;

win.delay(10);

winex.desktop.listview.setItemPos(i, moveToX, moveToY);

}

//初始化蛇的长度

tab[1].n = 1;

tab[1].x = 0;

tab[1].y = depHeight - 1;

moveTo(1);

head = 1;

snakeLen = 1;

showGem(snakeLen + 1);

}

initGame();

// 定时器蛇的移动

var tmId = winform.addtimer(

200,

function(hwnd, msg, id, tick){

c = tab[head];

select(vbKey) {

case 1 {

c.x = c.x-1;

}

case 2 {

c.y =c.y-1;

}

case 3 {

c.x = c.x+1;

}

case 4 {

c.y = c.y+1;

}

}

//判定吃到到食物

if(c.x = tab[snakeLen + 1].x and

c.y = tab[snakeLen + 1].y) {

snakeLen = snakeLen + 1;

tab[snakeLen].n = tab[head].n;

tab[head].n = snakeLen;

head = snakeLen;

if(snakeLen >= count) {

winform.killtimer(id) ;

hotket.close();

winform.msgbox("你赢了");

winform.close();

winex.desktop.listview.modifyStyle(, 0x100/*_LVS_AUTOARRANGE*/ );

winex.desktop.listview.setExtended(0x80000/*_LVS_EX_SNAPTOGRID*/, true);

}

else {

showGem(snakeLen + 1);

}

}

else {

//撞墙咬尾

if(c.x < 0 or c.x >= depWidth or

c.y < 0 or c.y >= depHeight) {

winform.killtimer(id);

if(winform.msgbox("您撞墙了","失败")){

winex.desktop.listview.modifyStyle( , 0x100/*_LVS_AUTOARRANGE*/ );

winex.desktop.listview.setExtended(0x80000/*_LVS_EX_SNAPTOGRID*/, true);

hotket.close();

winform.close();

return ;

}

}

else {

for(i=1; snakeLen; 1){

if( i!= head and tab[i].x = tab[head].x and

tab[i].y = tab[head].y) {

winform.killtimer(id);

if(winform.msgbox("您咬到自己的脚了","失败")){

winex.desktop.listview.modifyStyle( , 0x100/*_LVS_AUTOARRANGE*/ );

winex.desktop.listview.setExtended(0x80000/*_LVS_EX_SNAPTOGRID*/, true);

hotket.close();

winform.close();

}

}

}

}

head = tab[head].n;

tab[head].x = c.x;

tab[head].y = c.y;

moveTo (head);

}

}

)

// 以下是程序运行开始.

//注册热键

import key.hotkey

hotket = key.hotkey(winform);

// left

hotket.reg(

37,

function(hwnd, ...) {

vbKey = 1;

winform.show(false);

}

)

// up

hotket.reg(

38,

function(hwnd, ...) {

vbKey = 2;

winform.show(false);

}

)

// right

hotket.reg(

39,

function(hwnd,...) {

vbKey = 3;

winform.show(false);

}

)

// down

hotket.reg(

40,

function(hwnd, ...) {

vbKey = 4;

winform.show(false);

}

)

// ESC

hotket.reg(

27,

function(hwnd, ...){

winex.desktop.listview.modifyStyle(, 0x100/*_LVS_AUTOARRANGE*/ );

winex.desktop.listview.setExtended(0x80000/*_LVS_EX_SNAPTOGRID*/, true);

winform.close();

}

)

winform.about.text = "玩法:上下左右 按ESC退出,按方向键界面自动消失。"

winform.show();

win.loopMessage();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值