当前位置:   article > 正文

Android 开发--利用android studio 制作简单文字打怪升级游戏(伪地牢类)2.主页面及部分事件设计_android studio游戏

android studio游戏

时隔大半年,总算抽出时间更新这个博客了。去年下半年因为大四忙着备战考研,一直没有心情将第二篇继续更新,今年上半年又忙着搞毕业设计,焦头烂额了属于是orz

由于我的android studio的模拟器实在太卡了(用过的都知道),所以这一次的所有截图录屏都是我自己的手机来操作,看客老爷别太介意。。

言归正题,看过我上一篇文章的就知道,我们已经设计好了游戏前置事件以及设置等页面,现在摆在我们面前的就是对于游戏主体的设计。

一个游戏的趣味性必不可少,我目前给游戏设计的事件暂且有几种,分别是遇到怪物,发现宝箱,赌场事件,神秘守护者,商店老板,可怜的小女孩,小恶魔,每种事件的发生是随机的,在发生事件后,可以选择面对或者离开。除在发现怪物外,离开将不会带来任何影响。

在主页ui设计后,我将对这些事件进行详细的介绍。现在我们先介绍主页设计。

一个打怪升级的游戏必然得有一个较为简洁的主页面,不然看起来便花里胡哨,并且很难操作。为此,我特意录了一小段视频给各位看官老爷看看。视频有点小长,算是实机演示吧。

看完了视频,我接着说下面的内容。

游戏实机演示

首先是游戏的主体,肯定是打怪升级。既然是打怪,必然要有一套合理完备的战斗系统。在这里,我采用了传统的血条,蓝条的系统,包括攻击力,防御力,幸运值的设置。攻击力不足防御力则无法对敌人造成伤害,同理也是如此,当防御力高于敌方时将可能无伤通过战斗。

注意上面说的是可能。因为游戏中还设置了技能系统,作为怪物也可能存在专属的技能,主角也可以通过装备技能来武装自己。当然,在战斗开始前,设置了查看属性的功能,主角可以根据遇到的怪物的属性技能来确定策略,如果选择战斗,战斗中被击败后将直接结束游戏,当然选择逃跑也有可能付出代价:有可能会失去20%到50%的当前血量。下面是查看怪物属性。老鼠王是首领战,对于首领战不能逃跑,成功击败后将会进入下一个场景。

 

 

战斗模块的函数较为繁琐,简单来说,回合制,每回合可以进行普攻或者放技能或者使用恢复药剂,和其他游戏并无太多差异。看客老爷在看完开始的视频大概应该有所了解了。当然说着容易做着难,在真正编写时还是遇到了不少困难。对于怪物而言,其为随机释放技能,因此可能出现多次连续释放技能或者一场战斗一次也不用的情况。这是fight.java的文件。

  1. package com.example.dungeonsimulator;
  2. import android.app.AlertDialog;
  3. import android.content.DialogInterface;
  4. import android.content.Intent;
  5. import android.content.SharedPreferences;
  6. import android.media.MediaPlayer;
  7. import android.os.Bundle;
  8. import android.util.AttributeSet;
  9. import android.view.Gravity;
  10. import android.view.KeyEvent;
  11. import android.widget.ImageView;
  12. import android.widget.LinearLayout;
  13. import android.widget.TextView;
  14. import android.widget.ProgressBar;
  15. import android.os.Handler;
  16. import android.os.Message;
  17. import android.view.ViewGroup;
  18. import android.widget.Button;
  19. import android.os.Bundle;
  20. import android.util.Log;
  21. import android.view.View;
  22. import android.widget.TextView;
  23. import android.widget.Toast;
  24. import android.graphics.Color;
  25. import java.util.ArrayList;
  26. import java.util.Random;
  27. import androidx.appcompat.app.AppCompatActivity;
  28. import java.util.Timer;
  29. import java.util.TimerTask;
  30. import android.view.KeyEvent;
  31. public class fight extends AppCompatActivity{
  32. private static boolean win= true;
  33. LinearLayout ll1,ll2,ll3,ll4;
  34. private static int turn=0,num=0;
  35. TextView monster_name,skill,lead_name,monster_level,monster_words,monster_hp,lead_hp,monster_agress,monster_defend,monster_lucky,lead_agress,lead_defend,lead_lucky,textView,lead_level,lead_mp;
  36. Button attack;
  37. String text="";
  38. monster mon;
  39. Message ret;
  40. Handler handler;
  41. person a;
  42. ProgressBar progressbar1,progressbar2,progressbar3;
  43. Timer timer; @Override
  44. public boolean onKeyDown(int keyCode, KeyEvent event){
  45. if(keyCode== android.view.KeyEvent.KEYCODE_BACK)
  46. return true;
  47. return super.onKeyDown(keyCode, event);
  48. }
  49. protected void onCreate(Bundle savedInstanceState) {
  50. super.onCreate(savedInstanceState);
  51. setContentView(R.layout.fight);
  52. turn=0;
  53. monster_name = findViewById(R.id.monster_name);
  54. lead_name = findViewById(R.id.lead_name);
  55. monster_level = findViewById(R.id.monster_level);
  56. monster_words= findViewById(R.id.monster_words);
  57. skill=findViewById(R.id.skill);
  58. lead_name = findViewById(R.id.lead_name);
  59. monster_hp= findViewById(R.id.monster_hp);
  60. lead_hp = findViewById(R.id.lead_hp);
  61. ll1=findViewById(R.id.linear1);
  62. ll2=findViewById(R.id.ll2);
  63. ll3=findViewById(R.id.ll3);
  64. ll4=findViewById(R.id.ll4);
  65. MainActivity.lead.kill+=1;
  66. textView=findViewById(R.id.textView);
  67. lead_level=findViewById(R.id.lead_level);
  68. monster_agress = findViewById(R.id.monster_agress);
  69. monster_defend = findViewById(R.id.monster_defend);
  70. monster_lucky = findViewById(R.id.monster_lucky);
  71. lead_lucky = findViewById(R.id.lead_lucky);
  72. lead_agress = findViewById(R.id.lead_agress);
  73. lead_defend= findViewById(R.id.lead_defend);
  74. attack= findViewById(R.id.attack);
  75. progressbar1=findViewById(R.id.progressBar1);
  76. progressbar2=findViewById(R.id.progressBar2);
  77. progressbar3=findViewById(R.id.progressBar3);
  78. lead_mp=findViewById(R.id.lead_mp);
  79. initmonster.add();
  80. ArrayList<buff> temp1=new ArrayList<>();
  81. ArrayList<debuff> temp2=new ArrayList<>();
  82. a=new person(MainActivity.lead.get_aggress(),MainActivity.lead.get_defend(),MainActivity.lead.get_lucky(),MainActivity.lead.hp,MainActivity.lead.nowhp,MainActivity.lead.magic,MainActivity.lead.nowmagic,temp1,temp2);
  83. int level=main.monster_level;
  84. int i=main.monster_index;
  85. mon=new monster(level,initmonster.monster_index[i][1],initmonster.monster_index[i][2],
  86. initmonster.monster_index[i][3],initmonster.monster_index[i][4],initmonster.monster_index[i][5],initmonster.monster_index[i][6],initmonster.monster_index[i][7],initmonster.monster_index[i][8],initmonster.monster_index[i][9],initmonster.monster_index[i][10],initmonster.monster_index[i][11],initmonster.monster_index[i][12]);
  87. set_text();
  88. set_lead();
  89. set_monster();
  90. set_humanhp();
  91. set_monhp();
  92. set();
  93. set_humanmp();
  94. attack.setOnClickListener(new View.OnClickListener() {
  95. @Override
  96. public void onClick(View v) {
  97. Random r=new Random();
  98. String temp1="";
  99. int random_num=r.nextInt(100);
  100. if(MainActivity.lead.name.equals("刺客")){
  101. temp1=fight_process(MainActivity.lead,mon,main.monster_index);}
  102. else{
  103. if(monster_skill.have_skill[main.monster_index].length>0){
  104. if(random_num<40){
  105. temp1=monster_skill();
  106. p_debuff(a);
  107. turn+=1;
  108. }
  109. else{
  110. temp1=fight_process(MainActivity.lead,mon,main.monster_index);
  111. p_debuff(a);
  112. }}
  113. else{
  114. temp1=fight_process(MainActivity.lead,mon,main.monster_index);
  115. p_debuff(a);
  116. }
  117. }
  118. String temp2="";
  119. if(MainActivity.lead.nowhp>0&&mon.nowhp>0){
  120. if(!MainActivity.lead.name.equals("刺客")){
  121. temp2=fight_process(MainActivity.lead,mon,main.monster_index);}
  122. else{
  123. if(monster_skill.have_skill[main.monster_index].length>0){
  124. if(random_num<30){
  125. temp2=monster_skill();
  126. if(a.nowhp<=0){
  127. a.nowhp=0;
  128. MainActivity.back=0;
  129. timer.cancel();
  130. main.second=false;
  131. main.first=false;
  132. MainActivity.player.release();
  133. Intent intent = new Intent(fight.this, die.class);
  134. startActivity(intent);
  135. }
  136. turn+=1;
  137. }
  138. else{
  139. temp2=fight_process(MainActivity.lead,mon,main.monster_index);
  140. p_debuff(a);
  141. }}
  142. else{
  143. temp2=fight_process(MainActivity.lead,mon,main.monster_index);
  144. p_debuff(a);
  145. }
  146. }}
  147. text+=temp1;
  148. text+=temp2;
  149. }
  150. });
  151. handler=new Handler(){
  152. @Override
  153. public void handleMessage(Message msg) {
  154. super.handleMessage(msg);
  155. if (msg.what==0){
  156. set_text();
  157. set_humanhp();
  158. set_monhp();
  159. set_humanmp();
  160. change();
  161. }
  162. }
  163. };
  164. timer = new Timer();
  165. timer.schedule(new TimerTask() {
  166. @Override
  167. public void run() {
  168. handler.sendEmptyMessage(0);
  169. }
  170. },0,5);
  171. }
  172. private void set_text(){
  173. textView.setText(text);
  174. }
  175. private void change(){
  176. monster_agress.setText(String.valueOf(mon.get_aggress()));
  177. monster_defend.setText(String.valueOf(mon.get_defend()));
  178. monster_lucky.setText(String.valueOf(mon.get_lucky()));
  179. }
  180. private void set_lead(){
  181. int level=MainActivity.lead.level;
  182. lead_name.setText(MainActivity.lead.get_name());
  183. String slevel="lv"+String.valueOf(level);
  184. int agress=a.get_aggress();
  185. int defend=a.get_defend();
  186. int lucky=a.get_lucky();
  187. lead_agress.setText(String.valueOf(agress));
  188. lead_defend.setText(String.valueOf(defend));
  189. lead_lucky.setText(String.valueOf(lucky));
  190. lead_level.setText(slevel);
  191. }
  192. private void set_monster(){
  193. String slevel="lv";
  194. int level=main.monster_level;
  195. int i=main.monster_index;
  196. slevel+=String.valueOf(level);
  197. String temp="";
  198. if(monster_skill.have_skill[i].length>0){
  199. for(int index=0;index<monster_skill.have_skill[i].length;index++){
  200. temp+=monster_skill.skill_names[monster_skill.have_skill[i][index]];
  201. temp+="\n";
  202. }
  203. skill.setText(temp);
  204. }
  205. monster_level.setText(slevel);
  206. monster_name.setText(event_box.monsters[main.monster_index]);
  207. monster_words.setText(initmonster.monster_words[main.monster_index]);
  208. monster_agress.setText(String.valueOf(mon.get_aggress()));
  209. monster_defend.setText(String.valueOf(mon.get_defend()));
  210. monster_lucky.setText(String.valueOf(mon.get_lucky()));
  211. }
  212. public String monster_skill(){
  213. int i=main.monster_index;
  214. int len=monster_skill.have_skill[i].length;
  215. Random r=new Random();
  216. int next_num=r.nextInt(len);
  217. String temp= monster_effect(monster_skill.have_skill[i][next_num],monster_skill.skill_index[monster_skill.have_skill[i][next_num]],a,mon,monster_skill.skill_value[monster_skill.have_skill[i][next_num]]);
  218. return temp;
  219. }
  220. public String monster_effect(int nu,int ind,person a,monster b,int value){
  221. String temp1=event_box.monsters[main.monster_index];
  222. temp1+="使用了";
  223. num+=1;
  224. temp1+=monster_skill.skill_names[nu];
  225. temp1+=",";
  226. if(ind==0){
  227. value-=a.get_defend();
  228. temp1+="对你造成了";
  229. temp1+=String.valueOf(value);
  230. temp1+="点伤害!\n";
  231. a.nowhp-=value;
  232. if(a.nowhp<0){
  233. a.nowhp=0;
  234. Intent intent = new Intent(fight.this, MainActivity.class);
  235. startActivity(intent);
  236. }
  237. }
  238. if(ind==1){
  239. a.nowhp-=value;
  240. temp1+="对你造成了";
  241. temp1+=String.valueOf(value);
  242. temp1+="点伤害!\n";
  243. if(a.nowhp<0){
  244. a.nowhp=0;
  245. Intent intent = new Intent(fight.this, die.class);
  246. startActivity(intent);
  247. }
  248. }
  249. if(ind==2) {
  250. temp1 += "为自身回复了";
  251. temp1 += String.valueOf(value);
  252. temp1 += "点血量!\n";
  253. b.nowhp += value;
  254. if (b.nowhp > b.hp) {
  255. b.nowhp = b.hp;
  256. }
  257. }
  258. if(ind==3){
  259. temp1+="提升了自身";
  260. temp1+=String.valueOf(value);
  261. temp1+="点攻击力!\n";
  262. int temp=b.get_aggress()+value;
  263. b.set_aggress(temp);
  264. }
  265. if(ind==4){
  266. temp1+="提升了自身";
  267. temp1+=String.valueOf(value);
  268. temp1+="点防御力!\n";
  269. int temp=b.get_defend()+value;
  270. b.set_defend(temp);
  271. }
  272. if(ind==5){
  273. temp1+="提升了自身";
  274. temp1+=String.valueOf(value);
  275. temp1+="点幸运值!\n";
  276. int temp=b.get_lucky()+value;
  277. b.set_lucky(temp);
  278. }
  279. if(ind==6){
  280. temp1+="对你造成了";
  281. temp1+=String.valueOf(value);
  282. temp1+="点伤害,回复了自身";
  283. temp1+=String.valueOf(value);
  284. temp1+="点生命值!\n";
  285. a.nowhp-=value;
  286. b.nowhp+=value;
  287. if(a.nowhp<0){
  288. a.nowhp=0;
  289. Intent intent = new Intent(fight.this, die.class);
  290. startActivity(intent);
  291. }
  292. if (b.nowhp > b.hp) {
  293. b.nowhp = b.hp;
  294. }
  295. }
  296. if(ind==7){
  297. temp1+="提升了自身";
  298. temp1+=String.valueOf(value);
  299. temp1+="%攻击力!\n";
  300. int temp=b.get_aggress()*(100+value)/100;
  301. b.set_aggress(temp);
  302. }
  303. if(ind==8){
  304. temp1+="给你施加了debuff:每回合失去";
  305. temp1+=String.valueOf(value);
  306. temp1+="%生命值!\n";
  307. debuff de=new debuff(monster_skill.skill_names[nu],3,value,monster_skill.lasting_time[main.monster_index],monster_skill.image_index[nu]);
  308. a.pdebuff.add(de);
  309. LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams(20, 20);
  310. NumImageView iv1 = new NumImageView(fight.this);
  311. layoutParams1.setMargins(0, 0, 10, 0);
  312. iv1.setImageResource(debuff.debufflist[de.index]);
  313. iv1.setNum(de.turn);
  314. ll4.addView(iv1);
  315. iv1.setOnClickListener(new View.OnClickListener() {
  316. @Override
  317. public void onClick(View v) {
  318. final AlertDialog.Builder normalDialog =
  319. new AlertDialog.Builder(fight.this);
  320. normalDialog.setTitle(de.name);
  321. String temp1="每回合失去";
  322. temp1+=de.value;
  323. temp1+="%的生命值";
  324. normalDialog.setMessage(temp1);
  325. normalDialog.show();
  326. ;}});
  327. }
  328. if(ind==9){
  329. temp1+="降低了你";
  330. temp1+=String.valueOf(value);
  331. temp1+="%防御力!\n";
  332. int temp=a.get_defend()*(100-value)/100;
  333. a.set_defend(temp);
  334. }
  335. if(ind==10){
  336. temp1+="对你造成了两次伤害!\n";
  337. a.nowhp-=2*(b.aggress-a.defend);
  338. }
  339. if(ind==11){
  340. temp1+="提升了自身";
  341. temp1+=String.valueOf(value);
  342. temp1+="%的防御力!\n";
  343. b.defend=(100+value)/100*b.defend;
  344. }
  345. if(ind==12){
  346. temp1+="对你造成了";
  347. temp1+=String.valueOf(value);
  348. temp1+="%的攻击伤害!\n";
  349. a.nowhp-=value/100*(b.aggress-a.defend);
  350. }
  351. if(ind==13){
  352. temp1+="给你施加了debuff:三回合内不击杀本体,将失去50";
  353. temp1+="%生命值!\n";
  354. debuff de=new debuff(monster_skill.skill_names[nu],4,value,monster_skill.lasting_time[nu],monster_skill.image_index[nu]);
  355. a.pdebuff.add(de);
  356. LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams(20, 20);
  357. NumImageView iv1 = new NumImageView(fight.this);
  358. layoutParams1.setMargins(0, 0, 10, 0);
  359. iv1.setImageResource(debuff.debufflist[de.index]);
  360. iv1.setNum(de.turn);
  361. ll4.addView(iv1);
  362. iv1.setOnClickListener(new View.OnClickListener() {
  363. @Override
  364. public void onClick(View v) {
  365. final AlertDialog.Builder normalDialog =
  366. new AlertDialog.Builder(fight.this);
  367. normalDialog.setTitle(de.name);
  368. String temp=String.valueOf(monster_skill.lasting_time[nu]);
  369. temp+="回合后失去";
  370. temp+="50%的生命值";
  371. normalDialog.setMessage(temp);
  372. normalDialog.show();
  373. ;}});
  374. }
  375. return temp1;
  376. }
  377. public String fight_process(person a,monster b,int index){
  378. String process="";
  379. int agressa=a.get_aggress();
  380. int defenda=a.get_defend();
  381. int magica=a.get_magic();
  382. int luckya=a.get_lucky();
  383. int agressb=b.get_aggress();
  384. int defendb=b.get_defend();
  385. num+=1;
  386. int magicb=b.get_magic();
  387. int luckyb=b.get_lucky();
  388. Random r = new Random();
  389. int random1=r.nextInt(100);
  390. if(!a.name.equals("刺客")){
  391. if(turn %2==0){
  392. if(random1<luckya){
  393. process+="你往旁边一躲,险之又险地闪避了";
  394. process+=event_box.monsters[index];
  395. process+="的攻击!\n";
  396. }
  397. else{
  398. int damage=agressb-defenda;
  399. if(damage<0){
  400. damage=0;
  401. }
  402. a.nowhp-=damage;
  403. if(a.nowhp<=0){
  404. a.nowhp=0;
  405. MainActivity.back=0;
  406. timer.cancel();
  407. main.second=false;
  408. main.first=false;
  409. MainActivity.player.release();
  410. Intent intent = new Intent(fight.this, die.class);
  411. startActivity(intent);
  412. }
  413. String temp =String.valueOf(damage);
  414. process+=event_box.monsters[index];
  415. process+="上前攻击,对你";
  416. process+="造成了";
  417. process+=temp;
  418. process+="点伤害!\n";}
  419. }
  420. else{
  421. if(random1<luckyb){
  422. process+=event_box.monsters[index];
  423. process+="往旁边一躲,一下子闪避了你";
  424. process+="的攻击!\n";
  425. }
  426. else{
  427. int damage=agressa-defendb;
  428. if(damage<0){
  429. damage=0;
  430. }
  431. mon.nowhp-=damage;
  432. if(mon.nowhp<=0){
  433. mon.nowhp=0;
  434. timer.cancel();
  435. String temp="你战胜了(lv";
  436. temp+=String.valueOf(mon.level);
  437. temp+=")";
  438. MainActivity.lead.nowexp+=b.exp;
  439. MainActivity.lead.gold+=b.gold;
  440. MainActivity.lead.nowhp=a.nowhp;
  441. temp+=event_box.monsters[main.monster_index];
  442. temp+=",你获得了";
  443. temp+=String.valueOf(b.exp);
  444. temp+="点经验值和";
  445. temp+=String.valueOf(b.gold);
  446. temp+="个金币。\n";
  447. main.text+=temp;
  448. main.refresh=true;
  449. main.index+=1;
  450. if(main.second==true){
  451. main.first=false;
  452. main.second=false;
  453. Intent intent = new Intent(fight.this, stage.class);
  454. startActivity(intent);
  455. }
  456. else{
  457. Intent intent = new Intent(fight.this, main.class);
  458. startActivity(intent);}
  459. }
  460. String temp =String.valueOf(damage);
  461. process+="你上前攻击,对";
  462. process+=event_box.monsters[index];
  463. process+="造成了";
  464. process+=temp;
  465. process+="点伤害!\n";}
  466. }}
  467. else{if(turn %2!=0){
  468. if(random1<luckya){
  469. process+="你往旁边一躲,险之又险地闪避了";
  470. process+=event_box.monsters[index];
  471. process+="的攻击!\n";
  472. }
  473. else{
  474. int damage=agressb-defenda;
  475. if(damage<0){
  476. damage=0;
  477. }
  478. a.nowhp-=damage;
  479. if(a.nowhp<=0){
  480. a.nowhp=0;
  481. MainActivity.back=0;
  482. main.second=false;
  483. main.first=false;
  484. MainActivity.player.release();
  485. timer.cancel();
  486. Intent intent = new Intent(fight.this,die.class);
  487. startActivity(intent);
  488. }
  489. String temp =String.valueOf(damage);
  490. process+=event_box.monsters[index];
  491. process+="上前攻击,对你";
  492. process+="造成了";
  493. process+=temp;
  494. process+="点伤害!\n";}
  495. }
  496. else{
  497. if(random1<luckyb){
  498. process+=event_box.monsters[index];
  499. process+="往旁边一躲,一下子闪避了你";
  500. process+="的攻击!\n";
  501. }
  502. else{
  503. int damage=agressa-defendb;
  504. if(damage<0){
  505. damage=0;
  506. }
  507. mon.nowhp-=damage;
  508. if(mon.nowhp<=0){
  509. mon.nowhp=0;
  510. timer.cancel();
  511. String temp="你战胜了(lv";
  512. temp+=String.valueOf(mon.level);
  513. temp+=")";
  514. MainActivity.lead.nowexp+=b.exp;
  515. MainActivity.lead.gold+=b.gold;
  516. MainActivity.lead.nowhp=a.nowhp;
  517. temp+=event_box.monsters[main.monster_index];
  518. temp+=",你获得了";
  519. temp+=String.valueOf(b.exp);
  520. temp+="点经验值和";
  521. temp+=String.valueOf(b.gold);
  522. temp+="个金币。\n";
  523. main.text+=temp;
  524. main.index+=1;
  525. main.refresh=true;
  526. if(main.second==true){
  527. main.first=false;
  528. main.second=false;
  529. Intent intent = new Intent(fight.this, stage.class);
  530. startActivity(intent);
  531. }
  532. else{
  533. Intent intent = new Intent(fight.this, main.class);
  534. startActivity(intent);}
  535. }
  536. String temp =String.valueOf(damage);
  537. process+="你上前攻击,对";
  538. process+=event_box.monsters[index];
  539. process+="造成了";
  540. process+=temp;
  541. process+="点伤害!\n";}
  542. }}
  543. turn +=1;
  544. return process;
  545. }
  546. private void set_humanhp(){
  547. String temp=String.valueOf(a.nowhp);
  548. temp+="/";
  549. temp+=String.valueOf(a.hp);
  550. lead_hp.setText(temp);
  551. int progress=a.nowhp*100/a.hp;
  552. progressbar2.setProgress(progress);
  553. }
  554. private void set_humanmp(){
  555. String temp=String.valueOf(a.nowmagic);
  556. temp+="/";
  557. temp+=String.valueOf(a.get_magic());
  558. lead_mp.setText(temp);
  559. int progress=a.nowmagic*100/a.get_magic();
  560. progressbar3.setProgress(progress);
  561. }
  562. private void get_pet(){
  563. Random r=new Random();
  564. int rand=r.nextInt(100);
  565. if(rand<15){
  566. int num=r.nextInt(10);
  567. int qu=0;
  568. if(num<5){
  569. qu=1;
  570. }
  571. if(num>5&&num<8){
  572. qu=2;
  573. }
  574. if(num>8){
  575. qu=3;
  576. }
  577. String temp="同时你获得了从怪物身上掉落的一枚怪物蛋,你摇了摇头,收了起来。\n";
  578. main.text+=temp;
  579. int i=main.monster_index;
  580. pets mypet=new pets(initpets.names[i],initpets.attribute[i][0],initpets.attribute[i][1],initpets.attribute[i][2],initpets.attribute[i][3],initpets.attribute[i][4],
  581. initpets.attribute[i][5],initpets.attribute[i][6],initpets.attribute[i][7],qu);
  582. MainActivity.lead.have_pets.add(mypet);
  583. }
  584. }
  585. private void set_monhp(){
  586. String temp=String.valueOf(mon.nowhp);
  587. temp+="/";
  588. temp+=String.valueOf(mon.hp);
  589. monster_hp.setText(temp);
  590. int progress=mon.nowhp*100/mon.hp;
  591. progressbar1.setProgress(progress);
  592. }
  593. private void set_consume(int i){
  594. LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams(100, 100);
  595. NumImageView iv1 = new NumImageView(fight.this);
  596. layoutParams1.setMargins(0, 0, 0, 0);
  597. iv1.setImageResource(consumables.myconsumeList[i]);
  598. iv1.setNum(MainActivity.lead.have_consume[i]);
  599. ll2.addView(iv1);
  600. iv1.setOnClickListener(new View.OnClickListener() {
  601. @Override
  602. public void onClick(View v) {
  603. Random r =new Random();
  604. int random_num=r.nextInt(100);
  605. MainActivity.lead.have_consume[i]-=1;
  606. int type=consumables.con_types[i];
  607. if(type==0){
  608. a.nowhp+=consumables.con_value[i];
  609. if(a.nowhp>a.hp){
  610. a.nowhp=a.hp;
  611. }
  612. }
  613. if(type==1){
  614. a.nowmagic+=consumables.con_value[i];
  615. if(a.nowmagic>a.magic){
  616. a.nowmagic=a.magic;
  617. }
  618. }
  619. String temp="你使用了";
  620. temp+=consumables.con_names[i];
  621. temp+=",";
  622. if(MainActivity.lead.have_consume[i]==0) {
  623. ll2.removeView(iv1);
  624. }
  625. iv1.setNum(MainActivity.lead.have_consume[i]);
  626. temp+="你";
  627. temp+=consumables.introductions[i];
  628. temp+="\n";
  629. if(MainActivity.lead.name.equals("刺客")){
  630. turn+=1;
  631. }
  632. String temp2="";
  633. if(monster_skill.have_skill[main.monster_index].length>0){
  634. if(random_num<30){
  635. temp2=monster_skill();
  636. turn+=1;
  637. }
  638. else{
  639. temp2=fight_process(a,mon,main.monster_index);
  640. p_debuff(a);
  641. }}
  642. else{
  643. temp2=fight_process(a,mon,main.monster_index);
  644. p_debuff(a);
  645. }
  646. if(!MainActivity.lead.name.equals("刺客")){
  647. turn+=1;
  648. }
  649. text+=temp;
  650. text+=temp2;
  651. }});
  652. }
  653. private void set_skill(int index) {
  654. LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
  655. ImageView iv1 = new ImageView(fight.this);
  656. int i=MainActivity.lead.skills[index];
  657. layoutParams1.setMargins(120, 0, 0, 0);
  658. iv1.setImageResource(initskills.myskillList[i]);
  659. iv1.setLayoutParams(layoutParams1);
  660. ll1.addView(iv1);
  661. iv1.setOnClickListener(new View.OnClickListener() {
  662. @Override
  663. public void onClick(View v) {
  664. Random r=new Random();
  665. int random_num=r.nextInt(40);
  666. if(a.nowmagic<skills.skill_mp[i]){
  667. String temp="你没有足够的魔法值!";
  668. Toast toast = Toast.makeText(fight.this, temp, Toast.LENGTH_SHORT);
  669. toast.setGravity(Gravity.CENTER, 0, 0);
  670. toast.show();
  671. }
  672. else{
  673. String temp1=effect(i,skills.skill_index[i],a,mon,skills.skill_mp[i],skills.skill_value[i]);
  674. String temp2="";
  675. if(mon.nowhp<=0){
  676. mon.nowhp=0;
  677. timer.cancel();
  678. String temp="你战胜了(lv";
  679. temp+=String.valueOf(mon.level);
  680. temp+=")";
  681. MainActivity.lead.nowexp+=mon.exp;
  682. MainActivity.lead.gold+=mon.gold;
  683. temp+=event_box.monsters[main.monster_index];
  684. temp+=",你获得了";
  685. temp+=String.valueOf(mon.exp);
  686. temp+="点经验值和";
  687. temp+=String.valueOf(mon.gold);
  688. temp+="个金币。\n";
  689. main.text+=temp;
  690. main.index+=1;
  691. main.refresh=true;
  692. if(main.second==true){
  693. main.first=false;
  694. main.second=false;
  695. Intent intent = new Intent(fight.this, stage.class);
  696. startActivity(intent);
  697. }
  698. else{
  699. Intent intent = new Intent(fight.this, main.class);
  700. startActivity(intent);}}
  701. if(MainActivity.lead.name.equals("刺客")){
  702. turn+=1;
  703. }
  704. if(MainActivity.lead.nowhp>0&&mon.nowhp>0){
  705. if(monster_skill.have_skill[main.monster_index].length>0){
  706. if(random_num<30){
  707. temp2=monster_skill();
  708. p_debuff(a);
  709. turn+=1;
  710. }
  711. else{
  712. temp2=fight_process(a,mon,main.monster_index);
  713. p_debuff(a);
  714. }}
  715. else{
  716. temp2=fight_process(a,mon,main.monster_index);
  717. p_debuff(a);
  718. }}
  719. if(!MainActivity.lead.name.equals("刺客")){
  720. turn+=1;
  721. }
  722. text+=temp1;
  723. text+=temp2;
  724. }}
  725. });
  726. }
  727. public void show(person a,monster b){
  728. }
  729. private void p_debuff(person a ){
  730. String temp="";
  731. if(a.pdebuff.size()==0){
  732. return ;
  733. }
  734. else{
  735. ll4.removeAllViews();
  736. for(debuff i: a.pdebuff){
  737. if(i.type==3){
  738. if(i.turn>0){
  739. a.nowhp-=0.01*i.value*a.hp;
  740. temp="你受到了debuff";
  741. temp+=i.name;
  742. temp+="效果,失去了";
  743. temp+=i.value;
  744. temp+="%的生命值。\n";
  745. text+=temp;
  746. i.turn-=1;
  747. LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams(20, 20);
  748. NumImageView iv1 = new NumImageView(fight.this);
  749. layoutParams1.setMargins(0, 0, 10, 0);
  750. iv1.setImageResource(debuff.debufflist[i.index]);
  751. iv1.setNum(i.turn);
  752. ll4.addView(iv1);
  753. iv1.setOnClickListener(new View.OnClickListener() {
  754. @Override
  755. public void onClick(View v) {
  756. final AlertDialog.Builder normalDialog =
  757. new AlertDialog.Builder(fight.this);
  758. normalDialog.setTitle(i.name);
  759. String temp1="每回合失去";
  760. temp1+=i.value;
  761. temp1+="%的生命值";
  762. normalDialog.setMessage(temp1);
  763. normalDialog.show();
  764. ;}});
  765. if(i.turn==0){
  766. ll4.removeView(iv1);
  767. }
  768. }}
  769. if(i.type==4){
  770. if(i.turn>0){
  771. i.turn-=1;
  772. LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams(20, 20);
  773. NumImageView iv1 = new NumImageView(fight.this);
  774. layoutParams1.setMargins(0, 0, 10, 0);
  775. iv1.setImageResource(debuff.debufflist[i.index]);
  776. iv1.setNum(i.turn);
  777. ll4.addView(iv1);
  778. iv1.setOnClickListener(new View.OnClickListener() {
  779. @Override
  780. public void onClick(View v) {
  781. final AlertDialog.Builder normalDialog =
  782. new AlertDialog.Builder(fight.this);
  783. normalDialog.setTitle(i.name);
  784. String temp=String.valueOf(i.turn);
  785. temp+="回合后失去";
  786. temp+="50%的生命值";
  787. normalDialog.setMessage(temp);
  788. normalDialog.show();
  789. ;}});
  790. if(i.turn==0){
  791. a.nowhp-=0.01*i.value*a.nowhp;
  792. temp="你受到了debuff";
  793. temp+=i.name;
  794. temp+="效果,失去了";
  795. temp+=i.value;
  796. temp+="%的生命值。\n";
  797. text+=temp;
  798. ll4.removeView(iv1);
  799. }}
  800. }
  801. }}
  802. }
  803. public String effect(int nu,int ind,person a,monster b,int mp,int value){
  804. String temp1="你使用了";
  805. num+=1;
  806. temp1+=skills.skill_names[nu];
  807. temp1+=",";
  808. if(ind==0){
  809. value-=b.get_defend();
  810. temp1+="对敌人造成了";
  811. temp1+=String.valueOf(value);
  812. temp1+="点伤害!\n";
  813. b.nowhp-=value;
  814. a.nowmagic-=mp;
  815. }
  816. if(ind==1){
  817. b.nowhp-=value;
  818. temp1+="对敌人造成了";
  819. temp1+=String.valueOf(value);
  820. temp1+="点伤害!\n";
  821. a.nowmagic-=mp;
  822. }
  823. if(ind==2){
  824. temp1+="为自身回复了";
  825. temp1+=String.valueOf(value);
  826. temp1+="点血量!\n";
  827. a.nowhp+=value;
  828. if(a.nowhp>a.hp){
  829. a.nowhp=a.hp;
  830. }
  831. a.nowmagic-=mp;
  832. }
  833. return temp1;
  834. }
  835. private void set(){
  836. for(int i=0;i<2;i++){
  837. if(MainActivity.lead.skills[i]!=-1){
  838. set_skill(i);
  839. }
  840. }
  841. for(int i=0;i<MainActivity.lead.have_consume.length;i++){
  842. if(MainActivity.lead.have_consume[i]!=0){
  843. set_consume(i);
  844. }
  845. }
  846. }
  847. }

下一个功能也是重头戏。我要说的正是酒馆功能。酒馆中可以进行购买装备,技能,以及恢复药剂。对于这些物品的出现是完全随机的,另外每个酒馆只会出现三件装备,三个技能,以及三瓶恢复药剂,买完或没有合适的只能遇到下一个酒馆在做打算。另外,随着等级的升高,其中的装备也会更新换代,变得更加强大。

 

说到装备,就不得不提一下装备的品质机制。在游戏中的装备生成是随机的,品质也是完全随机的。当然这句话所限定的目标是酒馆中的装备。至于为什么我下面会说明。装备品质分为普通,稀有,大师,和传说。同一件装备随着品质不同属性也会不同。在酒馆中购买时,刷出的装备大概率是稀有打下的,大师装备出现的可能则较小,更别说传说装备了。当然,高品质的装备的售价更贵。下面是酒馆的功能代码。

  1. package com.example.dungeonsimulator;
  2. import android.content.Context;
  3. import android.content.Intent;
  4. import android.database.sqlite.SQLiteDatabase;
  5. import android.database.sqlite.SQLiteOpenHelper;
  6. import android.graphics.Color;
  7. import android.media.MediaPlayer;
  8. import android.os.Handler;
  9. import android.os.Message;
  10. import android.util.AttributeSet;
  11. import android.util.Log;
  12. import android.app.Activity;
  13. import android.os.Bundle;
  14. import android.view.Gravity;
  15. import android.view.KeyEvent;
  16. import android.view.ViewGroup;
  17. import android.widget.Button;
  18. import android.view.View;
  19. import android.app.AlertDialog;
  20. import android.widget.EditText;
  21. import android.media.MediaPlayer;
  22. import androidx.appcompat.app.AppCompatActivity;
  23. import android.database.sqlite.SQLiteDatabase;
  24. import android.database.Cursor;
  25. import android.widget.LinearLayout;
  26. import android.widget.TextView;
  27. import android.widget.Toast;
  28. import android.graphics.Canvas;
  29. import android.widget.ImageView;
  30. import java.util.Timer;
  31. import java.util.TimerTask;
  32. import android.content.DialogInterface;
  33. public class pub extends AppCompatActivity {
  34. MediaPlayer player=null;
  35. Timer timer;
  36. Button leave;
  37. LinearLayout ll1,ll2,ll3,ll4,ll5,ll6;
  38. TextView textview2,gold;
  39. @Override
  40. public boolean onKeyDown(int keyCode, KeyEvent event){
  41. if(keyCode== android.view.KeyEvent.KEYCODE_BACK)
  42. return true;
  43. return super.onKeyDown(keyCode, event);
  44. }
  45. @Override
  46. protected void onCreate(Bundle savedInstanceState) {
  47. super.onCreate(savedInstanceState);
  48. setContentView(R.layout.pub);
  49. ll1=findViewById(R.id.linear1);
  50. ll2=findViewById(R.id.linear2);
  51. ll3=findViewById(R.id.linear3);
  52. ll4=findViewById(R.id.linear4);
  53. ll5=findViewById(R.id.linear5);
  54. gold=findViewById(R.id.gold);
  55. textview2=findViewById(R.id.textView2);
  56. set_weapon();
  57. set_weapon();
  58. set_weapon();
  59. set_skill();
  60. set_skill();
  61. set_skill();
  62. set_consume();
  63. set_consume();
  64. set_consume();
  65. leave=findViewById(R.id.leave);
  66. leave.setOnClickListener(new View.OnClickListener() {
  67. @Override
  68. public void onClick(View v) {
  69. timer.cancel();
  70. main.refresh=true;
  71. String temp="你离开了酒馆。\n";
  72. main.index+=1;
  73. main.text+=temp;
  74. Intent intent = new Intent(pub.this, main.class);
  75. startActivity(intent);
  76. }
  77. });
  78. Handler handler=new Handler(){
  79. @Override
  80. public void handleMessage(Message msg) {
  81. super.handleMessage(msg);
  82. if (msg.what==0){
  83. set_gold();
  84. }
  85. }
  86. };
  87. timer = new Timer();
  88. timer.schedule(new TimerTask() {
  89. @Override
  90. public void run() {
  91. handler.sendEmptyMessage(0);
  92. }
  93. },0,4);
  94. }
  95. private void set_gold(){
  96. int num=MainActivity.lead.gold;
  97. gold.setText(String.valueOf(num));
  98. }
  99. private void set_weapon() {
  100. LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
  101. int i=event_box.choose_weapon();
  102. int qu=event_box.choose_quality();
  103. int gold=initweapon.weapon_values[i][4];
  104. ImageView iv1 = new ImageView(pub.this);
  105. iv1.setLayoutParams(layoutParams1);
  106. layoutParams1.setMargins(0, 0, 0, 0);
  107. iv1.setImageResource(initweapon.myweaponList[i]);
  108. ll1.addView(iv1);
  109. iv1.setOnClickListener(new View.OnClickListener() {
  110. @Override
  111. public void onClick(View v) {
  112. textview2.setText("酒馆老板:我们家的装备自然是最好的!");
  113. final AlertDialog.Builder normalDialog =
  114. new AlertDialog.Builder(pub.this);
  115. normalDialog.setTitle(initweapon.weapon_names[i]+"("+initweapon.quality[qu]+")");
  116. String temp="属性:\n";
  117. for(int j=0;j<4;j++){
  118. temp+=initweapon.attributes[j];
  119. temp+=":+";
  120. double temp1=initweapon.weapon_values[i][j]*initweapon.indexes[qu];
  121. int a=(int)temp1;
  122. temp+=a;
  123. temp+="\n";
  124. }
  125. temp+=initweapon.attributes[4];
  126. temp+=":";
  127. double temp1=initweapon.weapon_values[i][4]*initweapon.indexes[qu];
  128. int a=(int)temp1;
  129. temp+=a;
  130. temp+="金币\n";
  131. if(MainActivity.lead.weapon[initweapon.weapon_values[i][6]]!=-1){
  132. int index=MainActivity.lead.weapon[initweapon.weapon_values[i][6]];
  133. double temp3=index/4;
  134. int temp4=(int)temp3;
  135. temp+="\n";
  136. temp+="目前装备:\n";
  137. temp+=initweapon.weapon_names[index/4];
  138. temp+="(";
  139. temp+=initweapon.quality[MainActivity.lead.weapon[initweapon.weapon_values[index/4][6]]%4];
  140. temp+=")";
  141. temp+="\n";
  142. for(int j=0;j<4;j++){
  143. temp+=initweapon.attributes[j];
  144. temp+=":+";
  145. double temp2=initweapon.weapon_values[temp4][j]*initweapon.indexes[MainActivity.lead.weapon[initweapon.weapon_values[index/4][6]]%4];
  146. int b=(int)temp2;
  147. temp+=b;
  148. temp+="\n";
  149. }}
  150. normalDialog.setMessage(temp);
  151. normalDialog.setPositiveButton("购买", new DialogInterface.OnClickListener() {
  152. @Override
  153. public void onClick(DialogInterface dialog, int which) {
  154. if(MainActivity.lead.gold<a){
  155. String a="你没有足够的金币!";
  156. Toast toast = Toast.makeText(pub.this, a, Toast.LENGTH_SHORT);
  157. toast.setGravity(Gravity.CENTER, 0, 0);
  158. toast.show();
  159. }
  160. else{
  161. MainActivity.lead.gold-=a;
  162. String temp="你购买了";
  163. temp+=initweapon.weapon_names[i];
  164. temp+="(";
  165. temp+=initweapon.quality[qu];
  166. temp+=")";
  167. MainActivity.lead.have_weapons[4*i+qu]+=1;
  168. temp+="*1!\n";
  169. ll1.removeView(iv1);
  170. Toast toast = Toast.makeText(pub.this, temp, Toast.LENGTH_SHORT);
  171. toast.setGravity(Gravity.CENTER, 0, 0);
  172. toast.show();}
  173. }
  174. });
  175. normalDialog.setNegativeButton("确定", null);
  176. normalDialog.show();
  177. }
  178. });
  179. // 显示
  180. }
  181. private void set_skill() {
  182. LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
  183. int i=event_box.choose_skill();
  184. int gold=skills.skill_buy[i];
  185. ImageView iv1 = new ImageView(pub.this);
  186. layoutParams1.setMargins(0, 0, 0, 0);
  187. iv1.setLayoutParams(layoutParams1);
  188. iv1.setImageResource(initskills.myskillList[i]);
  189. ll4.addView(iv1);
  190. iv1.setOnClickListener(new View.OnClickListener() {
  191. @Override
  192. public void onClick(View v) {
  193. textview2.setText("酒馆老板:我们家的技能自然是最好的!");
  194. final AlertDialog.Builder normalDialog =
  195. new AlertDialog.Builder(pub.this);
  196. normalDialog.setTitle(skills.skill_names[i]);
  197. String temp="技能效果:\n";
  198. temp+= skills.introductions[i];
  199. temp+="\n";
  200. temp+="购入价格:";
  201. temp+=skills.skill_buy[i];
  202. temp+="金币\n";
  203. temp+="\n\n\n\n";
  204. temp+=skills.skill_words[i];
  205. normalDialog.setMessage(temp);
  206. normalDialog.setPositiveButton("购买", new DialogInterface.OnClickListener() {
  207. @Override
  208. public void onClick(DialogInterface dialog, int which) {
  209. if(MainActivity.lead.gold<skills.skill_buy[i]){
  210. String a="你没有足够的金币!";
  211. Toast toast = Toast.makeText(pub.this, a, Toast.LENGTH_SHORT);
  212. toast.setGravity(Gravity.CENTER, 0, 0);
  213. toast.show();
  214. }
  215. else{
  216. MainActivity.lead.gold-=skills.skill_buy[i];
  217. String temp="你购买了";
  218. temp+=skills.skill_names[i];
  219. MainActivity.lead.have_skills[i]+=1;
  220. temp+="*1!\n";
  221. ll4.removeView(iv1);
  222. Toast toast = Toast.makeText(pub.this, temp, Toast.LENGTH_SHORT);
  223. toast.setGravity(Gravity.CENTER, 0, 0);
  224. toast.show();}
  225. }
  226. });
  227. normalDialog.setNegativeButton("确定", null);
  228. normalDialog.show();
  229. }
  230. });
  231. }
  232. private void set_consume() {
  233. LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
  234. int i=event_box.choose_consume();
  235. int gold=consumables.con_buy[i];
  236. ImageView iv1 = new ImageView(pub.this);
  237. layoutParams1.setMargins(0, 0, 0, 0);
  238. iv1.setLayoutParams(layoutParams1);
  239. iv1.setImageResource(consumables.myconsumeList[i]);
  240. ll5.addView(iv1);
  241. iv1.setOnClickListener(new View.OnClickListener() {
  242. @Override
  243. public void onClick(View v) {
  244. textview2.setText("酒馆老板:我们家的消耗品喝下后永远不死!");
  245. final AlertDialog.Builder normalDialog =
  246. new AlertDialog.Builder(pub.this);
  247. normalDialog.setTitle(consumables.con_names[i]);
  248. String temp="消耗品效果:\n";
  249. temp+= consumables.introductions[i];
  250. temp+="\n";
  251. temp+="购入价格:";
  252. temp+=consumables.con_buy[i];
  253. temp+="金币\n";
  254. normalDialog.setMessage(temp);
  255. normalDialog.setPositiveButton("购买", new DialogInterface.OnClickListener() {
  256. @Override
  257. public void onClick(DialogInterface dialog, int which) {
  258. if(MainActivity.lead.gold<consumables.con_buy[i]){
  259. String a="你没有足够的金币!";
  260. Toast toast = Toast.makeText(pub.this, a, Toast.LENGTH_SHORT);
  261. toast.setGravity(Gravity.CENTER, 0, 0);
  262. toast.show();
  263. }
  264. else{
  265. MainActivity.lead.gold-=consumables.con_buy[i];
  266. String temp="你购买了";
  267. temp+=consumables.con_names[i];
  268. MainActivity.lead.have_consume[i]+=1;
  269. temp+="*1!\n";
  270. ll5.removeView(iv1);
  271. Toast toast = Toast.makeText(pub.this, temp, Toast.LENGTH_SHORT);
  272. toast.setGravity(Gravity.CENTER, 0, 0);
  273. toast.show();}
  274. }
  275. });
  276. normalDialog.setNegativeButton("确定", null);
  277. normalDialog.show();
  278. }
  279. });}
  280. }

接下来要介绍的是其中可能发生的其他事件。如发现宝箱事件,大概率可以发现一件装备,但是也有可能宝箱中存在一只怪物。因此,开宝箱并不完全是一件收益事件,也很大概率存在着风险。尤其在缺少血量的时候,更需要主角好好斟酌。这也正是为了游戏的趣味性所添加的。下面是开宝箱的函数代码。

 

  1. if(index==2){
  2. LinearLayout ll=findViewById(R.id.linear);
  3. LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
  4. TextView tv1=new TextView(this);
  5. layoutParams1.setMargins(0,20,0,100);
  6. tv1.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
  7. tv1.setText(event[0]);
  8. tv1.setTextSize(30);
  9. tv1.setLayoutParams(layoutParams1);
  10. tv1.setTextColor(Color.rgb(255, 255, 255));
  11. ll.addView(tv1);
  12. LinearLayout.LayoutParams layoutParams2 = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
  13. TextView tv2=new TextView(this);
  14. tv2.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
  15. layoutParams2.setMargins(0,10,0,150);
  16. tv2.setText(event[1]);
  17. tv2.setTextSize(20);
  18. tv2.setLayoutParams(layoutParams2);
  19. tv2.setTextColor(Color.rgb(255, 255, 255));
  20. ll.addView(tv2);
  21. LinearLayout.LayoutParams layoutParams3 = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
  22. Button bt1=new Button(this);
  23. bt1.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
  24. layoutParams3.setMargins(0,10,0,80);
  25. bt1.setText(event[2]);
  26. bt1.setTextSize(20);
  27. bt1.setLayoutParams(layoutParams3);
  28. bt1.setTextColor(Color.rgb(0, 0, 0));
  29. ll.addView(bt1);
  30. LinearLayout.LayoutParams layoutParams4 = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
  31. Button bt2=new Button(this);
  32. bt2.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
  33. layoutParams4.setMargins(0,10,0,50);
  34. bt2.setText(event[3]);
  35. bt2.setTextSize(20);
  36. bt2.setLayoutParams(layoutParams4);
  37. bt2.setTextColor(Color.rgb(0, 0, 0));
  38. ll.addView(bt2);
  39. Random r=new Random();
  40. int random=r.nextInt(100);
  41. if(random<80){
  42. bt1.setOnClickListener(new View.OnClickListener() {
  43. @Override
  44. public void onClick(View v) {
  45. main.index+=1;
  46. int num=event_box.choose_weapon();
  47. int quality=event_box.choose_quality();
  48. String qu=initweapon.quality[quality];
  49. String name=initweapon.weapon_names[num];
  50. name+="(";
  51. name+=qu;
  52. name+=")";
  53. MainActivity.lead.have_weapons[4*num+quality]+=1;
  54. String temp="你打开了宝箱,很快宝箱发出了耀眼的光芒,同时你发现宝箱的底部存在着一件宝物,\n";
  55. temp+="(你获得了";
  56. temp+=name;
  57. temp+="*1)。\n";
  58. text+=temp;
  59. ll.removeView(bt1);
  60. ll.removeView(bt2);
  61. ll.removeView(tv1);
  62. ll.removeView(tv2);
  63. refresh=true;
  64. }
  65. });
  66. }
  67. else{
  68. bt1.setOnClickListener(new View.OnClickListener() {
  69. @Override
  70. public void onClick(View v) {
  71. main.index+=1;
  72. String temp="你打开了宝箱,很快宝箱发出了诡异的光芒,你发现宝箱里竟是一只";
  73. monster_level=com.example.dungeonsimulator.event_box.choose_level();
  74. monster_index=com.example.dungeonsimulator.event_box.choose_monster();
  75. String a=event_box.monsters[monster_index];
  76. temp+=a;
  77. temp+=",你不得已与其开始了战斗。\n";
  78. timer.cancel();
  79. Intent intent = new Intent(main.this, fight.class);
  80. startActivity(intent);
  81. text+=temp;
  82. }
  83. });
  84. }
  85. bt2.setOnClickListener(new View.OnClickListener() {
  86. @Override
  87. public void onClick(View v) {
  88. escape_box();
  89. ll.removeView(bt1);
  90. ll.removeView(bt2);
  91. ll.removeView(tv1);
  92. ll.removeView(tv2);
  93. refresh=true;
  94. }
  95. });
  96. }

这次就先介绍到这里吧,要是有人催更我会接着往下更新的,谢谢大家啦,点点赞哈哈,有需要可以加q交流~q:1076051806

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/699420
推荐阅读
相关标签
  

闽ICP备14008679号