text:
<file_sep># Simple GUI Adventure Game

I wanted to get some experience with Java Swing as one of courses for University for Semester 1 2018 uses it. So I
stumbled upon "How to make a Text Adventure Game with GUI in Java" by [RyiSnow](https://www.youtube.com/channel/UCS94AD0gxLakurK-6jnqV1w)
on YouTube, and wanted to refactor it. If you haven't watched it, I recommend as it's a good introduction to Java Swing
and text adventure game logic.

The game is a simple GUI adventure game which uses Swing/AWT. My version of the code consists of 4 classes: Game,
GameWorld, GUI, and Player. I've tested the build on MacOS using Java 9 SE.
<file_sep>package adventure;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public final class Game {

    private final GUI gui = new GUI(new ChoiceHandler(), new TitleScreenHandler());
    private final GameWorld world = new GameWorld(gui);

    private Game() {
        gui.initializeStartScreen();
    }

    public static void main(String[] args) {
        new Game();
    }

    private class TitleScreenHandler implements ActionListener {

        public void actionPerformed(ActionEvent actionEvent) {
            gui.createGameScreen();
            world.startGame();
        }

    }

    private class ChoiceHandler implements ActionListener {

        public void actionPerformed(ActionEvent actionEvent) {
            String choice = actionEvent.getActionCommand();

            switch (world.getPlayerPosition()) {
                case "townGate":
                    switch (choice) {
                        case "c1":
                            if (!world.playerHasSilverRing()) {
                                world.talkToGuard();
                            }
                            break;
                        case "c2":
                            world.attackGuard();
                            break;
                        case "c3":
                            world.crossRoad();
                            break;
                    }
                    break;

                case "playerTalkedToGuard":
                    switch (choice) {
                        case "c1":
                            world.townGate();
                            break;
                    }
                    break;

                case "playerAttackedGuard":
                    switch (choice) {
                        case "c1":
                            if (world.playerIsAlive()) {
                                world.townGate();
                            }
                            break;
                    }
                    break;

                case "crossRoad":
                    switch (choice) {
                        case "c1":
                            world.north();
                            break;
                        case "c2":
                            world.east();
                            break;
                        case "c3":
                            world.townGate();
                            break;
                        case "c4":
                            world.west();
                            break;
                    }
                    break;

                case "north":
                    switch (choice) {
                        case "c1":
                            world.crossRoad();
                            break;
                    }
                    break;

                case "east":
                    switch (choice) {
                        case "c1":
                            world.crossRoad();
                            break;
                    }
                    break;

                case "west":
                    if (world.goblinIsAlive()) {
                        switch (choice) {
                            case "c1":
                                world.fightGoblin();
                                break;
                            case "c2":
                                world.crossRoad();
                                break;
                        }
                    } else {
                        switch (choice) {
                            case "c1":
                                world.crossRoad();
                                break;
                        }
                    }
                    break;

                case "goblinBattle":
                    switch (choice) {
                        case "c1":
                            world.attackGoblin();
                            break;
                        case "c2":
                            world.crossRoad();
                            break;
                    }
                    break;

                case "playerAttackedGoblin":
                    switch (choice) {
                        case "c1":
                            if (world.goblinIsAlive()) {
                                world.goblinAttacks();
                            }
                            break;
                    }
                    break;

                case "goblinAttackedPlayer":
                    switch (choice) {
                        case "c1":
                            if (world.playerIsAlive()) {
                                world.fightGoblin();
                            }
                            break;
                    }
                    break;

                case "playedKilledGoblin":
                    switch (choice) {
                        case "c1":
                            world.crossRoad();
                            break;
                    }
                    break;
            }
        }

    }

}

branch_name: refs/heads/main

languages: Java Markdown

repo_language: Java


text:
<repo_name>dearthm/hello-world<file_sep>/README.md
# hello-world
My first repository
Edited at 10:38

branch_name: refs/heads/master

repo_language: Markdown

repo_name: dearthm/hello-world


text:
<repo_name>maestroevn/OpenExchangeRatesAPIClient<file_sep>/src/Exceptions/ClientException.php
<?php

namespace TigranMaestro\OpenExchangeRatesPHPClient\Exceptions;

/**
 * Class ClientException
 * @package TigranMaestro\OpenExchangeRatesPHPClient\Exceptions
 */
class ClientException extends \Exception
{

}<file_sep>/src/Abstracts/Api.php
<?php

namespace TigranMaestro\OpenExchangeRatesPHPClient\Abstracts;

use TigranMaestro\OpenExchangeRatesPHPClient\Wrapper;
use TigranMaestro\OpenExchangeRatesPHPClient\Traits\WrapperAware;

/**
 * Class Api
 * @package TigranMaestro\OpenExchangeRatesPHPClient\Abstracts
 */
abstract class Api implements \TigranMaestro\OpenExchangeRatesPHPClient\Interfaces\Api
{
    /** @var string API URL to which to send the request */
    protected $apiUrl;

    /** @var array Settings on which optional fields to fetch */
    protected $fieldSettings = [];

    /** @var array Other API specific options */
    protected $otherOptions = [];

    /** @var  Wrapper The parent class which spawned this one */
    protected $wrapper;

    use WrapperAware;

    public function __construct()
    {

    }

    /**
     * @return string
     */
    public function buildUrl()
    {
        $url = rtrim($this->apiUrl, '/') . '?';

        // Add Token
        $url .= 'app_id=' . $this->wrapper->getAppId();

        // Add Other Options
        foreach ($this->otherOptions as $option => $value) {
            $url .= '&' . $option . '=' . $value;
        }

        return $url;
    }
}<file_sep>/src/Api/Latest.php
<?php
namespace TigranMaestro\OpenExchangeRatesPHPClient\Api;

use TigranMaestro\OpenExchangeRatesPHPClient\Abstracts\Api;

/**
 * Class Latest
 *
 * Get the latest exchange rates available from the Open Exchange Rates API.
 * @see https://docs.openexchangerates.org/docs/latest-json
 *
 * @package TigranMaestro\OpenExchangeRatesPHPClient\Api
 */
class Latest extends Api
{
    /** @var string API URL to which to send the request */
    protected $apiUrl = 'https://openexchangerates.org/api/latest.json';

    /**
     * @return \TigranMaestro\OpenExchangeRatesPHPClient\Entity\Latest
     */
    public function call()
    {
        $response = $this->wrapper->getHttpClient()->get($this->buildUrl());
        $arr = json_decode($response->getBody(), true, 512, 1);

        $entity = new \TigranMaestro\OpenExchangeRatesPHPClient\Entity\Latest($arr);

        return $entity;
    }

    /**
     * @param string $baseCurrency international-standard 3-letter ISO currency code
     * @return $this
     */
    public function setBaseCurrency($baseCurrency)
    {
        $this->otherOptions['base'] = $baseCurrency;
        return $this;
    }

    /**
     * @param array $symbols array of international-standard 3-letter ISO currency codes
     * @return $this
     */
    public function setSymbols($symbols = [])
    {
        $symbolsString = implode(',', $symbols);
        $this->otherOptions['symbols'] = $symbolsString;
        return $this;
    }
}<file_sep>/src/Entity/Rate.php
<?php

namespace TigranMaestro\OpenExchangeRatesPHPClient\Entity;

use TigranMaestro\OpenExchangeRatesPHPClient\Abstracts\Entity;

/**
 * Class Rate
 * @package TigranMaestro\OpenExchangeRatesPHPClient\Entity
 */
class Rate extends Entity
{
    /**
     * Rate constructor.
     * @param string $currencyCode
     * @param double $rate
     */
    public function __construct($currencyCode, $rate)
    {
        parent::__construct([]);
        $this->data['currency_code'] = $currencyCode;
        $this->data['rate'] = $rate;
    }

    /**
     * @return string
     */
    public function getRate()
    {
        return $this->data['rate'];
    }

    /**
     * @return string
     */
    public function getCurrencyCode()
    {
        return $this->data['currency_code'];
    }
}<file_sep>/README.md
# OpenExchangeRates PHP API Wrapper

This package is a slightly OpenExchangeRates API wrapper.
Right now it only supports latest.json endpoint

## Usage - simple

Simplest possible use case:

```php
$wrapper = new \TigranMaestro\OpenExchangeRatesPHPClient\Wrapper('__YOUR_APP_ID__');
$wrapper->setHttpClient();

$api = $wrapper->createLatestAPI();
$api->setSymbols([
    'EUR',
    'AMD'
]);

$result = $api->call();

echo "<pre>";
var_dump($result);
echo "</pre>";
```

That's it, this is all you need to get started.<file_sep>/src/Interfaces/Api.php
<?php

namespace TigranMaestro\OpenExchangeRatesPHPClient\Interfaces;

use TigranMaestro\OpenExchangeRatesPHPClient\Abstracts\Entity;

/**
 * Interface Api
 * @package TigranMaestro\OpenExchangeRatesPHPClient\Interfaces
 */
interface Api
{
    /**
     * @return Entity
     */
    public function call();

    /**
     * @return string
     */
    public function buildUrl();
}<file_sep>/src/Traits/WrapperAware.php
<?php

namespace TigranMaestro\OpenExchangeRatesPHPClient\Traits;

use TigranMaestro\OpenExchangeRatesPHPClient\Wrapper;

/**
 * Class WrapperAware
 * @property Wrapper wrapper
 * @package TigranMaestro\OpenExchangeRatesPHPClient\Traits
 */
trait WrapperAware
{
    /**
     * Sets the Wrapper instance on the child class
     * Used to later fetch the token, HTTP client, EntityFactory, etc
     * @param Wrapper $wrapper
     * @return $this
     */
    public function registerWrapper(Wrapper $wrapper)
    {
        $this->wrapper = $wrapper;
        return $this;
    }
}<file_sep>/src/Entity/Latest.php
<?php

namespace TigranMaestro\OpenExchangeRatesPHPClient\Entity;

use TigranMaestro\OpenExchangeRatesPHPClient\Abstracts\Entity;
use TigranMaestro\OpenExchangeRatesPHPClient\Entity\Rate;

/**
 * Class Latest
 * @package Swader\OpenExchangeRatesPHPClient\Entity
 */
class Latest extends Entity
{
    /**
     * @var array
     */
    protected $rates = [];

    /**
     * Latest constructor.
     * @param array $data
     */
    public function __construct(array $data)
    {
        parent::__construct($data);
        foreach ($this->data['rates'] as $currencyCode => $rate) {
            $this->rates[] = new Rate($currencyCode, $rate);
        }
        $this->data['rates'] = $this->rates;
        unset($this->rates);
    }

    /**
     * Provides the time (UNIX) that the rates were published
     * @return int
     */
    public function getTimestamp()
    {
        return intval($this->data['timestamp']);
    }

    /**
     * Provides the 3-letter currency code to which all the delivered exchange rates are relative
     * @return string
     */
    public function getBase()
    {
        return $this->data['base'];
    }

    /**
     * Returns an array of rates
     * Each rate is a Rate entity.
     *
     * @see Rate
     * @return array
     */
    public function getRates()
    {
        return $this->rates;
    }
}<file_sep>/src/Wrapper.php
<?php

namespace TigranMaestro\OpenExchangeRatesPHPClient;

use GuzzleHttp\Client;
use TigranMaestro\OpenExchangeRatesPHPClient\Abstracts\Entity;
use TigranMaestro\OpenExchangeRatesPHPClient\Api\Latest;
use TigranMaestro\OpenExchangeRatesPHPClient\Exceptions\ClientException;

/**
 * Class Wrapper
 *
 * The main class for API consumption
 *
 * @package TigranMaestro\OpenExchangeRatesPHPClient
 */
class Wrapper
{
    /** @var string app ID */
    private static $appId = null;

    /** @var string instance app ID, settable once per new instance */
    private $instanceAppId;

    /** @var Client The HTTP clients to perform requests with */
    protected $client;

    /** @var Entity */
    protected $entity;

    /**
     * @param string|null $appId app ID, as obtained on https://docs.openexchangerates.org/
     * @throws ClientException When no token is provided
     */
    public function __construct($appId = null)
    {
        if ($appId === null) {
            if (self::$appId === null) {
                $msg = 'No app ID provided, and none is globally set. ';
                $msg .= 'Use Wrapper::setToken, or instantiate the Wrapper class with a $appId parameter.';
                throw new ClientException($msg);
            }
        } else {
            self::validateAppId($appId);
            $this->instanceAppId = $appId;
        }
    }

    /**
     * Sets the app ID for all future new instances
     * @param $appId string app ID, as obtained on https://docs.openexchangerates.org/
     * @return void
     */
    public static function setAppId($appId)
    {
        self::validateAppId($appId);
        self::$appId = $appId;
    }

    /**
     * Validates given App ID
     * @param $appId string
     * @return bool
     */
    private static function validateAppId($appId)
    {
        if (!is_string($appId)) {
            throw new \InvalidArgumentException('App ID is not a string.');
        }
        if (strlen($appId) < 4) {
            throw new \InvalidArgumentException('App ID "' . $appId . '" is too short, and thus invalid.');
        }
        return true;
    }

    /**
     * Returns the app ID that has been defined.
     * @return null|string
     */
    public function getAppId()
    {
        return ($this->instanceAppId) ? $this->instanceAppId : self::$appId;
    }
    /**
     * Sets the client to be used for querying the API endpoints
     *
     * @param Client $client
     * @see http://php-http.readthedocs.org/en/latest/utils/#httpmethodsclient
     * @return $this
     */
    public function setHttpClient(Client $client = null)
    {
        if ($client === null) {
            $client = new Client();
        }

        $this->client = $client;

        return $this;
    }
    /**
     * Returns either the instance of the Guzzle client that has been defined, or null
     * @return Client|null
     */
    public function getHttpClient()
    {
        return $this->client;
    }

    /**
     * @param Entity $entity
     * @return $this
     */
    public function setEntity(Entity $entity)
    {
        $this->entity = $entity;
        return $this;
    }

    /**
     * @return Entity
     */
    public function getEntity()
    {
        return $this->entity;
    }

    /**
     * Creates a Latest Rates API interface
     *
     * @param string $url Url to analyze
     * @return Latest
     */
    public function createLatestAPI()
    {
        $api = new Latest();

        return $api->registerWrapper($this);
    }
}

languages: Markdown PHP

repo_name: maestroevn/OpenExchangeRatesAPIClient


text:
<repo_name>JuanM-MFranco/mano<file_sep>/README.md
# MANO ROBÓTICA
Mano controlada por un arduino a través de sensores flexibles.

Éste proyecto fue realizado para las sesiones del mes de marzo.

La construcción de la mano se divide en 2 partes:

### SESIÓN 1:

##### Objetivo:

Al término del tema los y las participantes elaborarán sensores flexibles de bajo costo y divisor
de voltaje, para controlar la mano articulada.

##### Material:

* Bolígrafo
* Lápiz
* Sacapuntas
* Laptop
* 2 hojas de papel
* Papel aluminio
* Pegamento
* 1m de cable conductor calibre 22
* Cinta de aislar
* Tijeras
* Regla
* Cinta adhesiva de 5 cm de ancho
* Resistencias de 4.7 k Ohms (kilo ohms)
* Protoboard
* Placa Arduino
* IDE de Arduino

A continuación se explica lo que se realizó en la primera sesión.

##### Procedimiento:

1. Mide cada uno de tus dedos desde la base del dedo hasta la punta.
2. Corta 5 tiras de papel, el largo debe ser del doble de la medida de cada uno de tus dedos y de 3 cm de ancho.
3. Dobla cada tira de papel por la mitad a lo ancho.
4. Rellena con grafito toda la cara interna de la hoja.
5. Corta 10 tiras de papel aluminio con la medida de cada uno de los dedos y con 1 cm de ancho.
6. Pega las tiras de aluminio a la hoja de papel, en la parte que tiene grafito, cuidando que no se toque estas tiras.
7. Corta el cable conductor por secciones de 6 cm.
8. Quita el aislante de los extremos del cable conductor.
9. Coloca un cable sobre cada tira de papel aluminio y fíjalo con un pedazo de cinta de aislar.
10. Dobla la tira de papel por la mitad, procurando que quede completamente simétrica.
11. Corta una tira de cinta adhesiva del mismo tamaño que la tira de papel.
12. Coloca la tira de papel sobre la cinta adhesiva y recortar el excedente.
13. Para comprobar la variación de señal en el sensor, conecta los circuitos como se muestra en el [diagrama 1](https://github.com/HackrobotsMX/mano/blob/master/Diagrama%201.jpg)
14. Se procede a abrir el IDE de Arduino.
15. Conecta el Arduino a tu computadora.

###### Nota1: comprueba que tu computadora reconozca tus puertos, en caso contrario, descárgalos de la página oficial de Arduino: www.arduino.cc/en/Guide/ArduinoUno#toc3 (recuerda que este método sólo funcionará sí tu Arduino es original.

###### Nota 2: Si tu Arduino es genérico, revisa la siguiente liga: http://www.geekfactory.mx/sin-categoria/driver-ch340-para-arduinochinos-o-genericos/

16. Selecciona la pestaña de “Archivo” o “File”.
17. Da click en “Ejemplos”--> click en “01.Basicos”-->click en “AnalogReadSerial”.
Si tienes la version en ingles “Examples-->01.Basics-->AnalogReadSerial”
18. Selecciona “Compilar” o “Verify” (icono con una palomita) para comprobar que no haya errores.
19. Carga el programa a la placa Arduino.
20. Ve a la pestaña de “Herramientas” o “Tools” y da click en “Monitor Serial”.
21. Al doblar el sensor flexible deberá generarse una variación de señal (valores de 0 a 1023) que se verá reflejada en el monitor serial. En caso de querer notar esa diferencia de manera lenta, en el código busca la instrucción ‘delay’ y cambia el valor por 1000 o 1500, el valor que cambies es en milisegundos, es decir, 1000 ms = 1seg.

##### IMPORTANTE:
No deben quedar bolsas de aire en los sensores pues esto ocasionará que no haya variación en los mismos. Así que procura que queden lo más lisos posibles.

<file_sep>/codigo_mano.ino
#include <Servo.h>

Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5; //define los servos

#define dedo1 A1
#define dedo2 A2
#define dedo3 A3
#define dedo4 A4
#define dedo5 A5 //define las ebtradas analogicas de los sensores

int val1;
int val2;
int val3;
int val4;
int val5; //define las variables para leer el valor de cada dedo

void setup() {
servo1.attach(1);
servo2.attach(2);
servo3.attach(3);
servo4.attach(4);
servo5.attach(5); //defines las salidas de cada servo

}

void loop() {

val1 = analogRead(dedo1);
val1 = map(val1, 750, 1023, 0, 179);
servo1.write(val1);
delay(5); //lee el dedo 1 i coloca el servo de este dedo

val2 = analogRead(dedo2);
val2 = map(val2, 570, 1023, 0, 179);
servo2.write(val2);
delay(5); //lee el dedo 2 i coloca el servo de este dedo

val3 = analogRead(dedo3);
val3 = map(val3, 770, 1023, 0, 179);
servo3.write(val3);
delay(5); //lee el dedo 3 i coloca el servo de este dedo

val4 = analogRead(dedo4);
val4 = map(val4, 1000, 1023, 0, 179);
servo4.write(val4);
delay(5); //lee el dedo 4 i coloca el servo de este dedo

val5 = analogRead(dedo5);
val5 = map(val5, 720, 1023, 0, 179);
servo5.write(val5);
delay(5); //lee el dedo 5 i coloca el servo de este dedo

}

languages: Markdown C++

repo_name: JuanM-MFranco/mano