JAVA遊戲編程01

來源:互聯網
上載者:User
 

編程

public class Project01 {
/**
  * @param args
  */
public static void main(String[] args) {
  // TODO 自動產生方法存根
     int Hp=0;
     int x=0;
     int y=0;
     boolean begin = true;
     System.out.println("遊戲開始之前 Hp="+Hp+" x="+x+" y="+y);
     if(begin==true){
      x=10;
      y=10;
      Hp=100;
     }
     System.out.println("遊戲開始之後 Hp="+Hp+" x="+x+" y="+y);
}
}

public class Project02 {
/**
  * @param args
  */
public static void main(String[] args) {
  // TODO 自動產生方法存根
      String type = "AK-47";
      int attactValue =0;
      int change=0;
      System.out.println("選擇槍支之前,槍支類型為: "+type+"  該槍的攻擊值是:"+attactValue);
      change =2;
      if (change==1){
       attactValue =30;
       type="M4";
              
      }
      if (change==2){
       attactValue=20;
       type="B31";
      }
      System.out.println("選擇槍支之後,槍支類型為:"+type+"  該槍的攻擊值是:"+attactValue);
}
}

public class Project03 {
/**
  * @param args
  */
public static void main(String[] args) {
  // TODO 自動產生方法存根
      int distance=15;
      int heroExp=0;
      int herox=10;
      int enemyx=30;
      int enemyHP=100;
      String attactState="進入攻擊狀態";
      
      
      if ((enemyx-herox)<distance){
       attactState="進入攻擊狀態";
       heroExp+=5;
       enemyHP-=10;
      }
      System.out.println("敵人位置改變之前,攻擊狀態:"+attactState);
      System.out.println("敵人位置改變之前,玩家經驗值:"+heroExp);
      System.out.println("敵人位置改變之前,敵人血值:"+enemyHP);
      enemyx-=10;
      if((enemyx-herox)<distance){
       attactState="進入攻擊狀態";
       heroExp +=5;
       enemyHP-=10;
      }
      System.out.println("--------------------------------------------------------");
      System.out.println("敵人位置改變之後,攻擊狀態:"+attactState);
      System.out.println("敵人位置改變之後,玩家經驗值:"+heroExp);
      System.out.println("敵人位置改變之後,敵人血值:"+enemyHP);
}
}

public class Project04 {
/**
  * @param args
  */
public static void main(String[] args) {
  // TODO 自動產生方法存根
      int HP=100;
      System.out.println("HP="+HP);
      if (HP>0){
       System.out.println("遊戲進行中");
      }else{
       System.out.println("遊戲結束");
      }
      HP -=110;
      System.out.println("----------------------------------------");
      System.out.println("HP變換之後 HP= "+HP);
      if(HP>0){
       System.out.println("遊戲進行中");
      }
      else{
       System.out.println("遊戲結束");
      }
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.