T-1
29
api/pexels.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
require_once __DIR__.'/../includes/pexels.php';
|
||||||
|
$qs = isset($_GET['queries']) ? explode(',', $_GET['queries']) : ['cute cat','kitten','playful cat','sleepy cat','silly cat'];
|
||||||
|
$out = [];
|
||||||
|
foreach ($qs as $q) {
|
||||||
|
$u = 'https://api.pexels.com/v1/search?query=' . urlencode(trim($q)) . '&orientation=square&per_page=1&page=' . rand(1, 100);
|
||||||
|
$d = pexels_get($u);
|
||||||
|
if ($d && !empty($d['photos'])) {
|
||||||
|
$p = $d['photos'][0];
|
||||||
|
$src = $p['src']['large'] ?? null;
|
||||||
|
$dest = __DIR__.'/../assets/images/pexels/'.$p['id'].'.jpg';
|
||||||
|
if ($src) download_to($src, $dest);
|
||||||
|
$out[] = [
|
||||||
|
'src' => 'assets/images/pexels/'.$p['id'].'.jpg',
|
||||||
|
'photographer' => $p['photographer'] ?? 'Unknown',
|
||||||
|
'photographer_url' => $p['photographer_url'] ?? '',
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
// Fallback: Picsum
|
||||||
|
$out[] = [
|
||||||
|
'src' => 'https://picsum.photos/600?random=' . rand(1,1000),
|
||||||
|
'photographer' => 'Random Picsum',
|
||||||
|
'photographer_url' => 'https://picsum.photos/'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo json_encode($out);
|
||||||
|
?>
|
||||||
188
assets/css/custom.css
Normal file
@ -0,0 +1,188 @@
|
|||||||
|
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;700&family=Roboto:wght@300;400&display=swap');
|
||||||
|
|
||||||
|
:root {
|
||||||
|
--primary-color: #BDE0FE; /* Baby Blue Eyes */
|
||||||
|
--accent-color: #FFC8B2; /* Pastel Peach */
|
||||||
|
--background-color: #FFFBF7; /* Very light, warm off-white */
|
||||||
|
--text-color: #6D6875; /* Muted, soft gray */
|
||||||
|
--surface-color: #FFFFFF;
|
||||||
|
--board-bg: #A3C4F3;
|
||||||
|
--cell-bg: #EAF4F4;
|
||||||
|
--border-radius: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
background-color: var(--background-color);
|
||||||
|
color: var(--text-color);
|
||||||
|
font-family: 'Roboto', sans-serif;
|
||||||
|
font-weight: 300;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1, h2, h3, h4, h5, h6 {
|
||||||
|
font-family: 'Poppins', sans-serif;
|
||||||
|
font-weight: 700;
|
||||||
|
color: var(--text-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.navbar {
|
||||||
|
background-color: var(--surface-color) !important;
|
||||||
|
box-shadow: 0 2px 10px rgba(0,0,0,0.05) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navbar-brand {
|
||||||
|
font-family: 'Poppins', sans-serif;
|
||||||
|
font-weight: 700;
|
||||||
|
color: var(--primary-color) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero {
|
||||||
|
background: linear-gradient(135deg, var(--primary-color) 0%, var(--accent-color) 100%);
|
||||||
|
color: white;
|
||||||
|
padding: 6rem 0;
|
||||||
|
text-align: center;
|
||||||
|
border-bottom-left-radius: var(--border-radius);
|
||||||
|
border-bottom-right-radius: var(--border-radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero h1 {
|
||||||
|
font-size: 3.5rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: white;
|
||||||
|
text-shadow: 1px 1px 3px rgba(0,0,0,0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary {
|
||||||
|
background-color: var(--accent-color);
|
||||||
|
border-color: var(--accent-color);
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
padding: 0.75rem 1.5rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: white;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
box-shadow: 0 4px 15px rgba(0,0,0,0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary:hover {
|
||||||
|
background-color: white;
|
||||||
|
border-color: white;
|
||||||
|
color: var(--accent-color);
|
||||||
|
transform: translateY(-2px);
|
||||||
|
box-shadow: 0 6px 20px rgba(0,0,0,0.15);
|
||||||
|
}
|
||||||
|
|
||||||
|
#game-section {
|
||||||
|
padding: 4rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.game-board {
|
||||||
|
display: grid;
|
||||||
|
gap: 10px;
|
||||||
|
width: 100%;
|
||||||
|
max-width: 500px;
|
||||||
|
margin: 2rem auto;
|
||||||
|
background-color: var(--board-bg);
|
||||||
|
border: 5px solid var(--board-bg);
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.game-cell {
|
||||||
|
width: 100%;
|
||||||
|
padding-bottom: 100%;
|
||||||
|
position: relative;
|
||||||
|
background-color: var(--cell-bg);
|
||||||
|
border-radius: 0.75rem;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.game-cell:hover {
|
||||||
|
transform: scale(1.05);
|
||||||
|
box-shadow: 0 4px 10px rgba(0,0,0,0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.game-cell .symbol {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
font-size: 1rem; /* Default for large boards */
|
||||||
|
font-weight: 400;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Board-size specific adjustments */
|
||||||
|
.game-board.size-5 {
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
.game-board.size-5 .game-cell .symbol {
|
||||||
|
font-size: 2.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.game-board.size-18,
|
||||||
|
.game-board.size-36 {
|
||||||
|
gap: 2px;
|
||||||
|
padding: 2px;
|
||||||
|
border-width: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#gallery-section {
|
||||||
|
padding: 4rem 0;
|
||||||
|
background-color: var(--primary-color-light);
|
||||||
|
}
|
||||||
|
|
||||||
|
.cat-gallery {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
||||||
|
gap: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cat-gallery-item {
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
overflow: hidden;
|
||||||
|
box-shadow: 0 4px 15px rgba(0,0,0,0.1);
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cat-gallery-item:hover {
|
||||||
|
transform: translateY(-5px) scale(1.03);
|
||||||
|
box-shadow: 0 8px 25px rgba(0,0,0,0.15);
|
||||||
|
}
|
||||||
|
|
||||||
|
.cat-gallery-item img {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cat-gallery-item .photographer-credit {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
background: rgba(0,0,0,0.5);
|
||||||
|
color: white;
|
||||||
|
padding: 0.5rem;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cat-gallery-item:hover .photographer-credit {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cat-gallery-item .photographer-credit a {
|
||||||
|
color: var(--accent-color);
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
footer {
|
||||||
|
background-color: var(--text-color);
|
||||||
|
color: white;
|
||||||
|
padding: 2rem 0;
|
||||||
|
}
|
||||||
BIN
assets/images/pexels/10914511.jpg
Normal file
|
After Width: | Height: | Size: 26 KiB |
BIN
assets/images/pexels/11163348.jpg
Normal file
|
After Width: | Height: | Size: 50 KiB |
BIN
assets/images/pexels/11497291.jpg
Normal file
|
After Width: | Height: | Size: 69 KiB |
BIN
assets/images/pexels/12692139.jpg
Normal file
|
After Width: | Height: | Size: 34 KiB |
BIN
assets/images/pexels/12915730.jpg
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
assets/images/pexels/14603745.jpg
Normal file
|
After Width: | Height: | Size: 35 KiB |
BIN
assets/images/pexels/14852082.jpg
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
assets/images/pexels/14904690.jpg
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
assets/images/pexels/15208769.jpg
Normal file
|
After Width: | Height: | Size: 47 KiB |
BIN
assets/images/pexels/160722.jpg
Normal file
|
After Width: | Height: | Size: 92 KiB |
BIN
assets/images/pexels/160839.jpg
Normal file
|
After Width: | Height: | Size: 29 KiB |
BIN
assets/images/pexels/16282655.jpg
Normal file
|
After Width: | Height: | Size: 52 KiB |
BIN
assets/images/pexels/16482823.jpg
Normal file
|
After Width: | Height: | Size: 52 KiB |
BIN
assets/images/pexels/16575029.jpg
Normal file
|
After Width: | Height: | Size: 55 KiB |
BIN
assets/images/pexels/16577552.jpg
Normal file
|
After Width: | Height: | Size: 27 KiB |
BIN
assets/images/pexels/17596619.jpg
Normal file
|
After Width: | Height: | Size: 71 KiB |
BIN
assets/images/pexels/179222.jpg
Normal file
|
After Width: | Height: | Size: 31 KiB |
BIN
assets/images/pexels/18002652.jpg
Normal file
|
After Width: | Height: | Size: 39 KiB |
BIN
assets/images/pexels/18159266.jpg
Normal file
|
After Width: | Height: | Size: 54 KiB |
BIN
assets/images/pexels/18168507.jpg
Normal file
|
After Width: | Height: | Size: 53 KiB |
BIN
assets/images/pexels/18533500.jpg
Normal file
|
After Width: | Height: | Size: 76 KiB |
BIN
assets/images/pexels/19012985.jpg
Normal file
|
After Width: | Height: | Size: 49 KiB |
BIN
assets/images/pexels/19500831.jpg
Normal file
|
After Width: | Height: | Size: 60 KiB |
BIN
assets/images/pexels/20782645.jpg
Normal file
|
After Width: | Height: | Size: 38 KiB |
BIN
assets/images/pexels/24018314.jpg
Normal file
|
After Width: | Height: | Size: 39 KiB |
BIN
assets/images/pexels/24600235.jpg
Normal file
|
After Width: | Height: | Size: 39 KiB |
BIN
assets/images/pexels/2646483.jpg
Normal file
|
After Width: | Height: | Size: 66 KiB |
BIN
assets/images/pexels/29235341.jpg
Normal file
|
After Width: | Height: | Size: 41 KiB |
BIN
assets/images/pexels/29983805.jpg
Normal file
|
After Width: | Height: | Size: 42 KiB |
BIN
assets/images/pexels/30247451.jpg
Normal file
|
After Width: | Height: | Size: 30 KiB |
BIN
assets/images/pexels/30374205.jpg
Normal file
|
After Width: | Height: | Size: 26 KiB |
BIN
assets/images/pexels/30389394.jpg
Normal file
|
After Width: | Height: | Size: 34 KiB |
BIN
assets/images/pexels/32552958.jpg
Normal file
|
After Width: | Height: | Size: 39 KiB |
BIN
assets/images/pexels/32849279.jpg
Normal file
|
After Width: | Height: | Size: 56 KiB |
BIN
assets/images/pexels/34368085.jpg
Normal file
|
After Width: | Height: | Size: 49 KiB |
BIN
assets/images/pexels/3652805.jpg
Normal file
|
After Width: | Height: | Size: 31 KiB |
BIN
assets/images/pexels/3780890.jpg
Normal file
|
After Width: | Height: | Size: 44 KiB |
BIN
assets/images/pexels/4612722.jpg
Normal file
|
After Width: | Height: | Size: 50 KiB |
BIN
assets/images/pexels/4790612.jpg
Normal file
|
After Width: | Height: | Size: 42 KiB |
BIN
assets/images/pexels/51439.jpg
Normal file
|
After Width: | Height: | Size: 79 KiB |
BIN
assets/images/pexels/8597460.jpg
Normal file
|
After Width: | Height: | Size: 69 KiB |
BIN
assets/images/pexels/8861204.jpg
Normal file
|
After Width: | Height: | Size: 26 KiB |
BIN
assets/images/pexels/8935989.jpg
Normal file
|
After Width: | Height: | Size: 83 KiB |
BIN
assets/images/pexels/9195549.jpg
Normal file
|
After Width: | Height: | Size: 36 KiB |
BIN
assets/images/pexels/9195629.jpg
Normal file
|
After Width: | Height: | Size: 37 KiB |
BIN
assets/images/pexels/9660361.jpg
Normal file
|
After Width: | Height: | Size: 33 KiB |
BIN
assets/images/pexels/9787888.jpg
Normal file
|
After Width: | Height: | Size: 43 KiB |
363
assets/js/main.js
Normal file
@ -0,0 +1,363 @@
|
|||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
const playNowButton = document.querySelector('.btn-primary');
|
||||||
|
if (playNowButton) {
|
||||||
|
playNowButton.addEventListener('click', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
document.querySelector('#game-section').scrollIntoView({ behavior: 'smooth' });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const gameBoard = document.getElementById('game-board');
|
||||||
|
const resetButton = document.getElementById('reset-button');
|
||||||
|
const gameStatus = document.getElementById('game-status');
|
||||||
|
const boardSizeSelect = document.getElementById('board-size-select');
|
||||||
|
const aiDifficultySelect = document.getElementById('ai-difficulty-select');
|
||||||
|
|
||||||
|
const WIN_CONDITION = 4;
|
||||||
|
const PLAYER_SYMBOL = '🐾';
|
||||||
|
const AI_SYMBOL = '🧶';
|
||||||
|
|
||||||
|
let BOARD_SIZE = 5;
|
||||||
|
let boardState;
|
||||||
|
let currentPlayer;
|
||||||
|
let gameActive;
|
||||||
|
let cells;
|
||||||
|
|
||||||
|
function createBoard(size) {
|
||||||
|
BOARD_SIZE = size;
|
||||||
|
gameBoard.innerHTML = '';
|
||||||
|
gameBoard.className = 'game-board';
|
||||||
|
gameBoard.classList.add(`size-${size}`);
|
||||||
|
|
||||||
|
gameBoard.style.gridTemplateColumns = `repeat(${size}, 1fr)`;
|
||||||
|
gameBoard.style.gridTemplateRows = `repeat(${size}, 1fr)`;
|
||||||
|
|
||||||
|
cells = [];
|
||||||
|
for (let i = 0; i < size * size; i++) {
|
||||||
|
const cell = document.createElement('div');
|
||||||
|
cell.classList.add('game-cell');
|
||||||
|
const row = Math.floor(i / BOARD_SIZE);
|
||||||
|
const col = i % BOARD_SIZE;
|
||||||
|
cell.addEventListener('click', () => handleCellClick(row, col));
|
||||||
|
gameBoard.appendChild(cell);
|
||||||
|
cells.push(cell);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleCellClick(row, col) {
|
||||||
|
if (!gameActive || boardState[row][col] !== null || currentPlayer !== 'PLAYER') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
boardState[row][col] = 'PLAYER';
|
||||||
|
renderBoard();
|
||||||
|
|
||||||
|
if (checkWin('PLAYER')) {
|
||||||
|
endGame('Player');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isDraw()) {
|
||||||
|
endGame('Draw');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentPlayer = 'AI';
|
||||||
|
updateStatus("AI's turn...");
|
||||||
|
setTimeout(makeAIMove, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeAIMove() {
|
||||||
|
if (!gameActive) return;
|
||||||
|
|
||||||
|
const difficulty = aiDifficultySelect.value;
|
||||||
|
let move;
|
||||||
|
|
||||||
|
if (difficulty === 'easy') {
|
||||||
|
move = findRandomMove();
|
||||||
|
} else if (difficulty === 'medium') {
|
||||||
|
move = findBestMoveMedium();
|
||||||
|
} else { // Hard
|
||||||
|
move = findBestMoveHard();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (move) {
|
||||||
|
boardState[move.row][move.col] = 'AI';
|
||||||
|
renderBoard();
|
||||||
|
|
||||||
|
if (checkWin('AI')) {
|
||||||
|
endGame('AI');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isDraw()) {
|
||||||
|
endGame('Draw');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
currentPlayer = 'PLAYER';
|
||||||
|
updateStatus("Your turn!");
|
||||||
|
}
|
||||||
|
|
||||||
|
function findRandomMove() {
|
||||||
|
let availableCells = [];
|
||||||
|
for (let i = 0; i < BOARD_SIZE; i++) {
|
||||||
|
for (let j = 0; j < BOARD_SIZE; j++) {
|
||||||
|
if (boardState[i][j] === null) {
|
||||||
|
availableCells.push({ row: i, col: j });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (availableCells.length > 0) {
|
||||||
|
return availableCells[Math.floor(Math.random() * availableCells.length)];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function findBestMoveMedium() {
|
||||||
|
// 1. Check if AI can win
|
||||||
|
for (let i = 0; i < BOARD_SIZE; i++) {
|
||||||
|
for (let j = 0; j < BOARD_SIZE; j++) {
|
||||||
|
if (boardState[i][j] === null) {
|
||||||
|
boardState[i][j] = 'AI';
|
||||||
|
if (checkWin('AI')) {
|
||||||
|
boardState[i][j] = null; // Reset
|
||||||
|
return { row: i, col: j };
|
||||||
|
}
|
||||||
|
boardState[i][j] = null; // Reset
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Check if Player is about to win and block
|
||||||
|
for (let i = 0; i < BOARD_SIZE; i++) {
|
||||||
|
for (let j = 0; j < BOARD_SIZE; j++) {
|
||||||
|
if (boardState[i][j] === null) {
|
||||||
|
boardState[i][j] = 'PLAYER';
|
||||||
|
if (checkWin('PLAYER')) {
|
||||||
|
boardState[i][j] = null; // Reset
|
||||||
|
return { row: i, col: j };
|
||||||
|
}
|
||||||
|
boardState[i][j] = null; // Reset
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Otherwise, make a random move
|
||||||
|
return findRandomMove();
|
||||||
|
}
|
||||||
|
|
||||||
|
function findBestMoveHard() {
|
||||||
|
let bestScore = -Infinity;
|
||||||
|
let move = null;
|
||||||
|
|
||||||
|
for (let i = 0; i < BOARD_SIZE; i++) {
|
||||||
|
for (let j = 0; j < BOARD_SIZE; j++) {
|
||||||
|
if (boardState[i][j] === null) {
|
||||||
|
boardState[i][j] = 'AI';
|
||||||
|
let score = evaluateBoard();
|
||||||
|
boardState[i][j] = null;
|
||||||
|
if (score > bestScore) {
|
||||||
|
bestScore = score;
|
||||||
|
move = { row: i, col: j };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return move || findRandomMove(); // Fallback to random if no good move
|
||||||
|
}
|
||||||
|
|
||||||
|
function evaluateBoard() {
|
||||||
|
let score = 0;
|
||||||
|
// Prioritize winning moves
|
||||||
|
if (checkWin('AI')) return 10000;
|
||||||
|
// Prioritize blocking player's winning moves
|
||||||
|
if (checkWin('PLAYER')) return -9000;
|
||||||
|
|
||||||
|
// Evaluate lines for potential
|
||||||
|
score += evaluateLinesForPlayer('AI');
|
||||||
|
score -= evaluateLinesForPlayer('PLAYER');
|
||||||
|
|
||||||
|
return score;
|
||||||
|
}
|
||||||
|
|
||||||
|
function evaluateLinesForPlayer(player) {
|
||||||
|
let score = 0;
|
||||||
|
const symbol = player;
|
||||||
|
|
||||||
|
for (let i = 0; i < BOARD_SIZE; i++) {
|
||||||
|
for (let j = 0; j < BOARD_SIZE; j++) {
|
||||||
|
// Horizontal
|
||||||
|
if (j + WIN_CONDITION <= BOARD_SIZE) {
|
||||||
|
score += evaluateLine(i, j, 0, 1, symbol);
|
||||||
|
}
|
||||||
|
// Vertical
|
||||||
|
if (i + WIN_CONDITION <= BOARD_SIZE) {
|
||||||
|
score += evaluateLine(i, j, 1, 0, symbol);
|
||||||
|
}
|
||||||
|
// Diagonal (down-right)
|
||||||
|
if (i + WIN_CONDITION <= BOARD_SIZE && j + WIN_CONDITION <= BOARD_SIZE) {
|
||||||
|
score += evaluateLine(i, j, 1, 1, symbol);
|
||||||
|
}
|
||||||
|
// Diagonal (down-left)
|
||||||
|
if (i + WIN_CONDITION <= BOARD_SIZE && j - WIN_CONDITION + 1 >= 0) {
|
||||||
|
score += evaluateLine(i, j, 1, -1, symbol);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return score;
|
||||||
|
}
|
||||||
|
|
||||||
|
function evaluateLine(row, col, dr, dc, player) {
|
||||||
|
let playerCount = 0;
|
||||||
|
let emptyCount = 0;
|
||||||
|
for (let k = 0; k < WIN_CONDITION; k++) {
|
||||||
|
const current = boardState[row + k * dr][col + k * dc];
|
||||||
|
if (current === player) {
|
||||||
|
playerCount++;
|
||||||
|
} else if (current === null) {
|
||||||
|
emptyCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the line is blocked by the opponent, it has no potential.
|
||||||
|
if (playerCount + emptyCount < WIN_CONDITION) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assign scores based on the number of pieces in a line
|
||||||
|
if (playerCount === 3 && emptyCount === 1) return 100;
|
||||||
|
if (playerCount === 2 && emptyCount === 2) return 10;
|
||||||
|
if (playerCount === 1 && emptyCount === 3) return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function checkWin(player) {
|
||||||
|
const symbol = player;
|
||||||
|
|
||||||
|
for (let i = 0; i < BOARD_SIZE; i++) {
|
||||||
|
for (let j = 0; j < BOARD_SIZE; j++) {
|
||||||
|
// Horizontal
|
||||||
|
if (j + WIN_CONDITION <= BOARD_SIZE) {
|
||||||
|
let count = 0;
|
||||||
|
for (let k = 0; k < WIN_CONDITION; k++) {
|
||||||
|
if (boardState[i][j + k] === symbol) count++;
|
||||||
|
}
|
||||||
|
if (count === WIN_CONDITION) return true;
|
||||||
|
}
|
||||||
|
// Vertical
|
||||||
|
if (i + WIN_CONDITION <= BOARD_SIZE) {
|
||||||
|
let count = 0;
|
||||||
|
for (let k = 0; k < WIN_CONDITION; k++) {
|
||||||
|
if (boardState[i + k][j] === symbol) count++;
|
||||||
|
}
|
||||||
|
if (count === WIN_CONDITION) return true;
|
||||||
|
}
|
||||||
|
// Diagonal (down-right)
|
||||||
|
if (i + WIN_CONDITION <= BOARD_SIZE && j + WIN_CONDITION <= BOARD_SIZE) {
|
||||||
|
let count = 0;
|
||||||
|
for (let k = 0; k < WIN_CONDITION; k++) {
|
||||||
|
if (boardState[i + k][j + k] === symbol) count++;
|
||||||
|
}
|
||||||
|
if (count === WIN_CONDITION) return true;
|
||||||
|
}
|
||||||
|
// Diagonal (down-left)
|
||||||
|
if (i + WIN_CONDITION <= BOARD_SIZE && j - WIN_CONDITION + 1 >= 0) {
|
||||||
|
let count = 0;
|
||||||
|
for (let k = 0; k < WIN_CONDITION; k++) {
|
||||||
|
if (boardState[i + k][j - k] === symbol) count++;
|
||||||
|
}
|
||||||
|
if (count === WIN_CONDITION) return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isDraw() {
|
||||||
|
return boardState.every(row => row.every(cell => cell !== null));
|
||||||
|
}
|
||||||
|
|
||||||
|
function endGame(winner) {
|
||||||
|
gameActive = false;
|
||||||
|
if (winner === 'Draw') {
|
||||||
|
updateStatus("It's a draw!");
|
||||||
|
} else {
|
||||||
|
updateStatus(`${winner} wins!`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetGame() {
|
||||||
|
const size = parseInt(boardSizeSelect.value);
|
||||||
|
createBoard(size);
|
||||||
|
boardState = Array(BOARD_SIZE).fill(null).map(() => Array(BOARD_SIZE).fill(null));
|
||||||
|
currentPlayer = 'PLAYER';
|
||||||
|
gameActive = true;
|
||||||
|
renderBoard();
|
||||||
|
updateStatus("Your turn!");
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderBoard() {
|
||||||
|
cells.forEach((cell, index) => {
|
||||||
|
const row = Math.floor(index / BOARD_SIZE);
|
||||||
|
const col = index % BOARD_SIZE;
|
||||||
|
const state = boardState[row][col];
|
||||||
|
|
||||||
|
if (state === 'PLAYER') {
|
||||||
|
cell.innerHTML = `<div class="symbol">${PLAYER_SYMBOL}</div>`;
|
||||||
|
} else if (state === 'AI') {
|
||||||
|
cell.innerHTML = `<div class="symbol">${AI_SYMBOL}</div>`;
|
||||||
|
} else {
|
||||||
|
cell.innerHTML = '';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateStatus(message) {
|
||||||
|
gameStatus.textContent = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resetButton) {
|
||||||
|
resetButton.addEventListener('click', resetGame);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (boardSizeSelect) {
|
||||||
|
boardSizeSelect.addEventListener('change', resetGame);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(aiDifficultySelect) {
|
||||||
|
aiDifficultySelect.addEventListener('change', resetGame);
|
||||||
|
}
|
||||||
|
|
||||||
|
resetGame();
|
||||||
|
|
||||||
|
const catGallery = document.getElementById('cat-gallery');
|
||||||
|
if (catGallery) {
|
||||||
|
fetch('api/pexels.php')
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(images => {
|
||||||
|
images.forEach(image => {
|
||||||
|
const galleryItem = document.createElement('div');
|
||||||
|
galleryItem.className = 'cat-gallery-item';
|
||||||
|
|
||||||
|
const img = document.createElement('img');
|
||||||
|
img.src = image.src;
|
||||||
|
img.alt = 'A cute cat';
|
||||||
|
|
||||||
|
const credit = document.createElement('div');
|
||||||
|
credit.className = 'photographer-credit';
|
||||||
|
credit.innerHTML = `Photo by <a href="${image.photographer_url}" target="_blank">${image.photographer}</a>`;
|
||||||
|
|
||||||
|
galleryItem.appendChild(img);
|
||||||
|
galleryItem.appendChild(credit);
|
||||||
|
catGallery.appendChild(galleryItem);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Error fetching cat images:', error);
|
||||||
|
catGallery.innerHTML = '<p class="text-center">Could not load cat pictures. Meow-be later?</p>';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
26
includes/pexels.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
function pexels_key() {
|
||||||
|
$k = getenv('PEXELS_KEY');
|
||||||
|
return $k && strlen($k) > 0 ? $k : 'Vc99rnmOhHhJAbgGQoKLZtsaIVfkeownoQNbTj78VemUjKh08ZYRbf18';
|
||||||
|
}
|
||||||
|
function pexels_get($url) {
|
||||||
|
$ch = curl_init();
|
||||||
|
curl_setopt_array($ch, [
|
||||||
|
CURLOPT_URL => $url,
|
||||||
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
CURLOPT_HTTPHEADER => [ 'Authorization: '. pexels_key() ],
|
||||||
|
CURLOPT_TIMEOUT => 15,
|
||||||
|
]);
|
||||||
|
$resp = curl_exec($ch);
|
||||||
|
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
curl_close($ch);
|
||||||
|
if ($code >= 200 && $code < 300 && $resp) return json_decode($resp, true);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
function download_to($srcUrl, $destPath) {
|
||||||
|
$data = @file_get_contents($srcUrl);
|
||||||
|
if ($data === false) return false;
|
||||||
|
if (!is_dir(dirname($destPath))) mkdir(dirname($destPath), 0775, true);
|
||||||
|
return file_put_contents($destPath, $data) !== false;
|
||||||
|
}
|
||||||
|
?>
|
||||||
224
index.php
@ -1,150 +1,84 @@
|
|||||||
<?php
|
<!DOCTYPE html>
|
||||||
declare(strict_types=1);
|
|
||||||
@ini_set('display_errors', '1');
|
|
||||||
@error_reporting(E_ALL);
|
|
||||||
@date_default_timezone_set('UTC');
|
|
||||||
|
|
||||||
$phpVersion = PHP_VERSION;
|
|
||||||
$now = date('Y-m-d H:i:s');
|
|
||||||
?>
|
|
||||||
<!doctype html>
|
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>New Style</title>
|
<title>Cute-Cat-Toe</title>
|
||||||
<?php
|
<meta name="description" content="A cute and playful Tic Tac Toe game with a cat motif.">
|
||||||
// Read project preview data from environment
|
<meta name="keywords" content="tic tac toe, cat game, browser game, online game, cute game, flatlogic">
|
||||||
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
|
|
||||||
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
<!-- Open Graph / Facebook -->
|
||||||
?>
|
<meta property="og:type" content="website">
|
||||||
<?php if ($projectDescription): ?>
|
<meta property="og:title" content="Cute-Cat-Toe">
|
||||||
<!-- Meta description -->
|
<meta property="og:description" content="A cute and playful Tic Tac Toe game with a cat motif.">
|
||||||
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
|
<meta property="og:image" content="<?php echo htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? '', ENT_QUOTES, 'UTF-8'); ?>">
|
||||||
<!-- Open Graph meta tags -->
|
|
||||||
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
<!-- Twitter -->
|
||||||
<!-- Twitter meta tags -->
|
<meta property="twitter:card" content="summary_large_image">
|
||||||
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
<meta property="twitter:title" content="Cute-Cat-Toe">
|
||||||
<?php endif; ?>
|
<meta property="twitter:description" content="A cute and playful Tic Tac Toe game with a cat motif.">
|
||||||
<?php if ($projectImageUrl): ?>
|
<meta property="twitter:image" content="<?php echo htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? '', ENT_QUOTES, 'UTF-8'); ?>">
|
||||||
<!-- Open Graph image -->
|
|
||||||
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
<!-- Twitter image -->
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||||
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
|
||||||
<?php endif; ?>
|
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
|
|
||||||
<style>
|
|
||||||
:root {
|
|
||||||
--bg-color-start: #6a11cb;
|
|
||||||
--bg-color-end: #2575fc;
|
|
||||||
--text-color: #ffffff;
|
|
||||||
--card-bg-color: rgba(255, 255, 255, 0.01);
|
|
||||||
--card-border-color: rgba(255, 255, 255, 0.1);
|
|
||||||
}
|
|
||||||
body {
|
|
||||||
margin: 0;
|
|
||||||
font-family: 'Inter', sans-serif;
|
|
||||||
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
|
|
||||||
color: var(--text-color);
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
min-height: 100vh;
|
|
||||||
text-align: center;
|
|
||||||
overflow: hidden;
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
body::before {
|
|
||||||
content: '';
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
|
|
||||||
animation: bg-pan 20s linear infinite;
|
|
||||||
z-index: -1;
|
|
||||||
}
|
|
||||||
@keyframes bg-pan {
|
|
||||||
0% { background-position: 0% 0%; }
|
|
||||||
100% { background-position: 100% 100%; }
|
|
||||||
}
|
|
||||||
main {
|
|
||||||
padding: 2rem;
|
|
||||||
}
|
|
||||||
.card {
|
|
||||||
background: var(--card-bg-color);
|
|
||||||
border: 1px solid var(--card-border-color);
|
|
||||||
border-radius: 16px;
|
|
||||||
padding: 2rem;
|
|
||||||
backdrop-filter: blur(20px);
|
|
||||||
-webkit-backdrop-filter: blur(20px);
|
|
||||||
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
|
|
||||||
}
|
|
||||||
.loader {
|
|
||||||
margin: 1.25rem auto 1.25rem;
|
|
||||||
width: 48px;
|
|
||||||
height: 48px;
|
|
||||||
border: 3px solid rgba(255, 255, 255, 0.25);
|
|
||||||
border-top-color: #fff;
|
|
||||||
border-radius: 50%;
|
|
||||||
animation: spin 1s linear infinite;
|
|
||||||
}
|
|
||||||
@keyframes spin {
|
|
||||||
from { transform: rotate(0deg); }
|
|
||||||
to { transform: rotate(360deg); }
|
|
||||||
}
|
|
||||||
.hint {
|
|
||||||
opacity: 0.9;
|
|
||||||
}
|
|
||||||
.sr-only {
|
|
||||||
position: absolute;
|
|
||||||
width: 1px; height: 1px;
|
|
||||||
padding: 0; margin: -1px;
|
|
||||||
overflow: hidden;
|
|
||||||
clip: rect(0, 0, 0, 0);
|
|
||||||
white-space: nowrap; border: 0;
|
|
||||||
}
|
|
||||||
h1 {
|
|
||||||
font-size: 3rem;
|
|
||||||
font-weight: 700;
|
|
||||||
margin: 0 0 1rem;
|
|
||||||
letter-spacing: -1px;
|
|
||||||
}
|
|
||||||
p {
|
|
||||||
margin: 0.5rem 0;
|
|
||||||
font-size: 1.1rem;
|
|
||||||
}
|
|
||||||
code {
|
|
||||||
background: rgba(0,0,0,0.2);
|
|
||||||
padding: 2px 6px;
|
|
||||||
border-radius: 4px;
|
|
||||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
||||||
}
|
|
||||||
footer {
|
|
||||||
position: absolute;
|
|
||||||
bottom: 1rem;
|
|
||||||
font-size: 0.8rem;
|
|
||||||
opacity: 0.7;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main>
|
|
||||||
<div class="card">
|
<header class="navbar navbar-expand-lg navbar-light">
|
||||||
<h1>Analyzing your requirements and generating your website…</h1>
|
<div class="container">
|
||||||
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
|
<a class="navbar-brand" href="#">🐾 Cute-Cat-Toe</a>
|
||||||
<span class="sr-only">Loading…</span>
|
</div>
|
||||||
</div>
|
</header>
|
||||||
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
|
|
||||||
<p class="hint">This page will update automatically as the plan is implemented.</p>
|
<main>
|
||||||
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
|
<section class="hero">
|
||||||
</div>
|
<div class="container">
|
||||||
</main>
|
<h1 class="display-3">Welcome to Cute-Cat-Toe!</h1>
|
||||||
<footer>
|
<p class="lead">The cutest Tic Tac Toe game on the web. Play with paws and yarn!</p>
|
||||||
Page updated: <?= htmlspecialchars($now) ?> (UTC)
|
<a href="#game-section" class="btn btn-primary btn-lg mt-3">Play a Game</a>
|
||||||
</footer>
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="game-section" class="container text-center">
|
||||||
|
<h2 class="mb-4">Let's Play!</h2>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="board-size-select">Board Size:</label>
|
||||||
|
<select id="board-size-select" class="form-select-sm">
|
||||||
|
<option value="5">5x5</option>
|
||||||
|
<option value="18">18x18</option>
|
||||||
|
<option value="36">36x36</option>
|
||||||
|
</select>
|
||||||
|
<label for="ai-difficulty-select" class="ms-3">AI Difficulty:</label>
|
||||||
|
<select id="ai-difficulty-select" class="form-select-sm">
|
||||||
|
<option value="easy">Easy</option>
|
||||||
|
<option value="medium" selected>Medium</option>
|
||||||
|
<option value="hard">Hard</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div id="game-status" class="mb-3"></div>
|
||||||
|
<div class="game-board" id="game-board">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<button id="reset-button" class="btn btn-secondary mt-4">Reset Game</button>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="gallery-section" class="py-5">
|
||||||
|
<div class="container">
|
||||||
|
<h2 class="text-center mb-4">Cute Cat Gallery</h2>
|
||||||
|
<div class="cat-gallery" id="cat-gallery">
|
||||||
|
<!-- Cat images will be loaded here by JavaScript -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer class="text-center">
|
||||||
|
<div class="container">
|
||||||
|
<p>© <?php echo date("Y"); ?> Cute-Cat-Toe. All rights reserved.</p>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||