用java做一个拼图游戏数字的,4*4 有一个空格求帮忙
已有模板和图片求大神帮忙填充比较急code大部分都没写:importjavax.swing.*;importjava.awt.*;importjava.awt.event...
已有模板和图片求大神帮忙填充比较急 code大部分都没写:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.Math;
public class PuzzleStartingPoint implements MouseListener
{
Drawing draw = new Drawing();
int [][] board = {{1,2,3,4}, //4X4 puzzle board
{5,6,7,8}, //0 is the blank spot
{9,10,11,12},
{13,14,15,0}};
ImageIcon[] boardPictures = new ImageIcon[16]; //stores the 16 tile pictures
int blankRow, blankCol;
public PuzzleStartingPoint() // constructor
{
for (int i = 0; i < boardPictures.length; i++)
boardPictures[i] = new ImageIcon(i + ".jpg");
JFrame frame = new JFrame("Puzzle");
frame.add(draw);
draw.addMouseListener(this);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(420, 440);
initializeBoard();
frame.setVisible(true);
}
// gets the 4X4 puzzle board ready to play
public void initializeBoard()
{
} // initializeBoard
// finds a blank spot and picks a tile randomly to move into it
public void shuffleBoard()
{
} // shuffleBoard
// finds where the blank spot is and stores its row and column into blankRow and blankCol
public void findBlank()
{
} // findBlank
// moves the chosen (mouse-clicked) tile into a blank spot if possible
public void moveTile(int row, int col)
{
} // moveTile
class Drawing extends JComponent
{
public void paint(Graphics g)
{
for (int row = 0; row < 4; row++)
for (int col = 0; col < 4; col++)
g.drawImage(boardPictures[board[row][col]].getImage(),col * 100, row * 100,100,100,this);
}
}
// --> starting implementing MouseListener - it has 5 methods
public void mousePressed(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e)
{
// find coords of mouse click
int row = e.getY()/100;
int col = e.getX()/100;
moveTile(row, col);
// get paint to be called to reflect your mouse work
draw.repaint();
}
public void mouseClicked(MouseEvent e)
{
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
// finishing implementing MouseListener <---
public static void main(String[] args)
{
new PuzzleStartingPoint();
}
}
nono 展开
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.Math;
public class PuzzleStartingPoint implements MouseListener
{
Drawing draw = new Drawing();
int [][] board = {{1,2,3,4}, //4X4 puzzle board
{5,6,7,8}, //0 is the blank spot
{9,10,11,12},
{13,14,15,0}};
ImageIcon[] boardPictures = new ImageIcon[16]; //stores the 16 tile pictures
int blankRow, blankCol;
public PuzzleStartingPoint() // constructor
{
for (int i = 0; i < boardPictures.length; i++)
boardPictures[i] = new ImageIcon(i + ".jpg");
JFrame frame = new JFrame("Puzzle");
frame.add(draw);
draw.addMouseListener(this);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(420, 440);
initializeBoard();
frame.setVisible(true);
}
// gets the 4X4 puzzle board ready to play
public void initializeBoard()
{
} // initializeBoard
// finds a blank spot and picks a tile randomly to move into it
public void shuffleBoard()
{
} // shuffleBoard
// finds where the blank spot is and stores its row and column into blankRow and blankCol
public void findBlank()
{
} // findBlank
// moves the chosen (mouse-clicked) tile into a blank spot if possible
public void moveTile(int row, int col)
{
} // moveTile
class Drawing extends JComponent
{
public void paint(Graphics g)
{
for (int row = 0; row < 4; row++)
for (int col = 0; col < 4; col++)
g.drawImage(boardPictures[board[row][col]].getImage(),col * 100, row * 100,100,100,this);
}
}
// --> starting implementing MouseListener - it has 5 methods
public void mousePressed(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e)
{
// find coords of mouse click
int row = e.getY()/100;
int col = e.getX()/100;
moveTile(row, col);
// get paint to be called to reflect your mouse work
draw.repaint();
}
public void mouseClicked(MouseEvent e)
{
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
// finishing implementing MouseListener <---
public static void main(String[] args)
{
new PuzzleStartingPoint();
}
}
nono 展开
3个回答
展开全部
用你的模板写还不如重写一个比较快。。。。
追问
不行啊,老师给了模板,求大神帮忙
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
eeeeeeee e e
e e e
eeeeeeee e e
e e e
eeeeeeee
e e e
eeeeeeee e e
e e e
eeeeeeee
追问
求不水
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-12-16
展开全部
已发送给你邮箱
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询