/*
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
class adder implements Runnable {
Vector<JLabel> s = new Vector<JLabel>();
JPanel p = new JPanel();
JLabel lb = new JLabel();
int time = 6000, line = 1000;
public adder(Vector<JLabel> s, JPanel c, JLabel sc) {
this.s = s;
this.p = c;
this.lb = sc;
}
@Override
public void run() {
while(true) {
try {
if(Integer.parseInt(lb.getText()) >= line) {
line *= 2;
time /= 2;
}
Words k = new Words(s,p);
Thread th = new Thread(k);
th.start();
Thread.sleep(time);
}
catch (InterruptedException e) {
}
}
}
}
class Words extends JLabel implements Runnable {
Vector<JLabel> saveFile = new Vector<JLabel>();
JPanel cnt = new JPanel();
String [] str = {"cuttlefish",
"public",
"same",
"different"};
public Words(Vector<JLabel> save, JPanel c) {
this.setFont(new Font("Gothic", Font.ITALIC, 35));
this.setLocation((int)(Math.random()*250) + 50, 50);
this.setForeground(Color.magenta);
this.setSize(150,60);
this.setOpaque(false);
this.setVisible(true);
this.saveFile = save;
this.cnt = c;
saveFile.add(this);
this.setText(str[(int)(Math.random()*str.length)]);
cnt.add(this);
}
@Override
public void run() {
while(this.getY() <= 470) {
try {
this.setLocation(this.getX(), this.getY() + 5);
Thread.sleep(200);
cnt.repaint();
cnt.revalidate();
System.out.println(saveFile.size());
}
catch(InterruptedException e) {
return;
}
}
cnt.remove(this);
saveFile.remove(this);
}
}
public class Main extends JFrame {
JPanel SouthPanel, NorthPanel;
JLabel Score;
TextField txtFld;
Vector<JLabel> NowText = new Vector<JLabel>();
public Main() {
setTitle("한컴타자연습");
setSize(400,600);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container cnt = getContentPane();
cnt.setVisible(true);
cnt.setLayout(new BorderLayout());
SouthPanel = new JPanel();
SouthPanel.setBackground(Color.DARK_GRAY);
SouthPanel.setLayout(new FlowLayout());
cnt.add(SouthPanel,BorderLayout.SOUTH);
txtFld = new TextField(30);
txtFld.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
for(int i = 0; i < NowText.size(); i++) {
if(NowText.get(i).getText().equals(txtFld.getText())) {
Score.setText(Integer.toString(Integer.parseInt(Score.getText()) + 100*NowText.get(i).getText().length()));
NorthPanel.remove(NowText.get(i));
NowText.remove(NowText.get(i));
txtFld.setText("");
break;
}
}
if(txtFld.getText().equals("그만")) {
System.exit(0);
}
}
});
SouthPanel.add(txtFld);
NorthPanel = new JPanel();
NorthPanel.setLayout(null);
cnt.add(NorthPanel,BorderLayout.CENTER);
Score = new JLabel("0");
Score.setSize(100,50);
Score.setLocation(35,15);
NorthPanel.add(Score);
adder editor = new adder(NowText,NorthPanel,Score);
Thread th = new Thread(editor);
th.start();
repaint();
}
public static void main(String[] args) {
new Main();
}
*/
/*
import java.io.*;
public class Main {
public static void main(String[] args) {
FileReader fin = null;
try {
fin = new FileReader("C:\\Users\\user\\Desktop\\java images\\test texts.txt");
int c;
while((c = fin.read()) != -1) {
System.out.print((char)c);
}
fin.close();
}
catch(IOException e) {
System.out.println("입출력 오류");
}
}
}
*/
/*
import java.io.*;
public class Main {
public static void main(String[] args) {
InputStreamReader in = null;
FileInputStream fin = null;
try {
fin = new FileInputStream("C:\\Users\\user\\Desktop\\java images\\test texts.txt");
in = new InputStreamReader(fin, "MS949");
int c;
System.out.println("인코딩 문자 집합은 " + in.getEncoding());
while ((c = in.read()) != -1) {
System.out.print((char)c);
}
in.close();
fin.close();
} catch (IOException e) {
System.out.println("입출력 오류");
}
}
}
*/
/*
import java.io.*;
public class Main {
public static void main(String[] args) {
InputStreamReader in = null;
FileInputStream fin = null;
try {
fin = new FileInputStream("C:\\Users\\user\\Desktop\\java images\\test texts.txt");
in = new InputStreamReader(fin, "US-ASCII");
int c;
System.out.println("인코딩 문자 집합은 " + in.getEncoding());
while((c = in.read()) != -1) {
System.out.print((char)c);
}
in.close();
fin.close();
} catch (IOException e) {
System.out.println("입출력 오류");
}
}
}
*/
/*
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
FileWriter fout = null;
int c;
try {
fout = new FileWriter("C:\\Users\\user\\Desktop\\java images\\test texts.txt");
while(true) {
String line = scanner.nextLine();
if(line.length() == 0)
break;
fout.write(line, 0, line.length());
fout.write("\r\n", 0, 2);
}
fout.close();
} catch (IOException e) {
System.out.println("입출력 오류");
}
scanner.close();
}
}
*/
/*
import java.io.*;
public class Main {
public static void main(String[] args) {
byte b[] = {7,51,3,4,-1,24};
try {
FileOutputStream fout = new FileOutputStream("C:\\Users\\user\\Desktop\\java images\\test texts.txt");
for(int i=0; i<b.length; i++)
fout.write(b[i]);
fout.close();
} catch(IOException e) {
System.out.println("C:\\Users\\user\\Desktop\\java images\\test texts.txt에 저장할 수 없습니다. 경로명을 확인해 주세요");
return;
}
System.out.println("C:\\Users\\user\\Desktop\\java images\\test texts.txt을 저장하였습니다.");
}
}
*/
/*
import java.io.*;
public class Main {
public static void main(String[] args) {
byte b[] = new byte[6];
try {
FileInputStream fin = new FileInputStream("C:\\Users\\user\\Desktop\\java images\\test texts.txt");
int n=0, c;
while((c = fin.read()) != -1) {
b[n] = (byte)c;
n++;
}
System.out.println("C:\\Users\\user\\Desktop\\java images\\test texts.txt에서 읽은 배열을 출력합니다.");
for(int i=0; i<b.length; i++)
System.out.print(b[i] + " ");
System.out.println();
fin.close();
} catch(IOException e) {
System.out.println("C:\\Users\\user\\Desktop\\java images\\test texts.txt에서 읽지 못했습니다. 경로명을 체크해보세요");
}
}
}
*/
/*
import java.io.*;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
FileReader fin = null;
int c;
try {
fin = new FileReader("C:\\Users\\user\\Desktop\\java images\\test texts.txt");
BufferedOutputStream out = new BufferedOutputStream(System.out, 5);
while((c = fin.read()) != -1) {
out.write(c);
}
new Scanner(System.in).nextLine();
out.flush();
fin.close();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
*/
/*
import java.io.File;
public class Main {
public static void listDirectory(File dir) {
System.out.println("-----" + dir.getPath() + "의 서브 리스트 입니다.-----");
File[] subFiles = dir.listFiles();
for(int i=0; i<subFiles.length; i++) {
File f = subFiles[i];
long t = f.lastModified();
System.out.print(f.getName());
System.out.print("\t파일 크기: " + f.length());
System.out.printf("\t수정한 시간: %tb %td %ta %tT\n",t, t, t, t);
}
}
public static void main(String[] args) {
File f1 = new File("C:\\Users\\user\\Desktop\\java images\\test texts.txt");
System.out.println(f1.getPath() + ", " + f1.getParent() + ", " + f1.getName());
String res="";
if(f1.isFile()) res = "파일";
else if(f1.isDirectory()) res = "디렉토리";
System.out.println(f1.getPath() + "은 " + res + "입니다.");
File f2 = new File("C:\\Users\\user\\Desktop\\java images\\test texts.txt");
if(!f2.exists()) {
f2.mkdir();
}
listDirectory(new File("C:\\Users\\user\\Desktop\\java images"));
f2.renameTo(new File("C:\\Users\\user\\Desktop\\java images\\test texts.txt"));
listDirectory(new File("C:\\Users\\user\\Desktop\\java images"));
}
}
*/
/*
import java.io.*;
public class Main {
public static void main(String[] args) {
File src = new File("C:\\Users\\user\\Desktop\\java images\\test texts.txt");
File dest = new File("C:\\Users\\user\\Desktop\\java images\\test textx.txt");
int c;
try {
FileReader fr = new FileReader(src);
FileWriter fw = new FileWriter(dest);
while((c = fr.read()) != -1) {
fw.write((char)c);
}
fr.close();
fw.close();
System.out.println(src.getPath() + "를 " + dest.getPath() + "로 복사하였습니다.");
} catch(IOException e) {
System.out.println("파일 복사 오류");
}
}
}
*/
/*
import java.io.*;
public class Main {
public static void main(String[] args) {
File src = new File("c:\\Windows\\Web\\Wallpaper\\Theme1\\img1.jpg");
File dest = new File("c:\\Users\\user\\Desktop\\java images\\youtube.jpg");
int c;
try {
FileInputStream fi = new FileInputStream(src);
FileOutputStream fo = new FileOutputStream(dest);
while((c = fi.read()) != -1) {
fo.write((byte)c);
}
fi.close();
fo.close();
System.out.println(src.getPath() + "를 " + dest.getPath() + "로 복사하였습니다.");
} catch (IOException e) {
System.out.println("파일 복사 오류");
}
}
}
*/
/*
import java.io.*;
public class Main {
public static void main(String[] args) {
File src = new File("c:\\Windows\\Web\\Wallpaper\\Theme1\\img1.jpg");
File dest = new File("c:\\Users\\user\\Desktop\\java images\\desert.jpg");
try {
FileInputStream fi = new FileInputStream(src);
FileOutputStream fo = new FileOutputStream(dest);
byte [] buf = new byte [1024*10];
while(true) {
int n = fi.read(buf);
fo.write(buf, 0, n);
if(n < buf.length)
break;
}
fi.close();
fo.close();
System.out.println(src.getPath() + "를" + dest.getPath() + "로 복사하였습니다.");
} catch (IOException e) { System.out.println("파일 복사 오류"); }
}
}
*/
import java.io.*;
import java.util.*;
class HangmanGame {
Vector<String> str;
String word;
int [] EscapeWord = new int[2];
public HangmanGame() {
str = new Vector<String>();
}
public void start() {
word = str.get((int)(Math.random() * str.size()));
EscapeWord[0] = (int)(Math.random()*word.length());
while(true) {
EscapeWord[1] = (int)(Math.random()*word.length());
if(EscapeWord[0] != EscapeWord[1])
break;
}
System.out.println("지금부터 행맨 개임을 시작합니다.");
working();
}
public void working() {
char letter;
char [] strx = word.toCharArray();
int [] stack = new int[EscapeWord.length];
Scanner scan = new Scanner(System.in);
System.out.println(word);
while(true) {
for(int i = 0; i < strx.length; i++) {
if(i == EscapeWord[0] || i == EscapeWord[1]) {
System.out.print("-");
}
else {
System.out.print(strx[i]);
}
}System.out.println();
System.out.print(">>");
String ss = scan.next();
letter = ss.charAt(0);
System.out.println(letter);
if(EscapeWord[0] != -1 && strx[EscapeWord[0]] == letter) {
EscapeWord[0] = -1;
}
else if(EscapeWord[1] != -1 && strx[EscapeWord[1]] == letter) {
EscapeWord[1] = -1;
}
else {
if(EscapeWord[0] != -1) {
stack[0] ++;
}
if(EscapeWord[1] != -1) {
stack[1] ++;
}
}
if(stack[0] >= 5 || stack[1] >= 5) {
System.out.println("5번 실패하였습니다.");
end();
break;
}
else if(EscapeWord[0] == -1 && EscapeWord[1] == -1) {
end();
break;
}
}
}
public void end() {
System.out.println(word);
}
}
public class Main {
public static void main(String[] args) {
HangmanGame game;
FileReader fin = null;
BufferedReader bun = null;
try {
game = new HangmanGame();
fin = new FileReader("C:\\Users\\user\\Desktop\\Java Programmig\\OpenChallengeAnswer\\OpenChallenge08\\words.txt");
bun = new BufferedReader(fin);
String line = "";
while((line = bun.readLine()) != null) {
game.str.add(line);
}
fin.close();
bun.close();
game.start();
} catch(IOException e) {
return;
}
}
}