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

📄 scorecard.java

📁 手机无线网络纸牌游戏源代码。非常适合学习使用
💻 JAVA
字号:
// ScoreCard.java
//
// Copyright (c) 2000-2001 Symbian Ltd. All rights reserved

package com.symbian.devnet.whist.game;

import java.util.*;

/**
 * A class implementing a Score Card.
 * @author Symbian Devnet
 */
class ScoreCard
{
	/** Represents the number of players in the game. */
	private static final int NO_OF_PLAYERS = 4;
	/** Represents the partnership between players 1 and 3. */
	private static final int PARTNERSHIP_A = 0;
	/** Represents the partnership between players 2 and 4. */
	private static final int PARTNERSHIP_B = 1;
	/** The number of points required to win a game. */
	private int noOfPointsToWin = 5;
	/** The number of tricks each player has won. */
	private int[] tricksWon;
	/** The number of games partnership A has won. */
	private int gamesWonPartnersA = 0;
	/** The number of games partnership B has won. */
	private int gamesWonPartnersB = 0;
	/** The number of games played. */
	private int gameNo = 1;
	
	/**
	 * Constructor which initialialises the tricksWon array.
	 */
	ScoreCard()
	{
		tricksWon = new int[NO_OF_PLAYERS];		
	}
	
	/**
	 * Calculates the winner of the game by determining which player won the 
	 * most tricks. The tricksWon array is then set to zero again, ready for 
	 * the next game.
	 */	
	private void setWinner()
	{
		int partnerA = (tricksWon[0] + tricksWon[2]);
		int partnerB = (tricksWon[1] + tricksWon[3]);
		if (partnerA > partnerB)
			gamesWonPartnersA++;
		else 
			gamesWonPartnersB++;
		gameNo++;	
		for (int i = 0; i < NO_OF_PLAYERS; i++)
			tricksWon[i] = 0;		
	}
	
	/**
	 * Calculates the number of tricks each partnership has won and
	 * determines if either has reached the number required to win
	 * a game.
	 * @return true if either partnership has reached the required 
	 * 				number of trick wins.
	 */
	public boolean hasGameEnded()
	{	
		boolean gameEnded;
		int leader;
		int inTheLead;
		int partnerA = (tricksWon[0] + tricksWon[2]);
		int partnerB = (tricksWon[1] + tricksWon[3]);
		if (partnerA > partnerB)
		{
			leader = partnerA;
			inTheLead = PARTNERSHIP_A;
		}
		else
		{
			leader = partnerB;
			inTheLead = PARTNERSHIP_B;
		}
		if ((leader - 6) >= noOfPointsToWin)
		{
			gameEnded = true;
			setWinner();
		}
		else
			gameEnded = false;	
		return gameEnded;		
	}	
		
	
	/**
	 * Returns the scores of the two partnerships, winners first.
	 * @return the number of tricks won by each of the players
	 */	
	public int[] getScore()
	{
		return tricksWon;
	}
	
	/** 
	 * Increments the trick winner by 1.  
	 * @param playerNo the player who won the trick.
	 */		
	public void trickWon(int playerNo)
	{
		tricksWon[playerNo]++;				
	}
	
	/**
	 * Returns the number of games played.
	 * @return the current game number
	 */
	public int getGameNo()
	{
		return gameNo;
	}
	
	/**
	 * Returns the scores of the two partnerships.
	 * @return the partnership scores
	 */
	public int[] getWinner()
	{
		int[] temp = new int[2];
		temp[0] = (gamesWonPartnersA);
		temp[1] = (gamesWonPartnersB);
		return temp;
	}		
}

⌨️ 快捷键说明

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