質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Q&A

解決済

1回答

1444閲覧

実行されない

yusuke.

総合スコア66

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

0グッド

0クリップ

投稿2016/06/27 09:04

なぜかmainを実行するとzairyoが実行されます。
mainのzairyoの読み込みのところをコメントに変えても戻りませんでした。なぜこうなったのでしょうか。解決方法を教えてください。

zairyo.rb

ruby

1#!ruby -Ks 2require "./window2" 3require "./syujinko" 4require "./item" 5 6def hit?(hero,bomb) 7 diffx = hero.centerX - bomb.centerX 8 diffy = hero.centerY - bomb.centerY 9 if (diffx > -30) and (diffx < 50) and (diffy > -20) and (diffy < 50) 10 return true 11 else 12 return false 13 end 14end 15def clicked?(x,y,bomb) 16 diffx = x - bomb.centerX 17 diffy = y - bomb.centerY 18 if (diffx > -20) and (diffx < 20) and (diffy > -20) and (diffy < 20) 19 return true 20 else 21 return false 22 end 23end 24 25def gameOver(window,hero) 26 window.drawEndBack 27 hero.draw 28 window.refresh 29 sleep 3 30 exit 31end 32 33def checkScore(window,score) 34 if score >= 200 35 window.drawEndClear 36 window.refresh 37 sleep 3 38 exit 39 end 40end 41 42window = Window.new 43hero = Hero.new(window,Window::WINDOW_WIDTH/2,Window::SKYLINE) 44bomb1 = Bomb.new(window) 45bomb2 = Bomb.new(window) 46bomb3 = Bomb.new(window) 47apple1 = Apple.new(window) 48apple2 = Apple.new(window) 49orange1 = Orange.new(window) 50orange2 = Orange.new(window) 51score = 0 52clickCount = 0 53 54 55while true do 56 time = window.getTime 57 while event = SDL::Event2.poll do 58 case event 59 when SDL::Event2::Quit 60 exit 61 when SDL::Event2::MouseButtonDown 62 x = event.x 63 y = event.y 64 isClickedBomb1 = clicked?(x,y,bomb1) 65 isClickedBomb2 = clicked?(x,y,bomb2) 66 isClickedBomb3 = clicked?(x,y,bomb3) 67 if isClickedBomb1 or isClickedBomb2 or isClickedBomb3 68 gameOver(window,hero) 69 end 70 isClickedApple1 = clicked?(x,y,apple1) 71 isClickedApple2 = clicked?(x,y,apple2) 72 isClickedOrange1 = clicked?(x,y,orange1) 73 isClickedOrange2 = clicked?(x,y,orange2) 74 if isClickedApple1 75 score = score + apple1.getScore 76 clickCount = clickCount + 1 77 apple1.reset 78 checkScore(window,score) 79 end 80 if isClickedApple2 81 score = score + apple2.getScore 82 clickCount = clickCount + 1 83 apple2.reset 84 checkScore(window,score) 85 end 86 if isClickedOrange1 87 score = score + orange1.getScore 88 clickCount = clickCount + 1 89 orange1.reset 90 checkScore(window,score) 91 end 92 if isClickedOrange2 93 score = score + orange2.getScore 94 clickCount = clickCount + 1 95 orange2.reset 96 checkScore(window,score) 97 end 98 end 99end 100 101 SDL::Key.scan 102 if SDL::Key.press?(SDL::Key::A) 103 hero.moveLeft 104 end 105 if SDL::Key.press?(SDL::Key::F) 106 hero.moveRight 107 end 108 109 window.drawBack 110 hero.draw 111 bomb1.drop 112 bomb2.drop 113 bomb3.drop 114 apple1.drop 115 apple2.drop 116 orange1.drop 117 orange2.drop 118 119 if hit?(hero,apple1) 120 score = score + apple1.getScore 121 apple1.reset 122 checkScore(window,score) 123 end 124 if hit?(hero,apple2) 125 score = score + apple2.getScore 126 apple2.reset 127 checkScore(window,score) 128 end 129 130if hit?(hero,orange1) 131 score = score + orange1.getScore 132 orange1.reset 133 checkScore(window,score) 134 end 135 if hit?(hero,orange2) 136 score = score + orange2.getScore 137 orange2.reset 138 checkScore(window,score) 139 end 140 141 if hit?(hero,bomb1) or hit?(hero,bomb2) or hit?(hero,bomb3) or time < 0 142 gameOver(window,hero) 143 end 144 145 time2 = time.to_s.tr(' 0-9a-zA-Z',' 0-9a-zA-Z') 146 score2 = score.to_s.tr(' 0-9a-zA-Z',' 0-9a-zA-Z') 147 clickCount2 = clickCount.to_s.tr(' 0-9a-zA-Z',' 0-9a-zA-Z') 148 hyouji = "あなたの得点 #{score2}点 残りは#{time2}秒 (クリック#{clickCount2} 回)" 149 window.writeChar(hyouji) 150 window.refresh 151end

main.rb

ruby

1#!ruby -Ks 2require "./window.rb" 3require "./kuizu.rb" 4require "./zairyo.rb" 5 6window = Window.new 7window.drawBack 8window.gamestart 9window.refresh 10 11while true do 12 while event = SDL::Event2.poll do 13 case event 14 when SDL::Event2::Quit 15 exit 16 when SDL::Event2::MouseButtonDown 17 x = event.x 18 y = event.y 19 if window.kuizuclicked?(x,y) 20 gamen 21 end 22 if window.zairyoclicked?(x,y) 23 zairyo 24 end 25 end 26 end 27 28end

実行した跡と、フォルダの中も見せます。フォルダの中](c2fa7d8b0c07229871a4addb8a17a939.png)
コマンドプロンプト

足りない部分があればコメントください。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

main.rbの require "./zairyo.rb" を削除してもzairyo.rbが呼ばれたと言うことでしょうか。
それならば他の window.rb か kuizu.rb で zairyo.rbを呼んでいないでしょうか。

投稿2016/06/27 10:50

shanxia

総合スコア1038

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

yusuke.

2016/06/28 08:52

requireを消去するとでなくなりました。解決しました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問