锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲欧美偷拍自拍,欧美h视频在线,蜜芽视频在线观看http://www.aygfsteel.com/hughmay/category/47209.htmlhugh_mayzh-cnTue, 30 Nov 2010 11:22:53 GMTTue, 30 Nov 2010 11:22:53 GMT60Java_鍒濈駭緙栫▼錛岀寽鑻辨枃鍗曡瘝娓告垙http://www.aygfsteel.com/hughmay/archive/2010/11/23/338854.html嫻﹂嫻﹂Tue, 23 Nov 2010 14:40:00 GMThttp://www.aygfsteel.com/hughmay/archive/2010/11/23/338854.htmlhttp://www.aygfsteel.com/hughmay/comments/338854.htmlhttp://www.aygfsteel.com/hughmay/archive/2010/11/23/338854.html#Feedback0http://www.aygfsteel.com/hughmay/comments/commentRss/338854.htmlhttp://www.aygfsteel.com/hughmay/services/trackbacks/338854.html澶у濂斤紝榪欐槸鎴戠涓嬈″湪BlogJava鍙戝笘錛屾湰浜洪叿鐖辯紪紼嬶紝鍔犲叆BlogJava紺懼尯錛屽氨鏄負浜嗚璇嗙粨浜ゆ洿澶氭湁鍏卞悓鍏磋叮鐖卞ソ鐨勬湅鍙嬶紝浜ゆ祦褰兼瀛︿範緙栫▼鐨勭粡楠岋紝璇峰ぇ瀹跺澶氭敮鎸佹垜
涓嬮潰鐨凧ava紼嬪簭鏄垜瀛︿範Java鍒濇湡鐨勪竴涓綔涓氾細鐚滆嫳鏂囧崟璇嶆父鎴忥紝浣滀負鎴態log絎竴綃囬殢絎旓紝榪欎釜紼嬪簭涔熷彲浠ョ洿鎺ョ偣鍑?a href="/Files/hughmay/Assignment_1.zip" style="color: #002c99; text-decoration: none; ">http://www.aygfsteel.com/Files/hughmay/Assignment_1.zip涓嬭澆錛岀劧鍚庤緭鍏ワ紙import錛夊埌Java緙栬緫杞歡錛屽eclipse銆傜洿鎺ヨ繍琛岃紼嬪簭銆?/div>
/*
 * Author: ZHUANG JIN YI_91237 
 * This program is a simple game application (GUI) that allows two players compete with each other 
 * by guessing a word from a pool of 10 letters. Players can choose to pass to next player or choose to quit to end this game :)
 * 2010 Copyright Zhuang Jinyi, Jason. 
 */

import java.util.*;
import javax.swing.*;

public class FindYourWords 
{
public static void main(String[] args) 
{
Scanner console = new Scanner (System.in);
Random generator = new Random();
String [] dict= FileUtil.readDictFromFile("words.txt");
int scorePlayerA = 0;
int scorePlayerB = 0;
int sumScoreA = 0;
int sumScoreB = 0;
int i;
int match = 0;
int match1 = 0;
int match2 = 0;
int match3 = 0;
int[] ranNum = new int[8];
int[] ranNumVowel = new int[2];
String junk;
String[] letters = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "g", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
String[] vowels = {"a", "e", "i", "o", "u"};
String[] randomLetter = new String[8];
String[] randomVowel = new String[2];
String playerAInput = "";
String playerBInput = "";
String[] point1 = {"E" ,"A" ,"O" ,"T", "I", "N", "R", "S", "L", "U"};
String[] point2 = {"D", "G"};
String[] point3 = {"C", "M","B", "P"};
String[] point4 = {"H","F", "W", "Y"}; 
String[] point5 = {"K"}; 
String[] point8 = {"J", "X"};  
String[] point10 = {"Q", "Z"}; 

JOptionPane.showMessageDialog (null, "-----------------------------------------Game: Find Your Words-----------------------------------------\n" + "=======================Ready to Play? Click 'Ok'=======================", "Find Your Words", JOptionPane.INFORMATION_MESSAGE);
try
{
while (!playerAInput.equalsIgnoreCase("!") && !playerBInput.equalsIgnoreCase("!"))
{
if (!playerAInput.equalsIgnoreCase("!") || playerBInput.equalsIgnoreCase("@"))
{
//random letters generation  
for (i = 0; i < ranNum.length; i++ )
{
ranNum[i] = generator.nextInt(26);
randomLetter[i] = letters[ranNum[i]];
}
for (i = 0; i < ranNumVowel.length; i++ )
{
ranNum[i] = generator.nextInt(5);
randomVowel[i] = vowels[ranNum[i]];
}
//store random letters & prompt user input 
String[] randomQues = {randomLetter[0], randomVowel[1], randomLetter[1], randomVowel[0], randomLetter[2], randomLetter[3], randomLetter[4], randomLetter[5], randomLetter[6], randomLetter[7]};
//GUI dialog box 
String randomLetters = "Letters of Player A: " + randomLetter[0] + " " + randomVowel[1] + " " + randomLetter[1] + " " + randomVowel[0] + " " + randomLetter[2] + " " + randomLetter[3] + " " +  randomLetter[4] + " " + randomLetter[5] + " " + randomLetter[6] + " " + randomLetter[7];
playerAInput = JOptionPane.showInputDialog (randomLetters + "\n" + "Enter your word (or ‘@’ to pass or ‘!’ to quit): ");
String[] playerA = new String[playerAInput.length()];
playerA = playerAInput.split("");
/*
for (i = 0; i < playerA.length; i++)
{
System.out.println(playerA[i]);
}
System.out.println(playerA.length);
*/
while (!playerAInput.equalsIgnoreCase("@") && !playerAInput.equalsIgnoreCase("!"))
{
//checking validity part 
scorePlayerA = 0;
match = 0;
match1 = 0;
for (i = 0; i < dict.length; i++)
{
if (dict[i].equalsIgnoreCase(playerAInput))
{
match += 1;
}
else
{
match += 0;
}
}
if (match >= 1)
{
for (i = 0; i < playerA.length; i++)
{
for (int m = 0; m < randomQues.length; m++)
{
if (playerA[i].equalsIgnoreCase(randomQues[m]))
{
match1 += 1;
break;
}
}
}
if (match1 >= (playerA.length - 1))
{
//Giving points to players
for (i = 0; i < playerA.length; i++)
{
for (int m = 0; m < point1.length; m++)
{
if (point1[m].equalsIgnoreCase(playerA[i]))
{
scorePlayerA += 1;
}
}
}
for (i = 0; i < playerA.length; i++)
{
for (int m = 0; m < point2.length; m++)
{
if (point2[m].equalsIgnoreCase(playerA[i]))
{
scorePlayerA += 2;
}
}
}
for (i = 0; i < playerA.length; i++)
{
for (int m = 0; m < point3.length; m++)
{
if (point3[m].equalsIgnoreCase(playerA[i]))
{
scorePlayerA += 3;
}
}
}
for (i = 0; i < playerA.length; i++)
{
for (int m = 0; m < point4.length; m++)
{
if (point4[m].equalsIgnoreCase(playerA[i]))
{
scorePlayerA += 4;
}
}
}
for (i = 0; i < playerA.length; i++)
{
for (int m = 0; m < point5.length; m++)
{
if (point5[m].equalsIgnoreCase(playerA[i]))
{
scorePlayerA += 5;
}
}
}
for (i = 0; i < playerA.length; i++)
{
for (int m = 0; m < point8.length; m++)
{
if (point8[m].equalsIgnoreCase(playerA[i]))
{
scorePlayerA += 8;
}
}
}
for (i = 0; i < playerA.length; i++)
{
for (int m = 0; m < point10.length; m++)
{
if (point10[m].equalsIgnoreCase(playerA[i]))
{
scorePlayerA += 10;
}
}
}
sumScoreA += scorePlayerA;
/*
System.out.println("Total score for word: " + scorePlayerA);
System.out.println("Total score for game: " + sumScoreA);
*/
String result = "Total score for word: " + scorePlayerA + "\n" + "Total score for game: " + sumScoreA;
JOptionPane.showMessageDialog(null, result, "This Round Result :)", JOptionPane.INFORMATION_MESSAGE);
break;
}
else
{
JOptionPane.showMessageDialog(null, "Error : A valid word is formed but one or more letter(s) used are not yours.", "Error :(", JOptionPane.QUESTION_MESSAGE);
playerAInput = JOptionPane.showInputDialog (randomLetters + "\n" + "Enter your word (or ‘@’ to pass or ‘!’ to quit): ");
playerA = playerAInput.split("");
}
}
else
{
JOptionPane.showMessageDialog(null, "Error : An invalid word is formed.", "Error :(", JOptionPane.ERROR_MESSAGE);
playerAInput = JOptionPane.showInputDialog (randomLetters + "\n" + "Enter your word (or ‘@’ to pass or ‘!’ to quit): ");
playerA = playerAInput.split("");
}
}
}
if (!playerAInput.equalsIgnoreCase("!") || playerAInput.equalsIgnoreCase("@"))
{
//random letters generation 
for (i = 0; i < ranNum.length; i++ )
{
ranNum[i] = generator.nextInt(26);
randomLetter[i] = letters[ranNum[i]];
}
for (i = 0; i < ranNumVowel.length; i++ )
{
ranNum[i] = generator.nextInt(5);
randomVowel[i] = vowels[ranNum[i]];
}
//store random letters & prompt user input 
String[] randomQues1 = {randomLetter[0], randomVowel[1], randomLetter[1], randomVowel[0], randomLetter[2], randomLetter[3], randomLetter[4], randomLetter[5], randomLetter[6], randomLetter[7]};
//GUI dialog box 
String randomLetters1 = "Letters of Player B: " + randomLetter[0] + " " + randomVowel[1] + " " + randomLetter[1] + " " + randomVowel[0] + " " + randomLetter[2] + " " + randomLetter[3] + " " +  randomLetter[4] + " " + randomLetter[5] + " " + randomLetter[6] + " " + randomLetter[7];
playerBInput = JOptionPane.showInputDialog (randomLetters1 + "\n" + "Enter your word (or ‘@’ to pass or ‘!’ to quit): ");
String[] playerB = new String[playerBInput.length()];
playerB = playerBInput.split("");

while (!playerBInput.equalsIgnoreCase("@") && !playerBInput.equalsIgnoreCase("!"))
{
//checking validity part 
scorePlayerB = 0;
match2 = 0;
match3 = 0;
for (i = 0; i < dict.length; i++)
{
if (dict[i].equalsIgnoreCase(playerBInput))
{
match2 += 1;
}
else
{
match2 += 0;
}
}
if (match2 >= 1)
{
for (i = 0; i < playerB.length; i++)
{
for (int m = 0; m < randomQues1.length ; m++)
{
if (playerB[i].equalsIgnoreCase(randomQues1[m]))
{
match3 += 1;
break;
}
}
}
if (match3 >= (playerB.length - 1))
{
//Giving points to players
for (i = 0; i < playerB.length; i++)
{
for (int m = 0; m < point1.length; m++)
{
if (point1[m].equalsIgnoreCase(playerB[i]))
{
scorePlayerB += 1;
}
}
}
for (i = 0; i < playerB.length; i++)
{
for (int m = 0; m < point2.length; m++)
{
if (point2[m].equalsIgnoreCase(playerB[i]))
{
scorePlayerB += 2;
}
}
}
for (i = 0; i < playerB.length; i++)
{
for (int m = 0; m < point3.length; m++)
{
if (point3[m].equalsIgnoreCase(playerB[i]))
{
scorePlayerB += 3;
}
}
}
for (i = 0; i < playerB.length; i++)
{
for (int m = 0; m < point4.length; m++)
{
if (point4[m].equalsIgnoreCase(playerB[i]))
{
scorePlayerB += 4;
}
}
}
for (i = 0; i < playerB.length; i++)
{
for (int m = 0; m < point5.length; m++)
{
if (point5[m].equalsIgnoreCase(playerB[i]))
{
scorePlayerB += 5;
}
}
}
for (i = 0; i < playerB.length; i++)
{
for (int m = 0; m < point8.length; m++)
{
if (point8[m].equalsIgnoreCase(playerB[i]))
{
scorePlayerB += 8;
}
}
}
for (i = 0; i < playerB.length; i++)
{
for (int m = 0; m < point10.length; m++)
{
if (point10[m].equalsIgnoreCase(playerB[i]))
{
scorePlayerB += 10;
}
}
}
sumScoreB += scorePlayerB;
String result1 = "Total score for word: " + scorePlayerB + "\n" + "Total score for game: " + sumScoreB;
JOptionPane.showMessageDialog(null, result1, "This Round Result :)", JOptionPane.INFORMATION_MESSAGE);
break;
}
else
{
JOptionPane.showMessageDialog(null, "Error : A valid word is formed but one or more letter(s) used are not yours.", "Error :(", JOptionPane.QUESTION_MESSAGE);
playerBInput = JOptionPane.showInputDialog (randomLetters1 + "\n" + "Enter your word (or ‘@’ to pass or ‘!’ to quit): ");
playerB = playerBInput.split("");
}
}
else
{
JOptionPane.showMessageDialog(null, "Error : An invalid word is formed.", "Error :(", JOptionPane.ERROR_MESSAGE);
playerBInput = JOptionPane.showInputDialog (randomLetters1 + "\n" + "Enter your word (or ‘@’ to pass or ‘!’ to quit): ");
playerB = playerBInput.split("");
}
}
}
}
//Calculate and compare the final result
if (sumScoreA > sumScoreB)
{
String finalResult = "Total score for Player A: " + sumScoreA + "\n" + "Total score for Player B: " + sumScoreB + "\n" + "Player A wins!";
JOptionPane.showMessageDialog (null, "(: *********************Final Result********************* :)\n" + finalResult, "Final Result :)", JOptionPane.INFORMATION_MESSAGE);
}
else if (sumScoreA < sumScoreB)
{
String finalResult = "Total score for Player A: " + sumScoreA + "\n" + "Total score for Player B: " + sumScoreB + "\n" + "Player B wins!";
JOptionPane.showMessageDialog (null, "(: *********************Final Result********************* :)\n" + finalResult, "Final Result :)", JOptionPane.INFORMATION_MESSAGE);
}
else if (sumScoreA == sumScoreB)
{
String finalResult = "Total score for Player A: " + sumScoreA + "\n" + "Total score for Player B: " + sumScoreB + "\n" + "The result is a draw!";
JOptionPane.showMessageDialog (null, "(: *********************Final Result********************* :)\n" + finalResult, "Final Result :)", JOptionPane.INFORMATION_MESSAGE);
}
}
catch (Exception e)
{
junk = console.nextLine();
String errorMessage = "Error, " + junk + " is not acceptable!" + "\n" + "Sorry, Game Over" + "\n" + "Please run this program again :)";
JOptionPane.showMessageDialog (null, errorMessage, "Error Message :(", JOptionPane.INFORMATION_MESSAGE);
}
}
}
PS錛?good night :)


嫻﹂ 2010-11-23 22:40 鍙戣〃璇勮
]]> 主站蜘蛛池模板: 大渡口区| 岳西县| 泰顺县| 噶尔县| 铜梁县| 怀化市| 微山县| 郴州市| 东台市| 峨眉山市| 密山市| 石门县| 宣汉县| 乌鲁木齐市| 繁昌县| 滕州市| 屏山县| 德格县| 桐梓县| 泸水县| 旬阳县| 峨眉山市| 临武县| 大悟县| 鞍山市| 甘肃省| 六盘水市| 将乐县| 读书| 巫溪县| 佳木斯市| 西宁市| 萍乡市| 东乡族自治县| 昌吉市| 顺昌县| 文昌市| 弥勒县| 沧源| 罗城| 正镶白旗|