📄 questionsquare.java
字号:
package com.xmu.typot.domain;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.swing.JOptionPane;
import javax.imageio.ImageIO;
import com.xmu.typot.constant.*;
public class QuestionSquare extends Square{
private BufferedImage bf = null;
public QuestionSquare(String name, int index) {
super(name, index);
try {
bf = ImageIO.read(new File("image/question.gif"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// TODO Auto-generated constructor stub
}
public void draw(Graphics2D g2d)
{
g2d.setPaint(Color.BLACK);
g2d.drawImage(bf, this.getStartX(), this.getStartY(), null);
}
public void doRun(Player[] players,int i)
{
int n = (int) (Math.random()*4+1);
String s;
switch(n)
{
case 1:
s = players[i].getName()+"路遇强盗,损失金钱2000";
JOptionPane.showMessageDialog(null, s);
players[i].setMoney(players[i].getMoney()-2000);
this.returnControl(s);
break;
case 2:
s = players[i].getName()+"拣到一个钱包,得到金钱2000";
players[i].setMoney(players[i].getMoney()+2000);
JOptionPane.showMessageDialog(null, s);
this.returnControl(s);
break;
case 3:
s = players[i].getName()+"遇到车祸,住院2天";
players[i].setStopTime(2);
players[i].setStopType(Constants.HOSPITAL_TYPE);
JOptionPane.showMessageDialog(null, s);
while(!players[i].getPiece().getLocation().getName().equals("hospital"))
players[i].getPiece().setLocation(players[i].getPiece().getLocation().getNextSquare());
this.returnControl(s);
break;
case 4:
s = players[i].getName()+"走私毒品被抓,关进监狱2天";
players[i].setStopTime(2);
players[i].setStopType(Constants.PRISON_TYPE);
JOptionPane.showMessageDialog(null, s);
while(!players[i].getPiece().getLocation().getName().equals("prison"))
players[i].getPiece().setLocation(players[i].getPiece().getLocation().getNextSquare());
this.returnControl(s);
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -