mirror of
https://github.com/lov3b/Schack.git
synced 2025-01-18 12:50:10 +01:00
taw bort sånt vi inte använder
This commit is contained in:
parent
06f6b4510c
commit
3139ca2db2
@ -3,6 +3,8 @@ package schack;
|
|||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import javax.swing.JMenuItem;
|
||||||
|
import javax.swing.JPopupMenu;
|
||||||
|
|
||||||
public class Pawn extends Piece {
|
public class Pawn extends Piece {
|
||||||
|
|
||||||
@ -74,7 +76,7 @@ public class Pawn extends Piece {
|
|||||||
* @param pieces
|
* @param pieces
|
||||||
*/
|
*/
|
||||||
private ArrayList<Point> addAttackMovesIfCan(Point pos, Piece[][] pieces) {
|
private ArrayList<Point> addAttackMovesIfCan(Point pos, Piece[][] pieces) {
|
||||||
ArrayList movable = new ArrayList<Point>();
|
ArrayList<Point> movable = new ArrayList();
|
||||||
// Se till att vi inte är utanför brädet
|
// Se till att vi inte är utanför brädet
|
||||||
if (pos.x >= pieces.length || pos.x < 0 || pos.y >= pieces[0].length || pos.y < 0) {
|
if (pos.x >= pieces.length || pos.x < 0 || pos.y >= pieces[0].length || pos.y < 0) {
|
||||||
return movable;
|
return movable;
|
||||||
|
@ -2,8 +2,6 @@ package schack;
|
|||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JMenu;
|
import javax.swing.JMenu;
|
||||||
import javax.swing.JMenuBar;
|
import javax.swing.JMenuBar;
|
||||||
@ -22,15 +20,8 @@ public class Schack {
|
|||||||
public Schack() throws IOException {
|
public Schack() throws IOException {
|
||||||
// Set theme
|
// Set theme
|
||||||
try {
|
try {
|
||||||
// FlatSolarizedLightIJTheme.setup();
|
|
||||||
// FlatLightLaf.setup();
|
|
||||||
//embedMenuBarIfSupported();
|
|
||||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||||
} catch (Exception cantThemeWithFlatLaf) {
|
} catch (Exception cantGetSystemTheme) {
|
||||||
try {
|
|
||||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
|
||||||
} catch (Exception cantThemeWithSystemLAF) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
frame = new JFrame();
|
frame = new JFrame();
|
||||||
@ -46,24 +37,9 @@ public class Schack {
|
|||||||
// Create menu
|
// Create menu
|
||||||
final JMenuBar menuBar = new JMenuBar();
|
final JMenuBar menuBar = new JMenuBar();
|
||||||
final JMenu gameMenu = new JMenu("Game");
|
final JMenu gameMenu = new JMenu("Game");
|
||||||
final JMenu connectMenu = new JMenu("Connect");
|
|
||||||
final JMenuItem connectToOpponent = new JMenuItem("Connect to opponent");
|
|
||||||
final JMenuItem showLocalIP = new JMenuItem("Show IP");
|
|
||||||
final JMenuItem askForRemi = new JMenuItem("Ask for remi");
|
final JMenuItem askForRemi = new JMenuItem("Ask for remi");
|
||||||
final JMenuItem surrender = new JMenuItem("Surrender");
|
final JMenuItem surrender = new JMenuItem("Surrender");
|
||||||
|
|
||||||
// Actions
|
|
||||||
connectToOpponent.addActionListener((ActionEvent ae) -> {
|
|
||||||
System.out.println("Connecting (TODO)");
|
|
||||||
});
|
|
||||||
showLocalIP.addActionListener((ActionEvent ae) -> {
|
|
||||||
try {
|
|
||||||
String localIp = InetAddress.getLocalHost().toString();
|
|
||||||
JOptionPane.showMessageDialog(frame, "Local IP: " + localIp);
|
|
||||||
} catch (UnknownHostException ex) {
|
|
||||||
JOptionPane.showMessageDialog(frame, "Could not get local IP");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
askForRemi.addActionListener((ActionEvent ae) -> {
|
askForRemi.addActionListener((ActionEvent ae) -> {
|
||||||
String whosWantingRemi = board.isWhitesTurn() ? "Vit" : "Svart";
|
String whosWantingRemi = board.isWhitesTurn() ? "Vit" : "Svart";
|
||||||
int choice = JOptionPane.showConfirmDialog(board, whosWantingRemi + " erbjuder remi\nAccepterar du?");
|
int choice = JOptionPane.showConfirmDialog(board, whosWantingRemi + " erbjuder remi\nAccepterar du?");
|
||||||
@ -91,9 +67,6 @@ public class Schack {
|
|||||||
// Add the menu stuff
|
// Add the menu stuff
|
||||||
frame.setJMenuBar(menuBar);
|
frame.setJMenuBar(menuBar);
|
||||||
menuBar.add(gameMenu);
|
menuBar.add(gameMenu);
|
||||||
menuBar.add(connectMenu);
|
|
||||||
connectMenu.add(connectToOpponent);
|
|
||||||
connectMenu.add(showLocalIP);
|
|
||||||
gameMenu.add(askForRemi);
|
gameMenu.add(askForRemi);
|
||||||
gameMenu.add(surrender);
|
gameMenu.add(surrender);
|
||||||
frame.pack();
|
frame.pack();
|
||||||
@ -105,21 +78,4 @@ public class Schack {
|
|||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
new Schack();
|
new Schack();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void embedMenuBarIfSupported() {
|
|
||||||
// Currently only supported in Windows 10+
|
|
||||||
String os = System.getProperty("os.name");
|
|
||||||
if (os.contains("Windows")) {
|
|
||||||
String versionNumberStr = os.split(" ")[1];
|
|
||||||
try {
|
|
||||||
int versionNumber = Integer.parseInt(versionNumberStr);
|
|
||||||
if (versionNumber >= 10) {
|
|
||||||
System.setProperty("flatlaf.menuBarEmbedded", "true");
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user