RockPaperScissorsLizardSpock/Documents/Workshop/Step5
dependabot[bot] da7d2a8a98
Bump qs and body-parser in /Documents/Workshop/Step5
Bumps [qs](https://github.com/ljharb/qs) to 6.11.0 and updates ancestor dependency [body-parser](https://github.com/expressjs/body-parser). These dependencies need to be updated together.


Updates `qs` from 6.7.0 to 6.11.0
- [Release notes](https://github.com/ljharb/qs/releases)
- [Changelog](https://github.com/ljharb/qs/blob/main/CHANGELOG.md)
- [Commits](https://github.com/ljharb/qs/compare/v6.7.0...v6.11.0)

Updates `body-parser` from 1.19.0 to 1.20.1
- [Release notes](https://github.com/expressjs/body-parser/releases)
- [Changelog](https://github.com/expressjs/body-parser/blob/master/HISTORY.md)
- [Commits](https://github.com/expressjs/body-parser/compare/1.19.0...1.20.1)

---
updated-dependencies:
- dependency-name: qs
  dependency-type: indirect
- dependency-name: body-parser
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-26 17:36:43 +00:00
..
public Add workshop (#2) 2019-12-12 14:10:13 +01:00
LICENSE Add workshop (#2) 2019-12-12 14:10:13 +01:00
README.md Add workshop (#2) 2019-12-12 14:10:13 +01:00
config.js Add workshop (#2) 2019-12-12 14:10:13 +01:00
index.js Add workshop (#2) 2019-12-12 14:10:13 +01:00
package-lock.json Bump qs and body-parser in /Documents/Workshop/Step5 2023-01-26 17:36:43 +00:00
package.json Bump qs and body-parser in /Documents/Workshop/Step5 2023-01-26 17:36:43 +00:00
process.json Add workshop (#2) 2019-12-12 14:10:13 +01:00
web.config Add workshop (#2) 2019-12-12 14:10:13 +01:00

README.md

Step5

Goal:

  • Add AI opponent
  • Show opponents move

Changes in public/index.html

Update opponents container with its pick

<div class="opponent-container">
    <img class="bot-player" src="img/bot.png" alt="engine player">
    <div class="bot-pick">
        <img class="bot-pick-img" src="img/bot/rock.png" alt="engine pick">
    </div>
</div>

Changes in public/css/app.css

.bot-pick {
    height: 10vw;
    width: 10vw;
    border-radius: 100%;
    background: #492f93;
    box-shadow: inset 0px 0px 0px 2px #492f93;
    box-sizing: border-box;
}

.bot-pick img {
    width: 100%;
    height: auto;
}

Changes in public/js/app.js

Add picks and engine pick logic as global variables

// Global variables
...
const picks = ["rock", "paper", "scissors", "lizard", "spock"];
const getEnginePick = () => picks[Math.floor(Math.random() * picks.length)];

Update setLayout elements arrays

const elements = [
    "video", "canvas", ".user-pick",
    ".bot-player", ".bot-pick",
    ".start-button", ".app-counter", ".restart-button"
];

const visibleElements = {
    "start": ["video", ".start-button", ".bot-player"],
    "countdown": ["video", ".app-counter", ".bot-player"],
    "predicting": ["canvas", ".app-counter", ".bot-player"],
    "results": ["canvas", ".user-pick", ".app-counter", ".bot-pick", ".restart-button"]
};

Add engine pick logic to showResults method


    const showResults = (prediction, enginePick) => {
        const userPickElement = appContainer.querySelector('.user-pick');
        const enginePickElement = appContainer.querySelector('.bot-pick-img');

        userPickElement.src = 'img/user/' + prediction + '.png';
        enginePickElement.src = 'img/bot/' + enginePick + '.png';

        setLayout("results");
    };

Inside submitImageFromCanvas method add engine pick and show results call

    const enginePick = getEnginePick();
    showResults(prediction, enginePick);