初学JAVA 好玩的打架小游戏代码 -
别妄想泡我
571次浏览
2020年08月01日 15:39
最佳经验
本文由作者推荐
mit是什么意思-拥挤的反义词
public class GameWithNumbers_GroupProject
{
public static void main(String[] args)
{
//Create buttons for you to choose the game.
Object[] options ={ "Game fight", "Find mere", "Guess numbers","Quit" };
int button = tionDialog(null, "Which action you want to do next?", "Combat Control Panel",
_NO_CANCEL_OPTION, ON_MESSAGE, null, options, options[0]);
if (button == _OPTION)
{
{
Object[] options1 ={ "Attack", "Heal", "Quit" };
int myap = 0
int enap = 0
int myhp = 500;
int enemyhp = 500;
ssageDialog(null, "This is a Fighting Game
You and your enemy both have 500 blood
You can choose attack your enemy or heal yourself next");
while (myhp > 0 && enemyhp > 0){
int myattack = (int)(()*100);
int enemyattack = (int)(()*100);
int myheal = (int)(()*50);
int enemyheal = (int)(()*50);
int i = tionDialog(null, "Which action you want to do next?", "Combat Control Panel",_NO_CANCEL_OPTION, ON_MESSAGE, null, options1, options[0]);
if (i == _OPTION){
if (myap != 100){
enemyhp-=myattack;
enap += 25;
if(enemyhp <= 0){ssageDialog(null,"You have attacked your enemy this turn
Your HP: " + myhp + ",
Your enemy's HP:" + "0" + "
Get into your enemy's turn?")
;
break;}
else{
ssageDialog(null,"You have attacked your enemy this turn
Your HP: " + myhp + ",
Your enemy's HP:" + enemyhp + "
Get into your enemy's turn?");
}}else{enemyhp-=myattack*2;
enap += 25;
myap = 0
if(enemyhp <= 0){ssageDialog(null,"You have attacked your enemy"
+ " critically this turn
Your HP: " + myhp + ",
Your enemy's HP:" + "0" +
"
Get into your enemy's turn?");
break;}
else{
ssageDialog(null,"You have attacked your enemy critially this "
+ "turn
Your HP: " + myhp + ",
Your enemy's HP:" + enemyhp +
"
Get into your enemy's turn?");
}}
if (i == _OPTION){
myhp+=myheal;if (myhp >= 1000){
myhp = 1000;}
}
ssageDialog(null,"You have healed yourself this turn
Your HP: " + myhp + ",
Your enemy's HP:" + enemyhp + "
Get into your enemy's turn?");
}
if (i == _OPTION){
break;
}
int enemyif = (int)(()*2);
if (enemyif == 0){if(enap !=100){
myhp-=enemyattack;
myap+=25;
if(myhp>=0){ssageDialog(null,"Your enemy has attacked you this turn
Your HP: " + myhp + ",
Your enemy's HP: " + enemyhp + "
Do you want to get into your turn?");
}
else
{ssageDialog(null,"Your enemy has attacked you this turn
Your HP: " + "0" + ",
Your enemy's HP: " + enemyhp + "
Do you want to get into your turn?");
break;}}
else{myhp-=enemyattack*2;
myap+=25;
enap = 0;
if(myhp>=0){
ssageDialog(null,"Your enemy has attacked you "
+ "critically this turn
Your HP: " + myhp +
",
Your enemy's HP: " + enemyhp + "
Do you want to get "
+ "into your turn?");}
else{ssageDialog(null,"Your enemy has attacked you "
+ "critically this turn
Your HP: " + "0" +
",
Your enemy's HP: " + enemyhp + "
Do you want to get "
+ "into your turn?");
break;}
}
}
if (enemyif == 1){
enemyhp+=enemyheal;
if(enemyhp >= 1000){enemyhp = 1000;}
ssageDialog(null,"Your enemy has healed himself this turn
your HP: " + myhp + ",
Your enemy's HP:" + enemyhp + "
Do you want to get into your turn?");
}
}
if (myhp <= 0){
ssageDialog(null,"You die, Game Over");
}
if (enemyhp <= 0){
ssageDialog(null,"Your enemy die, You are the winner!");
}
else{
ssageDialog(null,"The Player Quit The Game");
}
}
}
if (button == _OPTION)
{
//Prompt user enter his or her birthday.
int birthmonth=nt(putDialog(null,"Enter the month "
+ "you were born in(1 to 12):"));
int birthdate=nt(putDialog(null,"Enter the day "
+ "you were born in:"));
Constellation1(birthmonth,birthdate);
}
if (button == _OPTION)
{
//Create the number and tell reader whether it is prime number:
int guess=(int)(()*99+2);
int guess1=(int)((guess,0.5));
String judge="";
for (int check=2; check<=guess1;check++)
{
if(guess % check == 0)
judge="The number you will guess is not a prime number";
else
judge="The number you will guess is a prime number";
}
ssageDialog(null,judge);
//Prompt user to input the number
int user=nt(putDialog(null,"Guess the number(2 to 100): "));
do
{
if(user
if(user>guess)
ssageDialog(null,"The number you guessed is too large, please try again!");
u
ser=nt(putDialog(null,"Guess the number(2 to 100): "));
}
while(user != guess);
ssageDialog(null,"You got the right answer!","Congratulations!",2);
}
}
public static int Constellation1(int month, int date)
{
if((month==3 && date>=21 && date<=31)||(month==4 && date>=1 && date<=19))
{ssageDialog(null,"You are Aries!");}
else if((month==4 && date>=20 && date<=31)||(month==5 && date>=1 && date<=20))
{ssageDialog(null,"You are Taurus!");}
else if((month==5 && date>=21 && date<=31)||(month==6 && date>=1 && date<=21))
{ssageDialog(null,"You are Gemini!");}
else if((month==6 && date>=22 && date<=30)||(month==7 && date>=1 && date<=22))
{ssageDialog(null,"You are Cancer!");}
else if((month==7 && date>=23 && date<=31)||(month==8 && date>=1 && date<=22))
{ssageDialog(null,"You are Leo!");}
else if((month==9 && date>=1 && date<=22)||(month==8 && date>=23 && date<=31))
{ssageDialog(null,"You are Virgo!");}
else if((month==9 && date>=23 && date<=30)||(month==10 && date>=1 && date<=22))
{ssageDialog(null,"You are Libra!");}
else if((month==11 && date>=1 && date<=21)||(month==10 && date>=23 && date<=31))
{ssageDialog(null,"You are Scorpio!");}
else if((month==11 && date>=22 && date<=30)||(month==12 && date>=1 && date<=21))
{ssageDialog(null,"You are Sagittarius!");}
else if((month==1 && date>=1 && date<=19)||(month==12 && date>=22 && date<=31))
{ssageDialog(null,"You are Capricorn!");}
else if((month==1 && date>=20 && date<=31)||(month==2 && date>=1 && date<=18))
{ssageDialog(null,"You are Aquarius!");}
else
{ssageDialog(null,"You are Pisces!");}
return Constellation2(month,date);
}
public static int Constellation2(int month, int date)
{tt
month=(int)(()*12+1);
if(month==4 || month==6 || month==9 || month==11)
date=(int)(()*31+1);
else if(month==2)
date=(int)(()*29+1);
else
date=(int)(()*30+1);
String monthname="";
switch(month)
{
case 1:
monthname="January";
break;
case 2:
monthname="Feburary";
break;
case 3:
monthname="March";
break;
case 4:
monthname="April";
break;
case 5:
monthname="May";
break;
case 6:
monthname="June";
break;
case 7:
monthname="July";
break;
case 8:
monthname="August";
break;
case 9:
monthname="September";
break;
case 10:
monthname="October";
break;
case 11:
monthname="November";
break;
default:
monthname="December";
break;
}
JOptionP
ssageDialog(null, "You should find a fere whose birthday is "+date+
"th of "+monthname);
(0);
return Constellation1(month,date);t
}
}