Skip to content

Instantly share code, notes, and snippets.

@webcrafts
Last active December 21, 2015 09:59
Show Gist options
  • Save webcrafts/6288989 to your computer and use it in GitHub Desktop.
Save webcrafts/6288989 to your computer and use it in GitHub Desktop.
ナマケモノ育成ゲーム 2013/08/20 ryukyu.rb 亀島さんのお題 クラスの使い方をまだ勉強会でやっていなかったので、クラスの紹介をしようかと思ったり、ペットを増やせるようにといじりだしたらわかりにくくなってしまったので、また機会があれば修正したい
# encoding: utf-8
HARA = 8
HAPPY = 8
COUNT = 7 * 4
DAY_STAT = ['朝','昼','晩','夜中']
CMD = ['食事','掃除','散歩','睡眠']
day = 0
petnum = 1
game = 0
pet = []
BAR = "----------------------------------------"
class Namakemono
def initialize(hara,happy,pet_name)
@hara = hara
@happy = happy
@name = pet_name
@flg_0 = 0
@flg_1 = 0
@flg_2 = 0
@flg_3 = 0
end
def get_food
@hara = @hara + 2
# @happy = @happy - 1
@flg_1 = 1
end
def get_souji
@hara = @hara - 1
@happy = @happy - 1
@flg_2 = 1
end
def get_sanpo
@hara = @hara - 1
@happy = @happy + 1
@flg_3 = 1
end
def get_sleep
@hara = @hara - 2
@happy = @happy + 2
@flg_4 = 1
end
def chgstatus
# 一日の終りに一回だけ実行される
if @flg_0 == 0 then
# 食事していない場合
@hara = @hara - 3
end
if @flg_1 == 0 then
# 掃除していない場合
@happy = @happy - 2
end
if @flg_2 == 0 then
# 散歩していない場合
@happy = @happy - 2
end
if @flg_3 == 0 then
# 寝かしていない場合
@happy = @happy - 3
end
@flg_1 = 0
@flg_2 = 0
@flg_3 = 0
@flg_4 = 0
end
def showstatus
print "#{BAR}\n【#{@name}】 -> 満腹度 #{@hara} / ご機嫌度 #{@happy} \n#{BAR}\n"
end
attr_accessor :hara,:happy,:name
end
# ----------
puts "ペットは何匹にしますか?"
petnum = gets.chomp.to_i
count = COUNT
i = 1
while i <= petnum
puts "ペットの名前を決めてください"
pet_name = gets.chomp.to_s
pet[i] = Namakemono.new(HARA,HAPPY,pet_name)
i = i + 1
end
while count > 1 do
i = 1
while i <= petnum
print "\n#{((COUNT - count)/4)+1}日目 (#{DAY_STAT[day]})\n"
pet[i].showstatus
if pet[i].hara <= 0 then
print "\n#{BAR}\n#{pet[i].name} は死んでしまいました.....\n#{BAR}\n"
game = 1
exit
end
if pet[i].happy <= 0 then
print "\n#{BAR}\n#{pet[i].name} は逃げ出しました.....\n#{BAR}\n"
game = 1
exit
end
if game != 1 then
puts "コマンドを入力してください"
CMD.each_with_index do |i,index| puts "[#{index+1}] #{i}" end
cmd = gets.chomp.to_i
case cmd
when 1
pet[i].get_food
when 2
pet[i].get_souji
when 3
pet[i].get_sanpo
when 4
pet[i].get_sleep
end
i = i + 1
end
end
count = count - 1
puts count
day = day + 1
if day > 3 then
i = 1
while i <= petnum
pet[i].chgstatus
i = i + 1
end
day = 0
end
end
if game == 0 then
puts "おめでとうございます。無事に立派なナマケモノを育成しました"
end
=begin
ナマケモノ育成ゲーム
1. ナマケモノを7日間預かる
2.4コマンドで1日が経過する(7日でクリア)
3.ナマケモノのパラメータは満腹度と機嫌度
4.3のパラメータが0になったらゲームオーバー
5.コマンドは食事・掃除・散歩・睡眠とする
6.食事で満腹度+2、機嫌度+-0
7.掃除で満腹度-1、機嫌度-1
8.散歩で満腹度-1、機嫌度+1
9.睡眠で満腹度-2、機嫌度+2
10.1日食事を与えないと満腹度-3
11.1日寝かさないと機嫌度-3
12.1日掃除や散歩をしないと更に機嫌度-1
13.10、11、12は累積する
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment