-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.uconn.edu/jwb11006/CSE-4705-C…
- Loading branch information
Showing
5 changed files
with
175 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# CSE-4705-Checkers | ||
A very good checkers player. | ||
|
||
So far the view works. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,87 @@ | ||
package view; | ||
|
||
import java.awt.BorderLayout; | ||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ActionListener; | ||
import java.awt.event.KeyEvent; | ||
|
||
import javax.swing.JFrame; | ||
import javax.swing.JLabel; | ||
import javax.swing.JPanel; | ||
import javax.swing.JMenu; | ||
import javax.swing.JMenuBar; | ||
import javax.swing.JMenuItem; | ||
import javax.swing.JOptionPane; | ||
|
||
|
||
public class CheckersWindow extends JFrame { | ||
|
||
public static final int HEIGHT = 800; | ||
public static final int HEIGHT = 825; | ||
public static final int WIDTH = 800; | ||
private CheckersCanvas canvas; | ||
private GamePanel gamePanel; | ||
|
||
|
||
public CheckersWindow() { | ||
super("Checkers"); | ||
this.setSize(WIDTH, HEIGHT); | ||
this.setDefaultCloseOperation(EXIT_ON_CLOSE); | ||
this.setResizable(false); | ||
this.setLocationRelativeTo(null); | ||
this.getContentPane().add(new CheckersCanvas(), BorderLayout.CENTER); | ||
initGamePanel(); | ||
this.createMenuBar(); | ||
this.setVisible(true); | ||
this.setResizable(false); | ||
|
||
//pack(); | ||
} | ||
|
||
public CheckersCanvas getCanvas() { | ||
return canvas; | ||
|
||
private void createMenuBar() { | ||
JMenuBar menubar = new JMenuBar(); | ||
JMenu file = new JMenu("File"); | ||
//New Game | ||
JMenuItem newGame = new JMenuItem("New game"); | ||
newGame.setMnemonic(KeyEvent.VK_N); | ||
newGame.setToolTipText("Start a new game"); | ||
newGame.addActionListener(new ActionListener() { | ||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
//this.getContentPane().add(new CheckersCanvas(), BorderLayout.CENTER); | ||
} | ||
}); | ||
//Quit | ||
JMenuItem quit = new JMenuItem("Quit"); | ||
quit.setMnemonic(KeyEvent.VK_Q); | ||
quit.setToolTipText("Exit application"); | ||
quit.addActionListener(new ActionListener() { | ||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
System.exit(0); | ||
} | ||
}); | ||
//Rules | ||
JMenuItem instructions = new JMenuItem("Instructions"); | ||
instructions.setMnemonic(KeyEvent.VK_I); | ||
instructions.setToolTipText("How to play"); | ||
instructions.addActionListener(new ActionListener() { | ||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
JOptionPane.showMessageDialog(null, "<html><ol><li>instr 1</li></ol></html>", "title", JOptionPane.INFORMATION_MESSAGE); | ||
//JOptionPane.showMessageDialog(null, "<html>instr 1<br></html>", "title", JOptionPane.INFORMATION_MESSAGE); | ||
} | ||
}); | ||
|
||
file.add(quit); | ||
file.add(newGame); | ||
file.add(instructions); | ||
menubar.add(file); | ||
menubar.setVisible(true); | ||
setJMenuBar(menubar); | ||
} | ||
|
||
public void setCanvas(CheckersCanvas canvas) { | ||
this.canvas = canvas; | ||
|
||
|
||
private void initGamePanel() { | ||
this.gamePanel = new GamePanel(); | ||
this.getContentPane().add(this.gamePanel, BorderLayout.CENTER); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package view; | ||
|
||
import java.awt.event.MouseEvent; | ||
import java.awt.event.MouseListener; | ||
|
||
import javax.swing.JLabel; | ||
import javax.swing.JPanel; | ||
|
||
public class GamePanel extends JPanel implements MouseListener { | ||
private JLabel messageBar; | ||
private CheckersCanvas canvas; | ||
|
||
private Square moveDestination; | ||
private Square moveSource; | ||
|
||
public GamePanel() { | ||
this.messageBar = new JLabel("Select a piece to move."); | ||
this.canvas = new CheckersCanvas(this); | ||
|
||
this.add(this.messageBar); | ||
this.add(this.canvas); | ||
} | ||
|
||
public void displayMessage(String message) { | ||
this.messageBar.setText(message); | ||
} | ||
|
||
@Override | ||
public void mouseClicked(MouseEvent arg0) { | ||
|
||
|
||
} | ||
|
||
@Override | ||
public void mouseEntered(MouseEvent e) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public void mouseExited(MouseEvent e) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public void mousePressed(MouseEvent e) { | ||
Square square = (Square) e.getComponent(); | ||
if(square.hasPiece()) { | ||
if (!square.isSelected()) { | ||
square.setSelected(true); | ||
if (moveSource != null) | ||
moveSource.setSelected(false); | ||
if (moveDestination != null) | ||
moveDestination.setSelected(false); | ||
moveDestination = null; | ||
moveSource = square; | ||
displayMessage("Select a destination."); | ||
} else { | ||
if (square == moveSource) | ||
moveSource = null; | ||
square.setSelected(false); | ||
displayMessage("Select a piece to move."); | ||
} | ||
} else { | ||
|
||
if (!square.isSelected()) { | ||
square.setSelected(true); | ||
if (moveDestination != null) | ||
moveDestination.setSelected(false); | ||
moveDestination = square; | ||
if (moveSource != null) | ||
displayMessage("Select \"Move\" to move the piece."); | ||
else | ||
displayMessage("Select a piece to move."); | ||
} else { | ||
if (square == moveDestination) | ||
moveDestination = null; | ||
square.setSelected(false); | ||
if (moveSource != null) | ||
displayMessage("Select a destination."); | ||
} | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void mouseReleased(MouseEvent e) { | ||
|
||
} | ||
} |
This file was deleted.
Oops, something went wrong.