Efter första lektionen

This commit is contained in:
lov3b
2022-03-01 18:28:25 +01:00
commit bdb4731a5a
12 changed files with 2101 additions and 0 deletions

61
src/schack/Board.java Normal file
View File

@ -0,0 +1,61 @@
package schack;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Board extends JFrame
{
ArrayList<Piece> pieces = new ArrayList<>();
public Board()
{
setTitle("Schack");
setAlwaysOnTop(true);
setResizable(false);
setContentPane(cp);
cp.setPreferredSize(new Dimension(800, 800) );
pack();
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
JPanel cp = new JPanel()
{
public void paintComponent(Graphics g)
{
Graphics2D g2 = (Graphics2D) g;
g2.scale(100, 100);
g2.setBackground(Color.WHITE);
g2.setColor(Color.BLACK);
for (int i = 0; i < 8; i += 2) {
for (int j = 0; j < 8; j += 2) {
g.fillRect(i, j, 1, 1);
}
}
for (int i = 1; i < 8; i += 2) {
for (int j = 1; j < 8; j += 2) {
g.fillRect(i, j, 1, 1);
}
}
}
};
// for(Piece p : pieces){
// p.draw();
// }
public static void main(String[] args)
{
new Board();
}
}

View File

@ -0,0 +1,16 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package schack;
/**
*
* @author lovbil251
*/
public interface DiagonalWalk
{
public void walDiagonal();
}

6
src/schack/King.java Normal file
View File

@ -0,0 +1,6 @@
package schack;
public final class King extends Piece{
public boolean isSeen(){return true;}
}

17
src/schack/Piece.java Normal file
View File

@ -0,0 +1,17 @@
package schack;
import java.awt.Point;
import java.util.ArrayList;
public class Piece {
public Point position;
public boolean isValidMove(Point p, ArrayList<Piece> pieces){return true;}
void draw()
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

37
src/schack/Schack.java Normal file
View File

@ -0,0 +1,37 @@
package schack;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JFrame;
/**
*
* @author Love Billenius & Simon Hansson
*/
public class Schack extends JFrame
{
public Dimension size = new Dimension(800, 800);
public Schack()
{
setSize(size);
setAlwaysOnTop(true);
setBackground(Color.black);
setVisible(true);
}
private void drawSquares(Graphics g){
}
public static void main(String[] args)
{
new Schack();
}
}