资源简介
在控制台下的程序,是别人写的,这里只是借用给大家看看程序代码
代码片段和文件信息
/**
Pontoon
@author:
@version:
purpose: KXC151 assignment 2 2007
*/
import java.io.IOException;
public class Blackjack {
// final instance variables
// non-final instance variables
private Decks cards;
private boolean tracing;
private int played = 0;
private int playerWin = 0;
private int computerWin = 0;
private int drew = 0;
/**
* constructor
*
* @param none
* @return none
*/
public Blackjack() {
tracing = true;
setTracing(tracing); // set tracing off
introduceBlackjack();
cards = new Decks(1);
cards.setTracing(false);
}
/**
* play -- play a game of Blackjack
*
* @param none
* @return none
*/
public void play() {
boolean isPlayerTurn = true;
if (askBegin() == true) {
showDealCards();
while (askHitOrStand()) //if player choice Hit
{
showDraw(isPlayerTurn);
if(cards.isBust(isPlayerTurn) || (cards.getNumberOfCards(isPlayerTurn) == 5))
{
break;
}
}
showTotal(isPlayerTurn);
if(cards.getNumberOfCards(isPlayerTurn) == 5 && !cards.isBust(isPlayerTurn)) //if player has 5 cards with a value of 21 or less
{
showWinInfo(cards.Player);
}
else if(cards.isBust(isPlayerTurn))
{
showWinInfo(cards.COMPUTER);
}
else
{ isPlayerTurn = false; //It‘s Computer Turn
// if computer is not bust and number of Cards less than 5 and total of Cards less than system sits(16) then computer draw a card
while (!cards.isBust(isPlayerTurn) && cards.getNumberOfCards(isPlayerTurn) < 5 && cards.getTotalOfCards(isPlayerTurn) < cards.COMPUTER_SITS )
{
showDraw(isPlayerTurn);
}
showTotal(isPlayerTurn);
showWinInfo(cards.whoWon());
}
play();
}
else
{
showSummary();
}
}
/**
* explain -- give information on the game
*
* @param none
* @return none
*/
public void explain() {
trace(“explain: begins“);
}
/**
* setTracing - used to turn tracing messages on or off
*
* @param boolean --
* indicates the required state of messages (true on false off)
* @return none
*/
public void setTracing(boolean traceState) {
tracing = traceState;
}
/**
* trace - displays tracing messages
*
* @param String --
* the message to be displayed if instance variable tracing is
* true
* @return none
*/
public void trace(String message) {
if (tracing) {
System.out.println(message);
}
}
/**
* introduceBlackjack - introduce the game of Blackjack
*
* @return none
*/
public void introduceBlackjack() {
trace(“Blackjack - A Game of 21“);
trace(““);
trace(“The object of the game is to get as close to 21 as possible or to have 5 cards with a total under 21“);
trace(““);
trace(“The computer continues to draw cards if under 16“);
trace(““);
}
/**
* ask - ask
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 6575 2009-05-12 05:32 Blackjack.java
文件 11186 2009-05-12 05:32 Decks.java
文件 388 2009-05-12 05:32 PlayBlackjack07.java
- 上一篇:android opengl 贝塞尔曲线
- 下一篇:南京晓庄学院java考试题库
相关资源
- 南京晓庄学院java考试题库
- Java Slf4j依赖包
- 一个java swing 实现的拖拽组件 交换位
- 3种设计模式的java小程序
- java操作openldap代码
- java 基于p2p文件传输
- 加密与解密java课程设计
- JAVA 仿windows资源管理器的文件树
- java电子相册管理系统 sql 文件
- 操作系统实验及其代码Java编写
- php调用java写的webservice
- java web 博客
- 经典java小程序源代码合集.rar
- 用Java和SQL-Server做的学生管理系统
- 企业资产管理系统
- java web 文件上传与
- 银行账户管理系统 java课程设计 流程
- 精美Swing 折叠菜单
- 一个简单的抽奖机Java实现
- 完整的javaweb项目
- java排课算法核心代码及思想
- Java记事本
- java 学生管理系统界面
- HttpTools2.4
- 航空公司定订票系统B/S版
- java实现议程管理系统
- ASP HMAC_SHA256 HS256算法 基于JAVASCIRPT R
- 免费_图解java多线程设计模式
- primefaces 的主题jar包
- java中常用日语词汇
评论
共有 条评论