見出し画像

無料GPT-4を使ってゲームをプログラミングをしてみた結果・・・。

質問

You are an engineer.
Create a simple game using html and javascript.

訳:あなたはエンジニアです。htmlとジャバスクリプトを使って適当なゲームを作れ。

結果

Sure, I can help you create a simple game using HTML and JavaScript. How about we create a classic game of "Rock, Paper, Scissors"?

Here is the HTML code for the game:

phpCopy code<!DOCTYPE html>
<html>
<head>
	<title>Rock Paper Scissors Game</title>
	<style type="text/css">
		button {
			margin: 10px;
			padding: 10px 20px;
			font-size: 20px;
		}
	</style>
</head>
<body>
	<h1>Rock Paper Scissors</h1>
	<button id="rock">Rock</button>
	<button id="paper">Paper</button>
	<button id="scissors">Scissors</button>
	<p id="result"></p>

	<script type="text/javascript" src="game.js"></script>
</body>
</html>

And here is the JavaScript code:

javascriptCopy codeconst buttons = document.querySelectorAll('button');
let playerChoice = "";
let computerChoice = "";

buttons.forEach((button) => {
	button.addEventListener('click', () => {
		playerChoice = button.id;
		computerChoice = computerSelection();
		const result = playRound(playerChoice, computerChoice);
		document.getElementById("result").innerHTML = result;
	})
})

function computerSelection() {
	const choices = ["rock", "paper", "scissors"];
	const randomIndex = Math.floor(Math.random() * choices.length);
	return choices[randomIndex];
}

function playRound(playerSelection, computerSelection) {
	if (playerSelection === computerSelection) {
		return "It's a tie!";
	}
	if (playerSelection === "rock") {
		if (computerSelection === "paper") {
			return "You lose! Paper beats rock.";
		} else {
			return "You win! Rock beats scissors.";
		}
	}
	if (playerSelection === "paper") {
		if (computerSelection === "scissors") {
			return "You lose! Scissors beats paper.";
		} else {
			return "You win! Paper beats rock.";
		}
	}
	if (playerSelection === "scissors") {
		if (computerSelection === "rock") {
			return "You lose! Rock beats scissors.";
		} else {
			return "You win! Scissors beats paper.";
		}
	}
}

This code creates a simple game where the user can select one of three buttons: "Rock", "Paper", or "Scissors". The computer also makes a random choice, and the code determines the winner based on the classic game rules.

To play the game, simply open the HTML file in your web browser and click one of the three buttons to make your choice. The result of the game will be displayed below the buttons. Have fun!

Regenerat

上記がでてきた。

今回は適当なゲームですが、gptのプラスならもっと精度が高いハズです。


この記事が気に入ったらサポートをしてみませんか?