Skip to content

Commit

Permalink
kmom02/uppgift4 first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Barnå committed Apr 22, 2018
1 parent 191f983 commit 70fd4e9
Show file tree
Hide file tree
Showing 206 changed files with 20,820 additions and 6,080 deletions.
54 changes: 54 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
<!-- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -->
Semantic Versioning cannot be used as the exercise instructions specify final rev as 2.0.x

## [Unreleased]
- Create and add a UML-diagram for Dice100 classes

## [v2.0.3] - 2018-04-22
### Added
- This CHANGELOG file
- GameInit function to initialize default game settings for Dice100
- Game winner to show who won the game
- stopGame session variable to inhibit further throws after win
- checkbox for viewing $_SESSION
- Stop function
- Calcualtion of round and total score.
- Player switch.
- Selecting number of dices
- Creating game, functions for throw, reset, display dices results.
- Route and view for Dice100

### Changed
- Moved version info to CHANGELOG. README now contains general project info
- Made doDebug persistent
- Corrected game calcualations
- Navbar to incorporate link for game Dice100

## [v2.0.2] - 2018-04-13
### Added
- GET, POST and SESSION versions of the Guess game
- Built new documentation including Guess game

### Changed
- Navbar to incorporate link for game Gissa

## [v2.0.1] - 2018-04-09
### Added
- phpDocumentor
- Built documentation

### Changed
- Moved bootstrap stylesheet to Page.php

## [v1.0.x] - 2018-04-08
### Added
- Report text
- Styling
- Bootstrap stylesheets.
kmom01 finished.

2018-04-06 Project init
20 changes: 5 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
My redovisa in oophp
====================
# My redovisa in oophp-v4

This is a project repo for course oophp at BTH (bth.se).
Author: thba17

v2.0.2
2018-04-13 Added GET, POST and SESSION versions of the Guess game
Built new documentation including Guess game
## Built With
* [Anax-flat](https://github.com/canax/anax-flat) - The web framework used

v2.0.1
2018-04-09 Moved bootstrap stylesheet to Page.php
Added phpDocumentor
Built documentation

v1.0.x
2018-04-08 Added report text, styling and bootstrap stylesheets.
kmom01 finished.
2018-04-06 Project init
## Author
* **thba17
6 changes: 6 additions & 0 deletions content/dice100.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Tärningsspelet 100
===========================

Spelet spelas med en eller flera tärningar och det gäller att samla ihop poäng för att komma först till 100.

* [Tärningsspelet 100](dice100/dice100)
99 changes: 60 additions & 39 deletions doc/api/classes/Anax.App.App.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.App.AppDI.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.App.AppDIMagic.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Common.AppInjectableInterface.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Common.AppInjectableTrait.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Common.ConfigurationException.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Common.ConfigureInterface.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Common.ConfigureTrait.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Configure.Configure2Trait.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Configure.ConfigureInterface.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Configure.ConfigureTrait.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Configure.Exception.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.DI.DI.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.DI.DIFactoryConfig.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.DI.DIFactoryConfigMagic.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.DI.DIFactoryDefault.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.DI.DIFactoryTest.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.DI.DIInterface.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.DI.DIMagicTrait.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.DI.DIServiceSetBaseTrait.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.DI.Exception.DIExceptionInterface.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.DI.Exception.Exception.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.DI.Exception.NotFoundException.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.DI.Exception.NotFoundExceptionInterface.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.DI.InjectionAwareInterface.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.DI.InjectionAwareTrait.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.DI.InjectionMagicTrait.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Page.DebugController.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Page.ErrorController.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Page.FlatFileContentController.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Page.Page.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Page.PageRender.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Page.PageRenderInterface.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Request.Request.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Response.Exception.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Response.Response.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Response.ResponseUtility.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Route.Exception.ConfigurationException.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Route.Exception.ForbiddenException.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Route.Exception.InternalErrorException.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Route.Exception.NotFoundException.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Route.Route.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Route.Router.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Route.RouterInjectable.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Session.Session.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Session.SessionConfigurable.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Session.SessionInterface.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.TextFilter.Exception.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.TextFilter.TShortcode.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.TextFilter.TTextUtilities.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.TextFilter.TextFilter.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Url.Exception.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.Url.Url.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.View.Exception.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.View.View.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.View.View2.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.View.ViewCollection.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.View.ViewContainer.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.View.ViewHelperTrait.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.View.ViewRenderFile.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.View.ViewRenderFile2.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Anax.View.ViewRenderFileInterface.html

Large diffs are not rendered by default.

878 changes: 878 additions & 0 deletions doc/api/classes/Thba17.Dice100.Dice.html

Large diffs are not rendered by default.

692 changes: 692 additions & 0 deletions doc/api/classes/Thba17.Dice100.DiceException.html

Large diffs are not rendered by default.

1,084 changes: 1,084 additions & 0 deletions doc/api/classes/Thba17.Dice100.DiceGraphic.html

Large diffs are not rendered by default.

987 changes: 987 additions & 0 deletions doc/api/classes/Thba17.Dice100.DiceHand.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Thba17.Guess.Guess.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/classes/Thba17.Guess.GuessException.html

Large diffs are not rendered by default.

641 changes: 641 additions & 0 deletions doc/api/files/src.Dice100.Dice.html

Large diffs are not rendered by default.

641 changes: 641 additions & 0 deletions doc/api/files/src.Dice100.DiceException.html

Large diffs are not rendered by default.

641 changes: 641 additions & 0 deletions doc/api/files/src.Dice100.DiceGraphic.html

Large diffs are not rendered by default.

641 changes: 641 additions & 0 deletions doc/api/files/src.Dice100.DiceHand.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/files/src.Guess.Guess.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/files/src.Guess.GuessException.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/files/src.Page.DebugController.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/files/src.Page.ErrorController.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/files/src.Page.FlatFileContentController.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/files/src.Page.Page.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/files/src.route.app.html

Large diffs are not rendered by default.

634 changes: 634 additions & 0 deletions doc/api/files/src.route.dice100.html

Large diffs are not rendered by default.

99 changes: 60 additions & 39 deletions doc/api/files/src.route.gissa.html

Large diffs are not rendered by default.

634 changes: 634 additions & 0 deletions doc/api/files/src.route.zz_dice100-1.html

Large diffs are not rendered by default.

634 changes: 634 additions & 0 deletions doc/api/files/src.route.zz_dice100-2.html

Large diffs are not rendered by default.

634 changes: 634 additions & 0 deletions doc/api/files/src.route.zz_dice100-3.html

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions doc/api/files/src/Dice100/Dice.php.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
namespace Thba17\Dice100;

/**
* A dice throwing class
*/
class Dice
{
private $sides;
private $throws;
private $result = [];

/**
* Public function to throw the Dice
*
* @param integer $throws Number of times to throw dice. Default 6 for standard dice.
* @return array An array containing each dice result for the series.
*/
public function throwDice(int $throws = 6)
{
$this->throws = $throws;

if ($throws < 1) {
throw new DiceException("The dice must be thrown at least one (1) time.");
}

for ($i = 1; $i <= $this->throws; $i++) {
$this->result[$i] = rand(1, $this->sides);
}
return $this->result;
}

/**
* Constructor for class dice
*
* This is the constructor for the Dice class. It will take as in parameter
* the number of times the dice should be thrown.
*
*/
public function __construct(int $sides = 6)
{
$this->sides = $sides;
// echo __METHOD__ . "\n";
}

/**
* Destructor for class Dice
*/
public function __destruct()
{
// echo __METHOD__ . "\n";
}
}

10 changes: 10 additions & 0 deletions doc/api/files/src/Dice100/DiceException.php.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace Thba17\Dice100;

/**
* Exception class for DiceException.
*/
class DiceException extends \Exception
{
}

71 changes: 71 additions & 0 deletions doc/api/files/src/Dice100/DiceGraphic.php.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
namespace Thba17\Dice100;

/**
* A graphic dice.
*/
class DiceGraphic extends DiceHand
{
const SIDES = 6;
// const DICES = 5;
private $dices;


/**
* gameInit A function to initialize the game object
*
* @return void
*/
public function gameInit()
{
$_SESSION["game"]["disabled"] = "disabled";
$_SESSION["game"]["stopGame"] = $_SESSION["game"]["stopGame"] ?? null;
$_SESSION["game"]["player"] = $_SESSION["game"]["player"] ?? "Visitor";
$_SESSION["game"]["winner"] = $_SESSION["game"]["winner"] ?? null;
$_SESSION["game"]["Visitor"]["values"] = $_SESSION["game"]["Visitor"]["values"] ?? 0;
$_SESSION["game"]["Visitor"]["roundSum"] = $_SESSION["game"]["Visitor"]["roundSum"] ?? 0;
$_SESSION["game"]["Visitor"]["roundTotal"] = $_SESSION["game"]["Visitor"]["roundTotal"] ?? 0;
$_SESSION["game"]["Visitor"]["grandTotal"] = $_SESSION["game"]["Visitor"]["grandTotal"] ?? 0;
$_SESSION["game"]["Computer"]["values"] = $_SESSION["game"]["Computer"]["values"] ?? 0;
$_SESSION["game"]["Computer"]["roundSum"] = $_SESSION["game"]["Computer"]["roundSum"] ?? 0;
$_SESSION["game"]["Computer"]["roundTotal"] = $_SESSION["game"]["Computer"]["roundTotal"] ?? 0;
$_SESSION["game"]["Computer"]["grandTotal"] = $_SESSION["game"]["Computer"]["grandTotal"] ?? 0;
}

/**
* playComputer A function to roll dices for the computer. Called from
* src/route/dice100.php
*
* @return void
*/
public function playComputer()
{
// echo "In playComputer";
$_SESSION["game"]["Computer"]["roundSum"] = 0;
$_SESSION["game"]["Computer"]["roundTotal"] = 0;
$this->roll();
$_SESSION["game"]["Computer"]["values"] = $this->values();

if (!array_search(1, $_SESSION["game"]["Computer"]["values"])) {
$_SESSION["game"]["Computer"]["roundSum"] = $this->sum();
$_SESSION["game"]["Computer"]["roundTotal"] += $_SESSION["game"]["Computer"]["roundSum"];
if (($_SESSION["game"]["Computer"]["grandTotal"] + $_SESSION["game"]["Computer"]["roundTotal"]) >= 100) {
$_SESSION["game"]["winner"] = $_SESSION["game"]["player"];
$_SESSION["game"]["stopGame"] = "disabled";
}
$_SESSION["game"]["Computer"]["grandTotal"] += $_SESSION["game"]["Computer"]["roundTotal"];
}
}

/**
* Constructor to initiate five dices with six number of sides.
*
* @param integer $dices Number of dices to use in the game
*/
public function __construct(int $dices = 1)
{
$this->dices = $dices;
parent::__construct($this->dices, self::SIDES);
}
}

81 changes: 81 additions & 0 deletions doc/api/files/src/Dice100/DiceHand.php.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
namespace Thba17\Dice100;

/**
* Class for DiceHand
*/
class DiceHand
{
private $dices;
private $sides;
private $results = [];
private $value = [];

/**
* values A function to return an array containing all dice values for one throw
* @return array Containing the values of the thrown dices
*/
public function values()
{
return $this->results;
}

/**
* sum A function to return the sum of all dice values for one throw
* @return int The sum of all dices thrown
*/
public function sum()
{
return array_sum($this->results);
}

/**
* average The average value of all dices thrown rounded to two decimals
* @return int The rounded average of the dices thrown
*/
public function average()
{
return round($this->sum()/count($this->results), 2);
}

/**
* roll A function to roll the dices. The dice values are stored in an array.
* @return void
*/
public function roll()
{
$game = new Dice($this->sides);
for ($i = 1; $i <= $this->dices; $i++) {
$this->value = $game->throwDice(1);
$this->results[$i] = $this->value[1];
}
}

/**
* Constructor for class DiceHand
*
* This is the constructor for the Dice class. It will take as in parameter
* the number of times the dice should be thrown.
*
* @param integer $dices The number of dices to throw.
* @param integer $sides The number of sides of the dices.
*/
public function __construct(int $dices = 5, int $sides = 6)
{
if ($dices < 1 || $sides < 2) {
throw new DiceException("We need at least one (1) dice with at least 2 sides.");
}
$this->dices = $dices;
$this->sides = $sides;
// echo __METHOD__ . "\n";
}

/**
* Destructor for class Dice
*/
public function __destruct()
{
// echo __METHOD__ . "\n";
}
}

89 changes: 89 additions & 0 deletions doc/api/files/src/route/dice100.php.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* App specific routes.
*/

/**
* This route is for the game " Dice 100"
*/
$app->router->any(["GET", "POST"], "dice100/dice100", function () use ($app) {
$data = [
"title" => "Tärningsspelet 100",
];

// Check if user requests a new game
if (isset($_POST['doRestart'])) {
unset($_SESSION['game']);
}

// Get incoming
if (isset($_POST['doSetDices'])) {
$_SESSION["game"]["dices"] = $_POST["dices"];
}
$dices = isset($_SESSION["game"]["dices"]) ? $_SESSION["game"]["dices"] : 0;
$player = $_SESSION["game"]["player"] ?? "Visitor";

// Set session variables
$game = isset($_SESSION["game"]["game"]) ? $_SESSION["game"]["game"] : null;

if (isset($_SESSION["game"]["dices"]) && ($dices > 0)) {
//Dices selected, lock field, create game
$game = new \Thba17\Dice100\DiceGraphic($_SESSION["game"]["dices"]);
$game->gameInit();
$_SESSION["game"]["game"] = $game;
} else {
// No dices selected, unlock field
$_SESSION["game"]["disabled"] = "";
}

// Player rolls dices. Calculate sum of round.
if (isset($_POST['doThrow'])) {
$player = $_SESSION["game"]["player"];
$game->roll();
$_SESSION["game"]["Visitor"]["values"] = $game->values();

if (array_search(1, $_SESSION["game"]["Visitor"]["values"])) {
$_SESSION["game"][$player]["roundSum"] = 0;
$_SESSION["game"][$player]["roundTotal"] = 0;
if ($player == "Visitor") {
$_SESSION["game"]["player"] = "Computer";
$game->playComputer();
$_SESSION["game"]["player"] = "Visitor";
}
} else {
$_SESSION["game"][$player]["roundSum"] = $game->sum();
$_SESSION["game"][$player]["roundTotal"] += $_SESSION["game"][$player]["roundSum"];
if (($_SESSION["game"][$player]["grandTotal"] + $_SESSION["game"][$player]["roundTotal"]) >= 100) {
// $_SESSION["game"][$player]["grandTotal"] += $_SESSION["game"][$player]["roundSum"];
$_SESSION["game"]["winner"] = $_SESSION["game"]["player"];
$_SESSION["game"]["stopGame"] = "disabled";
}
}
}

// Player stops the current round. Switch to next player. Update player score.
if (isset($_POST['doStop'])) {
//Stop current round and add round result to total.
$player = $_SESSION["game"]["player"];
$_SESSION["game"][$player]["grandTotal"] += $_SESSION["game"][$player]["roundTotal"];
$_SESSION["game"][$player]["roundSum"] = 0;
$_SESSION["game"][$player]["roundTotal"] = 0;
if ($player == "Visitor") {
$_SESSION["game"]["player"] = "Computer";
$game->playComputer();
$_SESSION["game"]["player"] = "Visitor";
}
}

// Add to $data array
$data += [
"game" => $game,
"player" => $player,
"dices" => $dices,
];

// Add view and render page
$app->view->add("dice100/dice100", $data);
$app->page->render($data);
});

Loading

0 comments on commit 70fd4e9

Please sign in to comment.