|

楼主 |
发表于 2012-2-26 22:55:00
|
显示全部楼层
Re:【小w的回收站】杂文贴合集(或许有你想要的东西)
【想学程序的看过来】我的第一个java游戏
ManAndHouse.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class ManAndHouse {
public static void main(String args[]) throws IOException{
BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
String command;
iTem sword,healthbag;
me mySelf,oldMan;
mySelf=new me(200,30,"太极拳");
oldMan=new me(300,50,"火云邪神拳",1,"老爷爷");
sword=new iTem(0);
healthbag=new iTem(1);
mySelf.start();
while(true){
command=s.readLine();
if(!command.equalsIgnoreCase("")){
mySelf.setname(command);break;
}
}
mySelf.lookAround();
while(true){
mySelf.command();
command=s.readLine();
if(command.equalsIgnoreCase("m")){
mySelf.move();break;
}
else if(command.equalsIgnoreCase("e")){
mySelf.lookAround();
}
else{
System.out.println("很遗憾,没有您打出的命令:"+command);
}
}
mySelf.lookAround();
while(true){
mySelf.command();
command=s.readLine();
if(command.equalsIgnoreCase("t")){
mySelf.talk(oldMan);break;
}
else if(command.equalsIgnoreCase("p")){
if(mySelf.item[1]<1){
healthbag.beingGet(mySelf);
System.out.println("你获得了一个医药包");
}
}
else if(command.equalsIgnoreCase("g")){
if(mySelf.item[0]<1){
sword.beingGet(mySelf);
System.out.println("你获得了一把剑");
}
}
else if(command.equalsIgnoreCase("l")){
mySelf.lookAround();
}
else if(command.equalsIgnoreCase("c")){
mySelf.showMe();
}
else{
System.out.println("很遗憾,没有您打出的命令:"+command);
}
}
while(true){
System.out.println("请选择想要问的话:");
System.out.println("A.为什么我们火星人要来地球");
System.out.println("B.火星漂亮吗?");
System.out.println("C.我来地球的使命究竟是什么?");
System.out.println("D.您是不是有些苍老了?");
System.out.println("请输入:");
command=s.readLine();
if(command.equalsIgnoreCase("a")){
me.proGress=3;mySelf.talk(oldMan);
}
else if(command.equalsIgnoreCase("b")){
me.proGress=4;mySelf.talk(oldMan);
}
else if(command.equalsIgnoreCase("c")){
me.proGress=5;mySelf.talk(oldMan);
}
else if(command.equalsIgnoreCase("d")){
me.proGress=6;mySelf.talk(oldMan);break;
}
else{
System.out.println("很遗憾,没有您打出的命令:"+command);
}
}
while(true){
oldMan.attack(mySelf);
mySelf.command();
command=s.readLine();
if(command.equalsIgnoreCase("a")){
mySelf.attack(oldMan);
if(me.proGress==10){
break;
}
}
else if(command.equalsIgnoreCase("c")){
mySelf.showMe();
}
else if(command.equalsIgnoreCase("l")){
mySelf.lookAround(oldMan);
}
else if(command.equalsIgnoreCase("i")){
while(true){
mySelf.showItem();
System.out.println("Q键返回战斗");
command=s.readLine();
if(mySelf.item[0]>0&&command.equalsIgnoreCase("s")){
System.out.println("本装备无法使用");
}
else if(mySelf.item[1]>0&&command.equalsIgnoreCase("y")){
healthbag.useItem(mySelf);
}
else if(command.equalsIgnoreCase("q")){
break;
}
else{
System.out.println("很遗憾,没有您打出的命令:"+command);
}
}
}
else{
System.out.println("很遗憾,没有您打出的命令:"+command);
}
}
mySelf.end(oldMan);
}
}
me.java
import java.io.IOException;
public class me {
String name="小二";
String gofu;
int position,life,attack;
public int item[]={0,0,0,0};
static public int proGress=0;
//item[]={0,0,0,0},itemid[],itemnum=0;
public me(int l,int a,String g,int p,String n){
position=p;life=l;attack=a;name=n;gofu=g;
}
public me(int l,int a,String g){
life=l;attack=a;gofu=g;
}
public int getposition(){
return position;
}
public int getlife(){
return life;
}
public int getattack(){
return attack;
}
public int getproGress(){
return proGress;
}
public void setattack(int a){
attack=a;
}
public void setlife(int l){
life=l;
}
public void setname(String n){
name=n;
}
public void showMe() throws IOException{
System.out.print("姓名:"+name+";所在位置:");
switch(position){
case 0:
System.out.println("屋外周边");break;
case 1:
System.out.println("屋子里");break;
case 2:
System.out.println("战斗中");
}
System.out.print("生命值:"+life+";装备和物品:");
/*int i=0;
while(itemid==0){
item[itemid]=item[itemid]++;
i++;
}*/
/*
if(item[0]>0){
System.out.print("圣剑 x"+item[1]+";");
}
if(item[1]>0){
System.out.print("医药包 x"+item[1]+";");
}
else if(item[0]==0){
System.out.print("无");
}
System.out.println();*/
showItem();
wait.waiting();
}
public void lookAround() throws IOException{
if(position==0){
System.out.println("春光明媚,鸟语花香,冰河解冻,彩蝶纷飞。我"+name+",漫步在一望无垠的田野上,");
System.out.println("享受着清新的空气,和煦的阳光。咦,前面怎么出现一个房子?待我进去探险一番!");
}
else if(position==1){
if(proGress==1){
System.out.println("我一步一步的走进了这个屋子,屋子里漆黑到伸手不见五指的程度。OTA!有什么东西向我走来?");
System.out.println("原来是一个人!他用低沉的声音说:”你好,救世主。“这时,房间突然亮了起来!");
System.out.println("而光源,正是凝视着我的老头那双炯炯有神的眼睛!我下意识的扫了一眼四周:桌子上放着一个医药包,墙上挂着一把剑");
System.out.println("而我进来时的门,已经被牢牢封上了…………");
wait.waiting();
proGress=2;
}
else if(proGress==2){
System.out.print("房间四面密闭,放着一张桌子两个椅子。角落里还有一个破旧的衣柜。");
if(item[0]==1){
System.out.print("桌子上空无一物。");
}
else{
System.out.print("桌子上有一个医药包。");
}
if(item[1]==1){
System.out.print("墙壁上干干净净");
}
else{
System.out.print("墙壁上悬挂着一把剑");
}
System.out.println("");
}
}
}
public void lookAround(me b) throws IOException{
if(position==2){
if(b.life<50){
System.out.println("老头已经奄奄一息,但仍然愤怒的目视着我");
}
else if(b.life<150){
System.out.println("老头爆发了他的小宇宙,我能感觉到环绕在他身体周围那巨大的查克拉");
}
else if(b.life>250){
System.out.println("老头满脸微笑的看着我,我的攻击几乎没有给他造成伤害");
}
}
else{
this.lookAround();
}
}
public void command(){
System.out.println("请选择您所需要的操作:");
if (position==0){
System.out.println("进入房子(M) 察看四周(E)");
}
else if (position==1){
System.out.println("与老人对话(T) 捡起桌子上的医疗包(P)");
System.out.println("取下墙上的剑(G) 观察屋子里的布局(L) 查看自己状态(C)");
}
else if (position==2){
System.out.println("攻击老人(A) 使用物品(I)");
System.out.println("查看老人状态(L) 查看自己状态(C)");
}
}
public void move(){
System.out.println("下定决心,排除万难,我毅然决然的走向了那个神秘的房子");
position=1;
proGress=1;
}
public void start(){
System.out.println("大家好,我叫………………");
System.out.println("我叫什么来着?一不小心忘了。算了,您给我起一个名字吧");
}
public void showItem(){
if(item[0]>0){
System.out.print("圣剑【S】 x"+item[1]+";");
}
if(item[1]>0){
System.out.print("医药包【Y】 x"+item[1]+";");
}
else if(item[0]==0){
System.out.print("无");
}
System.out.println();
}
public void talk(me b) throws IOException{
if (proGress==2){
System.out.println(name+":您到底是谁?以前见过我吗?");
System.out.println(b.name+":我是谁并不重要,重要的是——你是谁,这个问题你想清楚了吗?");
System.out.println(name+":我是谁?我就是我呀。");
wait.waiting();
System.out.println(b.name+":你还记得自己身上背负的使命吗?你记得自己的父母吗?帮你来到这个星球的亲人又是谁?");
System.out.println(name+":我不知道,但我也不用知道");
wait.waiting();
System.out.println(b.name+":你还不明白吗?如果再不努力,你的故乡,生你养育你的火星,就要遭受灭顶之灾了!!!!");
System.out.println(name+":难到我真的是火星人?");
System.out.println(b.name+":你不是火星人,你是火星人的影子,简称火影");
wait.waiting();
System.out.println(name+":那我岂不是很强?");
System.out.println(b.name+"没错。还有什么不明白的问题,尽管问我这个老前辈好了。");
wait.waiting();
proGress=3;
}
else if(proGress==3){
System.out.println(b.name+":这个问题,要从十五万年前谈起。");
System.out.println(b.name+":火星,原本是一个和平而富饶的星球。放眼全银河系,哪个星球可以平均一年消费20颗核弹?");
System.out.println(b.name+":只有我们独立富强的火星人民做得到。");
System.out.println(name+":OTA!!!那么多核弹!都用到哪里去了?");
wait.waiting();
System.out.println(b.name+":当然是战争啊,火星人民热爱战争,把征服并控制他人作为自己人生的最高理想。无数的火星先烈,前赴后继的");
System.out.println(b.name+":为他们的伟大的理想献出一切,乃至生命。");
System.out.println(name+":好BT的星球-_-……这么说来火星上的那些环形山,都是核弹炸出来的了?");
wait.waiting();
System.out.println(b.name+":那是当然。然而,突然有一天,一场巨大的灾难降临在我们的星球,以致让所有的士兵丧失了斗志。");
System.out.println(b.name+":所有的百姓都寝食难安,社会出现了巨大的动乱,各国政府苦心经营的政治体系轰然倒塌,");
System.out.println(b.name+":火星陷入了无政府状态,一直到现在,还是如此。");
wait.waiting();
System.out.println(name+":真是让人伤感的故事啊,这又和地球有什么关系呢?");
System.out.println(b.name+":在各国政府下台之前,火星政府联合会调查出了火星上动乱的原因");
System.out.println(name+":是什么呢?");
System.out.println(b.name+":导致火星大规模动乱的元凶,是一种特殊的电磁波,而这种电磁波,就是地球发出的!");
wait.waiting();
System.out.println(b.name+":那种电磁波本来是很微弱的,本不可能到达火星。经调查发现,它居然是通过空间虫洞来到火星的");
System.out.println(b.name+":显然,这就是地球用来征服火星的新型战略武器。从知道了这个情况的那一天起,我们的前辈就下定了");
System.out.println(b.name+":决心,一定要向地球复仇!但是,以当时的研究来看,击败地球简直是天方夜谭。经过数十年的");
wait.waiting();
System.out.println(b.name+":观察,我们甚至还是无法找到地球的军事基地和有生力量,更不要说他们的大规模杀伤性武器。可见他们的隐形技术有多么的强大。");
System.out.println(b.name+":我们火影,虽然不是火星人,但我们是火星人民的代表,来到地球作间谍,刺探情报,为我们的星球做贡献。");
System.out.println(name+":原来是这样啊!");
wait.waiting();
}
else if(proGress==4){
System.out.println(b.name+":火星美丽而富饶。在地球袭击之前,天天都有战争,几乎所有人都在奴役别人或被人奴役的过程");
System.out.println(b.name+":中获得生命的快乐,找到生活的真谛。简直是人间天堂。");
wait.waiting();
System.out.println(b.name+":而现在……虽然人民生活在水深火热之中,但火星依然是美丽的,而火星的未来要靠我们的双手来创造。");
System.out.println(name+":明白了");
wait.waiting();
}
else if(proGress==5){
System.out.println(b.name+":你的任务就是继承我们火星人的意志,继续和地球人战斗。记住,你不是一个人在战斗");
System.out.println(b.name+":不是一个人!你继承了火星人的光荣的传统。阿克、萨卡、皮亚诺在你的危难时刻会灵魂附体!");
wait.waiting();
System.out.println(b.name+":你将代表了我们火星人悠久的历史和传统,胜利将属于你,属于阿克,属于皮亚诺,属于所有热爱火星的人!");
System.out.println(name+":我肩上的担子好重啊!");
System.out.println(b.name+":没错,你要努力了!");
wait.waiting();
}
else if(proGress==6){
System.out.println(b.name+":居然敢这样说我?好咱们两来比划比划");
position=2;
}
}
public void attack(me a) throws IOException{
if(a.life>0){
System.out.println(name+":看招!"+gofu+"!!!");
a.life-=attack;
if(a.life<50){
System.out.println(a.name+":啊!(吐出一口鲜血)");
}
else if(a.life<150){
System.out.println(a.name+":居然敢打我!!");
}
else if(a.life>250){
System.out.println(a.name+":哈哈,一点都不痛!");
}
}
wait.waiting();
if(a.life<0){
System.out.println(a.name+":啊,我挂了!");
proGress=10;
}
}
public void end(me a){
System.out.println(a.name+":恩,表现的很好很强大,火星的未来就要靠你了");
System.out.println(name+":恩,我一定会努力的!");
System.out.println(a.name+":明天再来这里,我来教你世界上最厉害的功夫");
System.out.println(a.name+":今天就到这里下次见!!");
}
}
wait.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class wait {
public static void waiting() throws IOException{
BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
System.out.println("【按回车键继续】");
s.readLine();
}
}
iTem.java
public class iTem {
int id;
public iTem(int i){
id=i;
}
public void beingGet(me a){
//a.itemid[a.itemnum++]=id;
a.item[id]++;
if(id==0){
a.setattack(a.getattack()+100);
}
}
public void useItem(me a){
if(a.item[id]>0){
if(id==1){
a.setlife(a.getlife()+60);
}
a.item[id]--;
}
}
} |
|