⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hangmangame.java

📁 java的插件
💻 JAVA
字号:
package com.swtdesigner;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Random;

public class HangmanGame implements Serializable {

	private int iMaxMisses = 5;
	private int iMissed = 0;
	private String sCurWord = "";
	private ArrayList alUnusedLetters = null;
	private String sGuess = "";
	private String sGuessedRightLetters = "";
	private boolean bGameComplete = false;
	private static Random r = new Random();

	public void start(int iMaxMisses) {
		this.iMaxMisses = iMaxMisses;
		iMissed = 0;

		bGameComplete = false;

		sCurWord = saWordList[r.nextInt(saWordList.length)].toUpperCase();
		sGuessedRightLetters = "";

		sGuess = "";
		for (int count = 0; count < sCurWord.length(); count++) {
			sGuess += "_ ";
		}

		alUnusedLetters = new ArrayList();
		String sLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		for (int count = 0; count < sLetters.length(); count++) {
			alUnusedLetters.add(sLetters.substring(count, count + 1));
		}
	}

	public String getCorrectWord() {
		return (sCurWord);
	}

	public boolean getGameComplete() {
		return (bGameComplete);
	}
	public void setGameComplete(boolean value) {
		bGameComplete = value;
	}

	//The current state of the guessed word
	public String getGuess() {
		return (sGuess);
	}

	public int getMaxMisses() {
		return (iMaxMisses);
	}

	public int getMissed() {
		return (iMissed);
	}

	public ArrayList getUnused() {
		return (alUnusedLetters);
	}

	public void guess(String sLetter) throws HangmanGameException {
		//Remove the letter from the "unused letter" list
		for (int count = 0; count < alUnusedLetters.size(); count++) {
			if (((String) alUnusedLetters.get(count)).equals(sLetter)) {
				alUnusedLetters.remove(count);
				break;
			}
		}
		//Is the letter in the word?
		if (sCurWord.indexOf(sLetter) == -1) {
			//This letter is NOT in the word
			iMissed++;
			throw new HangmanGameException(
				"Letter " + sLetter + " is not in the word");
		}
		//Good letter! Reveal it in the guess
		sGuessedRightLetters += sLetter;

		//Rebuild the guessed word... make sure
		//guessed letters are visible.
		sGuess = "";
		for (int count = 0; count < sCurWord.length(); count++) {
			String sFind = sCurWord.substring(count, count + 1);
			if (sGuessedRightLetters.indexOf(sFind) == -1) {
				sGuess += "_ ";
			} else {
				sGuess += sFind + " ";
			}
		}

	}

	public boolean getFailed() {
		if (iMissed > iMaxMisses) {
			return (true);
		}
		return (false);
	}

	public boolean getDone() {
		if (sGuess.indexOf("_") == -1) {
			//All letters guessed right!
			return (true);
		}
		return (false);
	}

	private static String saWordList[] =
		{
			"access",
			"account",
			"acquisition",
			"acrobat",
			"acronym",
			"active",
			"address",
			"adobe",
			"affiliate",
			"algorithm",
			"alias",
			"analog",
			"anchor",
			"animation",
			"anonymous",
			"apache",
			"apple",
			"aspect",
			"audio",
			"authorization",
			"backbone",
			"backdoor",
			"bandwidth",
			"banner",
			"barter",
			"batch",
			"benchmark",
			"beta",
			"binary",
			"biometrics",
			"bitmap",
			"bookmark",
			"broadband",
			"broadcast",
			"browser",
			"buzzword",
			"cable",
			"cache",
			"campus",
			"channel",
			"character",
			"clean",
			"click",
			"client",
			"collaborative",
			"command",
			"commerce",
			"compatible",
			"compression",
			"computer",
			"confidentiality",
			"configuration",
			"configure",
			"connect",
			"connectivity",
			"content",
			"convergence",
			"cookies",
			"coopetition",
			"counter",
			"crackable",
			"crash",
			"crusader",
			"customize",
			"cyborg",
			"daemon",
			"deactivation",
			"decode",
			"decryption",
			"default",
			"device",
			"digital",
			"directory",
			"distribution",
			"document",
			"domain",
			"download",
			"dynamic",
			"electronic",
			"embedded",
			"enterprise",
			"environment",
			"ethernet",
			"evangelist",
			"export",
			"extensions",
			"extranet",
			"failure",
			"favorite",
			"feature",
			"file",
			"filter",
			"finger",
			"firewall",
			"firmware",
			"flame",
			"flavor",
			"format",
			"forum",
			"fractal",
			"freeware",
			"functionality",
			"gaming",
			"gateway",
			"geek",
			"genius",
			"gigabyte",
			"globalization",
			"google",
			"graffiti",
			"graphics",
			"groupware",
			"guardian",
			"hacker",
			"hairball",
			"handle",
			"handshake",
			"handwriting",
			"headmount",
			"hexadecimal",
			"hierarchy",
			"homepage",
			"host",
			"hotmail",
			"hyperlink",
			"hypermedia",
			"hypertext",
			"identity",
			"inbox",
			"index",
			"information",
			"infotainment",
			"infrared",
			"infrastructure",
			"initialization",
			"install",
			"integrate",
			"integrity",
			"interactive",
			"interface",
			"internet",
			"interoperability",
			"intranet",
			"java",
			"javascript",
			"kernel",
			"keyboard",
			"kilobyte",
			"kiosk",
			"knowledge",
			"language",
			"laptop",
			"launch",
			"legacy",
			"leverage",
			"link",
			"link",
			"linux",
			"load",
			"log",
			"logoff",
			"macintosh",
			"macromedia",
			"mainframe",
			"management",
			"megabyte",
			"megahertz",
			"meltdown",
			"microsoft",
			"modem",
			"monitor",
			"mozilla",
			"multicast",
			"nanosecond",
			"napster",
			"navigate",
			"netscape",
			"newsgroups",
			"norton",
			"obsolete",
			"offline",
			"online",
			"optimize",
			"outage",
			"packet",
			"payment",
			"paypal",
			"peer",
			"peripheral",
			"photoshop",
			"portable",
			"portal",
			"postmaster",
			"program",
			"programmer",
			"programming",
			"prompt",
			"proprietary",
			"protocol",
			"publisher",
			"quantum",
			"query",
			"queue",
			"qwerty",
			"radar",
			"radio",
			"reboot",
			"redirect",
			"reformat",
			"refresh",
			"remote",
			"resolution",
			"resolve",
			"resonate",
			"robot",
			"runtime",
			"satellite",
			"scanner",
			"schedule",
			"script",
			"search",
			"security",
			"server",
			"shareware",
			"skyscraper",
			"sniffer",
			"socket",
			"spam",
			"speed",
			"spider",
			"spoofing",
			"spyware",
			"stack",
			"static",
			"strawman",
			"string",
			"stylus",
			"subscribe",
			"success",
			"support",
			"synchronization",
			"technobabble",
			"terminal",
			"thread",
			"throughput",
			"thumbnail",
			"titanium",
			"toggle",
			"toolbar",
			"trackball",
			"traffic",
			"transponder",
			"turnkey",
			"unix",
			"upgrade",
			"uplink",
			"upload",
			"upside",
			"upstream",
			"user",
			"vanilla",
			"vaporware",
			"vector",
			"video",
			"virtual",
			"virus",
			"wallpaper",
			"windows",
			"wireless",
			"workstation",
			"worm",
			"yahoo",
			"zip",
			"zombie",
			"zone" };

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -