오목 주석좀 도와주세요(자바 GUI 렌주룰 일반룰 있음)

익명 사용자의 이미지

이 코딩을 설명해야하는데 이 거 주석좀 달아주세요 ㅠ

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;

import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

class pos {
int x, y, z;

public pos(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
}

public class omok {
JRadioButton btn1 = new JRadioButton("일반룰");
JRadioButton btn2 = new JRadioButton("렌주룰");
ButtonGroup btnGroup = new ButtonGroup();
JFrame window = new JFrame("오목");
JPanel main = new JPanel(new BorderLayout());
boolean finish = false;
int r = 30, boardSize = 15; //보드 사이즈
int x = -150, y = -150;
int[][] position = new int[boardSize][boardSize];
ArrayList posArray = new ArrayList<>();
JPanel btnPanel = new JPanel(new FlowLayout());
JPanel panel1 = new JPanel() {

public void paintComponent(Graphics g) {
g.setColor(Color.lightGray); // 배경
g.fillRect(0, 0, 760, 760);
g.setColor(Color.black); // 선
for (int i = 0; i < boardSize; i++) {
g.drawLine(i * 40 + 10, 10, i * 40 + 10, boardSize * 40 - 30);
g.drawLine(10, i * 40 + 10, boardSize * 40 - 30, i * 40 + 10);
}
for (pos a : posArray) { // 돌
g.setColor(a.z == 1 ? Color.BLACK : Color.WHITE);
g.fillOval(a.x * 40 + 10 - r / 2, a.y * 40 + 10 - r / 2, r, r);
g.setColor((posArray.size() % 2 == 0 ? 1 : 2) == 1 ? Color.BLACK : Color.WHITE);
g.fillOval(x - r / 2, y - r / 2, r, r);
}
}
};

public omok() {
window.setVisible(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setBounds(0, 0, boardSize * 40, boardSize * 40 + 20 + 60);
JPanel panel2 = new JPanel(new BorderLayout());
panel1.setPreferredSize(new Dimension(boardSize * 40, boardSize * 40));
panel2.setPreferredSize(new Dimension(boardSize * 40, 40));

KeyAdapter key = new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_DELETE && !finish)
Back();
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
posArray.clear();
position = new int[boardSize][boardSize];
posArray.add(new pos(7, 7, 1));
position[7][7] = 1;
finish = false;
btn1.setEnabled(true);
btn2.setEnabled(true);
panel1.repaint();
}
}
};
panel1.addMouseListener(new MouseAdapter() {
@Override

public void mousePressed(MouseEvent e) {
if (posArray.size() > 0) {
btn1.setEnabled(!btn2.isSelected());
btn2.setEnabled(!btn1.isSelected());
}
if (e.getX() < boardSize * 40 - 15 && e.getY() < boardSize * 40 - 15 && !finish) {
int x = e.getX(), y = e.getY();

for (int i = 0; i < boardSize; i++) {
if (x > i * 40 - 10 && x <= i * 40 + 30)
x = i;
if (y > i * 40 - 10 && y <= i * 40 + 30)
y = i;
}
if (position[y][x] == 0) {
position[y][x] = posArray.size() % 2 == 0 ? 1 : 2;
posArray.add(new pos(x, y, posArray.size() % 2 == 0 ? 1 : 2));
panel1.repaint();
Rule(posArray.get(posArray.size() - 1).x, posArray.get(posArray.size() - 1).y,
posArray.get(posArray.size() - 1).z);
}
}
}
});
panel1.addMouseMotionListener(new MouseAdapter() {
@Override
public void mouseMoved(MouseEvent e) {
x = e.getX();
y = e.getY();
panel1.repaint();
}
});
posArray.add(new pos(7, 7, 1));
position[7][7] = 1;
window.addKeyListener(key);
panel1.addKeyListener(key);
panel2.addKeyListener(key);
btn1.addKeyListener(key);
btn2.addKeyListener(key);
btnGroup.add(btn1);
btnGroup.add(btn2);
btn2.setSelected(true);
btnPanel.add(btn1, BorderLayout.NORTH);
btnPanel.add(btn2, BorderLayout.SOUTH);
panel2.add(btnPanel, BorderLayout.WEST);
main.add(panel1, BorderLayout.NORTH);
main.add(panel2, BorderLayout.SOUTH);
window.add(main);
}

public static void main(String[] args) {
new omok();
}

private void Back() {
position[posArray.get(posArray.size() - 1).y][posArray.get(posArray.size() - 1).x] = 0;
posArray.remove(posArray.size() - 1);
panel1.repaint();
}

private void Rule(int y, int x, int z) {
String[] Check = new String[4];
for (int i = 5; i > 0; i--) {
if (x - i > -1 && y - i > -1)
Check[2] += position[x - i][y - i] + "";
if (x - i > -1 && y + i < boardSize)
Check[3] += position[x - i][y + i] + "";
if (y - i > -1)
Check[0] += position[x][y - i] + "";
if (x - i > -1)
Check[1] += position[x - i][y] + "";
}

for (int i = 0; i < 6; i++) {
if (x + i < boardSize && y + i < boardSize)
Check[2] += position[x + i][y + i] + "";
if (x + i < boardSize && y - i > -1)
Check[3] += position[x + i][y - i] + "";
if (y + i < boardSize)
Check[0] += position[x][y + i] + "";
if (x + i < boardSize)
Check[1] += position[x + i][y] + "";
}

if (btn2.isSelected() && z == 1) {

int Count33 = 0, Count44 = 0;
for (int i = 0; i < Check.length; i++) { //금수

if (Check[i].contains("01110") || Check[i].contains("010110") || Check[i].contains("011010"))
Count33++;

Count44 += ((Check[i].contains("1111") || Check[i].contains("11011") || Check[i].contains("11101")
|| Check[i].contains("10111")) && !Check[i].contains("211112") && !Check[i].contains("11211")
&& !Check[i].contains("12111") && !Check[i].contains("11121")) ? 1 : 0;
}

if (Count33 > 1 || Count44 > 1) {
Back();
JOptionPane.showMessageDialog(null, "착수 할 수 없습니다.");
}
}
for (int i = 0; i < Check.length; i++)

if ((Check[i].matches(".*[^1]" + "11111" + "[^1].*") && z == 1 && btn2.isSelected())
|| (Check[i].contains("22222") && z == 2)
|| (Check[i].contains("11111") && z == 1 && btn1.isSelected())) {
JOptionPane.showMessageDialog(null, z == 1 ? "흑 승" : "백 승");
finish = true;
}
}
}

참내 ㅋ의 이미지

해캠에서 사서 ㅋㅋㅋㅋㅋ
먼뜻인지 분석해서 리팩할생각은안하고
여기다가 주석쳐달라하는건 뭔 개도둑 발상이에요 ㅋㅋ
님표절걸리게 지금 깃헙에 업로드 하겠습니다 ㅋㅋ

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.