package LUDO_BUILD;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.Timer;
import javax.swing.JPanel;
public class GameMoves extends JPanel implements KeyListener, ActionListener,MouseListener{
private static final long serialVersionUID = 1L;
Layout la;
Build_Player p;
Timer time;
int delay=10;
int current_player,dice;
int flag=0,roll,kill=0;
public GameMoves() {
setFocusTraversalKeysEnabled(false);
requestFocus();
current_player=0;
la = new Layout(80,50);
p=new Build_Player(la.height,la.width);
dice=0;
flag=0;
roll=0;
kill=0;
}
@Override
public void paint(Graphics g) {
la.draw((Graphics2D)g);
p.draw((Graphics2D)g);
if(p.pl[current_player].coin==4) {
g.setColor(Color.WHITE);
g.fillRect(590, 100, 380,130);
if(current_player==0) {
g.setColor(Color.RED);
}
else if(current_player==1) {
g.setColor(Color.GREEN);
}
else if(current_player==2) {
g.setColor(Color.YELLOW);
}
else if(current_player==3) {
g.setColor(Color.BLUE);
}
g.setFont(new Font("serif", Font.BOLD, 40));
g.drawString("Player "+(current_player+1)+" wins.", 600, 150);
g.drawString("Congratulations.", 600, 200);
current_player=0;
la = new Layout(80,50);
p=new Build_Player(la.height,la.width);
dice=0;
flag=0;
roll=0;
kill=0;
}
else if(dice!=0) {
g.setColor(Color.WHITE);
g.fillRect(590, 100, 380,130);
if(current_player==0) {
g.setColor(Color.RED);
}
else if(current_player==1) {
g.setColor(Color.GREEN);
}
else if(current_player==2) {
g.setColor(Color.YELLOW);
}
else if(current_player==3) {
g.setColor(Color.BLUE);
}
g.setFont(new Font("serif", Font.BOLD, 40));
g.drawString("Player "+(current_player+1), 600, 150);
g.drawString("Number on dice is "+dice, 600, 200);
}
if(flag==0&&dice!=0&&dice!=6&&kill==0) {
current_player=(current_player+1)%4;
}
kill=0;
}
@Override
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
if (e.getKeyCode() == KeyEvent.VK_ENTER&&flag==0) {
roll=0;
dice=1 + (int)(Math.random() * 6);
repaint();
for(int i=0;i<4;i++) {
if(p.pl[current_player].pa[i].current!=-1&&p.pl[current_player].pa[i].current!=56&&(p.pl[current_player].pa[i].current+dice)<=56) {
flag=1;
break;
}
}
if(flag==0&&dice==6) {
for(int i=0;i<4;i++) {
if(p.pl[current_player].pa[i].current==-1) {
flag=1;
break;
}
}
}
}
}
public void mouseClicked(MouseEvent e) {
if(flag==1) {
int x=e.getX();
int y=e.getY();
x=x-80;
y=y-50;
x=x/30;
y=y/30;
int value=-1;
//System.out.println(x+" "+y);
if(dice==6) {
for(int i=0;i<4;i++) {
if(p.pl[current_player].pa[i].x==x&&p.pl[current_player].pa[i].y==y&&(p.pl[current_player].pa[i].current+dice)<=56) {
value=i;
flag=0;
break;
}
}
if(value!=-1) {
p.pl[current_player].pa[value].current+=dice;
if(p.pl[current_player].pa[value].current==56) {
p.pl[current_player].coin++;
}
int k=0;
int hou=p.pl[current_player].pa[value].current;
if((hou%13)!=0&&(hou%13)!=8&&hou<51)
{
for(int i=0;i<4;i++) {
if(i!=current_player) {
for(int j=0;j<4;j++) {
int tem1=Path.ax[current_player][p.pl[current_player].pa[value].current],tem2=Path.ay[current_player][p.pl[current_player].pa[value].current];
if(p.pl[i].pa[j].x==tem1&&p.pl[i].pa[j].y==tem2) {
p.pl[i].pa[j].current=-1;
kill=1;
k=1;
break;
}
}
}
if(k==1)
break;
}
}
}
else {
for(int i=0;i<4;i++) {
if(p.pl[current_player].pa[i].current==-1) {
p.pl[current_player].pa[i].current=0;
flag=0;
break;
}
}
}
}
else {
for(int i=0;i<4;i++) {
if(p.pl[current_player].pa[i].x==x&&p.pl[current_player].pa[i].y==y&&(p.pl[current_player].pa[i].current+dice)<=56) {
value=i;
flag=0;
break;
}
}
if(value!=-1) {
p.pl[current_player].pa[value].current+=dice;
if(p.pl[current_player].pa[value].current==56) {
p.pl[current_player].coin++;
}
int k=0;
int hou=p.pl[current_player].pa[value].current;
if((hou%13)!=0&&(hou%13)!=8&&hou<51)
{
for(int i=0;i<4;i++) {
if(i!=current_player) {
for(int j=0;j<4;j++) {
int tem1=Path.ax[current_player][p.pl[current_player].pa[value].current],tem2=Path.ay[current_player][p.pl[current_player].pa[value].current];
if(p.pl[i].pa[j].x==tem1&&p.pl[i].pa[j].y==tem2) {
p.pl[i].pa[j].current=-1;
kill=1;
k=1;
break;
}
}
}
if(k==1)
break;
}
}
}
}
repaint();
}
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyReleased(KeyEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
}
}
小云同志你好
- 粉丝: 1067
- 资源: 1067
最新资源
- 爱依克签批屏KY系列BS架构二次开发包,采用Websocket通信协议,内含驱动服务与开发文档,支持H5页面签名,PDF文件签名、指纹采集捺印以及摄像头拍摄和二代证身份身份信息读取
- Aspera高效文件传输产品技术解析与应用
- STM32DS3231硬件I2C读写,基于HAL库
- double数据做乘法保留两位小数的处理办法.txt
- 详细解读:毕业设计项目及写作技巧全程指南
- 学生成绩管理系统软件界面
- js判断时间多久之前.txt
- Temporal注解的作用.txt
- 五行与商业:古代智慧的探索与传承.docx
- 04747《Java语言程序设计(一)》真题试题 2019 -2021
- 处理苹果手机倒计时功能异常.txt
- HarmonyOS-ArkTS语言-购物商城的实现
- 导出表格报错net.sf.excelutils.ExcelException.txt
- 判断对象不为空的方法参考.txt
- Python爬虫技术入门与实战指南
- C++程序设计 课件PPT
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈