-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
537 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,66 @@ | ||
package game21; | ||
|
||
import java.util.Random; | ||
|
||
//abstract | ||
public class Card { | ||
private Integer id; | ||
private String suit; | ||
private String number; | ||
public void setCard(Integer id, String number, String suit) { | ||
this.number = number; | ||
this.id = id; | ||
this.suit = suit; | ||
private int cardId; | ||
private String cardSuit; | ||
private String cardNum; | ||
|
||
// 随机生成cardId放到获取方法中,节省新建对象数目 | ||
public int getCardId() { | ||
this.cardId = new Random().nextInt(52); | ||
return cardId; | ||
} | ||
public Integer getId() { | ||
return id; | ||
|
||
// 按照一定的方法将ID转换成卡牌信息 | ||
public String getCard(int cardId) { | ||
String card = getCardSuit(cardId) + getCardNum(cardId); | ||
return card; | ||
} | ||
public String getSuit() { | ||
return suit; | ||
|
||
public String getCardSuit(int cardId) { | ||
// cardSuit = Integer.toString((cardId / 13 + 1)) | ||
switch ((cardId / 13 + 1)) { | ||
case 1: | ||
cardSuit = "黑桃"; | ||
break; | ||
case 2: | ||
cardSuit = "红桃"; | ||
break; | ||
case 3: | ||
cardSuit = "梅花"; | ||
break; | ||
case 4: | ||
cardSuit = "方块"; | ||
break; | ||
default: | ||
break; | ||
} | ||
return cardSuit; | ||
} | ||
public String getNumber() { | ||
return number; | ||
|
||
public String getCardNum(int cardId) { | ||
// cardNum = Integer.toString((cardId % 13 + 1)) | ||
switch (cardId % 13 + 1) { | ||
case 1: | ||
cardNum = "A"; | ||
break; | ||
case 11: | ||
cardNum = "J"; | ||
break; | ||
case 12: | ||
cardNum = "Q"; | ||
break; | ||
case 13: | ||
cardNum = "K"; | ||
break; | ||
default: | ||
cardNum = Integer.toString((cardId % 13 + 1)); | ||
break; | ||
} | ||
return cardNum; | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package game21; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class CardInHand { | ||
private List<Integer> cardInHand = new ArrayList<Integer>(); | ||
|
||
public List<Integer> getCardInHand() { | ||
return cardInHand; | ||
} | ||
|
||
public void addCardInHand(int card) { | ||
this.cardInHand.add(card); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package game21; | ||
|
||
public class Checkinput { | ||
public boolean chkPassword(String userPassword, String userRptPassword) { | ||
if (userPassword.equals(userRptPassword)) | ||
return true; | ||
return false; | ||
} | ||
|
||
//WIP:¸÷ÖÖ·Ç·¨ÊäÈëÅжϡ£ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package game21; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.io.ObjectInputStream; | ||
import java.util.Scanner; | ||
|
||
public class InputStream { | ||
private Scanner in = new Scanner(System.in); | ||
|
||
public String inputString() { | ||
// WIP:输入含有空格后自动忽略。 | ||
String inputstring = in.next(); | ||
return inputstring; | ||
} | ||
|
||
/** | ||
* overloading inputString(),增加限定输入范围 特性: 当最小值大于最大值时候互换数值保证程序健壮 限定接受的数值范围,保证程序健壮 | ||
* | ||
* @param minLength | ||
* 可接受的取值范围:1-255 | ||
* @param maxLength | ||
* 可接受的取值范围:1-255 | ||
* @return | ||
* @throws IllegalArgumentException | ||
* 非法范围的参数值 | ||
*/ | ||
public String inputString(int minLength, int maxLength) throws IllegalArgumentException { | ||
// 检查输入参数的合法性 | ||
boolean chklegal = minLength <= 0 || maxLength <= 0 || minLength > 255 || maxLength > 255; | ||
if (chklegal) { | ||
throw new IllegalArgumentException("非法参数范围!取值范围为1-255。"); | ||
} | ||
// ADD:检查长度限定,如果最小值大于最大值,交换值 | ||
if (minLength > maxLength) { | ||
minLength += maxLength; | ||
maxLength = minLength - maxLength; | ||
minLength = minLength - maxLength; | ||
} | ||
String tmp; | ||
do { | ||
tmp = inputString(); | ||
if (tmp.length() < minLength) { | ||
System.out.println("输入长度过短,请输入大于" + minLength + "长度的字符!"); | ||
} else if (tmp.length() > maxLength) { | ||
System.out.println("输入长度过长,请输入小于" + maxLength + "长度的字符!"); | ||
} | ||
} while (tmp.length() < minLength || tmp.length() > maxLength); | ||
return tmp; | ||
} | ||
|
||
/** | ||
* overloading inputint() 增加输入范围的设置 | ||
* | ||
* @param min | ||
* @param max | ||
* @return | ||
* @throws IllegalArgumentException | ||
* 非法范围的参数值 | ||
*/ | ||
public int inputint(int min, int max) throws IllegalArgumentException { | ||
// 输入合法性检验 | ||
boolean illegal = min <= 0 || max <= 0 || min > 255 || max > 255; | ||
if (illegal) { | ||
throw new IllegalArgumentException("非法参数范围!取值范围为1-255。"); | ||
} | ||
if (min > max) { | ||
min = min + max; | ||
max = min - max; | ||
min = min - max; | ||
} | ||
int inputint = 0; | ||
do { | ||
try { | ||
inputint = in.nextInt(); | ||
} catch (Exception e) { | ||
System.out.println("请输入整数!"); | ||
} | ||
if (inputint < min) { | ||
System.out.println("输入数据超限!请输入大于" + min + "的数值"); | ||
} else if (inputint > max) { | ||
System.out.println("输入数据超限!请输入小于" + max + "的数值"); | ||
} | ||
} while (inputint < min || inputint > max); | ||
return inputint; | ||
} | ||
|
||
/* | ||
* 登陆数据载入以及验证登陆 | ||
*/ | ||
private static final String DATABASE_PATH = "./UserDatabase/"; | ||
|
||
static { | ||
File temp = new File(DATABASE_PATH); | ||
temp.mkdirs(); | ||
} | ||
|
||
public boolean extUser(String name) { | ||
File temp = new File(DATABASE_PATH + name + ".txt"); | ||
return temp.exists(); | ||
} | ||
|
||
public boolean chkPassword(String name, String password) | ||
throws FileNotFoundException, IOException, ClassNotFoundException { | ||
if (!extUser(name)) { | ||
System.out.println("用户名不存在或者密码错误!"); | ||
return false; | ||
} | ||
User user = readUserInfo(name); | ||
if (!user.getUserPassword().equals(password)) { | ||
System.out.println("用户名不存在或者密码错误!"); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
public User readUserInfo(String name) throws FileNotFoundException, IOException, ClassNotFoundException { | ||
File temp = new File(DATABASE_PATH + name + ".txt"); | ||
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(temp)); | ||
User user = (User) ois.readObject(); | ||
ois.close(); | ||
return user; | ||
} | ||
} |
Oops, something went wrong.