Created
May 3, 2024 18:31
-
-
Save asasu-m/315778584d2f7ebc67c4c7e157684275 to your computer and use it in GitHub Desktop.
簡単な釣りプログラム作ってみました。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Random; | |
import java.util.Scanner; | |
public class kantanturi { | |
public static void main(String[] args) { | |
// TODO 自動生成されたメソッド・スタブ | |
System.out.println("ちょっと釣りをしよう"); | |
System.out.println("よっこらせ"); | |
while(true) | |
{ | |
System.out.println("(釣り人が竿を投げようとしている・・)"); | |
System.out.println("そりゃ!"); | |
Random rnd = new Random(); | |
int kyori=rnd.nextInt(10)+10; | |
System.out.println(kyori+"m飛んだ!"); | |
System.out.println("さて何が釣れるかな・・"); | |
int waittime=rnd.nextInt(4)+4; | |
for(int i=0;i<waittime;i++) | |
{ | |
System.out.println("釣り人はたたずんでいる・・"); | |
try | |
{ | |
Thread.sleep(1000); | |
}catch(InterruptedException e) | |
{ | |
System.out.println(e); | |
} | |
} | |
turifight(kyori); | |
} | |
} | |
public static void turifight(int kyori) | |
{ | |
Fish fish; | |
if(kyori<=12) | |
{ | |
fish = new huna(); | |
System.out.println("軽い当たりのようだ・・"); | |
}else if(kyori<=15) | |
{ | |
fish = new basu(); | |
System.out.println("お・・少し引いている・・"); | |
}else | |
{ | |
fish = new suzuki(); | |
System.out.println("おお。。大物だ!"); | |
} | |
while(true) | |
{ | |
System.out.println("どのくらいの強さで引きますか?(1)大 (2)中 (3)小"); | |
Scanner sc = new Scanner(System.in); | |
int choice =sc.nextInt(); | |
int str; | |
if(choice==1) | |
{ | |
str=10; | |
System.out.println("思い切りリードを巻いた!"); | |
}else if(choice==2) | |
{ | |
str=7; | |
System.out.println("逃げられないように着実にリードを巻いた!"); | |
}else if(choice==3) | |
{ | |
str=5; | |
System.out.println("静かにゆっくりリードを巻いた・・・"); | |
}else | |
{ | |
str=0; | |
System.out.println("慌てて釣り竿を落としてしまった・・"); | |
} | |
System.out.println("魚に"+str+"ダメージ!"); | |
fish.setHP(fish.getHP()-str); | |
if(fish.getHP()<=0) | |
{ | |
break; | |
} | |
} | |
System.out.println(fish.getName()+"を釣りあげた!"); | |
try | |
{ | |
Thread.sleep(3000); | |
}catch(InterruptedException e) | |
{ | |
System.out.println(e); | |
} | |
System.out.println("まだ釣ろうかな・・"); | |
System.out.println("(1)はい(2)いいえ"); | |
Scanner sc = new Scanner(System.in); | |
switch(sc.nextInt()) | |
{ | |
case 1: | |
break; | |
case 2: | |
System.out.println("帰るかあ・・"); | |
System.out.println("釣り人は帰った・・"); | |
System.exit(0); | |
break; | |
default: | |
System.out.println("範囲外の値です"); | |
System.exit(-1); | |
break; | |
} | |
} | |
} | |
class Fish | |
{ | |
int hp; | |
String name; | |
Fish() | |
{ | |
hp=1; | |
name="名無し"; | |
} | |
public String getName() | |
{ | |
return name; | |
} | |
public void setHP(int hp) | |
{ | |
this.hp=hp; | |
} | |
public int getHP() | |
{ | |
return hp; | |
} | |
} | |
class huna extends Fish | |
{ | |
huna() | |
{ | |
super(); | |
name ="フナ"; | |
hp=10; | |
} | |
} | |
class basu extends Fish | |
{ | |
basu() | |
{ | |
super(); | |
name ="バス"; | |
hp=20; | |
} | |
} | |
class suzuki extends Fish | |
{ | |
suzuki() | |
{ | |
super(); | |
name = "スズキ"; | |
hp=30; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment