コード例 #1
0
ファイル: MouseClick.cs プロジェクト: jelazi/EvadeWPF
        private void field_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) //klik na pole při vybraném kameni přesun kamene
        {
            if (gameState == GameState.play)
            {
                countBlick = 10;

                if (selectStone.properties != Field.empty)
                {
                    selectField = FieldPosition(Convert.ToInt32(e.GetPosition(BoardForm).X), Convert.ToInt32(e.GetPosition(BoardForm).Y));
                    if (manager.Controlor.IsPossibleMove(selectField, selectStone, manager)) //možný tah?
                    {
                        manager.MoveChoisenStone(selectField, selectStone);                  //přesun vybraného kamene
                        selectStone = new Stone();
                        manager.Controlor.IsEnd(manager, manager.PlayerOnTurn);              //kontrola konce hry
                        HistoryToString();
                        RunningGame();                                                       //popisky ke hře
                        if (manager.End == false)                                            //není konec hry
                        {
                            manager.ChangeOnTurn();                                          //změna hráče na tahu
                            manager.PlayerOnTurn.MarkStones(manager.Board);                  //označení kamenů hráče na tahu
                            Timer.Start();                                                   //spuštění časovače
                        }

                        DrawStones();
                    }
                }
            }
        }
コード例 #2
0
ファイル: MouseClick.cs プロジェクト: jelazi/EvadeWPF
        private void Shape_MouseLeftButtonDownOn(object sender, MouseEventArgs e) //klik na kámen hráče k zamrznutí
        {
            if (gameState == GameState.play)
            {
                selectField = beforeField = FieldPosition(Convert.ToInt32(e.GetPosition(BoardForm).X), Convert.ToInt32(e.GetPosition(BoardForm).Y));
                Point newPosition = new Point();
                if (manager.Board.ContainStone(manager.Board.fields[selectField.x - 1, selectField.y - 1]) &&
                    manager.Board.ContainStonePlayer(manager.Board.fields[selectField.x - 1, selectField.y - 1], manager.OpositePlayer(manager.PlayerOnTurn)))
                {
                    if (manager.Controlor.IsPossibleMove(selectField, selectStone, manager))//možný tah?
                    {
                        newPosition.X = Canvas.GetLeft(source);
                        newPosition.Y = Canvas.GetTop(source);

                        manager.MoveChoisenStone(selectField, selectStone);     //přesun vybraného kamene
                        selectStone = new Stone();
                        manager.Controlor.IsEnd(manager, manager.PlayerOnTurn); //kontrola konce hry
                        HistoryToString();
                        RunningGame();                                          //popisky ke hře

                        if (manager.End == false)                               //není konec hry
                        {
                            manager.ChangeOnTurn();                             //změna hráče na tahu
                            manager.PlayerOnTurn.MarkStones(manager.Board);     //označení kamenů hráče na tahu
                            Timer.Start();                                      //spuštění časovače
                        }
                    }
                }



                DrawStones();
            }
        }
コード例 #3
0
ファイル: Controlor.cs プロジェクト: jelazi/EvadeWPF
        public bool ControlValidMove(move move, Manager manager)                                     //kontrola správnosti tahu
        {
            if (move.properties == manager.Board.fields[move.beforePos.x - 1, move.beforePos.y - 1]) //kontrola existence prvku
            {
                List <pos> possibleMove = new List <pos>();
                Stone      stone        = new Stone();
                stone.position   = move.beforePos;
                stone.properties = move.properties;
                pos NextPosition = move.nextPos;

                possibleMove = PossiblePosition(stone, move.beforePos, manager.Board);

                if (possibleMove.Contains(move.nextPos)) //kontrola možnosti tahu
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
コード例 #4
0
ファイル: Files.cs プロジェクト: jelazi/EvadeWPF
        public string PositionToString(pos pos) //pozice do textu
        {
            char xString = new char();

            switch (pos.x)
            {
            case 1:
                xString = 'A';
                break;

            case 2:
                xString = 'B';
                break;

            case 3:
                xString = 'C';
                break;

            case 4:
                xString = 'D';
                break;

            case 5:
                xString = 'E';
                break;

            case 6:
                xString = 'F';
                break;
            }
            return(xString + " : " + pos.y.ToString());
        }
コード例 #5
0
ファイル: Controlor.cs プロジェクト: jelazi/EvadeWPF
        const int HIGH = 400;                             //vysoká hodnota pole


        public List <pos> PossiblePosition(Stone stone, pos position, Board board) //najde všechny možné pozice - s ohledem na kraj a své kameny
        {
            List <pos> possiblePosition = new List <pos>();

            if (!((stone.properties & Field.freeze) == Field.freeze))
            {
                int i = 0;
                for (int j = -1; j < 2; j++)
                {
                    for (int k = -1; k < 2; k++)
                    {
                        pos pos;
                        pos.x = k + position.x;
                        pos.y = j + position.y;

                        if (!(
                                pos.x < 1 ||                                                                                                   //mimo pole
                                pos.y < 1 ||                                                                                                   //mimo pole
                                pos.x > 6 ||                                                                                                   // mimo pole
                                pos.y > 6 ||                                                                                                   // mimo pole
                                ((board.ContainStone(board.fields[(pos.x - 1), (pos.y - 1)])) &&
                                 (board.GetStoneColor(board.fields[(pos.x - 1), (pos.y - 1)]) == board.GetStoneColor(stone.properties))) ||    // kámen stejného hráče v sousedním poli
                                (board.fields[(pos.x - 1), (pos.y - 1)] & Field.freeze) == Field.freeze ||                                     // zamrzlé pole
                                (stone.properties & Field.king) == Field.king && (board.ContainStone(board.fields[(pos.x - 1), (pos.y - 1)]))) // král nesmí brát kámen
                            )
                        {
                            possiblePosition.Add(pos);
                        }
                        i++;
                    }
                }
            }
            return(possiblePosition);
        }
コード例 #6
0
ファイル: Controlor.cs プロジェクト: jelazi/EvadeWPF
        public List <pos> NextField(Stone stone, pos position, Manager manager) //najde všechny možné pozice - s ohledem na kraj bez ohledu na  ostatní kameny
        {
            List <pos> nextField = new List <pos>();

            if (!((stone.properties & Field.freeze) == Field.freeze))
            {
                int i = 0;
                for (int j = -1; j < 2; j++)
                {
                    for (int k = -1; k < 2; k++)
                    {
                        pos pos;
                        pos.x = k + position.x;
                        pos.y = j + position.y;

                        if (!(
                                pos.x < 1 ||                                             //mimo pole
                                pos.y < 1 ||                                             //mimo pole
                                pos.x > 6 ||                                             // mimo pole
                                pos.y > 6 ||                                             // mimo pole
                                (pos.x == stone.position.x && pos.y == stone.position.y) //stejné pole jako kámen
                                ))
                        {
                            nextField.Add(pos);
                        }
                        i++;
                    }
                }
            }
            return(nextField);
        }
コード例 #7
0
ファイル: Controlor.cs プロジェクト: jelazi/EvadeWPF
        public bool IsPossibleMove(pos posMove, Stone selectStone, Manager manager)  //vrátí bool jestli je možný tah
        {
            List <pos> possiblePosition = new List <pos>();

            possiblePosition = PossiblePosition(selectStone, selectStone.position, manager.Board);
            return(possiblePosition.Contains(posMove));
        }
コード例 #8
0
ファイル: Board.cs プロジェクト: jelazi/EvadeWPF
        public void MakeSelectField(pos selectField, Player playeronTurn, Manager manager) //vybrání pole
        {
            int nowX = selectField.x - 1;
            int nowY = selectField.y - 1;
            int beforeX;
            int beforeY;

            if (ContainStonePlayer(fields[nowX, nowY], playeronTurn))
            {
                beforeX = selectField.x - 1;
                beforeY = selectField.y - 1;
                Stone stone = new Stone();
                stone.properties = fields[nowX, nowY];
                stone.position   = selectField;

                if ((fields[beforeX, beforeY] & Field.choice) == Field.choice)
                {
                    fields[beforeX, beforeY] &= ~Field.choice;
                }
                fields[nowX, nowY] = fields[nowX, nowY] | Field.choice;
                SetSelectField(nowX + 1, nowY + 1);
                control.UnmarkPossibleFields(this);

                List <pos> possiblePosition = new List <pos>();
                possiblePosition = control.PossiblePosition(stone, stone.position, this);
                control.MarkPossibleField(this, possiblePosition);
            }
        }
コード例 #9
0
ファイル: Board.cs プロジェクト: jelazi/EvadeWPF
        public void Back(Manager manager) //tah zpět
        {
            if (manager.HistoryMove.Count > 0)
            {
                manager.PlayerOnTurn = (manager.FindPlayerByName(manager.HistoryMove.Last(), manager));
                Stone stone = new Stone();
                stone.position   = manager.HistoryMove.Last().nextPos;
                stone.properties = manager.HistoryMove.Last().properties;
                pos nextPos   = manager.HistoryMove.Last().nextPos;
                pos beforePos = manager.HistoryMove.Last().beforePos;

                if ((manager.Board.fields[nextPos.x - 1, nextPos.y - 1] & Field.freeze) == Field.freeze) //zamrznuté pole
                {
                    Stone stoneOpposite = new Stone();
                    stoneOpposite.position   = beforePos;
                    stoneOpposite.properties = manager.Board.FreezeStones.Last().properties;
                    manager.OpositePlayer(manager.PlayerOnTurn).Stones.Add(stoneOpposite);
                    manager.Board.fields[beforePos.x - 1, beforePos.y - 1] = stone.properties;
                    manager.Board.fields[nextPos.x - 1, nextPos.y - 1]     = manager.Board.FreezeStones.Last().properties;
                    manager.Board.FreezeStones.RemoveAt(manager.Board.FreezeStones.Count - 1);
                    manager.Board.FreezeStones.RemoveAt(manager.Board.FreezeStones.Count - 1);
                    manager.PlayerOnTurn.Stones.Add(stone);
                    manager.Board.EraseSelectField(manager);                                            //vymazání
                    manager.Board.EraseSelectStone(manager);
                }
                else //normální back
                {
                    manager.Board.MoveStone(stone, manager.HistoryMove.Last().beforePos, manager);
                    manager.HistoryMove.RemoveAt(manager.HistoryMove.Count - 1);
                }
                manager.HistoryMoveBack.Add(manager.HistoryMove.Last());
                manager.HistoryMove.RemoveAt(manager.HistoryMove.Count - 1);
                manager.GetStonesToPlayers();
            }
        }
コード例 #10
0
ファイル: Board.cs プロジェクト: jelazi/EvadeWPF
        public pos ChoicePossibleMove(List <pos> possiblePosition) //automatické vybrání možné pozice
        {
            pos position = new pos();
            int x        = rnd.Next(0, possiblePosition.Count - 1);

            position = possiblePosition[x];
            return(position);
        }
コード例 #11
0
ファイル: Manager.cs プロジェクト: jelazi/EvadeWPF
        public void ChooseStone(pos SelectField, Stone selectStone) //kliknutí na určité pole
        {
            board.MakeSelectField(SelectField, PlayerOnTurn, this); //označení vybraného pole
            Board.Stone = selectStone;                              //vybrání kamene dle označeného pole
            List <pos> possiblePosition = new List <pos>();

            possiblePosition = Controlor.PossiblePosition(selectStone, selectStone.position, Board); //zapsání všech možných pozic
            Controlor.MarkPossibleField(Board, possiblePosition);                                    //označení všech možných pozic
        }
コード例 #12
0
ファイル: Manager.cs プロジェクト: jelazi/EvadeWPF
        public void AddToOneMoveText(Field properties, pos beforePos, pos nextPos)     //přidání tahu do historie
        {
            move move = new move();

            move.properties = properties;
            move.beforePos  = beforePos;
            move.nextPos    = nextPos;
            historyMove.Add(move);
        }
コード例 #13
0
ファイル: MouseClick.cs プロジェクト: jelazi/EvadeWPF
        private void shape_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) //odklik myší z kamene
        {
            try
            {
                countBlick = 10;


                if (gameState == GameState.play)
                {
                    Mouse.Capture(null);
                    captured = false;
                    Canvas.SetZIndex(source, CanvasZindex); //object dolů
                    Cursor = Cursors.Arrow;



                    Canvas.SetLeft(source, beforePoint.X);
                    Canvas.SetTop(source, beforePoint.Y);



                    selectField = FieldPosition(Convert.ToInt32(e.GetPosition(BoardForm).X), Convert.ToInt32(e.GetPosition(BoardForm).Y));

                    if (selectField.x == selectStone.position.x && selectField.y == selectStone.position.y)
                    {
                        manager.Board.fields[beforeField.x - 1, beforeField.y - 1] = selectStone.properties; //vrácení zpátky
                    }
                    else
                    {
                        if (manager.Controlor.IsPossibleMove(selectField, selectStone, manager)) //možný tah?
                        {
                            manager.MoveChoisenStone(selectField, selectStone);                  //přesun vybraného kamene
                            selectStone = new Stone();
                            manager.Controlor.IsEnd(manager, manager.PlayerOnTurn);              //kontrola konce hry
                            HistoryToString();
                            RunningGame();                                                       //popisky ke hře

                            if (manager.End == false)                                            //není konec hry
                            {
                                manager.ChangeOnTurn();                                          //změna hráče na tahu
                                manager.PlayerOnTurn.MarkStones(manager.Board);                  //označení kamenů hráče na tahu
                                Timer.Start();                                                   //spuštění časovače
                            }
                        }
                        else
                        {
                            manager.Board.fields[beforeField.x - 1, beforeField.y - 1] = selectStone.properties; //vrácení zpátky
                        }
                    }


                    DrawStones();
                    RunningGame();
                }
            } catch { }
        }
コード例 #14
0
ファイル: Board.cs プロジェクト: jelazi/EvadeWPF
        public void MoveStone(Stone stone, pos pos, Manager manager) //přesun kamene
        {
            int stoneX = stone.position.x - 1;
            int stoneY = stone.position.y - 1;
            int nextX  = pos.x - 1;
            int nextY  = pos.y - 1;

            if (manager.Board.ContainStone(fields[nextX, nextY]))                                                                          //zamrznutí
            {
                stone.properties &= ~Field.onTurn;                                                                                         //vymazání že je kámen na tahu
                stone.properties &= ~Field.choice;                                                                                         //vymazání že je kámen vybrán
                manager.Board.freezeStones.Add(stone);                                                                                     //přidání útočícího kamene do listu zamrznutých kamenů
                manager.Board.fields[stoneX, stoneY] = Field.empty;                                                                        //vymazání útočícího kamene
                manager.Board.freezeStones.Add(manager.Board.SetStoneFromField(manager.Board.fields[nextX, nextY], nextX + 1, nextY + 1)); //vytvoření kamene z pole na které se útočí a přidání do listu zamrznutých kamenů
                manager.Board.fields[nextX, nextY] = Field.freeze;                                                                         //zamrznutí pole
                manager.Controlor.UnmarkPossibleFields(this);                                                                              //odznačení pole

                EraseSelectField(manager);                                                                                                 //vymazání
                EraseSelectStone(manager);

                pos posBefore;
                posBefore.x = stoneX + 1;
                posBefore.y = stoneY + 1;
                pos posNext;
                posNext.x = nextX + 1;
                posNext.y = nextY + 1;
                manager.AddToOneMoveText(stone.properties, posBefore, posNext);
            }
            else //normální posun
            {
                stone.properties &= ~Field.onTurn;                                  //vymazání že je kámen na tahu
                stone.properties &= ~Field.choice;                                  //vymazání že je kámen vybrán
                stone.position    = pos;                                            //přepsání pozice útočícího kamene
                manager.Board.fields[nextX, nextY]   = stone.properties;            //přesun kamene na nové pole
                manager.Board.fields[stoneX, stoneY] = Field.empty;                 //vymazání kamene z předchozího pole
                manager.Controlor.UnmarkPossibleFields(this);                       //odznačení možných polí

                EraseSelectField(manager);
                EraseSelectStone(manager);

                pos posBefore;
                posBefore.x = stoneX + 1;
                posBefore.y = stoneY + 1;
                pos posNext;
                posNext.x = nextX + 1;
                posNext.y = nextY + 1;
                manager.AddToOneMoveText(stone.properties, posBefore, posNext);
            }
            manager.GetStonesToPlayers();
        }
コード例 #15
0
ファイル: Manager.cs プロジェクト: jelazi/EvadeWPF
 public void MoveChoisenStone(pos selectField, Stone selectStone) //posun kamene po kliku
 {
     Board.MoveStone(selectStone, selectField, this);             //přesun kamene
     Controlor.UnmarkPossibleFields(Board);                       //odznačení předchozích možných pozic
 }
コード例 #16
0
ファイル: MouseClick.cs プロジェクト: jelazi/EvadeWPF
        private void shape_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) //klik myší na kámen
        {
            if (gameState == GameState.play)
            {
                countBlick    = 10;
                source        = (UIElement)sender;
                Cursor        = Cursors.Hand;
                beforePoint.X = Canvas.GetLeft(source);
                beforePoint.Y = Canvas.GetTop(source);
                Mouse.Capture(source);
                captured     = true;
                x_shape      = Canvas.GetLeft(source);
                x_canvas     = e.GetPosition(BoardForm).X;
                y_shape      = Canvas.GetTop(source);
                y_canvas     = e.GetPosition(BoardForm).Y;
                CanvasZindex = Canvas.GetZIndex(source);
                Canvas.SetZIndex(source, 1000); //object vždy navrchu



                selectField = beforeField = FieldPosition(Convert.ToInt32(e.GetPosition(BoardForm).X), Convert.ToInt32(e.GetPosition(BoardForm).Y));

                if (selectStone.properties == Field.empty)
                {
                    selectStone.properties = manager.Board.fields[selectField.x - 1, selectField.y - 1];
                    selectStone.position   = beforeField;

                    manager.ChooseStone(selectField, selectStone); //vybrání nového kamene
                }



                if (manager.Board.ContainStone(manager.Board.fields[selectField.x - 1, selectField.y - 1]) &&
                    manager.Board.ContainStonePlayer(manager.Board.fields[selectField.x - 1, selectField.y - 1], manager.PlayerOnTurn)) //vybral jsem kámen stejného hráče
                {
                    manager.Board.EraseSelectField(manager);                                                                            //odznačení vybraného pole
                    selectStone = new Stone();                                                                                          //odznačení vybraného kamene

                    selectStone.properties = manager.Board.fields[selectField.x - 1, selectField.y - 1];
                    selectStone.position   = beforeField;
                    manager.ChooseStone(selectField, selectStone); //vybrání nového kamene
                }
                if (manager.Board.ContainStone(manager.Board.fields[selectField.x - 1, selectField.y - 1]) &&
                    manager.Board.ContainStonePlayer(manager.Board.fields[selectField.x - 1, selectField.y - 1], manager.OpositePlayer(manager.PlayerOnTurn)))
                {
                    if (manager.Controlor.IsPossibleMove(selectField, selectStone, manager)) //možný tah?
                    {
                        manager.MoveChoisenStone(selectField, selectStone);                  //přesun vybraného kamene
                        selectStone = new Stone();
                        manager.Controlor.IsEnd(manager, manager.PlayerOnTurn);              //kontrola konce hry
                        HistoryToString();
                        RunningGame();                                                       //popisky ke hře
                        if (manager.End == false)                                            //není konec hry
                        {
                            manager.ChangeOnTurn();                                          //změna hráče na tahu
                            manager.PlayerOnTurn.MarkStones(manager.Board);                  //označení kamenů hráče na tahu
                            Timer.Start();                                                   //spuštění časovače
                        }
                    }
                }

                manager.Board.fields[selectField.x - 1, selectField.y - 1] = Field.empty;


                DrawStones();
                RunningGame();
            }
        }