Skip to content

Commit

Permalink
Merge pull request mouredev#3967 from daom89/diego
Browse files Browse the repository at this point in the history
Reto mouredev#25 - PHP Codigo Konami
  • Loading branch information
kontroldev authored Jun 29, 2023
2 parents 788785a + 1ccd48c commit c617ab8
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions Retos/Reto #25 - EL CÓDIGO KONAMI [Media]/php/daom89.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/*
Para ejecutarlo revisar el repositorio:
https://github.com/EjemplosADSI/konami-code
*/
require "vendor\autoload.php";

use Zenithies\Toolkit\ReadKey\Interceptor;

$key_position = 0;
$KONAMI_CODE = [
Interceptor::KEY_UP, Interceptor::KEY_UP, Interceptor::KEY_DOWN,
Interceptor::KEY_DOWN, Interceptor::KEY_LEFT, Interceptor::KEY_RIGHT,
Interceptor::KEY_LEFT, Interceptor::KEY_RIGHT, 98, 97,
];
$ICONS = [
Interceptor::KEY_UP => "", Interceptor::KEY_DOWN => "",
Interceptor::KEY_LEFT => "", Interceptor::KEY_RIGHT => "",
98 => "b", 97 => "a",
];

$keys = Interceptor::I();
echo "\033[31m\e[1mKonami Code \e[32m presione q para salir \n";

if ($keys->init()) {
while (true) {
$key = $keys->intercept();
if (in_array($key, [113, 81])) {
Interceptor::eprintln("\e[7;34;40mSalida registrada\e[0m");
exit(0);
}
if (!on_press($key)) {
exit(0);
}
}
}

function on_press($key)
{
global $key_position, $last_key, $KONAMI_CODE, $ICONS;
echo (in_array($key, $KONAMI_CODE)) ? "$ICONS[$key]" : chr($key);
if ($key == $KONAMI_CODE[$key_position]) {
$key_position += 1;
} elseif ($key == $KONAMI_CODE[0]) {
$key_position = ($last_key == $KONAMI_CODE[0]) ? 2 : 1;
} else {
$key_position = 0;
}

if ($key_position == count($KONAMI_CODE)) {
echo "\n\e[39m";
echo "\e[41m╦╔═╔═╗╔╗╔╔═╗╔╦╗╦ ╔═╗╔═╗╔╦╗╔═╗\n";
echo "\e[41m╠╩╗║ ║║║║╠═╣║║║║ ║ ║ ║ ║║║╣ \n";
echo "\e[41m╩ ╩╚═╝╝╚╝╩ ╩╩ ╩╩ ╚═╝╚═╝═╩╝╚═╝\n";
echo "\e[0m";
return false;
}
$last_key = $key;
return true;
}

0 comments on commit c617ab8

Please sign in to comment.