示例#1
0
        public GameTurn GetObjectTurn(GridObjectType objectType)
        {
            GameTurn turn;

            switch (objectType)
            {
            case GridObjectType.X:
                turn = GameTurn.Player1;
                break;

            case GridObjectType.O:
                if (Mode == GameMode.PlayerVsPlayer)
                {
                    turn = GameTurn.Player2;
                }
                else
                {
                    turn = GameTurn.Ai;
                }
                break;

            default:
                throw new NotImplementedException();
            }

            return(turn);
        }
        public void SetWinner(GameTurn winner, GridObjectType winnerObjectType)
        {
            switch (winner)
            {
            case GameTurn.None:
                _turnText.text = "Draw";
                break;

            case GameTurn.Player1:
                _turnText.text = "Player 1 won!";
                break;

            case GameTurn.Player2:
                _turnText.text = "Player 2 won!";
                break;

            case GameTurn.Ai:
                _turnText.text = "AI won!";
                break;

            default:
                throw new NotImplementedException();
            }

            _turnText.color = GetColor(winnerObjectType);
        }
        public void SetTurn(GameTurn turn, GridObjectType turnObjectType)
        {
            switch (turn)
            {
            case GameTurn.None:
                _turnText.text = string.Empty;
                break;

            case GameTurn.Player1:
                _turnText.text = "Player 1's turn";
                break;

            case GameTurn.Player2:
                _turnText.text = "Player 2's turn";
                break;

            case GameTurn.Ai:
                _turnText.text = "AI's turn";
                break;

            default:
                throw new NotImplementedException();
            }

            _turnText.color = GetColor(turnObjectType);
        }
    public void Reset()
    {
        bool fail = true;

        //Clear Local Wire
        if (localWire.Count >= 3)
        {
            GridObject endPoint = gridManager.GetCell(localWire[localWire.Count - 1]);
            if (endPoint != null)
            {
                GridObjectType endPointType = endPoint.ObjectType;
                if (endPointType == GridObjectType.Gate || endPointType == GridObjectType.Output)
                {
                    foreach (GameObject o in localGameObjects)
                    {
                        Wire_Visualiser v = o.GetComponent <Wire_Visualiser>();
                        v.StartPulsing();
                    }
                    completedWires.Add(new VisualWire(localWire[1], localGameObjects));
                    fail = false;
                }
            }
        }

        if (fail)
        {
            ClearLocalPath();
        }

        localWire          = null;
        localGameObjects   = null;
        isShowingLocalWire = false;
    }
        public void Reset(GameTurn turn, GridObjectType turnObjectType)
        {
            while (_xPool.OldestActive)
            {
                _xPool.OldestActive.Despawn();
            }
            while (_oPool.OldestActive)
            {
                _oPool.OldestActive.Despawn();
            }

            SetTurn(turn, turnObjectType);
        }
        public GameView(GameTurn turn, GridObjectType turnObjectType, Text turnText, Button[] gridButtons, Button quitButton, Button resetButton, PoolObject xPrefab, PoolObject oPrefab)
        {
            _turnText    = turnText;
            _gridButtons = gridButtons;
            _quitButton  = quitButton;
            _resetButton = resetButton;

            int poolSize = Mathf.CeilToInt(_gridButtons.Length / 2.0F);

            _xPool = new Pool(xPrefab);
            _xPool.Instantiate(poolSize);

            _oPool = new Pool(oPrefab);
            _oPool.Instantiate(poolSize);

            Reset(turn, turnObjectType);
        }
    private GridObject SelectGridObject(GridObjectType type)
    {
        if (type == GridObjectType.Hazard)
        {
            List <Hazard> availableHazards = new List <Hazard>();
            for (int i = 0; i < gridObjectPrefabs.Length; i++)
            {
                if (gridObjectPrefabs[i] is Hazard)
                {
                    availableHazards.Add(gridObjectPrefabs[i] as Hazard);
                }
            }

            int selector = Random.Range(0, availableHazards.Count - 1);
            if (VerboseConsole)
            {
                Debug.Log("Selected a Hazard.");
            }
            return(availableHazards[selector]);
        }
        else if (type == GridObjectType.Phenomena)
        {
            List <Phenomena> availablePhenomena = new List <Phenomena>();
            for (int i = 0; i < gridObjectPrefabs.Length; i++)
            {
                if (gridObjectPrefabs[i] is Phenomena)
                {
                    availablePhenomena.Add(gridObjectPrefabs[i] as Phenomena);
                }
            }

            int selector = Random.Range(0, availablePhenomena.Count - 1);
            if (VerboseConsole)
            {
                Debug.Log("Selected a Phenomenon.");
            }
            return(availablePhenomena[selector]);
        }
        else
        {
            return(null);
        }
    }
        public Color GetColor(GridObjectType turnObjectType)
        {
            Color color;

            switch (turnObjectType)
            {
            case GridObjectType.X:
                color = Color.red;
                break;

            case GridObjectType.O:
                color = Color.blue;
                break;

            default:
                color = Color.white;
                break;
            }

            return(color);
        }
        public void PlaceAt(int x, int y, GridObjectType objectType)
        {
            Pool poolToUse;

            switch (objectType)
            {
            case GridObjectType.X:
                poolToUse = _xPool;
                break;

            case GridObjectType.O:
                poolToUse = _oPool;
                break;

            default:
                poolToUse = null;
                break;
            }

            PoolObject objectPlaced = poolToUse.Spawn();

            objectPlaced.transform.SetParent(_gridButtons[x + y * 3].transform, false);
        }
示例#10
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        EditorGUILayout.Space();

        grid = (Grid)target;

        if (grid.HasGrid)
        {
            EditorGUILayout.BeginHorizontal();

            _selectedGridObjectType =
                (GridObjectType)EditorGUILayout.Popup((int)_selectedGridObjectType, EnumHelper.GetObjectTypes(), GUILayout.Width(250));

            if (_selectedGridObjectType == GridObjectType.OilField)
            {
                _selectedIntValue = EditorGUILayout.IntField(_selectedIntValue);
            }

            EditorGUILayout.EndHorizontal();

            for (int x = 0; x < (int)grid.SizeX; x++)
            {
                EditorGUILayout.BeginHorizontal();
                for (int y = 0; y < (int)grid.SizeY; y++)
                {
                    string buttonString = "";
                    if (grid[x, y].ContainedObject == null)
                    {
                        buttonString = "";
                    }
                    else
                    {
                        switch (grid[x, y].ContainedObject.name)
                        {
                        case "Rocket":
                            buttonString = "R";
                            break;

                        case "OilField":
                            buttonString = "O";
                            break;

                        case "Blocker":
                            buttonString = "X";
                            break;

                        case "Empty":
                            buttonString = "";
                            break;

                        default:
                            buttonString = "?";
                            break;
                        }
                    }

                    if (GUILayout.Button(buttonString, GUILayout.Height(40), GUILayout.Width(40)))
                    {
                        if (grid[x, y].ContainedObject == null)
                        {
                            grid[x, y].ContainedObject = CreateNewObject(grid, x, y);
                        }
                        else
                        {
                            if (grid[x, y].ContainedObject.name.Equals(_selectedGridObjectType.ToString()) ||
                                grid[x, y].ContainedObject.name.Equals("Empty"))
                            {
                                DestroyImmediate(grid[x, y].transform.GetChild(0).gameObject);
                                grid[x, y].ContainedObject = null;
                            }
                            else
                            {
                                DestroyImmediate(grid[x, y].transform.GetChild(0).gameObject);
                                grid[x, y].ContainedObject = CreateNewObject(grid, x, y);
                            }
                        }
                    }
                }
                EditorGUILayout.EndHorizontal();
            }
        }

        EditorGUILayout.Space();
        if (GUILayout.Button("Create New Grid", GUILayout.Height(40), GUILayout.Width(200)))
        {
            grid.SetNewGrid(grid.ThisGrid);
        }

        if (!grid.HasGrid)
        {
            return;
        }
        if (GUILayout.Button("Delete Grid", GUILayout.Width(200)))
        {
            grid.RemoveGrid();
        }
    }
示例#11
0
 protected GridObject(GridObjectType _type, CellCoordinates[] _coordinates)
 {
     ObjectType  = _type;
     Coordinates = _coordinates;
 }
示例#12
0
 public GridObject(GridObjectType type)
 {
     Type = type;
     SpriteSetLocation = new Point();
 }
示例#13
0
 /// <summary>
 /// Gets the bitmap for the specified tiletype.
 /// </summary>
 public static Bitmap GetBitmapForType(GridObjectType type)
 {
     return Instance.BitmapDictionary[type];
 }
示例#14
0
        public bool Update()
        {
            var stop = false;

            bool grid  = false;
            var  gridX = 0;
            var  gridY = 0;

            switch (_model.Turn)
            {
            case GameTurn.None:
            case GameTurn.Player1:
            case GameTurn.Player2:
                switch (_view.GetLastButtonClick(out gridX, out gridY))
                {
                case GameButton.Grid:
                    grid = _model.Turn != GameTurn.None;
                    break;

                case GameButton.Quit:
                    stop = true;
                    break;

                case GameButton.Reset:
                    _model.Reset(42069);
                    _view.Reset(_model.Turn, _model.GetTurnObject(_model.Turn));
                    break;
                }

                break;

            case GameTurn.Ai:
                grid = _model.GetRandomSpot(42069, out gridX, out gridY);
                break;
            }

            _view.ClearLastButtonClick();

            if (grid)
            {
                GridObjectType  turnObjectType = _model.GetTurnObject(_model.Turn);
                GamePlaceResult result         = _model.PlaceObjectAt(gridX, gridY);

                switch (result)
                {
                case GamePlaceResult.Fail:
                    break;

                case GamePlaceResult.Success:
                    _view.PlaceAt(gridX, gridY, turnObjectType);
                    _view.SetTurn(_model.Turn, _model.GetTurnObject(_model.Turn));
                    break;

                case GamePlaceResult.End:
                    _view.PlaceAt(gridX, gridY, turnObjectType);
                    _view.SetWinner(_model.Winner, _model.GetTurnObject(_model.Winner));
                    break;
                }
            }

            return(stop);
        }