제1편 블로그: 이색구 게임, 그리고 개인 소개

이색구 게임
이색 구형(6 빨간색 1 파란색):
package top.liaoyingpeng.bean;

import java.util.Arrays;

public class Balls {
	private int[] red = new int[6];
	private int blue;
	private BallBox makeBy;

	//      
	protected Balls(BallBox bx) {
		makeBy = bx;
	}

	//   
	public byte[] equals(Balls obj) {
		byte[] num = { 0, 0 };
		if (blue == obj.blue) {
			num[1] = 1;
		} else {
			num[1] = 0;
		}

		for (int i : obj.red) {
			for (int j : this.red) {
				if (i == j)
					num[0]++;
			}
		}
		return num;
	}

	//    
	public int getRed(int n) {
		return this.red[n];
	}

	public int[] getAllRed(){
		return red;
	}
	
	protected void setRed(int n, int red) {
		this.red[n] = red;
	}

	public int getBlue() {
		return blue;
	}

	protected void setBlue(int blue) {
		this.blue = blue;
		makeBy.blue = true;
	}

	//     
	@Override
	public String toString() {

		return Arrays.toString(red) + "[" + blue + "]";

	}
}

캐비닛 클래스(이색 구 생성):
package top.liaoyingpeng.bean;

import java.util.LinkedHashSet;
import java.util.Random;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class BallBox {
	private LinkedHashSet red = new LinkedHashSet();// 1-33      
	Scanner sc = new Scanner(System.in);
	private Balls Making = null;//       
	private Random rd = new Random();
	protected boolean blue = false;//          

	//    
	public BallBox() {
	}

	//         
	public Balls getRandomBalls() {
		if (!isUsed()) {
			Making = new Balls(this);
			int num;
			for (int i = 0 + red.size(); i  33 || ball[i] == 0) {
					break;
				}
			} else {
				break;
			}
		}
		// System.out.println(i);
		if (ball[6] <= 16 && i == 7//   7 
				&& balls.matches("\\s*(\\[\\s*\\d{2}\\s*,\\s*\\d{2}\\s*,\\s*\\d{2}\\s*,\\s*\\d{2}\\s*,\\s*\\d{2}\\s*,\\s*\\d{2}\\s*\\])(\\[\\d\\d\\])\\s*")) {
			return ball;
		} else {
			System.out.println("             ");
			return null;
		}
	}

	//     
	public void clear() {
		red.clear();
		blue = false;
		Making = null;
	}

	//         
	public boolean isBlued() {
		return blue;
	}

	//        
	public int alRed() {
		return red.size();
	}

	//      
	public boolean isUsed() {
		if (red.size() == 6 && blue)
			return true;
		else
			return false;
	}

	//         
	public boolean isUsing() {
		if (Making != null)
			return true;
		else
			return false;
	}
}

메인 인터페이스(main):
package top.liaoyingpeng.view;

import java.util.Scanner;

import top.liaoyingpeng.bean.BallBox;
import top.liaoyingpeng.bean.Balls;

public class Test {
	static Scanner sc = new Scanner(System.in);
	static int[] hasPrize = { 0, 0, 0, 0, 0, 0, 0 };// 1-6     ;
	static int times = 0;//    

	public static void main(String[] args) {

		System.out.println("**********     **********");
		System.out
				.println("  :
\t 6 1  
\t 1--33
\t 1--16 "); System.out.println("\t
\t

"); sc.nextLine(); while (game()) ; System.out.println(" --- ing"); sc.close(); } public static boolean game() { System.out.println("******************************"); BallBox bx = new BallBox(); Balls player; Balls gover; System.out.println(" :
\t1)
\t2) "); if ("1".equals(sc.nextLine())) { player = bx.buy(); } else { player = bx.getRandomBalls(); System.out.println(" :" + player.toString()); } bx.clear();//  gover = bx.getRandomBalls(); byte[] result = player.equals(gover); int prize = prize(result); System.out.println(" :" + gover.toString()); System.out.println(" " + result[0] + " , " + result[1] + "
"); if (prize > 0) { String lv = level(prize); System.out.println(" " + lv + "  " + prize + " "); } else { System.out.println("  
******************************"); } times++; showPrize(); System.out.println("
exit "); if ("exit".equals(sc.nextLine())) return false; else return true; } public static void showPrize() { System.out.println(" :
\t  " + hasPrize[0] + "  "); System.out.println("\t  " + hasPrize[1] + "  "); System.out.println("\t  " + hasPrize[2] + "  "); System.out.println("\t  " + hasPrize[3] + "  "); System.out.println("\t  " + hasPrize[4] + "  "); System.out.println("\t  " + hasPrize[5] + "  "); System.out.println("\t\t  " + hasPrize[6] + "  "); System.out.println("\t\t  " + times + " 
"); } public static int prize(byte[] result) { int prize = 0; switch (result[0]) { case 6: { if (result[1] == 1) prize = 10000000; else prize = 3000000; break; } case 5: { if (result[1] == 1) prize = 3000; else prize = 200; break; } case 4: { if (result[1] == 1) prize = 200; else prize = 10; break; } case 3: { if (result[1] == 1) prize = 10; break; } case 2: { if (result[1] == 1) prize = 5; break; } case 1: { if (result[1] == 1) prize = 5; break; } case 0: { if (result[1] == 1) prize = 5; break; } } hasPrize[6] += prize; return prize; } public static String level(int prize) { switch (prize) { case 10000000: hasPrize[0]++; return " "; case 3000000: hasPrize[1]++; return " "; case 3000: hasPrize[2]++; return " "; case 200: hasPrize[3]++; return " "; case 10: hasPrize[4]++; return " "; case 5: hasPrize[5]++; return " "; default: return " "; } } }

----------------------------------------------------------------------------------------------------------------------------------
이 투톤 볼 게임은 제가 체험 캠프에서 하는 작은 숙제입니다. 본뜻은 수조의 사용을 연습하는 것입니다. 하지만 저는 관련 지식을 조금 배웠기 때문에 정규 표현식과 대상을 대상으로 하는 문법을 사용해 보았습니다. 이 글을 쓸 때 저는 자바를 접한 지 얼마 되지 않았습니다. 클래스 간의 의존 관계가 좋지 않고 아예 c언어의 기초가 있습니다.자바를 배우는 것도 재미있지만 대상을 향한 사상은 많이 연습해야 한다.
----------------------------------------------------------------------------------------------------------------------------------
자기소개
저는 현재 대학교 1학년 재학생입니다. 원래 기계학과였는데 지난 학기에 과학 창작 동아리에 가입하여 처음으로 프로그램 설계를 진정으로 접했습니다.접촉한 후에 나는 그에게 깊이 빠져들었고 다음 학기에 컴퓨터를 전공하기로 결심했다.
동아리에서 저는 단편기 프로그래밍을 했습니다. 개인은 사이트 개발에 관심이 많고 앞으로도 컴퓨터 업계에 취직하고 싶습니다. 그래서 여름방학 체험캠프에 Java를 공부하러 지원했습니다. 체험캠프의 선생님은 우리에게 자신의 기술 블로그를 일찍 쓰라고 권하셨습니다. 그래서 고민한 후에 이곳에서 자신의 첫 블로그를 시작하기로 결정했습니다.비록 많은 사람들이 보지 않더라도 저는 견지해 나가고 싶습니다. 도움이 되지 않아도 자신의 필기라고 할 수 있습니다. 만약에 나중에 자신의 글이 누군가의 문제를 해결하는 데 도움을 줄 수 있다면 매우 기쁩니다. 왜냐하면 이전에 겪은 몇 가지 문제는 모두 여러분의 블로그에서 해결된 것입니다.
이곳에서 많은 지역사회의 친구들과 함께 발전하고 프로그램의 매력을 느끼기를 바랍니다.

좋은 웹페이지 즐겨찾기