承接 alex-patterson-webdev/tennis-game 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

alex-patterson-webdev/tennis-game

Composer 安装命令:

composer require alex-patterson-webdev/tennis-game

包简介

Simple Tennis score calculator

README 文档

README

Build Status codecov

Arp\TennisGame

About

A PHP solution to the Tennis scoring challenge.

Installation

Installation via composer.

require alex-patterson-webdev/tennis-game ^1

Usage

In order to calculate the Tennis score, first create a new instance of the Arp\TennisGame\TennisGame class.

use Arp\TennisGame\TennisGame;
$tennisGame = new TennisGame();

Once created, we can record scores for PlayerOne and PlayerTwo by calling either playerOneWinsShot() or playerTwoWinsShot(). Internally the TennisGame class will keep a record of each player's score, regardless of the order of the winning shots.

$tennisGame->playerOneWinsShot(); // Increase PlayerOne score by 1 point
$tennisGame->playerTwoWinsShot(); // Increase PlayerOne score by 1 point

By default, score for both players start at a value of love (zero). At any time we can review the score of each of the players by calling the renderScore() method. The score for both players will be returned as a string, x-y where x represents the first players' score and y represents the seconds players' score.

echo $tennisGame->renderScore(); // output string 'love-love'

$tennisGame->playerOneWinsShot();
echo $tennisGame->renderScore(); // output string 'fifteen-love'

$tennisGame->playerTwoWinsShot();
echo $tennisGame->renderScore(); // output string 'fifteen-fifteen'

In accordance with the rules of Tennis, when players tie and have both reached a score of at least forty, then the result of the call to renderScore() will be deuce, indicating the scores are level.

$tennisGame->playerOneWinsShot();
$tennisGame->playerOneWinsShot();
$tennisGame->playerOneWinsShot();

$tennisGame->playerTwoWinsShot();
$tennisGame->playerTwoWinsShot();
$tennisGame->playerTwoWinsShot();
    
echo $tennisGame->renderScore(); // output string 'deuce'

If the score is a tie at deuce, players must then score 1 additional point to gain an advantage. In these cases, calls to method renderScore() will display the player who has the current advantage.

$tennisGame->playerOneWinsShot(); // 15
$tennisGame->playerOneWinsShot(); // 30
$tennisGame->playerOneWinsShot(); // 40

$tennisGame->playerTwoWinsShot(); // 15
$tennisGame->playerTwoWinsShot(); // 30
$tennisGame->playerTwoWinsShot(); // 40 (Deuce)
$tennisGame->playerTwoWinsShot(); // advantage PlayerOne
    
echo $tennisGame->renderScore(); // output string 'advantage PlayerTwo';

In order to win the game, players must have a score which exceeds forty points and have at least two points more than the competing player. Calls to renderScore() will show the name of the player who is the winner.

$tennisGame->playerOneWinsShot(); // 15

$tennisGame->playerTwoWinsShot(); // 15
$tennisGame->playerTwoWinsShot(); // 30
$tennisGame->playerTwoWinsShot(); // 40
$tennisGame->playerTwoWinsShot(); // win
    
echo $tennisGame->renderScore(); // output string 'win PlayerTwo';

Unit Tests

Unit test can be run using PHPUnit.

php vendor/bin/phpunit

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2020-07-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固