众所周知,OpenAI推出了GPT-4O模型,速度极快,已经接近AGI了,大家如果不知道可以看新闻:`https://new.qq.com/rain/a/20240514A03HH600`,可是OpenAI官网被封禁了,而且OpenAI账号容易被封,这可怎么办?我们可不能落后。
现在AI有多厉害,我不必多说,大家看张图片: 我只是一点指令,一个200多行的十分复杂的俄罗斯方块代码瞬间生成,我把文件代码放上来,大家玩玩试试,打开记事本,保存为html文件:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>俄罗斯方块</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #333;
color: white;
font-family: Arial, sans-serif;
}
.game-container {
display: flex;
}
.game-area {
width: 200px;
height: 400px;
background-color: black;
border: 2px solid #fff;
display: grid;
grid-template-columns: repeat(10, 20px);
grid-template-rows: repeat(20, 20px);
}
.game-area div {
width: 20px;
height: 20px;
border: 1px solid #444;
}
.info-area {
margin-left: 20px;
}
#nextTetromino {
width: 80px;
height: 80px;
background-color: black;
border: 2px solid #fff;
display: grid;
grid-template-columns: repeat(4, 20px);
grid-template-rows: repeat(4, 20px);
}
#nextTetromino div {
width: 20px;
height: 20px;
border: 1px solid #444;
}
.tetromino {
background-color: #FF5733;
}
.taken {
background-color: #aaa;
}
</style>
</head>
<body>
<div class="game-container">
<div class="game-area" id="gameArea">
<!-- This will be filled dynamically with JavaScript -->
<script>
for (let i = 0; i < 200; i++) {
const div = document.createElement('div');
document.getElementById('gameArea').appendChild(div);
}
for (let i = 0; i < 10; i++) {
const div = document.createElement('div');
div.classList.add('taken');
document.getElementById('gameArea').appendChild(div);
}
</script>
</div>
<div class="info-area">
<div>
<h3>下一方块</h3>
<div id="nextTetromino"></div>
</div>
<div>
<h3>得分</h3>
<p id="score">0</p>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
const grid = document.querySelector('.game-area');
const nextTetrominoDisplay = document.querySelector('#nextTetromino');
const scoreDisplay = document.querySelector('#score');
const width = 10;
let timerId;
let score = 0;
let nextRandom = 0;
const tetrominoes = [
// L-Tetromino
[
[1, width + 1, width * 2 + 1, 2],
[width, width + 1, width + 2, width * 2 + 2],
[1, width + 1, width * 2 + 1, width * 2],
[width, width * 2, width * 2 + 1, width * 2 + 2]
],
// Z-Tetromino
[
[0, width, width + 1, width * 2 + 1],
[width + 1, width + 2, width * 2, width * 2 + 1],
[0, width, width + 1, width * 2 + 1],
[width + 1, width + 2, width * 2, width * 2 + 1]
],
// T-Tetromino
[
[1, width, width + 1, width + 2],
[1, width + 1, width + 2, width * 2 + 1],
[width, width + 1, width + 2, width * 2 + 1],
[1, width, width + 1, width * 2 + 1]
],
// O-Tetromino
[
[0, 1, width, width + 1],
[0, 1, width, width + 1],
[0, 1, width, width + 1],
[0, 1, width, width + 1]
],
// I-Tetromino
[
[1, width + 1, width * 2 + 1, width * 3 + 1],
[width, width + 1, width + 2, width + 3],
[1, width + 1, width * 2 + 1, width * 3 + 1],
[width, width + 1, width + 2, width + 3]
]
];
let currentPosition = 4;
let currentRotation = 0;
let random = Math.floor(Math.random() * tetrominoes.length);
let current = tetrominoes[random][currentRotation];
function draw() {
current.forEach(index => {
grid.children[currentPosition + index].classList.add('tetromino');
});
}
function undraw() {
current.forEach(index => {
grid.children[currentPosition + index].classList.remove('tetromino');
});
}
timerId = setInterval(moveDown, 1000);
function control(e) {
if (e.keyCode === 37) {
moveLeft();
} else if (e.keyCode === 38) {
rotate();
} else if (e.keyCode === 39) {
moveRight();
} else if (e.keyCode === 40) {
moveDown();
}
}
document.addEventListener('keydown', control);
function moveDown() {
undraw();
currentPosition += width;
draw();
freeze();
}
function freeze() {
if (current.some(index => grid.children[currentPosition + index + width].classList.contains('taken'))) {
current.forEach(index => grid.children[currentPosition + index].classList.add('taken'));
random = nextRandom;
nextRandom = Math.floor(Math.random() * tetrominoes.length);
current = tetrominoes[random][currentRotation];
currentPosition = 4;
draw();
displayShape();
addScore();
gameOver();
}
}
function moveLeft() {
undraw();
const isAtLeftEdge = current.some(index => (currentPosition + index) % width === 0);
if (!isAtLeftEdge) currentPosition -= 1;
if (current.some(index => grid.children[currentPosition + index].classList.contains('taken'))) {
currentPosition += 1;
}
draw();
}
function moveRight() {
undraw();
const isAtRightEdge = current.some(index => (currentPosition + index) % width === width - 1);
if (!isAtRightEdge) currentPosition += 1;
if (current.some(index => grid.children[currentPosition + index].classList.contains('taken'))) {
currentPosition -= 1;
}
draw();
}
function rotate() {
undraw();
currentRotation++;
if (currentRotation === current.length) {
currentRotation = 0;
}
current = tetrominoes[random][currentRotation];
draw();
}
function displayShape() {
nextTetrominoDisplay.innerHTML = '';
tetrominoes[nextRandom][0].forEach(index => {
const div = document.createElement('div');
div.classList.add('tetromino');
nextTetrominoDisplay.appendChild(div);
});
}
function addScore() {
for (let i = 0; i < 199; i += width) {
const row = [i, i + 1, i + 2, i + 3, i + 4, i + 5, i + 6, i + 7, i + 8, i + 9];
if (row.every(index => grid.children[index].classList.contains('taken'))) {
score += 10;
scoreDisplay.innerHTML = score;
row.forEach(index => {
grid.children[index].classList.remove('taken');
grid.children[index].classList.remove('tetromino');
});
const squaresRemoved = Array.from(grid.children).splice(i, width);
grid.append(...squaresRemoved);
}
}
}
function gameOver() {
if (current.some(index => grid.children[currentPosition + index].classList.contains('taken'))) {
scoreDisplay.innerHTML = 'end';
clearInterval(timerId);
}
}
});
</script>
</body>
</html>
再不用上AI,绝对会落后,我给大家找了个好网站,应价比超高,199块钱gpt4o随便用,新模型随时跟进,大家用起来吧!:`https://smartwritegpt.com/?user_sn=66542617`