ウルトラマンが怪獣ちゃんを殴る

3552 ワード

一、プロジェクトの説明
    1 
     
     
               1 
              
          10%   30%   60%  
    
       4 
     
     
       
  
        
       :
========  1   ========
(aa   ,  :100)
	    ,   b1   ,     :80
	    ,   b2   ,     :80
	    ,   b3   ,     :80
	    ,   b4   ,     :80
(b1   ,  :80)
	    ,   aa   ,     :95
(b2   ,  :80)
	    ,   aa   ,     :90
(b3   ,  :80)
	    ,   aa   ,     :85
(b4   ,  :80)
	    ,   aa   ,     :80

  
         0,     
            ,     

         、  、            ,   、            
      、          0
二、コード
2.1 AMan.scala
// AMan.scala

package Practice.AplayB

import scala.collection.mutable.ListBuffer
import scala.util.Random

class AMan (val name2:String = "aa", val live2: Int = 100) {
  val name = name2
  var live = live2
  var x: Int = 40 //   
  var y: Int = 100 //   
  var z: Int = 20 //   
  def this(name2: String, live2: Int, x2: Int, y2: Int, z2: Int) {
    this(name2, live2) //    this()
    x = x2
    y = y2
    z = z2
  }
  def playB(lst: List[BMan]): Boolean = {
    var idlist = ListBuffer[Int]()
    for(i  0){
        idlist.append(i)
      }
    }
    if(idlist.length == 0){
      return true
    }
    val t = Random.nextInt(idlist.length) // [0, idlist.length)
    val bd = idlist(t) //    B   
    val d = Random.nextInt(10) //[0, 10)
    if(d < 6){ // 60%     
      lst(bd).live -= x
      if(lst(bd).live < 0){
        lst(bd).live = 0
      }
      printf("\t    ,   %s   ,     :%d
", lst(bd).name, lst(bd).live) } else if(d < 9){ // 30% for(x 0){ x.live -= z if(x.live < 0){ x.live = 0 } printf("\t , %s , :%d
", x.name, x.live) } } } else { // 10% lst(bd).live -= y if(lst(bd).live < 0){ lst(bd).live = 0 } printf("\t , %s , :%d
", lst(bd).name, lst(bd).live) } false } }
2.2 BMan.scala
// BMan.scala

package Practice.AplayB

class BMan (name2: String, live2: Int = 100) {
  val name = name2
  var live = live2
  var x = 10
  def this(name2: String, live2: Int, x2: Int) {
    this(name2, live2)
    x = x2
  }
  def playA(a: AMan): Boolean = {
    if(a.live <= 0){
      return true
    }
    a.live -= x
    if(a.live < 0){
      a.live = 0
    }
    printf("\t    ,   %s   ,     :%d
", a.name, a.live) false } }
2.3 Test.scala
// Test.scala

package Practice.AplayB

import scala.util.control.Breaks._

object Test {
  def main(args: Array[String]): Unit = {
    var aa = new AMan("aa", 100)
    var b1 = new BMan("b1", 100, 5)
    var b2 = new BMan("b2", 100, 5)
    var b3 = new BMan("b3", 100, 5)
    var b4 = new BMan("b4", 100, 5)
    val lst = List(b1, b2, b3, b4)
    var k = 1
    breakable(
      while(true){
        printf("========  %d   ========
", k) k += 1 println(aa.name + " ", " :" + aa.live) if(aa.live > 0){ aa.playB(lst) } for(x 0){ x.playA(aa) } } if(aa.live == 0){ println(" ") break() } var tmp = false for(x 0){ tmp = true } } if(tmp == false){ println(" ") break() } println() } ) } }