public void PercentageAddsTo100() { var obj = new DiskAttributes(0, 0, 0); var result = obj.PercentageFree + obj.PercentageFilled; Assert.AreEqual(100, result); }
public void UsedPercentage() { var obj = new DiskAttributes(150, 400, 200); Assert.AreEqual(50, obj.PercentageFilled); }
public GameObject GetDisk(int round) { GameObject disk; if (free.Count != 0) { disk = free[0]; //used.Add(free[0]); free.Remove(disk); //disk.SetActive(true); } else { disk = GameObject.Instantiate(Resources.Load("Prefabs/disk", typeof(GameObject))) as GameObject; disk.AddComponent <DiskAttributes>(); disk.AddComponent <Rigidbody>(); //used.Add(disk.GetComponent<DiskAttributes>()); } //根据不同round设置diskAttributes的值 //随意的旋转角度 disk.transform.localEulerAngles = new Vector3(-rand.Next(20, 40), 0, 0); DiskAttributes attri = disk.GetComponent <DiskAttributes>(); attri.score = rand.Next(1, 4); //由分数来决定速度、颜色、大小 attri.speedX = (rand.Next(1, 5) + attri.score + round) * 0.2f; attri.speedY = (rand.Next(1, 5) + attri.score + round) * 0.2f; if (attri.score == 3) { disk.GetComponent <Renderer>().material.color = Color.red; disk.transform.localScale += new Vector3(-0.5f, 0, -0.5f); } else if (attri.score == 2) { disk.GetComponent <Renderer>().material.color = Color.green; disk.transform.localScale += new Vector3(-0.2f, 0, -0.2f); } else if (attri.score == 1) { disk.GetComponent <Renderer>().material.color = Color.blue; } //飞碟可从四个方向飞入(左上、左下、右上、右下) int direction = rand.Next(1, 5); //print(attri.score); //print(direction); //direction = 3; if (direction == 1) { disk.transform.Translate(Camera.main.ScreenToWorldPoint(new Vector3(0, Camera.main.pixelHeight * 1.5f, 8))); attri.speedY *= -1; } else if (direction == 2) { disk.transform.Translate(Camera.main.ScreenToWorldPoint(new Vector3(0, Camera.main.pixelHeight * 0f, 8))); } else if (direction == 3) { disk.transform.Translate(Camera.main.ScreenToWorldPoint(new Vector3(Camera.main.pixelWidth, Camera.main.pixelHeight * 1.5f, 8))); attri.speedX *= -1; attri.speedY *= -1; } else if (direction == 4) { disk.transform.Translate(Camera.main.ScreenToWorldPoint(new Vector3(Camera.main.pixelWidth, Camera.main.pixelHeight * 0f, 8))); attri.speedX *= -1; } used.Add(disk); disk.SetActive(true); Debug.Log("generate disk"); return(disk); }