public class Test {
public static void main(String[] args) {
Scanner input=new Scanner(System.in)
System.out.println("请输入几*几")
int num=input.nextInt()
String str=""
for (int i = 0i <numi++) {
System.out.println("请输入第"+(i+1)+"行出现在第几个")
int pos=input.nextInt()
for (int j = 1j <= numj++) {
if (pos==j) {
str+="Q"
}else {
str+="*"
}
}
str+="\n"
}
System.out.println(str)
}
}
有什么不懂可以HI我
因为看你是初学,我就不用stringBuffer了,如果要用其它方式 HI我
package com.fzhw.appimport java.awt.BorderLayout
import java.awt.Graphics
import java.awt.Graphics2D
import java.awt.HeadlessException
import javax.swing.JFrame
import javax.swing.JPanel
public class Xiangqi extends JFrame{
private static final long serialVersionUID = 1
public Xiangqi() throws HeadlessException {
super()
setTitle("my board")
this.getContentPane().setLayout(new BorderLayout())
this.getContentPane().add(new Board(), BorderLayout.CENTER)
this.setSize(960, 960)
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
}
public static void main(String args[]){
new Xiangqi().setVisible(true)
}
}
class Board extends JPanel{
private static final long serialVersionUID = 1L
protected void paintComponent(Graphics g) {
super.paintComponent(g)
Graphics2D g2d=(Graphics2D)g
int width=this.getWidth()
int height=this.getHeight()
int hGap=height/9
int wGap=width/8
for(int i=0i<10i++){
g2d.drawLine(0, i*hGap, width, i*hGap)
}
for(int i=0i<9i++){
g2d.drawLine(i*wGap, 0, i*wGap, 4*hGap)
g2d.drawLine(i*wGap, 5*hGap, i*wGap, height)
}
g2d.drawString("楚河 汉界", width/2, height/2)
g2d.drawLine(3*wGap, 0, 5*wGap, 2*hGap)
g2d.drawLine(5*wGap, 0, 3*wGap, 2*hGap)
g2d.drawLine(3*wGap, height, 5*wGap, height-2*hGap)
g2d.drawLine(3*wGap, height-2*hGap, 5*wGap, height)
g2d.dispose()
}
}
象棋绝杀java后端判断输赢的方法有很多,可以使用搜索算法,比如极大极小值算法、蒙特卡洛树搜索算法等。可以使用棋型判断,比如五连子、六六长连等,可以使用规则来判断,比如棋子落子后,如果有一方棋子被吃掉,则另一方获胜等。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)