예제 #1
0
        private static bool Select(ref SelectState state, SelectionType selectionType, bool onlyOnHover = true)
        {
            var oldState = state;

            if (onlyOnHover && (oldState & SelectState.Hovering) != SelectState.Hovering)
            {
                return(false);
            }

            var newState = oldState;

            switch (selectionType)
            {
            case SelectionType.Subtractive:         newState &= ~SelectState.Selected; break;

            case SelectionType.Toggle:                      newState ^= SelectState.Selected; break;

            case SelectionType.Replace:
            case SelectionType.Additive:            newState |= SelectState.Selected; break;

            default:
                throw new ArgumentOutOfRangeException("selectionType", selectionType, null);
            }

            if (oldState == newState)
            {
                return(false);
            }

            state = newState;
            return(true);
        }
예제 #2
0
 void Start()
 {
     st = SelectState.SelectPlayer;
     bs = BattleSimulation.GetInstance;
     target.SetActive(true);
     SetIndicatorPosition(st == SelectState.SelectEnemy ? true : false);
 }
예제 #3
0
 public DialogResult SafeShow(SelectState state, string Server = "")
 {
     this.state      = state;
     this.ServerName = Server;
     LoadItems();
     return(this.ShowDialog());
 }
예제 #4
0
        protected virtual SqlCommand Command(SelectState type)
        {
            SqlCommand command = null;

            switch (type)
            {
            case SelectState.Select:
            {
                command = SelectCommand();
                break;
            }

            case SelectState.Insert:
            {
                command = InsertCommand();
                break;
            }

            case SelectState.Update:
            {
                command = UpdateCommand();
                break;
            }

            case SelectState.Delete:
            {
                command = DeleteCommand();
                break;
            }
            }
            SetParameters(command, ObjectClass.SqlProperty);
            return(command);
        }
예제 #5
0
        public void Start()
        {
            CurrentState = SelectState.volume;                   //默认的选择项是volume

            _volume.Start();                                     //volume 的Start 初始化
            initPosition();
        }
예제 #6
0
        public void SetCurrentObject(ARProduct obj, SelectState st = SelectState.Actived)
        {
            if (currentObj != null)
            {
                if (currentObj == obj)
                {
                    currentObj.Selected = st;
                    return;
                }
                else
                {
                    currentObj.Selected = SelectState.None;
                }
            }
            currentObj = obj;


            if (currentObj != null)
            {
                currentObj.Selected = st;
            }
            //---Stripped down version---0818
            //    frame.SetObject(currentObj);
            //    arui.OpenProductMenu();
            //}
            //else
            //{
            //    frame.SetObject(null);
            //    arui.CloseProductMenu();
            //}
        }
예제 #7
0
 public StateAdapter(
     [NotNull] IReadOnlyList <T> adaptee,
     [NotNull] SelectState <T, TAdaptee> state)
 {
     _adaptee = adaptee;
     _state   = state;
 }
예제 #8
0
        public void SelectNewObject(GameObject obj, SelectState setSelectStateTo = SelectState.Drag)
        {
            if (!(obj != null))
            {
                return;
            }
            ResetSelected(objectBeingDeleted: false, deleteChildren: false);
            CurrentState.ExitState();
            addNewSelectedObject(obj);
            InputProcessingPaused = false;
            if (this.NewObjectAdded != null && CurrentlySelectedObject != null)
            {
                ManipulatableObject component = CurrentlySelectedObject.GetComponent <ManipulatableObject>();
                if (component != null)
                {
                    this.NewObjectAdded.InvokeSafe(component);
                }
            }
            switch (setSelectStateTo)
            {
            case SelectState.Active:
                CurrentState = activeSelectionState;
                break;

            case SelectState.Drag:
                CurrentState = dragItemInputInteractionState;
                break;
            }
            CurrentState.EnterState(TargetLayerMask, MinTimeToMoveInput);
        }
    // Start is called before the first frame update
    void Start()
    {
        currentCube    = GameController.Instance.currentCube;
        gameState      = GameController.Instance.gameState;
        selectState    = GameController.Instance.selectState;
        levelHowToBoss = GameController.Instance.levelHowToBoss;
        levelUnlocks   = GameController.Instance.levelUnlocks;
        levelSelects   = GameController.Instance.levelSelects;
        cubeNames      = GameController.Instance.cubeNames;

        colorCube = GameObject.Find("ColorCube");
        cubes     = new GameObject[cubeNames.Length];
        for (int i = 0; i < cubeNames.Length; i++)
        {
            cubes[i] = GameObject.Find(cubeNames[i] + "Cube");
            cubes[i].transform.rotation = Quaternion.Euler(Random.Range(0, 360), Random.Range(0, 360), Random.Range(0, 360));
        }

        cubeSelectText = GameObject.Find("CubeSelect").GetComponent <Text>();
        controlsText   = GameObject.Find("Controls").GetComponent <Text>();

        cam      = GameObject.FindWithTag("MainCamera");
        camOrbit = GameObject.Find("CameraOrbit");

        AudioController.Instance.PlayMusic(AudioController.Instance.menuMusic);
        InitCamera();
    }
예제 #10
0
        public void Start()
        {
            CurrentState = SelectState.volume;                   //默认的选择项是volume

            _volume.Start();                                     //volume 的Start 初始化
            initPosition();
        }
예제 #11
0
        bool Select(ref SelectState state, SelectionType selectionType, bool onlyOnHover = true)
        {
            var old_state = state;

            if (onlyOnHover && (old_state & SelectState.Hovering) != SelectState.Hovering)
            {
                return(false);
            }
            var new_state = old_state;

            if (selectionType == SelectionType.Subtractive)
            {
                new_state &= ~SelectState.Selected;
            }
            else if (selectionType == SelectionType.Toggle)
            {
                new_state ^= SelectState.Selected;
            }
            else
            {
                new_state |= SelectState.Selected;
            }
            if (old_state == new_state)
            {
                return(false);
            }
            state = new_state;
            return(true);
        }
    // Orients camera to cube's last selected level
    IEnumerator FixCamRotation(int whichLevel)
    {
        camIsMoving = true;
        Quaternion camRotation = Quaternion.Euler(0, whichLevel * -90, 0);

        if (levelHowToBoss[currentCube, 0] < 2)
        {
            camRotation = Quaternion.Euler(90, whichLevel * -90, 0);
            SetControlsText(4);
            cubeSelectText.text = "How To Play";
            //StartCoroutine(HowToCamOrbit(currentCube));
        }
        while (Quaternion.Angle(camOrbit.transform.localRotation, camRotation) > 0.1f)
        {
            camOrbit.transform.localRotation = Quaternion.Slerp(camOrbit.transform.localRotation, camRotation, Time.smoothDeltaTime * camRotateSpeed);
            yield return(null);
        }
        camOrbit.transform.localRotation = camRotation;
        if (selectState == SelectState.HOW_TO)
        {
            SetControlsText(1);
            selectState = SelectState.LEVELS;
        }
        if (levelHowToBoss[currentCube, 0] < 2)
        {
            selectState = SelectState.HOW_TO;
        }
        camIsMoving = false;
    }
예제 #13
0
 public override void mUpdate()
 {
     base.mUpdate();
     if (Input.GetMouseButtonDown(0) && uguiHitUI.uiHited == false)
     {
         Vector2 v2 = GetScreenToWorldPos(Input.mousePosition);
         colli = Physics2D.OverlapPoint(v2);
     }
     if (colli != null && Input.GetMouseButtonUp(0))
     {
         Vector2    v2     = GetScreenToWorldPos(Input.mousePosition);
         Collider2D colli2 = Physics2D.OverlapPoint(v2);
         if (colli2 != colli)
         {
             colli = null;
             return;
         }
         ObjView view = colli.GetComponent <ObjView>();
         if (view == null)
         {
             return;
         }
         string      stateName = view.GetState();
         SelectState state     = getSelectState(stateName);
         if (state == null)
         {
             Debug.LogError("stateName = {0}未注册!" + stateName);
             return;
         }
         state.viewTarget = view;
         setState(stateName);
     }
 }
예제 #14
0
 public void NotifyChildrenOfStateChange(SelectState newState, bool useTriState)
 {
     if (OnStateChangeNotifyChildrenEvent != null)
     {
         OnStateChangeNotifyChildrenEvent(newState, useTriState);
     }
 }
예제 #15
0
 public void NotifyParentOfStateChange(SelectState newState, SelectState fromState, bool useTriState)
 {
     if (OnStateChangeNotifyParentEvent != null)
     {
         OnStateChangeNotifyParentEvent(newState, fromState, useTriState);
     }
 }
예제 #16
0
        public override void mouseStateLogic(MouseState mouseState, ContentManager content)
        {
            if (!cardProps.exhausted)
            {
                switch (selectState)
                {
                case SelectState.Regular:
                    if (isWithinBox(mouseState))
                    {
                        selectState = SelectState.Hovered;
                    }

                    break;

                case SelectState.Hovered:
                    if (mouseState.LeftButton == ButtonState.Pressed)
                    {
                        selectState = SelectState.Selected;
                    }
                    break;

                case SelectState.Selected:
                    if (mouseState.MiddleButton == ButtonState.Pressed)
                    {
                        selectState = SelectState.Regular;
                    }
                    break;
                }
            }
            else
            {
                selectState = SelectState.Hovered;
            }
        }
예제 #17
0
        public async Task <IActionResult> GET()
        {
            using (SqlConnection conn = Connection)
            {
                conn.Open();
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = @"
                        SELECT Id, State
                        FROM States"
                    ;

                    SqlDataReader reader = cmd.ExecuteReader();
                    var           states = new List <SelectState>();


                    while (reader.Read())
                    {
                        var state = new SelectState
                        {
                            Id    = reader.GetInt32(reader.GetOrdinal("Id")),
                            State = reader.GetString(reader.GetOrdinal("State"))
                        };

                        states.Add(state);
                    }
                    reader.Close();

                    return(Ok(states));
                }
            }
        }
예제 #18
0
 public void Init(Vector3 inPoint1, Vector3 inPoint2, XYGrid inGrid, Orientation inOrientation = Orientation.HORIZONTAL)
 {
     point1         = inPoint1;
     point2         = inPoint2;
     containingGrid = inGrid;
     selectState    = SelectState.NONE;
     orientation    = inOrientation;
 }
예제 #19
0
 public Change(
     [NotNull] IChange <CollectionOperation <T> > adaptee,
     [NotNull] SelectState <T, TAdaptee> state,
     [CanBeNull] Dictionary <T, TAdaptee> removedOnChange)
 {
     _adaptee         = adaptee;
     _state           = state;
     _removedOnChange = removedOnChange;
 }
예제 #20
0
 public ListChange(
     [NotNull] IChange <ListOperation <T> > adaptee,
     [NotNull] SelectState <T, TAdaptee> state,
     [CanBeNull] Dictionary <T, TAdaptee> removed)
 {
     _adaptee = adaptee;
     _state   = state;
     _removed = removed;
 }
예제 #21
0
 bool HoverOn(ref SelectState state)
 {
     if ((state & SelectState.Hovering) == SelectState.Hovering)
     {
         return(false);
     }
     state |= SelectState.Hovering;
     return(true);
 }
예제 #22
0
파일: Enemy.cs 프로젝트: Penjat/SQuest
 public void SetState(SelectState state)
 {
     if (_isDead)
     {
         return;
     }
     _state = state;
     _card.SetState(state);
 }
예제 #23
0
    public override void mPhoneUpdate()
    {
        base.mPhoneUpdate();
        if (Input.touchCount != 1 || uguiHitUI.uiHited == true)
        {
            return;
        }
        Touch touch = Input.GetTouch(0);

        switch (touch.phase)
        {
        case TouchPhase.Began:
            Vector2 v2 = GetScreenToWorldPos(touch.position);
            colli = Physics2D.OverlapPoint(v2);
            return;

        case TouchPhase.Moved:
            if (colli != null)
            {
                colli = null;
            }
            return;

        case TouchPhase.Ended:
            break;

        case TouchPhase.Stationary:
        case TouchPhase.Canceled:
        default:
            return;
        }

        if (colli != null)
        {
            Vector2    v2     = GetScreenToWorldPos(Input.mousePosition);
            Collider2D colli2 = Physics2D.OverlapPoint(v2);
            if (colli2 != colli)
            {
                colli = null;
                return;
            }
            ObjView view = colli.GetComponent <ObjView>();
            if (view == null)
            {
                return;
            }
            string      stateName = view.GetState();
            SelectState state     = getSelectState(stateName);
            if (state == null)
            {
                return;
            }
            state.viewTarget = view;
            setState(stateName);
        }
    }
예제 #24
0
    public SelectState getSelectState(string stateName)
    {
        if (stateDic.ContainsKey(stateName) == false)
        {
            return(null);
        }
        SelectState state = stateDic[stateName] as SelectState;

        return(state);
    }
예제 #25
0
    public void OnEnable()
    {
        playerName   = this.tag;
        hittedObj    = null;
        hittedPlayer = null;
        hittedSquare = null;

        selectState = SelectState.playerSelect;
        rayhitted   = false;
    }
예제 #26
0
 public void SetCurrentObjectState(SelectState st)
 {
     if (st == SelectState.None)
     {
         SetCurrentObject(null);
     }
     else if (currentObj != null)
     {
         currentObj.Selected = st;
     }
 }
예제 #27
0
 public virtual void SetCurrentObjectState(SelectState st)
 {
     if (currentObject != null)
     {
         currentObject.Selected = st;
     }
     if (st == SelectState.None)
     {
         currentObject = null;
     }
 }
예제 #28
0
 /// <summary>
 /// Gets the color for background of the variable of the specified type.
 /// </summary>
 /// <param name="variableType">Type of the variable.</param>
 /// <param name="selectState">State of the scene node.</param>
 /// <returns>Color for background of the specified variable.</returns>
 public static Color ForVariableBackground(VariableType variableType, SelectState selectState)
 {
     if (selectState == SelectState.Select)
     {
         return(Color.FromArgb(85, 90, 78));
     }
     else
     {
         return(ForVariableBackground(variableType));
     }
 }
 void FixedUpdate()
 {
     remainingStateTime -= Time.fixedDeltaTime;
     if (remainingStateTime < 0)
     {
         currentState = nextState;
         SetNextState();
         SetTimeForState();
         stateHandlerLookup[(int)currentState]();
     }
 }
예제 #30
0
 void UpdateInactive()
 {
     if (joystick.GetButtonDown("UISubmit"))
     {
         selectManager.ActivatePlayer(playerIndex);
         state = SelectState.selecting;
     }
     else if (joystick.GetButton("UICancel"))
     {
         selectManager.HoldingBack();
     }
 }
예제 #31
0
 void UpdateChosen()
 {
     if (joystick.GetButtonDown("UICancel"))
     {
         selectManager.UnlockCharacter(playerIndex);
         state = SelectState.selecting;
     }
     if (joystick.GetButtonDown("UISubmit"))
     {
         selectManager.TryStageSelect();
     }
 }
예제 #32
0
        public ChangeOption(TextureManager _t, SoundManagerEx _s)
        {
            this.texturemanager = _t;
            this.soundmanager = _s;
            CurrentState = new SelectState();

            initSprites();
            _volume = new volume(Sprits);
            _volume.Level = soundmanager.Volume / 10;

            System.Diagnostics.Debug.Print(soundmanager.Volume.ToString () +"and"+ _volume.Level.ToString());
            initPosition();
        }
예제 #33
0
        public MainWindow()
        {
            InitializeComponent();

            offBoard.Selected += (sender, args) =>
            {
                switch (selectState)
                {
                    case SelectState.From:
                        FromOffboard = args.Piece;
                        selectState = SelectState.To;
                        break;
                    case SelectState.To:
                        if (FromOffboard == args.Piece)
                        {
                            // Unselect it
                            FromOffboard = null;
                            selectState = SelectState.From;
                        }
                        else if (FromOffboard != null)
                        {
                            FromOffboard = args.Piece;
                        }
                        else
                        {
                            // Unsupported
                        }
                        break;
                    case SelectState.Special:
                        if (mustSelectFrom.Contains(args.Piece))
                        {
                            SetSelected(args.Piece);
                        }
                        break;
                }
                gamePanel.InvalidateVisual();
                offBoard.InvalidateVisual();
            };

            gamePanel.Selected += (sender, args) =>
            {
                switch (selectState)
                {
                    case SelectState.From:
                        FromCoord = args.Coords;
                        if (FromCoord != null)
                        {
                            selectState = SelectState.To;
                        }
                        break;
                    case SelectState.To:
                        if (fromCoord != null && Coords.Match(fromCoord, args.Coords))
                        {
                            FromCoord = null;
                            selectState = SelectState.From;
                        }
                        else
                        {
                            toCoord = args.Coords;
                            MakeMove();
                        }
                        break;
                    case SelectState.Special:
                        foreach (var kvp in game.GetPieces(gameState))
                        {
                            if (Coords.Match(kvp.Key, args.Coords) && mustSelectFrom.Contains(kvp.Value))
                            {
                                SetSelected(kvp.Value);
                                return;
                            }
                        }
                        break;
                }
                gamePanel.InvalidateVisual();
                offBoard.InvalidateVisual();
            };

            App.Current.DispatcherUnhandledException += (sender, args) =>
            {
                InvalidGameException ex = args.Exception as InvalidGameException;
                if (ex != null)
                {
                    System.Windows.MessageBox.Show(ex.Message, "Invalid game", MessageBoxButton.OK, MessageBoxImage.Error);
                    args.Handled = true;
                }
            };
        }
예제 #34
0
        private Piece SelectPiece(GameState state, IEnumerable<Piece> pieces)
        {
            selectState = SelectState.Special;
            this.mustSelectFrom = pieces;

            offBoard.ClearHighlight();
            gamePanel.ClearHighlight();
            foreach (var p in mustSelectFrom)
            {
                offBoard.AddHighlight(p);
                gamePanel.AddHighlight(p);
            }
            offBoard.InvalidateVisual();
            gamePanel.InvalidateVisual();

            selectionFrame = new DispatcherFrame();
            Dispatcher.PushFrame(selectionFrame);
            selectionFrame = null;

            selectState = SelectState.From;
            this.mustSelectFrom = null;

            return selectedPiece;
        }
예제 #35
0
        private void MakeMove()
        {
            if (fromOffboard != null && toCoord != null)
            {
                // From offboard to board
                var newGameState = game.TryMakeMoveFromOffboard(gameState, FromOffboard, toCoord);
                if (newGameState != null) gameState = newGameState;

                offBoard.Refresh();
                gamePanel.InvalidateVisual();
            }
            else if (fromCoord != null && toCoord != null)
            {
                // From coords to coords
                var newGameState = game.TryMakeMove(gameState, FromCoord, toCoord);
                if (newGameState != null) gameState = newGameState;

                offBoard.Refresh();
                gamePanel.InvalidateVisual();
            }

            if (game.GameOver)
            {
                if (game.PlayerCount == 1)
                {
                    if (game.Winners.Count() == 1)
                    {
                        System.Windows.MessageBox.Show("You won!");
                    }
                    else
                    {
                        System.Windows.MessageBox.Show("You lost!");
                    }
                }
                else
                {
                    if (game.Winners.Count() == 0)
                    {
                        System.Windows.MessageBox.Show("Game over!\nThe game ended in a tie!");
                    }
                    else if (game.Winners.Count() == 1)
                    {
                        System.Windows.MessageBox.Show("Game over!\nThe winner is: " + game.Winners.First().ToString());
                    }
                    else
                    {
                        System.Windows.MessageBox.Show("Game over!\nThe winners are: " + string.Join(", ", game.Winners));
                    }
                }
                NewGame();
            }
            selectState = SelectState.From;
            FromCoord = null;
            FromOffboard = null;
            toCoord = null;
            currentPlayerLabel.Content = gameState.CurrentPlayer.ToString();
        }
예제 #36
0
        /// <summary>
        /// Handles editor input.
        /// </summary>
        public void Input (SceneView view) {

            Event e = Event.current;

            if (e.isKey) {

                if (e.type == EventType.KeyDown) {

                    if (e.keyCode == settings.APPLY_SINGLE) {

                        if (state == SelectState.Two) {

                            state = SelectState.None;
                            GetSelectionOfObjects();

                        }

                    }

                }

            }

            if (e.type == EventType.MouseDown) {

                Vector3 tar = VMEGlobal.GetPositionNextToHoveredTile();
    
                if (e.button == 0) {

                    if (tar == new Vector3(0, 9000, 0)) {

                        firstTarget.transform.position = new Vector3(0, 9000, 0);
                        secondTarget.transform.position = new Vector3(0, 9000, 0);
                        state = SelectState.None;

                    } else {

                        if (state == SelectState.None) {

                            firstTarget.transform.position = tar;
                            state = SelectState.One;

                        } else if (state == SelectState.One) {

                            secondTarget.transform.position = tar;
                            state = SelectState.Two;

                        }

                    }

                }

            }

        }
예제 #37
0
        private void Ellipse_MouseDown(object sender, MouseButtonEventArgs e)
        {
            var ellipse = sender as Ellipse;
            if (ellipse == null) return;
            var tile = game.Tiles.FirstOrDefault(t => ellipse.Tag as string == t.TileName);
            if (tile == null) return;

            if (currentState == SelectState.RemoveOpponentPiece)
            {
                if (players.PlayerOne.IsPlayersTurn && tile.Status == TileStatus.P2)
                {
                    tile.Status = TileStatus.Unoccupied;
                    players.PlayerTwo.PiecesLeft--;
                    if (players.PlayerTwo.PiecesLeft == 3 && players.PlayerTwo.InvisiblePieces == 0)
                        game.State = GameState.Flying;
                    if (players.PlayerTwo.PiecesLeft == 2 && players.PlayerTwo.InvisiblePieces == 0)
                    {
                        // game over logic
                        players.PlayerOne.IsPlayersTurn = false;
                        players.PlayerTwo.IsPlayersTurn = false;
                        game.Winner = players.PlayerOne.Name;
                        this.Content = new GameOverPage();
                    }
                    currentState = SelectState.Neutral;
                    players.SwitchTurns();
                }
                else if (players.PlayerTwo.IsPlayersTurn && tile.Status == TileStatus.P1)
                {
                    tile.Status = TileStatus.Unoccupied;
                    players.PlayerOne.PiecesLeft--;
                    if (players.PlayerOne.PiecesLeft == 3 && players.PlayerOne.InvisiblePieces == 0)
                        game.State = GameState.Flying;
                    if (players.PlayerOne.PiecesLeft == 2 && players.PlayerOne.InvisiblePieces == 0)
                    {
                        // game over logic
                        players.PlayerOne.IsPlayersTurn = false;
                        players.PlayerTwo.IsPlayersTurn = false;
                        game.Winner = players.PlayerTwo.Name;
                        this.Content = new GameOverPage();
                    }
                    currentState = SelectState.Neutral;
                    players.SwitchTurns();
                }
            }
            else if (game.State == GameState.Placing)
            {
                if (tile.Status != TileStatus.Unoccupied)
                {
                    // can't place on top of another piece
                }
                else if (players.PlayerOne.IsPlayersTurn)
                {
                    tile.Status = TileStatus.P1;
                    players.PlayerOne.InvisiblePieces--;
                    players.PlayerOne.PiecesLeft++;
                    if (players.PlayerOne.AddNewMills(game.Tiles, TileStatus.P1, tile))
                    {
                        currentState = SelectState.RemoveOpponentPiece;
                    }
                    else players.SwitchTurns();
                }
                else if (players.PlayerTwo.IsPlayersTurn)
                {
                    tile.Status = TileStatus.P2;
                    players.PlayerTwo.InvisiblePieces--;
                    players.PlayerTwo.PiecesLeft++;
                    if (players.PlayerTwo.AddNewMills(game.Tiles, TileStatus.P2, tile))
                    {
                        currentState = SelectState.RemoveOpponentPiece;
                    }
                    else players.SwitchTurns();
                }
                if (players.PlayerOne.InvisiblePieces == 0 &&
                    players.PlayerTwo.InvisiblePieces == 0)
                {
                    game.State = GameState.Moving;
                }
            }
            else if (game.State == GameState.Moving)
            {
                if (game.CurrentlyMovingPiece == null)
                // This means that he hasn't selected a piece to move. Highlight the piece
                {
                    if (players.PlayerOne.IsPlayersTurn && tile.Status == TileStatus.P1 ||
                        players.PlayerTwo.IsPlayersTurn && tile.Status == TileStatus.P2)
                    {
                        game.CurrentlyMovingPiece = tile;
                        tile.Highlight();
                    }
                }
                else
                // This means that he has already selected a piece to move selected
                {
                    if (tile.Status == TileStatus.Unoccupied && game.CurrentlyMovingPiece.AdjacentTiles.Contains(tile))
                    {
                        tile.Status = game.CurrentlyMovingPiece.Status;
                        game.CurrentlyMovingPiece.Status = TileStatus.Unoccupied;
                        if (players.PlayerOne.IsPlayersTurn)
                        {
                            if (players.PlayerOne.AddNewMills(game.Tiles, TileStatus.P1, tile))
                            {
                                currentState = SelectState.RemoveOpponentPiece;
                            }
                            else players.SwitchTurns();
                        }
                        else if (players.PlayerTwo.IsPlayersTurn)
                        {
                            if (players.PlayerTwo.AddNewMills(game.Tiles, TileStatus.P2, tile))
                            {
                                currentState = SelectState.RemoveOpponentPiece;
                            }
                            else players.SwitchTurns();
                        }
                    }
                    game.CurrentlyMovingPiece.UnHighlight();
                    game.CurrentlyMovingPiece = null;
                }
            }
            else if (game.State == GameState.Flying)
            {
                if (game.CurrentlyMovingPiece == null)
                // This means that he hasn't selected a piece to move. Highlight the piece
                {
                    if (players.PlayerOne.IsPlayersTurn && tile.Status == TileStatus.P1 ||
                        players.PlayerTwo.IsPlayersTurn && tile.Status == TileStatus.P2)
                    {
                        game.CurrentlyMovingPiece = tile;
                        tile.Highlight();
                    }
                }
                else
                // This means that he has already selected a piece to move selected
                {
                    if (tile.Status == TileStatus.Unoccupied)
                    {
                        tile.Status = game.CurrentlyMovingPiece.Status;
                        game.CurrentlyMovingPiece.Status = TileStatus.Unoccupied;
                        if (players.PlayerOne.IsPlayersTurn)
                        {
                            if (players.PlayerOne.AddNewMills(game.Tiles, TileStatus.P1, tile))
                            {
                                currentState = SelectState.RemoveOpponentPiece;
                            }
                            else players.SwitchTurns();
                        }
                        else if (players.PlayerTwo.IsPlayersTurn)
                        {
                            if (players.PlayerTwo.AddNewMills(game.Tiles, TileStatus.P2, tile))
                            {
                                currentState = SelectState.RemoveOpponentPiece;
                            }
                            else players.SwitchTurns();
                        }
                    }
                    game.CurrentlyMovingPiece.UnHighlight();
                    game.CurrentlyMovingPiece = null;
                }
            }
            if (players.PlayerOne.IsPlayersTurn && players.PlayerOne.IsComputer)
            {
                PlayComputer();
            }
            else if(players.PlayerTwo.IsPlayersTurn && players.PlayerTwo.IsComputer)
            {
                PlayComputer();
            }
        }
예제 #38
0
        private void PlayComputer()
        {
            if (players.PlayerTwo.IsPlayersTurn && players.PlayerTwo.IsComputer)
            {

                System.Threading.Thread.Sleep(TimeSpan.FromMilliseconds(200));
                if (currentState == SelectState.RemoveOpponentPiece)
                {
                    #region RemoveOpponentPiece
                    var possibleTiles = game.Tiles.Where(x => x.Status == TileStatus.P1);
                    Random r = new Random();
                    var index = r.Next(possibleTiles.Count());
                    var tileA = possibleTiles.ToArray()[index];
                    var tile = game.Tiles.FirstOrDefault(x => x.TileName == tileA.TileName);
                    tile.Status = TileStatus.Unoccupied;
                    Debug.WriteLine("{0} removing tile {1}", players.PlayerTwo.Name, tile.TileName);
                    players.PlayerOne.PiecesLeft--;
                    if (players.PlayerOne.PiecesLeft == 3 && players.PlayerOne.InvisiblePieces == 0)
                        game.State = GameState.Flying;
                    if (players.PlayerOne.PiecesLeft == 2 && players.PlayerOne.InvisiblePieces == 0)
                    {
                        // game over logic
                        players.PlayerOne.IsPlayersTurn = false;
                        players.PlayerTwo.IsPlayersTurn = false;
                        game.Winner = players.PlayerTwo.Name;
                        this.Content = new GameOverPage();
                    }
                    currentState = SelectState.Neutral;
                    players.SwitchTurns();
                    #endregion
                }
                else if (game.State == GameState.Placing)
                {
                    #region Placing
                    var openTiles = game.Tiles.Where(x => x.Status == TileStatus.Unoccupied);
                    Random r = new Random();
                    int tileIndex = r.Next(openTiles.Count());
                    var tile = openTiles.ToArray()[tileIndex];
                    Debug.WriteLine("{0} {1}", players.PlayerTwo.Name, tile.TileName);
                    game.Tiles.FirstOrDefault(x => x.TileName == tile.TileName).Status = TileStatus.P2;
                    players.PlayerTwo.InvisiblePieces--;
                    players.PlayerTwo.PiecesLeft++;
                    if (players.PlayerTwo.AddNewMills(game.Tiles, TileStatus.P2, tile))
                    {
                        currentState = SelectState.RemoveOpponentPiece;
                    }
                    else
                    {
                        players.SwitchTurns();
                    }

                    if (players.PlayerOne.InvisiblePieces == 0 && players.PlayerTwo.InvisiblePieces == 0)
                    {
                        currentState = SelectState.Neutral;
                        game.State = GameState.Moving;
                    }
                    #endregion
                }
                else if (game.State == GameState.Moving || game.State == GameState.Flying)
                {
                    #region Moving
                    var myTiles = game.Tiles.Where(x => x.Status == TileStatus.P2);
                    var contprog = false;
                    Random r = new Random();
                    Tile newTile = null;
                    while (!contprog)
                    {
                        var index = r.Next(myTiles.Count());
                        var tile = myTiles.ToArray()[index];
                        var possible = tile.AdjacentTiles.ToArray();
                        for (int i = 0; i < possible.Count(); i++)
                        {
                            var current = game.Tiles.FirstOrDefault(x => x.TileName == possible[i].TileName);
                            if (current.Status == TileStatus.Unoccupied)
                            {
                                current.Status = TileStatus.P2;
                                game.Tiles.FirstOrDefault(x => x.TileName == tile.TileName).Status = TileStatus.Unoccupied;
                                newTile = current;
                                contprog = true;
                                break;
                            }
                        }
                    }
                    if (players.PlayerTwo.AddNewMills(game.Tiles, TileStatus.P2, newTile))
                    {
                        currentState = SelectState.RemoveOpponentPiece;
                    }
                    else
                    {
                        players.SwitchTurns();
                    }
                    #endregion
                }
            }
            else if (players.PlayerTwo.IsPlayersTurn && players.PlayerTwo.IsComputer)
            {
                PlayComputer();
            }
        }