📄 ycgdiamonds.java
字号:
if(user2.CanRound())
{
user2.ClearTemp();
int x1=user2.tempMyImage.x1-user2.tempMyImage.x3;
int x2=user2.tempMyImage.x2-user2.tempMyImage.x3;
int x4=user2.tempMyImage.x4-user2.tempMyImage.x3;
int y1=user2.tempMyImage.y1-user2.tempMyImage.y3;
int y2=user2.tempMyImage.y2-user2.tempMyImage.y3;
int y4=user2.tempMyImage.y4-user2.tempMyImage.y3;
user2.tempMyImage.x1=user2.tempMyImage.x3+y1;
user2.tempMyImage.y1=user2.tempMyImage.y3-x1;
user2.tempMyImage.x2=user2.tempMyImage.x3+y2;
user2.tempMyImage.y2=user2.tempMyImage.y3-x2;
user2.tempMyImage.x4=user2.tempMyImage.x3+y4;
user2.tempMyImage.y4=user2.tempMyImage.y3-x4;
user2.PrintTemp();
}
}
}
else if(key_num==user2.right_key)//>
{
{
if(user2.CanRight())
{
user2.ClearTemp();
user2.tempMyImage.y1++;
user2.tempMyImage.y2++;
user2.tempMyImage.y3++;
user2.tempMyImage.y4++;
user2.PrintTemp();
}
}
}
else if(key_num==user2.down_key)//V
{
{
if(user2.CanDown())
{
user2.ClearTemp();
user2.tempMyImage.x1++;
user2.tempMyImage.x2++;
user2.tempMyImage.x3++;
user2.tempMyImage.x4++;
user2.PrintTemp();
}
else
{
user2.diamonds_panel[user2.tempMyImage.x1][user2.tempMyImage.y1]=user2.tempMyImage.color;
user2.diamonds_panel[user2.tempMyImage.x2][user2.tempMyImage.y2]=user2.tempMyImage.color;
user2.diamonds_panel[user2.tempMyImage.x3][user2.tempMyImage.y3]=user2.tempMyImage.color;
user2.diamonds_panel[user2.tempMyImage.x4][user2.tempMyImage.y4]=user2.tempMyImage.color;
user2.PrintTemp();
if(user2.HaveWin(user2.tempMyImage.x1,user2.tempMyImage.x2,user2.tempMyImage.x3,user2.tempMyImage.x4))
{
//System.out.println("have win");
user2.DealWin();
}
user2.RandomMyImage();
}
}
}
else if(key_num==user2.bottom_key)//到底
{
num1.setText("1消去"+user1.win_number+"分数:"+user1.mark);
num2.setText("2消去"+user2.win_number+"分数:"+user2.mark);
num3.setText("3消去"+user3.win_number+"分数:"+user3.mark);
{
while(user2.CanDown())
{
user2.ClearTemp();
user2.tempMyImage.x1++;
user2.tempMyImage.x2++;
user2.tempMyImage.x3++;
user2.tempMyImage.x4++;
//user2.PrintTemp();
}
user2.diamonds_panel[user2.tempMyImage.x1][user2.tempMyImage.y1]=user2.tempMyImage.color;
user2.diamonds_panel[user2.tempMyImage.x2][user2.tempMyImage.y2]=user2.tempMyImage.color;
user2.diamonds_panel[user2.tempMyImage.x3][user2.tempMyImage.y3]=user2.tempMyImage.color;
user2.diamonds_panel[user2.tempMyImage.x4][user2.tempMyImage.y4]=user2.tempMyImage.color;
user2.PrintTemp();
if(user2.HaveWin(user2.tempMyImage.x1,user2.tempMyImage.x2,user2.tempMyImage.x3,user2.tempMyImage.x4))
{
//System.out.println("have win");
user2.DealWin();
}
user2.RandomMyImage();
}
}
else if(key_num==user3.left_key)//<
{
{
if(user3.CanLeft())
{
user3.ClearTemp();
user3.tempMyImage.y1--;
user3.tempMyImage.y2--;
user3.tempMyImage.y3--;
user3.tempMyImage.y4--;
user3.PrintTemp();
}
}
}
else if(key_num==user3.up_key)//^
{
{
if(user3.CanRound())
{
user3.ClearTemp();
int x1=user3.tempMyImage.x1-user3.tempMyImage.x3;
int x2=user3.tempMyImage.x2-user3.tempMyImage.x3;
int x4=user3.tempMyImage.x4-user3.tempMyImage.x3;
int y1=user3.tempMyImage.y1-user3.tempMyImage.y3;
int y2=user3.tempMyImage.y2-user3.tempMyImage.y3;
int y4=user3.tempMyImage.y4-user3.tempMyImage.y3;
user3.tempMyImage.x1=user3.tempMyImage.x3+y1;
user3.tempMyImage.y1=user3.tempMyImage.y3-x1;
user3.tempMyImage.x2=user3.tempMyImage.x3+y2;
user3.tempMyImage.y2=user3.tempMyImage.y3-x2;
user3.tempMyImage.x4=user3.tempMyImage.x3+y4;
user3.tempMyImage.y4=user3.tempMyImage.y3-x4;
user3.PrintTemp();
}
}
}
else if(key_num==user3.right_key)//>
{
{
if(user3.CanRight())
{
user3.ClearTemp();
user3.tempMyImage.y1++;
user3.tempMyImage.y2++;
user3.tempMyImage.y3++;
user3.tempMyImage.y4++;
user3.PrintTemp();
}
}
}
else if(key_num==user3.down_key)//V
{
{
if(user3.CanDown())
{
user3.ClearTemp();
user3.tempMyImage.x1++;
user3.tempMyImage.x2++;
user3.tempMyImage.x3++;
user3.tempMyImage.x4++;
user3.PrintTemp();
}
else
{
user3.diamonds_panel[user3.tempMyImage.x1][user3.tempMyImage.y1]=user3.tempMyImage.color;
user3.diamonds_panel[user3.tempMyImage.x2][user3.tempMyImage.y2]=user3.tempMyImage.color;
user3.diamonds_panel[user3.tempMyImage.x3][user3.tempMyImage.y3]=user3.tempMyImage.color;
user3.diamonds_panel[user3.tempMyImage.x4][user3.tempMyImage.y4]=user3.tempMyImage.color;
user3.PrintTemp();
if(user3.HaveWin(user3.tempMyImage.x1,user3.tempMyImage.x2,user3.tempMyImage.x3,user3.tempMyImage.x4))
{
//System.out.println("have win");
user3.DealWin();
}
user3.RandomMyImage();
}
}
}
else if(key_num==user3.bottom_key)//到底
{
num1.setText("1消去"+user1.win_number+"分数:"+user1.mark);
num2.setText("2消去"+user2.win_number+"分数:"+user2.mark);
num3.setText("3消去"+user3.win_number+"分数:"+user3.mark);
{
while(user3.CanDown())
{
user3.ClearTemp();
user3.tempMyImage.x1++;
user3.tempMyImage.x2++;
user3.tempMyImage.x3++;
user3.tempMyImage.x4++;
//user3.PrintTemp();
}
user3.diamonds_panel[user3.tempMyImage.x1][user3.tempMyImage.y1]=user3.tempMyImage.color;
user3.diamonds_panel[user3.tempMyImage.x2][user3.tempMyImage.y2]=user3.tempMyImage.color;
user3.diamonds_panel[user3.tempMyImage.x3][user3.tempMyImage.y3]=user3.tempMyImage.color;
user3.diamonds_panel[user3.tempMyImage.x4][user3.tempMyImage.y4]=user3.tempMyImage.color;
user3.PrintTemp();
if(user3.HaveWin(user3.tempMyImage.x1,user3.tempMyImage.x2,user3.tempMyImage.x3,user3.tempMyImage.x4))
{
//System.out.println("have win");
user3.DealWin();
}
user3.RandomMyImage();
}
}
}
}//end of dealwith key();
boolean flag_game=false;
//添加键盘事件
public void OpenKey(){
this.addKeyListener(
new KeyListener()
{
public void keyPressed(KeyEvent event)
{
if(event.getKeyCode()==user2.begin_key&&!flag_game)
{
flag_game=true;
net_state.setText("正在搜索网络");
try{
new GameStart().start();
}catch(Exception e){
net_state.setText("连接失败");
};
}
if(event.getKeyCode()==user1.pause_key)
{
try{
if(user1.flag)
{
user1.flag=!user1.flag;
user1.diamonds_thread.suspend();
}
else
{
user1.flag=!user1.flag;
user1.diamonds_thread.resume();
}
}catch(Exception e){};
}
if(event.getKeyCode()==user2.pause_key)
{
try{
if(user2.flag)
{
user2.flag=!user2.flag;
user2.diamonds_thread.suspend();
}
else
{
user2.flag=!user2.flag;
user2.diamonds_thread.resume();
}
}catch(Exception e){};
}
if(event.getKeyCode()==user2.left_key||
event.getKeyCode()==user2.up_key||
event.getKeyCode()==user2.right_key||
event.getKeyCode()==user2.down_key||
event.getKeyCode()==user2.bottom_key
)
{
try{
output.write(event.getKeyCode());
output.flush();
}catch(IOException e){
JOptionPane.showMessageDialog(null,"服务器工作出错");
System.exit(0);};
}
}
public void keyReleased(KeyEvent event)
{
}
public void keyTyped(KeyEvent event)
{
}
});
}
//初始化
public void PictureCreat(){
picture1=new LinkedList();
picture2=new LinkedList();
picture3=new LinkedList();
///预存旗子
{
int temp=picture[(picture_key++)%PICTURE_NUM];
MyImage tt_tempMyImage=new MyImage(0,0,0,0,0,0,0,0,0);
if(temp==1)
tt_tempMyImage.SetMyImage(1,5,2,5,3,5,4,5,BLUE);
if(temp==2)
tt_tempMyImage.SetMyImage(2,5,4,5,3,5,3,4,GREEN);
if(temp==3)
tt_tempMyImage.SetMyImage(2,5,4,5,3,5,2,4,RED);
if(temp==4)
tt_tempMyImage.SetMyImage(2,5,4,5,3,5,2,6,PINK);
if(temp==5)
tt_tempMyImage.SetMyImage(3,5,4,5,3,4,4,4,YELLOW);
if(temp==6)
tt_tempMyImage.SetMyImage(2,5,3,5,3,4,4,4,PURPLE);
if(temp==7)
tt_tempMyImage.SetMyImage(2,5,3,5,3,6,4,6,BLACK);
picture1.addLast(tt_tempMyImage.clone());
picture2.addLast(tt_tempMyImage.clone());
picture3.addLast(tt_tempMyImage.clone());
}
}
//攻击对方
void Destroy(int num)
{
if(user1.win_num==num)
{
user1.win_num=0;
if(have_three)
PutRandom3(num);
PutRandom2(num);
}
if(user2.win_num==num)
{
user2.win_num=0;
PutRandom1(num);
if(have_three)
PutRandom3(num);
}
if(user3.win_num==num)
{
user3.win_num=0;
PutRandom2(num);
PutRandom1(num);
}
}
void PutRandom1(int num){
for(int k=1;k<=num-1;k++)
{ int i,j;
for(i=5;i<=SIZEI-1;i++)
{
for(j=1;j<=SIZEJ;j++)
user1.diamonds_panel[i][j]=user1.diamonds_panel[i+1][j];
}
for(j=1;j<=SIZEJ;j++)
{
user1.diamonds_panel[i][j]=random_point[(random_key++)%POINT_NUM];
}
}
user1.ReDraw();
//user1.ClearTemp();
//user1.PrintTemp();
}
void PutRandom2(int num){
for(int k=1;k<=num-1;k++)
{ int i,j;
for(i=5;i<=SIZEI-1;i++)
{
for(j=1;j<=SIZEJ;j++)
user2.diamonds_panel[i][j]=user2.diamonds_panel[i+1][j];
}
for(j=1;j<=SIZEJ;j++)
{
user2.diamonds_panel[i][j]=random_point[(random_key++)%POINT_NUM];
}
}
user2.ReDraw();
//user2.ClearTemp();
//user2.PrintTemp();
}
void PutRandom3(int num){
for(int k=1;k<=num-1;k++)
{ int i,j;
for(i=5;i<=SIZEI-1;i++)
{
for(j=1;j<=SIZEJ;j++)
user3.diamonds_panel[i][j]=user3.diamonds_panel[i+1][j];
}
for(j=1;j<=SIZEJ;j++)
{
user3.diamonds_panel[i][j]=random_point[(random_key++)%POINT_NUM];
}
}
user3.ReDraw();
//user3.ClearTemp();
//user3.PrintTemp();
}
//请求随机图片
void AskRandom(){
int temp=picture[(picture_key++)%PICTURE_NUM];
MyImage tt_tempMyImage=new MyImage(0,0,0,0,0,0,0,0,0);
if(temp==1)
tt_tempMyImage.SetMyImage(1,5,2,5,3,5,4,5,BLUE);
if(temp==2)
tt_tempMyImage.SetMyImage(2,5,4,5,3,5,3,4,GREEN);
if(temp==3)
tt_tempMyImage.SetMyImage(2,5,4,5,3,5,2,4,RED);
if(temp==4)
tt_tempMyImage.SetMyImage(2,4,4,4,3,4,2,5,PINK);
if(temp==5)
tt_tempMyImage.SetMyImage(2,5,3,5,2,4,3,4,YELLOW);
if(temp==6)
tt_tempMyImage.SetMyImage(2,5,3,5,3,4,4,4,PURPLE);
if(temp==7)
tt_tempMyImage.SetMyImage(2,4,3,4,3,5,4,5,BLACK);
picture1.addLast(tt_tempMyImage);
picture2.addLast(tt_tempMyImage);
picture3.addLast(tt_tempMyImage);
if(user1.flag_random)
{
MyImage tt1=(MyImage)picture1.removeFirst();
user1.flag_random=false;
user1.tempMyImage.SetMyImage(tt1.x1,tt1.y1,tt1.x2,tt1.y2,tt1.x3,tt1.y3,tt1.x4,tt1.y4,tt1.color);
if(user1.diamonds_panel[2][5]!=0)
{
user1.diamonds_panel[2][6]=1;
result.setForeground(new Color(43,43,255));
result.setText("1已结束");
flag1_fail=true;
if(flag1_fail&&flag2_fail)
{
flag1_fail=false;
flag2_fail=false;
user1.CreatDiamondsPanel();
user2.CreatDiamondsPanel();
user3.CreatDiamondsPanel();
this.PictureCreat();
user1.ReDraw();
user2.ReDraw();
user3.ReDraw();
user1.RandomMyImage();
user2.RandomMyImage();
user3.RandomMyImage();
}
}
}
if(user2.flag_random)
{
MyImage tt2=(MyImage)picture2.removeFirst();
user2.flag_random=false;
user2.tempMyImage.SetMyImage(tt2.x1,tt2.y1,tt2.x2,tt2.y2,tt2.x3,tt2.y3,tt2.x4,tt2.y4,tt2.color);
if(user2.diamonds_panel[2][5]!=0)
{
user2.diamonds_panel[2][6]=1;
result.setForeground(new Color(43,43,255));
result.setText("2已结束");
flag2_fail=true;
if(flag1_fail&&flag2_fail)
{
flag1_fail=false;
flag2_fail=false;
user1.CreatDiamondsPanel();
user2.CreatDiamondsPanel();
user3.CreatDiamondsPanel();
this.PictureCreat();
user1.ReDraw();
user2.ReDraw();
user3.ReDraw();
user1.RandomMyImage();
user2.RandomMyImage();
user3.RandomMyImage();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -