public void Bomb_CheckEncodeAndDecode() { Tick t1 = new Tick(); List <Excuse> eList = new List <Excuse> { CreateExcuse(10), CreateExcuse(11), CreateExcuse(12) }; List <WhiningTwine> wtList = new List <WhiningTwine> { CreateTwine(20), CreateTwine(21), CreateTwine(22) }; Bomb b1 = new Bomb(1, eList, wtList, t1); Assert.AreEqual(1, b1.CreatorId); Assert.AreSame(eList, b1.Excuses); Assert.AreSame(wtList, b1.Twine); Assert.AreSame(t1, b1.BuiltOnTick); ByteList bytes = new ByteList(); b1.Encode(bytes); Bomb b2 = Bomb.Create(bytes); Assert.AreEqual(b1.CreatorId, b2.CreatorId); Assert.AreEqual(b1.Excuses.Count, b2.Excuses.Count); Assert.AreEqual(b1.Twine.Count, b2.Twine.Count); Assert.AreEqual(b1.BuiltOnTick.LogicalClock, b2.BuiltOnTick.LogicalClock); Assert.AreEqual(b1.BuiltOnTick.HashCode, b2.BuiltOnTick.HashCode); bytes.Clear(); b1.Encode(bytes); bytes.GetByte(); // Read one byte, which will throw the length off try { b2 = Bomb.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } bytes.Clear(); b1.Encode(bytes); bytes.Add((byte)100); // Add a byte bytes.GetByte(); // Read one byte, which will make the ID wrong try { b2 = Bomb.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } }
private void CmdCreateBomb(Vector3 position) { var cellForBomb = position.ToCell(); var bomb = new Bomb(cellForBomb, bangDistance, 2, 1) { ActionAfterDeath = () => TargetOnDetonateBomb(connectionToClient), BangController = new BangController() }; var field = gameObject.scene.GetField(); if (field != null) { field.AddElement(cellForBomb, bomb); } RpcOnPlantBomb(bomb.Create()); }
protected override void UpdateInput() { // Queue up direction keys foreach (Direction direction in Enum.GetValues(typeof(Direction))) { KeyCode keyCode = direction.GetKeyCode(); if (Input.GetKeyDown(keyCode)) { pushedKeyQueue.Enqueue(keyCode); } } // Process keys when not moving if (!isMoving && pushedKeyQueue.Any()) { KeyCode pushedKeyCode = pushedKeyQueue.Dequeue(); Direction direction = pushedKeyCode.GetDirection(); push(direction); } // Suicide if (Input.GetKeyDown(KeyCode.Escape)) { level.gameOver(); } // Action Key if (Input.GetKeyDown(KeyCode.Space)) { if (bombCount > 0 && !(level.GetObjectInPosition(position) is Bomb)) { bombCount -= 1; Bomb.Create(position, bombFuse, bombLength); } } }
// Update is called once per frame void Update() { float angle = transform.rotation.eulerAngles.z; if (isTurn && !isAir) { // TODO : GetKeyDown will be changed GetKey if (Input.GetKeyDown(KeyCode.LeftArrow)) { if (angle < 285 && angle >= 270 || wallDirection == 1 || tankData.m_iRemainMove <= 0) { } } if (Input.GetKeyDown(KeyCode.RightArrow)) { if (angle > 75 && angle <= 90 || wallDirection == 2 || tankData.m_iRemainMove <= 0) { audio.Stop(); audio.clip = tankData.m_audioClips[clip_move + 1]; audio.loop = false; audio.Play(0); } } if (Input.GetKey(KeyCode.LeftArrow)) { if (renderer.flipX == true) { renderer.flipX = false; } if (angle < 285 && angle >= 270 || wallDirection == 1 || tankData.m_iRemainMove <= 0) { if (audio.clip != tankData.m_audioClips[clip_move + 1]) { audio.Stop(); audio.clip = tankData.m_audioClips[clip_move + 1]; audio.loop = false; audio.Play(0); } return; } float remainGauge = (float)(--tankData.m_iRemainMove) / tankData.m_iMaxMove * smallGaugeWidth; SetGaugeFill(moveGauge.transform.Find("Fill").GetComponent <RectTransform>(), remainGauge); transform.Translate(new Vector3(-Time.deltaTime * moveSpeed, 0, 0), Space.Self); CalculateAngle(); cameraController.FollowCamera(transform.position); if (audio.clip != tankData.m_audioClips[clip_move]) { audio.Stop(); audio.clip = tankData.m_audioClips[clip_move]; audio.loop = true; audio.Play(0); } } else if (Input.GetKey(KeyCode.RightArrow)) { if (renderer.flipX == false) { renderer.flipX = true; } if (angle > 75 && angle <= 90 || wallDirection == 2 || tankData.m_iRemainMove <= 0) { if (audio.clip != tankData.m_audioClips[clip_move + 1]) { audio.Stop(); audio.clip = tankData.m_audioClips[clip_move + 1]; audio.loop = false; audio.Play(0); } return; } float remainGauge = (float)(--tankData.m_iRemainMove) / tankData.m_iMaxMove * smallGaugeWidth; SetGaugeFill(moveGauge.transform.Find("Fill").GetComponent <RectTransform>(), remainGauge); transform.Translate(new Vector3(Time.deltaTime * moveSpeed, 0, 0), Space.Self); CalculateAngle(); cameraController.FollowCamera(transform.position); if (audio.clip != tankData.m_audioClips[clip_move]) { audio.Stop(); audio.clip = tankData.m_audioClips[clip_move]; audio.loop = true; audio.Play(0); } } else { if (audio.clip) { audio.Stop(); audio.clip = null; } } if (Input.GetKey(KeyCode.UpArrow)) { if (tankData.m_iCurrentAngle >= tankData.m_iMaxAngle) { return; } // angle change sound tankData.m_iCurrentAngle++; } if (Input.GetKey(KeyCode.DownArrow)) { if (tankData.m_iCurrentAngle <= tankData.m_iMinAngle) { return; } // angle change sound tankData.m_iCurrentAngle--; } if (Input.GetKey(KeyCode.Space)) { RectTransform fill = powerGauge.transform.Find("Fill").GetComponent <RectTransform>(); int current = tankData.m_iShootingValue; if (tankData.m_isShooting == false) { tankData.m_isShooting = true; tankData.m_iShootingValue = 0; RectTransform lastFill = powerGauge.transform.Find("LastFill").GetComponent <RectTransform>(); float gauge = fill.sizeDelta.x; if (gauge > 40) { SetGaugeFill(lastFill, gauge); } else { SetGaugeFill(lastFill, fill.GetComponent <Image>().fillAmount * 40); } } else { if (++current > maxPower) { current = maxPower; } tankData.m_iShootingValue = current; SetGaugeFill(fill, current * bigGaugeWidth / maxPower); } } else { if (tankData.m_isShooting) { tankData.m_isShooting = false; isTurn = false; // shoot bomb Tool.EmitWeaponSound(tankData.m_audioClips[clip_fire + tankData.m_iBombType]); cameraController.StopCameraSmoothMove(); float shootAngle = (renderer.flipX ? angle + tankData.m_iCurrentAngle : 180 + angle - tankData.m_iCurrentAngle); Bomb bomb = Bomb.Create(collider.bounds.center, shootAngle, tankData.m_iShootingValue, tankData.m_audioClips[clip_bomb + tankData.m_iBombType], (renderer.flipX ? 1 : -1)); bomb.GetComponent <SpriteRenderer>().sprite = Resources.Load <Sprite>("Images/UI/Weapons/" + tankData.GetTankPath() + "/" + tankData.m_iBombType); bomb.radius = tankData.m_iBombRadius[tankData.m_iBombType]; bomb.remain = tankData.m_iBombCount[tankData.m_iBombType]; cameraController.FollowCamera(bomb.transform.position, true); RectTransform lastFill = powerGauge.transform.Find("LastFill").GetComponent <RectTransform>(); SetGaugeFill(lastFill, 0); } } } if (transform.position.y <= 0) { tankData.m_isDeadTank = true; if (isTurn) { TankController tank = GameDirector.GetNextTank(); if (tank) { tank.NextTurn(1); } else { // Game End } audio.Stop(); isTurn = false; } //gameObject.SetActive(false); renderer.color = new Color(1, 1, 1, 0); return; } int groundHeight = groundController.GetGroundHeight(transform.position); if (groundHeight == int.MinValue) { Debug.Log("can't get ground height " + transform.position); return; } // 움직이다가 땅속으로 빠지는것 방지 if (!isAir && groundHeight < -2 && !((angle > 89 && angle < 91) || (angle > 269 && angle < 271))) { transform.Translate(new Vector3(0, 0.0125f * -groundHeight), Space.World); groundHeight = groundController.GetGroundHeight(transform.position); } if (groundHeight > 0) { if (groundHeight > 30) { cameraController.FollowCamera(transform.position); // angle reset transform.rotation = Quaternion.Euler(new Vector3()); audio.Stop(); } else { CalculateAngle(); } float maxDropHeight = (float)groundHeight / 80 * -1; transform.Translate(new Vector3(0, Mathf.Max(maxDropHeight, -Time.deltaTime * dropSpeed), 0), Space.World); //transform.position = new Vector3(transform.position.x, (float)((int)(transform.position.y * 80)) / 80); isAir = true; return; } if (isAir) { CalculateAngle(); } }