--乱数の設定
math.randomseed(os.time())
--プレイヤーの変数の定義
local player = {
name = "tomatokun",
hp = 100,
attack = 0,
money = 200
}
local shopitem = {
{name = "木の剣", price = 50, attack = 15},
{name = "回復ポーション", price = 25, heal = 25},
{name = "確率のタネ", price = 0, attack = 999, heal = 899}
}
--入力したものを読み取る
local input = io.read()
local choice = tonumber(input)
--ショップのアイテム一覧表示
print("--トマトのカスみたいな店--")
print("プレイヤー情報")
print("名前: " .. player.name .. " HP: " .. player.hp)
print("攻撃力: " .. player.hp .. " お金: " .. player.money)
print("トマト:何買ってく?")
print("1 " .. shopitem[1].name .. " 攻撃力:" .. shopitem[1].attack)
print("2 " .. shopitem[2].name .. " 回復量:" .. shopitem[2].heal)
print("3 " .. shopitem[3].name)
print("-------------------------")
--購入時の処理
if choice == 1 then
print(shopitem[1].name .. "を購入した!少し強くなった気がする")
print("トマト:買ってくれてありがと!")
player.money = player.money - shopitem[1].price
player.attack = player.attack + shopitem[1].attack
print("プレイヤー情報")
print("名前: " .. player.name .. " HP: " .. player.hp)
print("攻撃力: " .. player.name .. " お金: " .. player.money)
elseif choice == 2 then
player.money = player.money - shopitem[2].price
print("名前: " .. player.name .. " HP: " .. player.hp)
print("攻撃力: " .. player.attack .. " お金: " .. player.money)
print(shopitem[2].name .. "を購入した!ちがらがみなぎった気がする")
print("トマト:買ってくれてありがと!体を大事にね!")
print("プレイヤー情報")
print("名前: " .. player.name .. " HP: " .. player.hp)
print("攻撃力: " .. player.attack .. " お金: " .. player.money)
elseif choice == 3 then
print("トマト:運試し〜!今回の確率は1000万分の1だよ!")
local fate = math.random(1, 1)
if fate == 1 then
player.attack = player.attack + shopitem[3].attack
player.hp = player.hp + shopitem[3].heal
print("攻撃力: " .. player.attack .. " お金: " .. player.money)
print("!!!!!!!!!!!!!!!!!なんかすごいことをした気がする")
print("トマト:おめでとう!大当たりだよ!すごいね!1000万分の1を引き当てるなんて!")
print("名前: " .. player.name .. " HP: " .. player.hp)
print("攻撃力: " .. player.attack .. " お金: " .. player.money)
else
print("トマト:残念!流石に1000万分の1はなかなか当たらないよね。")
end
end
To embed this project on your website, copy the following code and paste it into your website's HTML: