* @copyright 2025 Bartolomé Sintes Marco * @license http://www.gnu.org/licenses/agpl.txt AGPL 3 or later * @version 2025-02-08 * @link https://www.mclibre.org * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ ?> Reparto de cartas. Matrices (3). Sin formularios. Ejercicios. PHP. Bartolomé Sintes Marco. www.mclibre.org

Reparto de cartas

Las " . 2 * $n . " cartas a repartir\n"; print "\n"; print "

\n"; foreach ($cartas as $carta) { print " \"$carta\n"; } print "

\n"; print "\n"; // Barajamos los valores de las cartas shuffle($cartas); // Creamos una matriz con las $n primeras cartas $cartasA = []; for ($i = 0; $i < $n; $i++) { $cartasA[] = $cartas[$i]; } // Creamos una matriz con las $n siguientes cartas for ($i = 0; $i < $n; $i++) { $cartasB[] = $cartas[$i + $n]; } // Mostramos las imágenes de las cartas del primer jugador print "

Las $n cartas del jugador A

\n"; print "\n"; print "

\n"; foreach ($cartasA as $carta) { print " \"$carta\n"; } print "

\n"; print "\n"; // Mostramos las imágenes de las cartas del segundo jugador print "

Las $n cartas del jugador B

\n"; print "\n"; print "

\n"; foreach ($cartasB as $carta) { print " \"$carta\n"; } print "

\n"; print "\n"; ?>