「Amazon Q CLI でゲームを作ろう Tシャツキャンペーン」が 2025年5月20日から6月20日まで開催されていました。
今までAmazon Qをまったく触っていなかったのですが、
「ゲームがチャットで作れる」ということで非常に興味がでました。
やってみた結果や、Amazon Q のすごさを紹介します。
作るゲームを考える
チャットでゲームが作れるということで、色々考えたのですが
Tシャツがもらえるキャンペーンということで、Tシャツを奪い合うゲームにしてみます。
Tシャツを奪い合うゲームをつくって
この1文だけで、240行のコードが作成されました。
「詳細」をクリックするとコードが表示されます。
「Tシャツを奪い合う」というキーワードから「引っ張り合う」ゲームになりました。
python
import tkinter as tk
import random
from PIL import Image, ImageTk
import os
class TshirtGameApp:
def init(self, root):
self.root = root
self.root.title("Tシャツ奪い合いゲーム")
self.root.geometry("800x600")
self.root.configure(bg="#E6F2FF")
self.player1_score = 0
self.player2_score = 0
self.round_number = 0
self.max_rounds = 10
self.setup_ui()
self.start_new_round()
def setup_ui(self):
# タイトル
title_label = tk.Label(self.root, text="Tシャツ奪い合いゲーム",
font=("IPAGothic", 24, "bold"),
bg="#E6F2FF", fg="#3366CC")
title_label.pack(pady=10)
# ゲーム説明
instruction_label = tk.Label(self.root,
text="ボタンを連打して、Tシャツを奪い合おう!\n先に5ラウンド勝った方が勝利!",
font=("IPAGothic", 14),
bg="#E6F2FF")
instruction_label.pack(pady=5)
# Tシャツ表示エリア
self.tshirt_frame = tk.Frame(self.root, bg="#E6F2FF")
self.tshirt_frame.pack(pady=20)
# Tシャツの初期位置(中央)
self.tshirt_position = 0 # -5から+5の範囲で表現(-5:完全に左側、0:中央、+5:完全に右側)
# Tシャツ画像(簡易的な表現)
self.tshirt_canvas = tk.Canvas(self.tshirt_frame, width=600, height=200, bg="#E6F2FF", highlightthickness=0)
self.tshirt_canvas.pack()
# プレイヤーエリア
players_frame = tk.Frame(self.root, bg="#E6F2FF")
players_frame.pack(fill="x", expand=True, pady=10)
# プレイヤー1(左側)
player1_frame = tk.Frame(players_frame, bg="#E6F2FF")
player1_frame.pack(side="left", expand=True)
player1_label = tk.Label(player1_frame, text="プレイヤー1", font=("IPAGothic", 16), bg="#E6F2FF", fg="#CC3366")
player1_label.pack(pady=5)
self.player1_score_label = tk.Label(player1_frame, text="スコア: 0", font=("IPAGothic", 14), bg="#E6F2FF")
self.player1_score_label.pack(pady=5)
self.player1_button = tk.Button(player1_frame,
text="引っ張る!",
font=("IPAGothic", 16),
bg="#FF6699",
fg="white",
command=self.player1_pull,
width=10, height=2)
self.player1_button.pack(pady=10)
# プレイヤー2(右側)
player2_frame = tk.Frame(players_frame, bg="#E6F2FF")
player2_frame.pack(side="right", expand=True)
player2_label = tk.Label(player2_frame, text="プレイヤー2", font=("IPAGothic", 16), bg="#E6F2FF", fg="#3366CC")
player2_label.pack(pady=5)
self.player2_score_label = tk.Label(player2_frame, text="スコア: 0", font=("IPAGothic", 14), bg="#E6F2FF")
self.player2_score_label.pack(pady=5)
self.player2_button = tk.Button(player2_frame,
text="引っ張る!",
font=("IPAGothic", 16),
bg="#6699FF",
fg="white",
command=self.player2_pull,
width=10, height=2)
self.player2_button.pack(pady=10)
# ラウンド情報
self.round_label = tk.Label(self.root,
text="ラウンド: 0/10",
font=("IPAGothic", 16),
bg="#E6F2FF")
self.round_label.pack(pady=10)
# 結果表示
self.result_label = tk.Label(self.root,
text="",
font=("IPAGothic", 18, "bold"),
bg="#E6F2FF")
self.result_label.pack(pady=10)
# 新しいゲーム開始ボタン
self.new_game_button = tk.Button(self.root,
text="新しいゲームを始める",
font=("IPAGothic", 14),
bg="#66CC99",
fg="white",
command=self.reset_game)
self.new_game_button.pack(pady=10)
self.new_game_button.pack_forget() # 最初は非表示
def draw_tshirt(self):
self.tshirt_canvas.delete("all")
# Tシャツの位置を計算(-5から+5の範囲を0から600の範囲に変換)
position_x = 300 + (self.tshirt_position * 30)
# Tシャツを描画(簡易的な表現)
# 本体
self.tshirt_canvas.create_rectangle(position_x-50, 50, position_x+50, 150, fill="#FFFFFF", outline="#000000", width=2)
# 袖
self.tshirt_canvas.create_polygon(position_x-50, 50, position_x-80, 70, position_x-80, 90, position_x-50, 70, fill="#FFFFFF", outline="#000000", width=2)
self.tshirt_canvas.create_polygon(position_x+50, 50, position_x+80, 70, position_x+80, 90, position_x+50, 70, fill="#FFFFFF", outline="#000000", width=2)
# 首元
self.tshirt_canvas.create_oval(position_x-15, 30, position_x+15, 60, fill="#E6F2FF", outline="#000000", width=2)
# プレイヤー表示
if self.tshirt_position <= -4:
self.tshirt_canvas.create_text(position_x, 100, text="P1", font=("IPAGothic", 20, "bold"), fill="#CC3366")
elif self.tshirt_position >= 4:
self.tshirt_canvas.create_text(position_x, 100, text="P2", font=("IPAGothic", 20, "bold"), fill="#3366CC")
def player1_pull(self):
if self.round_number <= self.max_rounds and not self.is_round_over():
# プレイヤー1が引っ張る(左側に移動)
pull_strength = random.uniform(0.2, 0.8)
self.tshirt_position -= pull_strength
# 範囲を制限
if self.tshirt_position < -5:
self.tshirt_position = -5
self.draw_tshirt()
self.check_round_status()
def player2_pull(self):
if self.round_number <= self.max_rounds and not self.is_round_over():
# プレイヤー2が引っ張る(右側に移動)
pull_strength = random.uniform(0.2, 0.8)
self.tshirt_position += pull_strength
# 範囲を制限
if self.tshirt_position > 5:
self.tshirt_position = 5
self.draw_tshirt()
self.check_round_status()
def is_round_over(self):
return self.tshirt_position <= -5 or self.tshirt_position >= 5
def check_round_status(self):
if self.is_round_over():
# ラウンド終了
if self.tshirt_position <= -5:
# プレイヤー1の勝ち
self.player1_score += 1
self.result_label.config(text="プレイヤー1がTシャツを獲得!", fg="#CC3366")
else:
# プレイヤー2の勝ち
self.player2_score += 1
self.result_label.config(text="プレイヤー2がTシャツを獲得!", fg="#3366CC")
# スコア更新
self.player1_score_label.config(text=f"スコア: {self.player1_score}")
self.player2_score_label.config(text=f"スコア: {self.player2_score}")
# 次のラウンドを開始(少し遅延を入れる)
self.root.after(1500, self.start_new_round)
def start_new_round(self):
self.round_number += 1
if self.round_number <= self.max_rounds:
# 新しいラウンド開始
self.round_label.config(text=f"ラウンド: {self.round_number}/{self.max_rounds}")
self.tshirt_position = 0 # Tシャツを中央に戻す
self.draw_tshirt()
self.result_label.config(text="引っ張れ!")
# ボタンを有効化
self.player1_button.config(state="normal")
self.player2_button.config(state="normal")
else:
# ゲーム終了
self.end_game()
def end_game(self):
# 最終結果表示
if self.player1_score > self.player2_score:
self.result_label.config(text=f"プレイヤー1の勝利! {self.player1_score}-{self.player2_score}", fg="#CC3366")
elif self.player2_score > self.player1_score:
self.result_label.config(text=f"プレイヤー2の勝利! {self.player2_score}-{self.player1_score}", fg="#3366CC")
else:
self.result_label.config(text=f"引き分け! {self.player1_score}-{self.player1_score}", fg="#663399")
# ボタンを無効化
self.player1_button.config(state="disabled")
self.player2_button.config(state="disabled")
# 新しいゲーム開始ボタンを表示
self.new_game_button.pack(pady=10)
def reset_game(self):
# ゲームをリセット
self.player1_score = 0
self.player2_score = 0
self.round_number = 0
# スコア表示をリセット
self.player1_score_label.config(text="スコア: 0")
self.player2_score_label.config(text="スコア: 0")
# 新しいゲーム開始ボタンを非表示
self.new_game_button.pack_forget()
# 新しいラウンドを開始
self.start_new_round()
def main():
root = tk.Tk()
app = TshirtGameApp(root)
root.mainloop()
if name == "main":
main()
TシャツのデザインをAmazon Q CLI でゲームを作ろう キャンペーンでもらえるTシャツにして
Tシャツが白シャツなので、Amazonデザイン変更します。
すると、、すごい。Tシャツだけでなく画面全体がAmazonデザインになりました。
奪い合うところをボタンを押すのはやめたい。パソコンなので2人が同時に操作できない。ほかに奪い合う案あるかな
ゲーム内容の改善案をきいてみるといくつか提案してくれました。
自分にないアイデアも出してくれるのがいいですね。
しかも実装も簡単(答えるだけです)。リズムゲームにしてみました。
ゲームを変えて、たくさんのTシャツが飛び回るゲームにしたい。相手はコンピュータにしよう。
シャツの数を増やす。色の違うTシャツが飛び回る。Tシャツごとにスコアが異なるようにする。
自動的にTシャツの上に点数が表示され、なおかつ、
TシャツをGETすると、アニメーションで+〇点が表示されました。
いい!すごくいい
画面を3Dでグラフィカルにして
疑似的ですが奥行でた。
それに伴い、操作も3Dになって「奥へ」「手前へ」が増えてます。
もうアイデア次第でどんどん機能アップデートできるし
デバッグもある程度チャットで直してほしいところ指示するだけだし、
ほんと今後楽しみなAmazonQです。