Skip to content

susanBuck/rock-paper-scissors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rock Paper Scissors

An example package used to demonstrate dependencies in DGMD E-2 Web Programming for Beginners with PHP.

Installation

composer require susanbuck/rock-paper-scissors

Usage

Basic example:

require __DIR__.'/vendor/autoload.php';

use RPS\Game;

$game = new Game();

# Each invocation of the `play` method will play and track a new round of player (given move) vs. computer
$game->play('rock');

The Game class accepts three constructor parameters:

  • bool $persistResults
    • Indicates whether or not results should be persisted to the SESSION
    • Defaults to false
  • int $maxResults
    • Indicates the max # of results to record in the SESSION
    • Defaults to 5
  • string $timezone
    • Indicates what timezone each round should be recorded in
    • Defaults to 'America/New_York'

Methods

play(String $move): array

Accepts a string of either 'rock', 'paper', or 'scissors'.

Will halt the execution of the program if an invalid move is given.

Returns an array of results:

[
    'player' => player's move
    'computer' => computer's move
    'outcome' => outcome (won, lost, tie)
    'timestamp' => timestamp for when the round was played
];

getResults(): array

Returns an array of the last x results, where x is $maxResults.

Returns null if $persistResults is set to false.

clearResults(): void

Clears the session of results

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages