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

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

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

Processingは、オープンソースプロジェクトによるCGのためのプログラミング言語です。Javaをベースにしており、グラフィック機能に特化しています。イメージの生成やアニメーションなど、視覚的なフィードバックを簡単に得ることが可能です。

Q&A

1回答

15354閲覧

unexpected token : voidとエラーする解決法

fodihf345

総合スコア8

Processing

Processingは、オープンソースプロジェクトによるCGのためのプログラミング言語です。Javaをベースにしており、グラフィック機能に特化しています。イメージの生成やアニメーションなど、視覚的なフィードバックを簡単に得ることが可能です。

0グッド

0クリップ

投稿2017/07/31 01:19

processingでこのようなコードを打ち込んだのですが、
エラーが出ます。
どこが悪いのか教えてください。
ちなみにエラーはunexpected token : voidとでます。

import processing.sound.*;

PFont myFont;
PImage doorImg, wallImg, floorImg, clockImg, keyImg;
SoundFile jiggleSound, clankSound, openSound;
Item door, clock, theKey;
boolean solvedFlg = false;
boolean searchFlg = false;
boolean keyFlg = false;
String message = "";
int stat=0; //画面状態を表す状態変数
int x1=0, y1;

void setup() {
size(480, 480);
background(255, 255, 255);
fill(0, 0, 0);
noStroke();
frameRate(40);
myFont = createFont("YuGothic", 24, true);
textFont(myFont);
y1=height;

doorImg = loadImage("sign_door.jpg"); wallImg = loadImage("01murocrep512.jpg"); floorImg = loadImage("metal_s01.png"); clockImg = loadImage("BlackAndWhite2_S.png"); keyImg = loadImage("key.png"); jiggleSound = new SoundFile(this, "LockedDoorHandleJiggle.wav"); clankSound = new SoundFile(this, "dropmetalthing.ogg"); openSound = new SoundFile(this, "closing door.ogg"); door = new Item(doorImg, 150, 133, 6); clock = new Item(clockImg, 350, 100, 50); theKey = new Item(keyImg, 350, 310, 7);

}

void draw() {
background(200);
switch(stat) {

case 0: //状態変数が0(つまり画面がTitle)のときの動作 fill(0); textSize(48); text("脱出せよ", 160, 240); textSize(24); text("click to the screan", 150, 300); break;

case 1: //ゲーム画面

image(wallImg, 0, 0, 480, 300); image(floorImg, 0, 300, 480, 150); door.draw(); clock.draw(); if (searchFlg && !keyFlg) { theKey.draw(); } if (solvedFlg) { fill(0); textSize(48); text("CLEAR!", 100, 240); } fill(255); text(message, 10, 475);

}
}
void draw() {
int imgWidth = img.width / scale;
int imgHeight = img.height / scale;
image(img, xpos, ypos, imgWidth, imgHeight);
}

boolean isIn(int x, int y) {
if (x >= xpos && x <= xpos + img.width / scale &&
y >= ypos && y <= ypos + img.height / scale) {
return true;
} else {
return false;
}

class Item {
PImage img;
int xpos;
int ypos;
int scale;

Item(PImage _img, int _xpos, int _ypos, int _scale) { img = _img; xpos = _xpos; ypos = _ypos; scale = _scale; } void draw() { int imgWidth = img.width / scale; int imgHeight = img.height / scale; image(img, xpos, ypos, imgWidth, imgHeight); } boolean isIn(int x, int y) { if (x >= xpos && x <= xpos + img.width / scale && y >= ypos && y <= ypos + img.height / scale) { return true; } else { return false; } }

}

void mousePressed()
{
switch(stat) {
case 0:
if (mouseX<width) {
x1=0; //次の状態で必要な変数の初期化
stat=1;//ゲーム画面1状態に移る
}
break;
case 1:
message = "";
if (solvedFlg) {
return;
}

if (door.isIn(mouseX, mouseY)) { if (keyFlg) { solvedFlg = true; openSound.play(); } else { jiggleSound.play(); message = "鍵がかかっている。"; } } if (clock.isIn(mouseX, mouseY)) { if (!searchFlg) { searchFlg = true; clankSound.play(); message = "何かが落ちたようだ…"; } } if (theKey.isIn(mouseX, mouseY)) { if (searchFlg && !keyFlg) { keyFlg = true; message = "鍵を見つけた!"; } }

}
}

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

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

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

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

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

guest

回答1

0

ソースコードは見やすいようにインデントした方がいいですよ(spaceでもtabでいいのでとりあえずやったほうがいいです・・・・と思いましたが、ソースコードとして埋め込んでないからっぽいので、
https://teratail.com/help
コードを入力
を参考にしてください。)

isIn関数の}が足りないのと多すぎるのと、boolean関数なのに値を返してないのが問題ではと思います。

↓とりあえずインデント入れてみたので、括弧多い少ないがわかりやすいはず

processing

1import processing.sound.*; 2 3PFont myFont; 4PImage doorImg, wallImg, floorImg, clockImg, keyImg; 5SoundFile jiggleSound, clankSound, openSound; 6Item door, clock, theKey; 7boolean solvedFlg = false; 8boolean searchFlg = false; 9boolean keyFlg = false; 10String message = ""; 11int stat=0; //画面状態を表す状態変数 12int x1=0, y1; 13 14void setup() { 15 size(480, 480); 16 background(255, 255, 255); 17 fill(0, 0, 0); 18 noStroke(); 19 frameRate(40); 20 myFont = createFont("YuGothic", 24, true); 21 textFont(myFont); 22 y1=height; 23 24 doorImg = loadImage("sign_door.jpg"); 25 wallImg = loadImage("01murocrep512.jpg"); 26 floorImg = loadImage("metal_s01.png"); 27 clockImg = loadImage("BlackAndWhite2_S.png"); 28 keyImg = loadImage("key.png"); 29 jiggleSound = new SoundFile(this, "LockedDoorHandleJiggle.wav"); 30 clankSound = new SoundFile(this, "dropmetalthing.ogg"); 31 openSound = new SoundFile(this, "closing door.ogg"); 32 door = new Item(doorImg, 150, 133, 6); 33 clock = new Item(clockImg, 350, 100, 50); 34 theKey = new Item(keyImg, 350, 310, 7); 35} 36 37void draw() { 38 background(200); 39 switch(stat) { 40 41 case 0: //状態変数が0(つまり画面がTitle)のときの動作 42 43 fill(0); 44 textSize(48); 45 text("脱出せよ", 160, 240); 46 textSize(24); 47 text("click to the screan", 150, 300); 48 break; 49 50 case 1: //ゲーム画面 51 52 image(wallImg, 0, 0, 480, 300); 53 image(floorImg, 0, 300, 480, 150); 54 door.draw(); 55 clock.draw(); 56 57 if (searchFlg && !keyFlg) { 58 theKey.draw(); 59 } 60 if (solvedFlg) { 61 fill(0); 62 textSize(48); 63 text("CLEAR!", 100, 240); 64 } 65 fill(255); 66 text(message, 10, 475); 67 } 68} 69void draw() { 70 int imgWidth = img.width / scale; 71 int imgHeight = img.height / scale; 72 image(img, xpos, ypos, imgWidth, imgHeight); 73} 74 75boolean isIn(int x, int y) { 76 if (x >= xpos && x <= xpos + img.width / scale && 77 y >= ypos && y <= ypos + img.height / scale) { 78 return true; 79 } else { 80 return false; 81 } 82 83class Item { 84 PImage img; 85 int xpos; 86 int ypos; 87 int scale; 88 89 Item(PImage _img, int _xpos, int _ypos, int _scale) { 90 img = _img; 91 xpos = _xpos; 92 ypos = _ypos; 93 scale = _scale; 94 } 95 96 void draw() { 97 int imgWidth = img.width / scale; 98 int imgHeight = img.height / scale; 99 image(img, xpos, ypos, imgWidth, imgHeight); 100 } 101 102 boolean isIn(int x, int y) { 103 if (x >= xpos && x <= xpos + img.width / scale && 104 y >= ypos && y <= ypos + img.height / scale) { 105 return true; 106 } else { 107 return false; 108 } 109 } 110 } 111 112 void mousePressed() 113 { 114 switch(stat) { 115 case 0: 116 if (mouseX<width) { 117 x1=0; //次の状態で必要な変数の初期化 118 stat=1;//ゲーム画面1状態に移る 119 } 120 break; 121 case 1: 122 message = ""; 123 if (solvedFlg) { 124 return; 125 } 126 127 if (door.isIn(mouseX, mouseY)) { 128 if (keyFlg) { 129 solvedFlg = true; 130 openSound.play(); 131 } else { 132 jiggleSound.play(); 133 message = "鍵がかかっている。"; 134 } 135 } 136 137 if (clock.isIn(mouseX, mouseY)) { 138 if (!searchFlg) { 139 searchFlg = true; 140 clankSound.play(); 141 message = "何かが落ちたようだ…"; 142 } 143 } 144 145 if (theKey.isIn(mouseX, mouseY)) { 146 if (searchFlg && !keyFlg) { 147 keyFlg = true; 148 message = "鍵を見つけた!"; 149 } 150 } 151 } 152}

投稿2017/07/31 07:56

編集2017/07/31 08:14
rururu3

総合スコア5545

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問