发一个processing写的英雄连连看。请大家雅俗共赏。
{:soso_e113:}本来打算就看看的,结果好奇之下就做了一个连连看,算法十分简陋,请算法厉害的帮忙改进。指出错误。
在此感谢那些为我免费纠错的朋友~
此版本为0.01版本,含有大量位置bug.
但不影响演示。
PImage []img;
int [][]map;
int []testMap;
int []testMap2;
Point []CanConnectA;
Point []CanConnectB;
Point []CanConnectC;
Point []CanConnectW;
CPoint point;
int buttonMouse=0;
int x1, y1, x2, y2;
String temp;
boolean GameWin;
class Point
{
int x;
int y;
}
class CPoint
{
int cx;//Screen coordinates
int cy;//Screen coordinates
int x;//Logical coordinates
int y;//Logical coordinates
CPoint()
{
cx=0;
cy=0;
x=0;
y=0;
}
void ScreenToLogical(int cx, int cy)
{
if (cx<600&&cy<400)
{
x=cx/50;
y=cy/50;
}
}
}
////////////////////////////////////////////////////////////setup
void setup()
{
size(640, 400);
background(0);
textFont(createFont("MicrosoftYaHei-80", 10));
point =new CPoint();
CanConnectA=new Point;
CanConnectB=new Point;
CanConnectC=new Point;
CanConnectW=new Point;
for (int i=0;i<100;i++)
{
CanConnectA=new Point();
CanConnectB=new Point();
CanConnectC=new Point();
CanConnectW=new Point();
}
Arrary_Null(CanConnectA);
Arrary_Null(CanConnectB);
Arrary_Null(CanConnectC);
Arrary_Null(CanConnectW);
x1=0;
y1=0;
x2=0;
y2=0;
img=new PImage;
for (int i=1;i<12;i++)
{
temp=i+".png";
img=loadImage(temp);
}
InitGame();
}
void draw()
{
DrawMap();
}
void InitGame()
{
while (true)
{
InitMap();
if (TestMapIsOk())
{
break;
}
}
}
void GameMain()
{
if (IsAWiner())
{
GameOver();
}
if (buttonMouse==1)
{
x1=point.x;
y1=point.y;
println(x1+","+y1+":"+map);
}
if (buttonMouse==2)
{
x2=point.x;
y2=point.y;
println(x2+","+y2+":"+map);
if (map==map&&!((x1==x2)&&(y1==y2))&&(IsCanConnect(x1, y1, x2, y2)))
{
DrawALine(x1, y1, x2, y2);
println(map+":"+map);
map=0;
map=0;
x1=0;
y1=0;
x2=0;
y2=0;
DrawMap();
background(0);
buttonMouse=0;
}
else
{
x1=0;
y1=0;
x2=0;
y2=0;
background(0);
buttonMouse=0;
}
}
}
void InitMap()
{
map = new int;
testMap=new int;
int temp=0;
boolean bottonRandom=false;
for (int i=0;i<8;i++)
{
for (int j=0;j<12;j++)
{
if (!bottonRandom)
{
temp=(int)random(1, 11);
}
else
{
temp++;
if (temp>11)
{
temp=1;
}
}
testMap++;
if (testMap>8)
{
map=temp;
}
else
{
map=(int)random(1, 11);
}
}
}
}
void DrawMap()
{
for (int i=0;i<8;i++)
{
for (int j=0;j<12;j++)
{
if (map==0)
{
continue;
}
image(img], 0+j*50, 0+i*50, 50, 50);
}
}
}
boolean TestMapIsOk()
{
testMap2=new int;
for (int i=0;i<8;i++)
{
for (int j=0;j<12;j++)
{
testMap2]++;
}
}
for (int i=1;i<12;i++)
{
if (((testMap2)%2)!=0)
{
return false;
}
}
return true;
}
boolean IsCanConnect(int x1, int y1, int x2, int y2)
{
if (map==map&&map!=0)
{
println("come in iscan");
FindAllCanConnect(x1, y1, CanConnectA);
for (int i=0;i<CanConnectA.length;i++)
{
FindAllCanConnect(CanConnectA.x, CanConnectA.y, CanConnectB);
}
for (int i=0;i<CanConnectB.length;i++)
{
FindAllCanConnect(CanConnectB.x, CanConnectB.y, CanConnectC);
}
for (int i=0;i<CanConnectW.length;i++)
{
if (CanConnectW.x==-1&&CanConnectW.y==-1)
{
break;
}
println("CanConnectWx:"+CanConnectW.x+"CanConnectWy:"+CanConnectW.y);
if (CanConnectW.x==x2&&CanConnectW.y==y2)
{
return true;
}
}
Arrary_Null(CanConnectA);
Arrary_Null(CanConnectB);
Arrary_Null(CanConnectC);
Arrary_Null(CanConnectW);
}
return false;
}
void DrawALine(int x1, int y1, int x2, int y2)
{
}
void mousePressed()
{
if (mouseButton==LEFT)
{
point.ScreenToLogical(mouseX, mouseY);
buttonMouse++;
if (buttonMouse<3&&buttonMouse>0)
{
GameMain();
fill(0, 0, 255);
rect(point.x*50, point.y*50, 50, 50);
DrawMap();
}
}
}
void FindAllCanConnect(int x, int y, Point []CanConnect)
{
if (x<0||y<0)
{
// println("x:"+x+"y:"+y);
}
else
{
println("come in FindAll");
for (int i=y-1;i>0;i--)//shang
{
if (map==0)
{
Arrary_Add(x, i, CanConnect);
}
else
if (map==map)
{
println("come in FindAll shang");
Arrary_Add(x, i, CanConnectW);
break;
}
else
{
break;
}
}
for (int i=y+1;i<8;i++)//xia
{
if (map==0)
{
Arrary_Add(x, i, CanConnect);
}
else
if (map==map)
{
println("come in FindAll xia");
Arrary_Add(x, i, CanConnectW);
break;
}
else
{
break;
}
}
for (int i=x-1;i>0;i--)//zuo
{
if (map==0)
{
Arrary_Add(i, y, CanConnect);
}
else
if (map==map)
{
println("come in FindAll zuo");
Arrary_Add(i, y, CanConnectW);
break;
}
else
{
break;
}
}
for (int i=x+1;i<12;i++)//you
{
if (map==0)
{
Arrary_Add(i, y, CanConnect);
}
else
if (map==map)
{
println("come in FindAll you"+map+"--"+map);
Arrary_Add(i, y, CanConnectW);
break;
}
else
{
break;
}
}
}
}
void Arrary_Add(int x, int y, Point []CanConnect)
{
int end=0;
for (int i=0;i<CanConnect.length;i++)
{
if (CanConnect.x==-1&&CanConnect.y==-1)
{
end=i;
break;
}
}
CanConnect.x=x;
CanConnect.y=y;
println("end:"+end+"CanConnect"+CanConnect.x+""+CanConnect.y);
}
void Arrary_Null(Point []CanConnect)
{
for (int i=0;i<CanConnect.length;i++)
{
CanConnect.x=-1;
CanConnect.y=-1;
}
}
boolean IsAWiner()
{
for (int i=0;i<8;i++)
{
for (int j=0;j<12;j++)
{
if (map!=0)
{
return false;
}
}
}
return true;
}
void GameOver()
{
fill(200, 0, 100);
textSize(80);
text("You Win!", 160, 160);
fill(100, 200, 100);
rect(160, 200, 150, 80);
rect(330, 200, 150, 80);
fill(0, 0, 100);
textSize(60);
text("Again", 160, 260);
text("Exit", 330, 260);
if (point.x>160&&point.x<310&&point.y>200&&point.y<280)
{
InitGame();
println("again");
}
if (point.x>330&&point.x<480&&point.y>200&&point.y<280)
{
println("exit");
exit();
}
}
{:soso_e142:} 。。 发表于 2013-3-29 13:21 static/image/common/back.gif
:victory: 嘿嘿嘿,谢谢啦 把运行的截图视频什么的贴上来,会大大增加坛友的兴趣 我下载了可是反正编译器里 不显示英雄 解决了 哈哈
挺好玩的确实有挺多的BUG 好多的英雄都消不掉 ;P
支持楼主!! 软件-蹄飞 发表于 2013-9-2 11:24 static/image/common/back.gif
解决了 哈哈
挺好玩的确实有挺多的BUG 好多的英雄都消不掉
支持楼主!!
哈哈,当时就是试着写写,很多算法bug都没改。 yangfanconan你真的是个有趣的人呢~竟然真的用强于交互的processing去做游戏,哈哈~不过很好玩呢,有机会多交流吧~ linkong 发表于 2014-6-23 18:08 static/image/common/back.gif
yangfanconan你真的是个有趣的人呢~竟然真的用强于交互的processing去做游戏,哈哈~不过很好玩呢,有机会多 ...
哈哈。:lol
页:
[1]