void Start()
    {
        minescript = GameObject.Find ("ClickBoxVein").GetComponent<Mine> ();
        uiscript = GameObject.Find ("UIManager").GetComponent<UIManagerScript> ();

        StartCoroutine (DeathTimer ());
    }
        /// <summary>Takes the remaining content of the stream and deserialze it into the instance.</summary>
        public static Mine.Nullables.MyMessageV1 Deserialize(Stream stream, Mine.Nullables.MyMessageV1 instance)
        {
            while (true)
            {
                int keyByte = stream.ReadByte();
                if (keyByte == -1)
                    break;
                // Optimized reading of known fields with field ID < 16
                switch (keyByte)
                {
                    // Field 1 Varint
                    case 8:
                        instance.FieldA = (int)global::SilentOrbit.ProtocolBuffers.ProtocolParser.ReadUInt64(stream);
                        continue;
                }

                var key = global::SilentOrbit.ProtocolBuffers.ProtocolParser.ReadKey((byte)keyByte, stream);

                // Reading field ID > 16 and unknown field ID/wire type combinations
                switch (key.Field)
                {
                    case 0:
                        throw new global::SilentOrbit.ProtocolBuffers.ProtocolBufferException("Invalid field id: 0, something went wrong in the stream");
                    default:
                        if (instance.PreservedFields == null)
                            instance.PreservedFields = new List<global::SilentOrbit.ProtocolBuffers.KeyValue>();
                        instance.PreservedFields.Add(new global::SilentOrbit.ProtocolBuffers.KeyValue(key, global::SilentOrbit.ProtocolBuffers.ProtocolParser.ReadValueBytes(stream, key)));
                        break;
                }
            }

            return instance;
        }
Example #3
0
        public void TestDetonate1WithAllMinesInsideFieldDoesNotDetonateUnnecessaryCells()
        {
            int n = 5;
            IGameboard board = this.GenerateGameboard(n);
            board[1, 1] = new Mine(MineRadius.MineRadiusOne);
            board.Detonate(new Position(1, 1));
            bool patternOneDetonatesMoreThanFiveCells = false;
            int i = 0;
            int j = 0;
            for (; i < n; i++)
            {
                for (; j < n; j++)
                {
                    if (
                        ((i != 1 && j != 1) &&
                            (i != 0 && j != 0) &&
                            (i != 0 && j != 2) &&
                            (i != 2 && j != 2) &&
                            (i != 2 && j != 0))
                            && board[i, j].Exploded)
                    {
                        patternOneDetonatesMoreThanFiveCells = true;
                        break;
                    }
                }

                if (patternOneDetonatesMoreThanFiveCells)
                {
                    break;
                }
            }

            Assert.IsFalse(patternOneDetonatesMoreThanFiveCells, String.Format("Mine at {0}, {1} was detonated.", i, j));
        }
Example #4
0
        public void TestDetonate1With2MinesInsideFieldDoesNotDetonateUnnecessaryCells()
        {
            int n = 5;
            IGameboard board = this.GenerateGameboard(n);
            board[0, 0] = new Mine(MineRadius.MineRadiusOne);
            board.Detonate(new Position(0, 0));
            int i = 0;
            int j = 0;
            bool moreThanOneCellIsDetonated = false;
            for (; i < n; i++)
            {
                for (; j < n; j++)
                {
                    if (i != 0 && j != 0 && i != 1 && j != 1 && !board[i, j].Exploded)
                    {
                        moreThanOneCellIsDetonated = true;
                        break;
                    }
                }

                if (moreThanOneCellIsDetonated)
                {
                    break;
                }
            }

            Assert.IsFalse(moreThanOneCellIsDetonated, String.Format("Cell at {0}, {1} was detonated", i, j));
        }
Example #5
0
        public void TestDetonate1With2MinesInsideFieldDetonates2Cells()
        {
            IGameboard board = this.GenerateGameboard(5);
            board[0, 0] = new Mine(MineRadius.MineRadiusOne);
            board.Detonate(new Position(0, 0));
            bool twoCellsAreDetonated = board[0, 0].Exploded && board[1, 1].Exploded;

            Assert.IsTrue(twoCellsAreDetonated);
        }
Example #6
0
 private static void ExplosionFive(char[,] field, Mine mine)
 {
     for (int row = mine.X - 2; row <= mine.X + 2; row++)
     {
         for (int col = mine.Y - 2; col <= mine.Y + 2; col++)
         {
             if (IsInsideField(field, row, col))
             {
                 field[row, col] = DetonatedCell;
             }
         }
     }
 }
        protected override Location CreateLocation(string locationTypeString, string locationName)
        {
            Location location = null;

            switch (locationTypeString)
            {
                case "forest": location = new Forest(locationName); break;
                case "mine": location = new Mine(locationName); break;
                default: return base.CreateLocation(locationTypeString, locationName);
            }

            return location; 
        }
Example #8
0
        public void TestDetonate1WithAllMinesInsideFieldDetonates5Cells()
        {
            IGameboard board = this.GenerateGameboard(5);
            board[1, 1] = new Mine(MineRadius.MineRadiusOne);
            board.Detonate(new Position(1, 1));
            bool patternOneDetonatesFiveCells =
                    board[1, 1].Exploded &&
                    board[0, 0].Exploded &&
                    board[0, 2].Exploded &&
                    board[2, 2].Exploded &&
                    board[2, 0].Exploded;

            Assert.IsTrue(patternOneDetonatesFiveCells);
        }
Example #9
0
        public void GenerateRandomCoordinateTest()
        {
            for (int i = 0; i < 100; i++)
            {
                Random     rnd      = new Random();
                Mine       instance = new Mine(rnd);
                Coordinate mine     = instance.GenerateRandomCoordinate(rnd);

                if (mine.X < 2 && mine.Y < 2)
                {
                    Assert.Fail("Less than 2");
                }

                if (mine.X > 6 && mine.Y > 6)
                {
                    Assert.Fail(mine.X.ToString() + " : " + mine.Y.ToString());
                }
            }
        }
Example #10
0
        public void CollisionDetectionTest()
        {
            Mine mine = new Mine(new Random());

            mine.location.X = 3;
            mine.location.Y = 4;

            if (mine.hasCollided(new Coordinate()
            {
                X = 1,
                Y = 1
            }))
            {
                Assert.Fail();
            }

            if (mine.hasCollided(new Coordinate()
            {
                X = 3,
                Y = 1
            }))
            {
                Assert.Fail();
            }

            if (mine.hasCollided(new Coordinate()
            {
                X = 1,
                Y = 4
            }))
            {
                Assert.Fail();
            }

            if (!mine.hasCollided(new Coordinate()
            {
                X = 3,
                Y = 4
            }))
            {
                Assert.Fail();
            }
        }
Example #11
0
        public void TurtleMove_TurtleMovesToMine_Throws()
        {
            Board  gameBoard = TestHelper.GetEmptyBoard(1, 3);
            Mine   mine      = new Mine();
            Turtle turtle    = new Turtle(Direction.North, gameBoard);

            gameBoard.AddGameObject(0, 1, mine);
            gameBoard.AddGameObject(0, 2, turtle);

            try
            {
                turtle.Move();
                throw new Exception("Mine not hit!");
            }
            catch (GameOverException ex)
            {
                Assert.Equal(GameOver.MineHit, ex.GameOver);
            }
        }
Example #12
0
        public void ObsorveIfMine()
        {
            // Arrange
            Board board = new Board(4, 5);
            Point pos   = new Point(2, 2);
            Mine  mine  = new Mine()
            {
                Position = pos
            };

            board[pos] = mine;
            Observer observer = new Observer(board);

            // Act
            IsMine actual = observer.Observe(pos) as IsMine;

            // Assert
            Assert.IsInstanceOfType(actual, typeof(IsMine));
        }
Example #13
0
        private static int GetMinePriority(Mine m)
        {
            var score = m.Id;

            score += m.IsOnline ? 750 : 0;
            score += (int)(DateTime.Now - m.NextCheckTime).TotalHours;

            if (string.IsNullOrWhiteSpace(m.DefaultAccount) || string.IsNullOrWhiteSpace(m.DefaultPassword))
            {
                score = -1;
            }

            if (!m.Offshore)
            {
                score = -1;
            }

            return(score);
        }
        public void LoseToPowerfulGuard()
        {
            var player = new Player {
                Id = 1
            };
            var mine = new Mine
            {
                Army = new Army {
                    Power = 10
                },
                Treasure = new Treasure {
                    Amount = 2
                },
            };

            Interaction.Make(player, mine);
            Assert.AreEqual(true, player.Dead);
            Assert.AreEqual(0, mine.Owner);
            Assert.AreEqual(0, player.Gold);
        }
Example #15
0
	//public void resetSelectedMine(float id, GameObject target)
  public static void resetSelectedMine(Mine mine)
	{
    GameObject target = mine.gameObject;
		float x = target.transform.position.x; 
		float z = target.transform.position.z;
	
		iTween.Stop(target, true);
		Destroy(target);

		GameObject go = (GameObject)Instantiate(_instance.mine, new Vector3(x,0,z),Quaternion.identity);
    Mine newMine = (Mine)go.GetComponent<Mine>();
    newMine.mineName = mine.mineName;

		detonatedMines--;

    if (isReseting && detonatedMines == 0)
    {
      isReseting = false;
    }
  }
Example #16
0
    private void HitMinions(Mine mine, Player player, int minRange, int maxRange)
    {
        var minionsInRadius = this.minionsByPosition
                              .Range(minRange, true, maxRange, true)
                              .SelectMany(m => m.Value)
                              .ToList();

        foreach (var minion in minionsInRadius)
        {
            minion.Health -= mine.Damage;

            if (minion.Health <= 0)
            {
                this.minionsByPosition[minion.XCoordinate].Remove(minion);
                this.orderedMinions.Remove(minion);

                player.Score++;
            }
        }
    }
Example #17
0
    public void ThrowMine(Vector3 direction)
    {
        if (!mineEnabled)
        {
            return;
        }

        Vector3 spawn = transform.position + transform.forward * 1.5f;
        Mine    m     = Instantiate(mine, spawn, Quaternion.identity) as Mine;

        m.originShip        = gameObject;
        m.transform.forward = transform.forward;
        m.GetComponent <Rigidbody>().velocity = rb.velocity;
        m.direction = direction;
        mineEnabled = false;
        if (tag == "Player")
        {
            itemFrameController.RemoveItemIcon();
        }
    }
Example #18
0
    void Start()
    {
        rb       = GetComponent <Rigidbody2D>();
        fsm      = new FSM((int)States._count, (int)Flags._count);
        goldMine = FindObjectOfType <Mine>();
        if (goldMine)
        {
            fsm.SetState((int)States.goToMining);
        }
        else
        {
            fsm.SetState((int)States.idle);
        }

        fsm.SetRelation((int)States.goToMining, (int)Flags.inMine, (int)States.minning);
        fsm.SetRelation((int)States.minning, (int)Flags.OnFullDeposit, (int)States.goToHome);
        fsm.SetRelation((int)States.minning, (int)Flags.OnEmptyMine, (int)States.goToHome);
        fsm.SetRelation((int)States.goToHome, (int)Flags.inHome, (int)States.deposit);
        fsm.SetRelation((int)States.deposit, (int)Flags.OnEmptyDeposit, (int)States.goToMining);
    }
Example #19
0
        private void SeedPlayer(Player player, int offset)
        {
            Coordinate townCenterCoordinate = new Coordinate(offset, offset);
            TownCenter townCenter           = new TownCenter();

            player.AddEntity(townCenter);
            mapController.AddToMap(townCenterCoordinate, townCenter);

            Coordinate mineCoordinate = new Coordinate(offset + 2, offset + 2);
            Mine       mine           = new Mine();

            player.AddEntity(mine);
            mapController.AddToMap(mineCoordinate, mine);

            Coordinate workerCoordinate = new Coordinate(offset + 1, offset + 1);
            Worker     worker           = new Worker();

            player.AddEntity(worker);
            mapController.AddToMap(workerCoordinate, worker);
        }
Example #20
0
        public void TestTokenizeCard()
        {
            // ReSharper disable StringLiteralTypo
            var card = Mine.TokenizeCard(
                "123 Fake Street",
                "Jollywood",
                null,
                "90210",
                "Homer Jay",
                "4112344112344113",
                "123",
                12,
                2013);

            // ReSharper restore StringLiteralTypo
            Assert.AreEqual(card.name, "Homer Jay");
            Assert.AreEqual(card.last_four, "4113");
            Assert.AreEqual(card.expiration_year, 2013);
            Assert.AreEqual(card.expiration_month, 12);
        }
Example #21
0
        public int Do_Powerball_Bet()
        {
            if (Mine == null || Theirs == null)
            {
                throw new InvalidOperationException("Must define Mine and Theirs before betting");
            }

            int multiplier = 1;

            if (Mine.CompareTo(Theirs) == 0)
            {
                multiplier = -1;
                return(WagerAmount * multiplier);
            }
            else
            {
                multiplier = 2;
                return(jackpot);
            }
        }
Example #22
0
        public void TestDetonate4With8MinesInsideFieldDetonates8Cells()
        {
            int        n        = 7;
            IGameboard board    = this.GenerateGameboard(n);
            Position   position = new Position(0, 6);

            board[0, 6] = new Mine(MineRadius.MineRadiusFour);
            board.Detonate(position);
            bool cellsAreDetonated =
                board[0, 4].Exploded == board[0, 5].Exploded &&
                board[0, 5].Exploded == board[0, 6].Exploded &&
                board[0, 6].Exploded == board[1, 4].Exploded &&
                board[1, 4].Exploded == board[1, 5].Exploded &&
                board[1, 5].Exploded == board[1, 6].Exploded &&
                board[1, 6].Exploded == board[2, 5].Exploded &&
                board[2, 5].Exploded == board[2, 6].Exploded &&
                board[2, 6].Exploded == true;

            Assert.IsTrue(cellsAreDetonated);
        }
Example #23
0
    public void DisplayNewLayout()
    {
        DestroyCurrentTiles();
        mineType      = GameData.Instance.playerMineLocations[playerID];
        _currentFloor = GameData.Instance.playerFloors[playerID][GameData.Instance.playerMineLocations[playerID]];

        if (MineRecorder.CheckMineFloorExists(mineType, _currentFloor))
        {
            _tiles         = MineRecorder.GetMineFloor(mineType, _currentFloor);
            _prevTileTypes = MakeCopyOfTileSetTypes(_tiles);
        }
        else
        {
            _tiles         = MineRecorder.CreateMineFloor(mineType, _currentFloor, _gridWidth, _gridHeight);
            _prevTileTypes = MakeCopyOfTileSetTypes(_tiles);
        }
        SetOtherPlayerLocations();
        DrawGrid();
        StartCoroutine(RescanMap());
    }
Example #24
0
    void HandelResearchCanvas(Mine mine)
    {
        int index = mineList.FindIndex(i => i.Name == mine.Name);

//		Debug.Log (index);
        if (minerUpgrade.minerList [index].Unlocked)
        {
            minerUpgrade.ShowResearchCanvas(true);
            minerUpgrade.minerTextList[0].text = "";
            minerUpgrade.minerTextList[1].text = "Owned";
            minerUpgrade.SetResearchText(minerUpgrade.minerList [index]);
        }
        else if (!minerUpgrade.minerList [index].Unlocked)
        {
            minerUpgrade.ShowResearchCanvas(false);
            minerUpgrade.minerTextList[0].text = "$ " + minerUpgrade.minerList[index].Cost;
            minerUpgrade.minerTextList[1].text = "";
            minerUpgrade.SetResearchText(minerUpgrade.minerList [index]);
        }
    }
Example #25
0
    public void FocusAround(Vector3 pos)
    {
        for (int x = -1; x <= 1; x++)
        {
            for (int y = -1; y <= 1; y++)
            {
                for (int z = -1; z <= 1; z++)
                {
                    Mine neighbor = GetMineAtPos(pos + new Vector3(x, y, z));
                    if (neighbor != null)
                    {
                        neighbor.SetFocused(true);
                    }
                }
            }
        }

        lastFocus    = currentFocus;
        currentFocus = pos;
    }
Example #26
0
        private void Explode(Mine closestToExplosion)
        {
            var startOfExplodion = closestToExplosion.XCoordinate - closestToExplosion.Player.Radius;
            var endOfExplodion   = closestToExplosion.XCoordinate + closestToExplosion.Player.Radius;

            var range = this.minions.Range(startOfExplodion, true, endOfExplodion, true).Values.ToList();

            foreach (var minion in range)
            {
                minion.Health -= closestToExplosion.Damage;
                if (minion.Health <= 0)
                {
                    this.minions.Remove(minion.XCoordinate);
                    var player = closestToExplosion.Player;
                    this.topPlayers.Remove(player);
                    player.Score++;
                    this.topPlayers.Add(player);
                }
            }
        }
        protected override Location CreateLocation(string locationTypeString, string locationName)
        {
            Location location = null;

            switch (locationTypeString)
            {
            case "mine":
                location = new Mine(locationName);
                break;

            case "forest":
                location = new Forest(locationName);
                break;

            default:
                location = base.CreateLocation(locationTypeString, locationName);
                break;
            }
            return(location);
        }
        public void BeatWeakGuardAndOwnMine()
        {
            var player = new Player {
                Id = 1
            };
            var mine = new Mine
            {
                Army = new Army {
                    Power = 1
                },
                Treasure = new Treasure {
                    Amount = 2
                },
            };

            Interaction.Make(player, mine);
            Assert.AreEqual(false, player.Dead);
            Assert.AreEqual(player.Id, mine.Owner);
            Assert.AreEqual(2, player.Gold);
        }
Example #29
0
    public void SelectMine(string type)
    {
        Mine m = Mine.IronMine;

        if (type == "ironmine")
        {
            m = Mine.IronMine;
        }
        if (type == "jellymine")
        {
            m = Mine.JellyMine;
        }
        if (type == "coalmine")
        {
            m = Mine.CoalMine;
        }

        gridCreator.SelectMine(m);
        Destroy(gameObject);
    }
Example #30
0
    void LaunchMine(Vector2 direction, Mine.MineTypes mineType)
    {
        if (!_collectedMines.Exists(mineType))
        {
            return;
        }

        if (Time.time - _lastMineLaunchTime < MINE_LAUNCH_COOLDOWN)
        {
            return;
        }

        RaycastHit2D[] hits = Physics2D.RaycastAll(transform.position, (Vector2)direction, MINE_LAUNCH_MIN_DISTANCE);
        for (int i = 0; i < hits.Length; i += 1)
        {
            if (hits [i].collider.GetType() == typeof(EdgeCollider2D))
            {
                return;
            }
        }

        if (direction.magnitude == 0)
        {
            return;
        }

        _lastMineLaunchTime = Time.time;

        GameObject mineObj = Instantiate(MinePrefab, transform.position + (Vector3)direction * 0.75f, Quaternion.identity);

        System.Type typeOfMine = Mine.GetTypeOfMineByIntCode(mineType);
        mineObj.AddComponent(typeOfMine);

        Mine mine = mineObj.GetComponent(typeOfMine) as Mine;

        mine.Spawn(direction, _rb.velocity, _playerIndex);

        _collectedMines.Remove(mineType);
        UpdateInternals();
        GetComponent <AudioSource>().Play();
    }
Example #31
0
    //Wached level and upgrades
    public string ShowInfo(string Collection, string Build)
    {
        if (Collection == "Levels")
        {
            switch (Build)
            {
            case "R":
                return(levelRocket.ToString());

            case "E":
                return(levelElevator.ToString());

            case "F":
                return(levelFactory.ToString());

            case "L":
                return(levelLab.ToString());

            case "M":
                return(levelMine.ToString());
            }
        }
        else if (Collection == "Lab")
        {
            switch (Build)
            {
            case "B":
                return(Bag.ToString());

            case "S":
                return(Speed.ToString());

            case "M":
                return(Mine.ToString());

            case "E":
                return(Energy.ToString());
            }
        }
        return("Error");
    }
Example #32
0
        public int DoBet()
        {
            if (Mine == null || Theirs == null)
            {
                throw new InvalidOperationException("Must define Mine and Theirs before betting");
            }
            if (Theirs.Length == 0)
            {
                return(WagerAmount);
            }

            T highest = Mine;

            foreach (T them in Theirs)
            {
                if (highest.CompareTo(them) < 0)
                {
                    highest = them;
                }
            }

            int numberOfHighest = 0;

            if (Mine.CompareTo(highest) == 0)
            {
                numberOfHighest++;
                foreach (T them in Theirs)
                {
                    if (highest.CompareTo(them) == 0)
                    {
                        numberOfHighest++;
                    }
                }

                return((WagerAmount * Theirs.Length + WagerAmount) / numberOfHighest);
            }
            else
            {
                return(0);
            }
        }
    /// <summary>
    /// Find all deterministic mines and safe tiles of a single iteration
    /// </summary>
    public void FindMinesandSafeTiles()
    {
        List <Vector2Int> newmines = new List <Vector2Int>();

        //Find 'Mine' tiles
        foreach (var item in Closed)
        {
            List <Vector2Int> localmine = new List <Vector2Int>();
            for (int i = 0; i < Operators.Length; i++)
            {
                Vector2Int newpos = item.Key + Operators[i];
                if (Open.ContainsKey(newpos))
                {
                    localmine.Add(newpos);
                }
            }
            if (item.Value == localmine.Count)
            {
                newmines.AddRange(localmine);
            }
        }

        List <Vector2Int> newmines2 = new List <Vector2Int>();

        for (int i = 0; i < newmines.Count; i++)
        {
            Vector2Int current = newmines[i];

            if (Open.Remove(current))
            {
                Mine.Add(current);
                newmines2.Add(current);
            }
        }

        //Find 'Safe' tiles
        for (int i = 0; i < newmines2.Count; i++)
        {
            AddingMineCheck(newmines2[i]);
        }
    }
Example #34
0
        private void ExplodeMine(Mine mine)
        {
            int           radius   = mine.Player.Radius;
            int           min      = mine.XCoordinate - radius;
            int           max      = mine.XCoordinate + radius;
            List <Minion> toDelete = new List <Minion>();

            foreach (var minion in minions.Range(new Minion(min, 1), true, new Minion(max, int.MaxValue), true))
            {
                minion.Health -= mine.Damage;
                if (minion.Health <= 0)
                {
                    toDelete.Add(minion);
                    mine.Player.Score++;
                }
            }
            foreach (var minion in toDelete)
            {
                minions.Remove(minion);
            }
        }
    public void GenerateMines(GameObject[] mines)
    {
        probability = (probability <= 0) ? 1 : probability;

        foreach (GameObject mine in mines)
        {
            Mine mineScript = mine.GetComponent <Mine>();
            if (mineScript != null)
            {
                if (numberOfMines < maxOfMines && Random.Range(0, Mathf.CeilToInt(100 / probability)) == 0 && !mineScript.already)
                {
                    mineScript.isMine = true;
                    numberOfMines++;
                }
                else
                {
                    mineScript.isMine = false;
                }
            }
        }
    }
Example #36
0
    public List <Mine> GetNeighborsOfPoint(Vector3 pos)
    {
        List <Mine> list = new List <Mine> ();

        for (int x = -1; x <= 1; x++)
        {
            for (int y = -1; y <= 1; y++)
            {
                for (int z = -1; z <= 1; z++)
                {
                    Mine neighbor = GetMineAtPos(pos + new Vector3(x, y, z));
                    if (neighbor != null)
                    {
                        list.Add(neighbor);
                    }
                }
            }
        }

        return(list);
    }
Example #37
0
    public void AssignNum(Mine mine)
    {
        int num = GetMineNum(1, 10);

        mine.gameObject.SetActive(false);
        mine.NumText.text = num.ToString();
        AddNumTODB.Add(num);
        TotalMetalNum += num;
        if (MineOpened >= 3)
        {
            OverText.text = "恭喜獲得 " + TotalMetalNum + " 金屬!";
            ClosePanel.SetActive(true);
            MaterialManager.ResetSetMine();
            MaterialManager.ResetFirstMine();
            foreach (int num2 in AddNumTODB)
            {
                Meterial.AddMaterial("Metal", num2);
            }
            Meterial.MineProgress = 0;
        }
    }
Example #38
0
        /// <summary>
        /// Gets a Board instance based on a loaded configuration json (dynamic)
        /// </summary>
        /// <param name="json">dynamic json with game configuration</param>
        /// <param name="board">Board to be loaded</param>
        /// <returns>Loaded Board</returns>
        private Board GetGameSettings(dynamic json)
        {
            Board currentBoard = new Board((int)json.BoardSizeX, (int)json.BoardSizeY, this);

            Turtle turtle = new Turtle((Direction)json.TurtleDirection, currentBoard);
            Exit   exit   = new Exit();

            // Add Turtle
            currentBoard.AddGameObject((int)json.TurtlePosX, (int)json.TurtlePosY, turtle);
            // Add Exit
            currentBoard.AddGameObject((int)json.ExitPosX, (int)json.ExitPosY, exit);

            // Add Mines
            foreach (var item in json.Mines)
            {
                Mine mine = new Mine();
                currentBoard.AddGameObject((int)item.MinePosX, (int)item.MinePosY, mine);
            }

            return(currentBoard);
        }
Example #39
0
    List <Mine> GetRemainingSafeBoxes()
    {
        List <Mine> remaining = new List <Mine> ();

        for (int x = 0; x < Size; x++)
        {
            for (int y = 0; y < Size; y++)
            {
                for (int z = 0; z < Size; z++)
                {
                    Mine mine = GetMineAtPos(new Vector3(x, y, z));
                    if (mine != null && !mine.isExposed && !mine.isMine)
                    {
                        remaining.Add(mine);
                    }
                }
            }
        }

        return(remaining);
    }
        internal static void MakeSureMineHasAccessToVillage(Labyrinth labyrinth, Mine mine, Village village)
        {
            int xFrom, yFrom, xTo, yTo;

            if (mine.LabyrinthCorX >= village.LabyrinthCorX)
            {
                xFrom = village.LabyrinthCorX;
                xTo = mine.LabyrinthCorX;
            }
            else
            {
                xFrom = mine.LabyrinthCorX;
                xTo = village.LabyrinthCorX;
            }

            if (mine.LabyrinthCorY >= village.LabyrinthCorY)
            {
                yFrom = village.LabyrinthCorY;
                yTo = mine.LabyrinthCorY;
            }
            else
            {
                yFrom = mine.LabyrinthCorY;
                yTo = village.LabyrinthCorY;
            }

            for (int i = xFrom; i <= xTo; i++)
            {
                labyrinth.Remove(i, yFrom);
                labyrinth.Remove(i, yTo);
            }

            for (int k = yFrom; k <= yTo; k++)
            {
                labyrinth.Remove(xTo, k);
                labyrinth.Remove(xFrom, k);
            }
        }
Example #41
0
        public static void Explode(char[,] field, Mine mine)
        {
            char mineType = field[mine.X, mine.Y];

            switch (mineType)
            {
                case '1':
                    ExplosionOne(field, mine);
                    break;
                case '2':
                    ExplosionTwo(field, mine);
                    break;
                case '3':
                    ExplosionThree(field, mine);
                    break;
                case '4':
                    ExplosionFour(field, mine);
                    break;
                case '5':
                    ExplosionFive(field, mine);
                    break;
            }
        }
Example #42
0
        private static void ExplosionFour(char[,] field, Mine mine)
        {
            for (int row = mine.X - 2; row <= mine.X + 2; row++)
            {
                for (int col = mine.Y - 2; col <= mine.Y + 2; col++)
                {
                    bool isInUpperLeftCorner = row == mine.X - 2 && col == mine.Y - 2;
                    bool isInBottomLeftCorner = row == mine.X - 2 && col == mine.Y + 2;
                    bool isInUpperRightCorner = row == mine.X + 2 && col == mine.Y - 2;
                    bool isInBottomRightCorner = row == mine.X + 2 && col == mine.Y + 2;

                    if (isInUpperLeftCorner || isInBottomLeftCorner || isInUpperRightCorner || isInBottomRightCorner)
                    {
                        continue;
                    }

                    if (IsInsideField(field, row, col))
                    {
                        field[row, col] = DetonatedCell;
                    }
                }
            }
        }
Example #43
0
 internal override void ShowCard(string s,int x,int y)
 {
     PlayCard a = new PlayCard();
     switch (s)
     {
         case "銅貨":
             a = new Cooper(ShowField, ShowHand, this);
             break;
         case "銀貨":
             a = new Silver(ShowField, ShowHand, this);
             break;
         case "金貨":
             a = new Gold(ShowField, ShowHand, this);
             break;
         case "屋敷":
             a = new Mansion(ShowField, ShowHand, this);
             break;
         case "公領":
             a = new Landtag(ShowField, ShowHand, this);
             break;
         case "属州":
             a = new Province(ShowField, ShowHand, this);
             break;
         case "地下貯蔵庫":
             a = new UndergroundRepository(ShowField, ShowHand, this);
             break;
         case "市場":
             a = new Market(this);
             break;
         case "民兵":
             a = new Militia(ShowField, ShowHand, this);
             break;
         case "鉱山":
             a = new Mine(ShowField, ShowHand, this);
             break;
         case "堀":
             a = new Moat(this);
             break;
         case "鍛冶屋":
             a = new Smithy(this);
             break;
         case "村":
             a = new Village(this);
             break;
         case "木こり":
             a = new Woodcutter(this);
             break;
         case "改築":
             a = new Remodel(this);
             break;
         case "工房":
             a = new Workshop(this);
             break;
     }
     a.Location = new System.Drawing.Point(x,y);
     a.Size = new System.Drawing.Size(70, 110);
     a.Name = s;
     a.SizeMode = PictureBoxSizeMode.StretchImage;
     a.Image = global::dominion.Properties.Resources.back;
     form1.Controls.Add(a);
     a.BringToFront();
     ShowHand.Add(a);
     a.ChangePointPara(880 + 20 * ShowHand.Count, 10 + 120 * num);
     for (int i = 0; i < ShowHand.Count; i++)
     {
         ShowHand[i].Refresh();
     }
     ShowDeck.Refresh();
 }
Example #44
0
 public void RemoveMine(Mine mine)
 {
     _mines.Remove(mine);
 }
Example #45
0
        public void TestDetonate3With6MinesInsideFieldDetonates6Cells()
        {
            int n = 7;
            IGameboard board = this.GenerateGameboard(n);
            Position position = new Position(6, 6);
            board[6, 6] = new Mine(MineRadius.MineRadiusThree);
            board.Detonate(position);
            bool cellsAreDetonated =
                    board[4, 6].Exploded == board[5, 5].Exploded &&
                    board[5, 5].Exploded == board[5, 6].Exploded &&
                    board[5, 6].Exploded == board[6, 4].Exploded &&
                    board[6, 4].Exploded == board[6, 5].Exploded &&
                    board[6, 5].Exploded == board[6, 6].Exploded &&
                    board[6, 6].Exploded == true;

            Assert.IsTrue(cellsAreDetonated);
        }
        /// <summary>Read the VarInt length prefix and the given number of bytes from the stream and deserialze it into the instance.</summary>
        public static Mine.MyMessageV1 DeserializeLengthDelimited(Stream stream, Mine.MyMessageV1 instance)
        {
            long limit = global::SilentOrbit.ProtocolBuffers.ProtocolParser.ReadUInt32(stream);
            limit += stream.Position;
            while (true)
            {
                if (stream.Position >= limit)
                {
                    if (stream.Position == limit)
                        break;
                    else
                        throw new InvalidOperationException("Read past max limit");
                }
                int keyByte = stream.ReadByte();
                if (keyByte == -1)
                    throw new System.IO.EndOfStreamException();
                // Optimized reading of known fields with field ID < 16
                switch (keyByte)
                {
                    // Field 1 Varint
                    case 8:
                        instance.FieldA = (int)global::SilentOrbit.ProtocolBuffers.ProtocolParser.ReadUInt64(stream);
                        continue;
                }

                var key = global::SilentOrbit.ProtocolBuffers.ProtocolParser.ReadKey((byte)keyByte, stream);

                // Reading field ID > 16 and unknown field ID/wire type combinations
                switch (key.Field)
                {
                    case 0:
                        throw new InvalidDataException("Invalid field id: 0, something went wrong in the stream");
                    default:
                        if (instance.PreservedFields == null)
                            instance.PreservedFields = new List<global::SilentOrbit.ProtocolBuffers.KeyValue>();
                        instance.PreservedFields.Add(new global::SilentOrbit.ProtocolBuffers.KeyValue(key, global::SilentOrbit.ProtocolBuffers.ProtocolParser.ReadValueBytes(stream, key)));
                        break;
                }
            }

            return instance;
        }
Example #47
0
 public void MineConstrustor_MustThrowExceptionYIsNegative()
 {
     Mine invalidMine = new Mine(5, -7);
 }
Example #48
0
        public void TestDetonate5WithAllMinesInsideFieldDetonates25Cells()
        {
            int n = 9;
            IGameboard board = this.GenerateGameboard(n);
            Position position = new Position(4, 4);
            board[4, 4] = new Mine(MineRadius.MineRadiusFive);
            board.Detonate(position);
            bool cellsAreDetonated = true;
            for (int i = 2; i <= 6; i++)
            {
                for (int j = 2; j <= 6; j++)
                {
                    if (!board[i, j].Exploded)
                    {
                        cellsAreDetonated = false;
                        break;
                    }
                }

                if (!cellsAreDetonated)
                {
                    break;
                }
            }

            Assert.IsTrue(cellsAreDetonated);
        }
Example #49
0
        public void TestDetonate3WithAllMinesInsideFieldDoesNotDetonateUnnecessaryCells()
        {
            int n = 9;
            IGameboard board = this.GenerateGameboard(n);
            Position position = new Position(4, 4);
            board[4, 4] = new Mine(MineRadius.MineRadiusThree);
            board.Detonate(position);
            bool moreThanThirteenCellsDetonated = false;
            int i = 0;
            int j = 0;
            for (; i < n; i++)
            {
                for (; j < n; j++)
                {
                    if (!((3 <= i) && (i <= 5) && (3 <= j) && (j <= 5)) &&
                        (i != 2 && j != 4) &&
                        (i != 4 && j != 6) &&
                        (i != 6 && j != 4) &&
                        (i != 2 && j != 2))
                    {
                        if (board[i, j].Exploded)
                        {
                            moreThanThirteenCellsDetonated = true;
                            break;
                        }
                    }
                }

                if (moreThanThirteenCellsDetonated)
                {
                    break;
                }
            }

            Assert.IsFalse(moreThanThirteenCellsDetonated, String.Format("A cell was detonated at {0}, {1}", i, j));
        }
Example #50
0
 public void MineConstrustor_CreateNewMine()
 {
     Mine mine = new Mine(2, 6);
     Assert.AreEqual(2, mine.X);
     Assert.AreEqual(6, mine.Y);
 }
Example #51
0
        public void TestDetonate4WithAllMinesInsideFieldDetonates21Cells()
        {
            int n = 7;
            IGameboard board = this.GenerateGameboard(n);
            Position position = new Position(3, 3);
            board[3, 3] = new Mine(MineRadius.MineRadiusFour);
            board.Detonate(position);
            bool cellsAreDetonated = true;
            for (int i = 2; i <= 4; i++)
            {
                for (int j = 1; j <= 5; j++)
                {
                    if (!board[i, j].Exploded)
                    {
                        cellsAreDetonated = false;
                        break;
                    }
                }

                if (!cellsAreDetonated)
                {
                    break;
                }
            }

            cellsAreDetonated = cellsAreDetonated &&
                    board[1, 2].Exploded == board[1, 3].Exploded &&
                    board[1, 3].Exploded == board[1, 4].Exploded &&
                    board[1, 4].Exploded == board[5, 2].Exploded &&
                    board[5, 2].Exploded == board[5, 3].Exploded &&
                    board[5, 3].Exploded == board[5, 4].Exploded &&
                    board[5, 4].Exploded == true;

            Assert.IsTrue(cellsAreDetonated);
        }
 /// <summary>Helper: put the buffer into a MemoryStream before deserializing</summary>
 public static Mine.Nullables.MyMessageV1 Deserialize(byte[] buffer, Mine.Nullables.MyMessageV1 instance)
 {
     using (var ms = new MemoryStream(buffer))
         Deserialize(ms, instance);
     return instance;
 }
Example #53
0
        public void TestDetonate5WithAllMinesInsideFieldDoesNotDetonateUnnecessaryCells()
        {
            int n = 9;
            IGameboard board = this.GenerateGameboard(n);
            Position position = new Position(4, 4);
            board[4, 4] = new Mine(MineRadius.MineRadiusFive);
            board.Detonate(position);
            bool cellsAreDetonated = false;
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (!((2 <= i) && (i <= 6) && (2 <= j) && (j <= 6)))
                    {
                        if (board[i, j].Exploded)
                        {
                            cellsAreDetonated = true;
                            break;
                        }
                    }
                }

                if (cellsAreDetonated)
                {
                    break;
                }
            }

            Assert.IsFalse(cellsAreDetonated);
        }
Example #54
0
    private int previousScore = 0; // The score in the previous frame.

    #endregion Fields

    #region Methods

    void Awake()
    {
        // Setting up the reference.
        playerControl = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerControl>();
        mine = GameObject.Find ("mine").GetComponent<Mine> ();
    }
Example #55
0
        public void TestDetonate4With8MinesInsideFieldDetonates8Cells()
        {
            int n = 7;
            IGameboard board = this.GenerateGameboard(n);
            Position position = new Position(0, 6);
            board[0, 6] = new Mine(MineRadius.MineRadiusFour);
            board.Detonate(position);
            bool cellsAreDetonated =
                    board[0, 4].Exploded == board[0, 5].Exploded &&
                    board[0, 5].Exploded == board[0, 6].Exploded &&
                    board[0, 6].Exploded == board[1, 4].Exploded &&
                    board[1, 4].Exploded == board[1, 5].Exploded &&
                    board[1, 5].Exploded == board[1, 6].Exploded &&
                    board[1, 6].Exploded == board[2, 5].Exploded &&
                    board[2, 5].Exploded == board[2, 6].Exploded &&
                    board[2, 6].Exploded == true;

            Assert.IsTrue(cellsAreDetonated);
        }
Example #56
0
        /// <summary>
        /// Creates a new card based on how many cards have already been made.
        /// </summary>
        /// <param name="card">
        /// The name of the card to be created.
        /// </param>
        /// <returns>
        /// The new created card.
        /// </returns>
        public static Card CreateCard(CardName card)
        {
            Contract.Requires(card != CardName.Backside & card != CardName.Empty);

            Contract.Ensures(Contract.Result<Card>().Name == card);

            Card c;
            switch (card)
            {
                case CardName.Copper:
                    c = new Copper();
                    break;
                case CardName.Silver:
                    c = new Silver();
                    break;
                case CardName.Gold:
                    c = new Gold();
                    break;
                case CardName.Curse:
                    c = new Curse();
                    break;
                case CardName.Estate:
                    c = new Estate();
                    break;
                case CardName.Duchy:
                    c = new Duchy();
                    break;
                case CardName.Province:
                    c = new Province();
                    break;
                case CardName.Gardens:
                    c = new Gardens();
                    break;
                case CardName.Cellar:
                    c = new Cellar();
                    break;
                case CardName.Chapel:
                    c = new Chapel();
                    break;
                case CardName.Chancellor:
                    c = new Chancellor();
                    break;
                case CardName.Village:
                    c = new Village();
                    break;
                case CardName.Woodcutter:
                    c = new Woodcutter();
                    break;
                case CardName.Workshop:
                    c = new Workshop();
                    break;
                case CardName.Feast:
                    c = new Feast();
                    break;
                case CardName.Moneylender:
                    c = new Moneylender();
                    break;
                case CardName.Remodel:
                    c = new Remodel();
                    break;
                case CardName.Smithy:
                    c = new Smithy();
                    break;
                case CardName.ThroneRoom:
                    c = new ThroneRoom();
                    break;
                case CardName.CouncilRoom:
                    c = new CouncilRoom();
                    break;
                case CardName.Festival:
                    c = new Festival();
                    break;
                case CardName.Laboratory:
                    c = new Laboratory();
                    break;
                case CardName.Library:
                    c = new Library();
                    break;
                case CardName.Market:
                    c = new Market();
                    break;
                case CardName.Mine:
                    c = new Mine();
                    break;
                case CardName.Adventurer:
                    c = new Adventurer();
                    break;
                case CardName.Bureaucrat:
                    c = new Bureaucrat();
                    break;
                case CardName.Militia:
                    c = new Militia();
                    break;
                case CardName.Spy:
                    c = new Spy();
                    break;
                case CardName.Thief:
                    c = new Thief();
                    break;
                case CardName.Witch:
                    c = new Witch();
                    break;
                case CardName.Moat:
                    c = new Moat();
                    break;
                default:
                    throw new NotImplementedException("Tried to create a card that was not implemented when CardFactory was last updated.");
            }

            c.Initialize(card, CardsMade[card]);
            CardsMade[card] += 1;
            createdCards.Add(c, true);
            return c;
        }
Example #57
0
 public void MineConstrustor_MustThrowExceptionXIsNegative()
 {
     Mine invalidMine = new Mine(-2, 2);
 }
Example #58
0
        public static void DropMine(Car sender)
        {
            Mine tempMine = new Mine();
            if (sender.LastFire >= tempMine.ReloadTime)
            {
                tempMine.Initialize();
                tempMine.LoadContent();

                mines.Add(tempMine);
                mines[mines.Count - 1].Drop(sender.Position, sender.Driver);

                //Set the last fire to 0
                sender.LastFire = 0;
            }
        }
Example #59
0
 public void MineConstrustor_MustThrowExceptionYIsBiggerThan10()
 {
     Mine invalidMine = new Mine(5, 12);
 }
Example #60
0
        public void TestDetonate4WithAllMinesInsideFieldDoesNotDetonateUnnecessaryCells()
        {
            int n = 9;
            IGameboard board = this.GenerateGameboard(n);
            Position position = new Position(4, 4);
            board[4, 4] = new Mine(MineRadius.MineRadiusFour);
            board.Detonate(position);
            bool moreThan21CellsAreDetonated = false;
            int i = 0;
            int j = 0;
            for (; i < n; i++)
            {
                for (; j < n; j++)
                {
                    if (!((2 <= i) && (i <= 6) && (2 <= j) && (j <= 6)) ||
                            (i == 2 && j == 2) ||
                            (i == 2 && j == 6) ||
                            (i == 6 && j == 6) ||
                            (i == 6 && j == 2))
                    {
                        if (board[i, j].Exploded)
                        {
                            moreThan21CellsAreDetonated = false;
                            break;
                        }
                    }
                }

                if (!moreThan21CellsAreDetonated)
                {
                    break;
                }
            }

            Assert.IsFalse(moreThan21CellsAreDetonated);
        }