Inheritance: IState
Esempio n. 1
0
 public Figure(FigureType type, int r, int c, Board b)
 {
     _figureType = type;
     _row        = r;
     _col        = c;
     _board      = b;
 }
Esempio n. 2
0
 public Player(Board b, bool w, EntityType ptype, ref AbstractGame.StepHandler onStep)
 {
     type = ptype;
     white = w;
     board = b;
     callback    = onStep;
 }
Esempio n. 3
0
 public Game()
 {
     _deck = new Deck();
     _deck.OutOfCards += OnOutOfCards;
     _board = new Board();
     _board.HasWinner += OnWinner;
     _players = new Dictionary<int, Player>();
 }
Esempio n. 4
0
        public Board(Board src)
        {
            Order = src.Order;
            _grid = new List<Tile>();

            foreach (var tile in src._grid)
            {
                _grid.Add(new Tile(tile));
            }
        }
Esempio n. 5
0
        //A lehetséges lépések kiszámítása
        public override IEnumerable<AbstractStep> GetAvailableSteps(IState st)
        {
            try
            {
                Board  state = new Board((Board)st);
                List<QuartoStep> lista = new List<QuartoStep>();

                QuartoStep step;

                if (state.SelectedPiece != null )
                {
                    for (int j = 0; j < 4; j++)
                    {
                        for (int k = 0; k < 4; k++)
                        {
                            if (state.BBoard[j, k].color == 2)
                            {
                                step = new QuartoStep(j, k, state.SelectedPiece);
                                lista.Add(step);
                            }
                        }

                    }
                }
                else
                {
                    for (int i = 0; i < state.ActivePieces.Length; i++)
                    {
                        for (int j = 0; j < 4; j++)
                        {
                            for (int k = 0; k < 4; k++)
                            {
                                if (state.BBoard[j, k].color == 2)
                                {
                                    step = new QuartoStep(j, k, state.ActivePieces[i]);
                                    lista.Add(step);
                                }

                            }

                        }

                    }
                }

                return lista;
            }
            catch (Exception)
            {
                return new List<QuartoStep>();
            }
        }
Esempio n. 6
0
        public Board(Board board)
        {
            // Create the squares and map.
            squares = new int[GridMaxRow, GridMaxCol];
            randomNumber = new Random();

            // Copy the given board.
            for (int i = 0; i < GridMaxRow; i++)
            {
                for (int j = 0; j < GridMaxCol; j++)
                {
                    squares[i, j] = board.squares[i, j];
                }
            }
        }
Esempio n. 7
0
 public static async Task<Move> PickBestMove(Board Board, int Depth)
 {
     CountOfConfigurationsScored = 0;
     DepthReached = 0;
     WinConditionFound = false;
     var entry = AI.CreateEntry(Board);
     await Task.Run(() =>
         {
             while (DepthReached < Depth && !WinConditionFound)
                 ExpandMax(entry, 0, Depth);
         });
     if (entry.Moves.Count == 0) throw new InvalidOperationException();
     var max = entry.Moves.Where(m => !m.Ignored).Max(m => m.Score);
     var index = Random.Next(0, entry.Moves.Where(m => !m.Ignored && m.Score == max).Count());
     return entry.Moves.Where(m => !m.Ignored && m.Score == max).ElementAt(index).Move;
 }
Esempio n. 8
0
 public Board(Board oBoard)
 {
     bBoard = new Piece[4, 4];
         for (int i = 0; i < BHeight; i++)
         {
             for (int j = 0; j < BWidth; j++)
             {
                 bBoard[i, j] = new Piece(oBoard.BBoard[i, j].color,
                                          oBoard.BBoard[i, j].height,
                                          oBoard.BBoard[i, j].shape,
                                          oBoard.BBoard[i, j].full);
             }
         }
         ActivePieces = new Piece[oBoard.activePieces.Length];
         for (int i = 0; i < oBoard.activePieces.Length; ++i)
         {
             ActivePieces[i] = new Piece(oBoard.ActivePieces[i].height, oBoard.ActivePieces[i].color, oBoard.ActivePieces[i].shape, oBoard.ActivePieces[i].full);
         }
         SelectedPiece = oBoard.SelectedPiece;
 }
Esempio n. 9
0
        public List<Move> Solution()
        {
            var root = new SolutionNode(null, Game.Current);
            if (Game.Current.IsSameBoard(Game.Solved))
            {
                var moves = new List<Move>();
                moves.Add(new Move(Move.Moves.Start));
                return moves;
            }

            var legalMoves = Game.Current.LegalMoves();
            var visited = new List<Tuple<SolutionNode, Move>>();

            visited.Add(new Tuple<SolutionNode, Move>(root,
                new Move(Move.Moves.Start)));

            var nodeQueue = new Queue<Tuple<SolutionNode, Move>>();

            foreach (var move in legalMoves)
            {
                var board = new Board(Game.Current);
                board.ApplyMove(move);

                var node = new SolutionNode(root, board);
                root.Children.Add(move, node);

                if (board.IsSameBoard(Game.Solved))
                {
                    var n = new Tuple<SolutionNode, Move>(node, move);
                    visited.Add(n);
                    return SolutionPath(n, visited);
                }
                else
                {
                    nodeQueue.Enqueue(
                        new Tuple<SolutionNode, Move>(node, move));
                }
            }

            return BreadthFirstSearch(nodeQueue, visited);
        }
Esempio n. 10
0
        internal Village(Game game, string name)
            : base(game)
        {
            Debug.Assert(!String.IsNullOrWhiteSpace(name));
            Debug.Assert(game != null, @"(village, Village) Game is null");

            // Initialize village's grid
            _villageGrid = new Board();

            // Initilize village's lists
            BuildingsList = new Buildings.BuildingsList(this);
            EmptyHouseList = new List<Buildings.House>();
            JobsList = new JobList(this);
            _familiesList = new FamilyInVillageList(this);
            _upgrades = new UpgradesList(this);

            // Initialize historized values
            _offeringsPointsPerTick = new HistorizedValue<int, Village>(this, @"_offeringsPointsPerTick", 20);
            _villagePop = new HistorizedValue<int, Village>(this, @"_villagePop", 20);

            // Set values
            _name = name;
            _offeringsPointsPerTick.Current = 1;
        }
Esempio n. 11
0
 public Puzzle(int order, int shuffleMoves = 10)
 {
     Solved = new Board(order);
     Current = new Board(Solved);
     Current.Shuffle(shuffleMoves);
 }
Esempio n. 12
0
 void Start()
 {
     slots = transform.GetComponentsInChildren <Slot>();
     board = new Game.Board(3, 3, 3);
 }
Esempio n. 13
0
        public IEnumerable<Move> Shuffle(int count)
        {
            var moves = new List<Move>();
            var gameStates = new List<Board>();
            var legalMoves = new List<Move>(LegalMoves());
            ShuffleMoves(legalMoves);
            Move moveToApply = null;

            gameStates.Add(this);

            for (int i = 0; i < count; i++)
            {
                foreach (var move in legalMoves)
                {
                    Board board = new Board(this);
                    board.ApplyMove(move);

                    bool hasBoard = false;

                    foreach (var gameState in gameStates)
                    {
                        if (gameState.IsSameBoard(board))
                        {
                            hasBoard = true;
                            break;
                        }
                    }

                    if (hasBoard)
                    {
                        gameStates.Add(board);
                        moveToApply = move;
                        break;
                    }
                }

                ApplyMove(moveToApply);
                moves.Add(moveToApply);
            }

            return moves;
        }
Esempio n. 14
0
 public bool Equals(Board Other)
 {
     fixed (byte* x = Data)
         for (byte i = 0; i < 20; ++i)
             if (x[i] != Other._data(i)) return false;
     return true;
 }
Esempio n. 15
0
 public Board WithTile(byte Index, Tile Tile)
 {
     var r = new Board(this);
     r.Data[Index + 1] = Tile.Data;
     return r;
 }
Esempio n. 16
0
 // Grid Methods
 private List<SquareControl> SetEmptySquaresList(List<SquareControl> list, Board b, SquareControl[,] g)
 {
     for (int i = 0; i < Board.GridMaxRow; i++)
         for (int j = 0; j < Board.GridMaxCol; j++)
             if(b.IsValidSquare(i, j))
                 list.Add(g[i, j]);
     return list;
 }
Esempio n. 17
0
 public BoardTests()
 {
     _board = new Board();
     _hasWinner = false;
 }
Esempio n. 18
0
 public SolutionNode(SolutionNode parent, Board board)
 {
     _parent = parent;
     _current = board;
 }
Esempio n. 19
0
        // Megadja a legális lépéseket
        public static LinkedList<int[]> getLegalSteps(Board board, Figure figure, bool fromCheckTest)
        {
            if (figure == null || figure.getFigureType() == FigureType.Nothing)
                return null;

            LinkedList<int[]>  LegalSteps       = new LinkedList<int[]>();
            FigureType figureType               = figure.getFigureType();

            bool					white		= figure.isWhite();
            int                     j           = -1;
            LinkedList<int[]>       steps       = new LinkedList<int[]>();

            int fromRow                         = figure.getRow();
            int fromCol                         = figure.getCol();

            switch (figureType)
            {
            case FigureType.King:

                StepType ans;

                steps.AddLast(new int[] { fromRow - 1, fromCol - 1, 0 });
                steps.AddLast(new int[] { fromRow - 1, fromCol, 0 });
                steps.AddLast(new int[] { fromRow - 1, fromCol + 1, 0 });
                steps.AddLast(new int[] { fromRow, fromCol - 1, 0 });
                steps.AddLast(new int[] { fromRow, fromCol + 1, 0 });
                steps.AddLast(new int[] { fromRow + 1, fromCol - 1, 0 });
                steps.AddLast(new int[] { fromRow + 1, fromCol, 0 });
                steps.AddLast(new int[] { fromRow + 1, fromCol + 1, 0 });

                foreach (int[] step in steps)
                {
                    ans = Figure.isLegalStep(board, fromRow, fromCol, step[0], step[1]);
                    if (ans == StepType.Success)
                    {
                        step[2] = 1;
                        LegalSteps.AddLast(step);
                    } else if (ans == StepType.Capture)
                    {
                        step[2] = 2;
                        LegalSteps.AddLast(step);
                    } else if (ans == StepType.CaptureKing)
                    {
                        step[2] = 3;
                        LegalSteps.AddLast(step);
                    }
                }

                break;

            case FigureType.Queen:

                steps.AddLast( new int[] {1,	0,	0 } );
                steps.AddLast( new int[] {-1,	0,	0 } );
                steps.AddLast( new int[] {0,	1,	0 } );
                steps.AddLast( new int[] {0,	-1,	0 } );
                steps.AddLast( new int[] {1,	1,	0 } );
                steps.AddLast( new int[] {1,	-1,	0 } );
                steps.AddLast( new int[] {-1,	1,	0 } );
                steps.AddLast( new int[] {-1,	-1,	0 } );

                foreach (int[] step in steps)
                {
                    j   = 0;
                    while (j >= 0)
                    {
                        ++j;
                        ans = Figure.isLegalStep(board, fromRow, fromCol, fromRow + step[0] * j, fromCol + step[1] * j);
                        if (ans == StepType.Success)				LegalSteps.AddLast( new int[] {fromRow + step[0] * j, fromCol + step[1] * j, 1} );
                        else if (ans == StepType.Capture){		    LegalSteps.AddLast( new int[] {fromRow + step[0] * j, fromCol + step[1] * j, 2} ); j = -1; }
                        else if (ans == StepType.CaptureKing){	    LegalSteps.AddLast( new int[] {fromRow + step[0] * j, fromCol + step[1] * j, 3} ); j = -1; }
                        else if (ans == StepType.Failure)		    j = -1;
                    }
                }

                break;

            case FigureType.Rook:
                steps.AddLast( new int[] {1,	0,	0 } );
                steps.AddLast( new int[] {-1,	0,	0 } );
                steps.AddLast( new int[] {0,	1,	0 } );
                steps.AddLast( new int[] {0,	-1,	0 } );

                foreach (int[] step in steps)
                {
                    j   = 0;
                    while (j >= 0)
                    {
                        ++j;
                        ans = Figure.isLegalStep(board, fromRow, fromCol, fromRow + step[0] * j, fromCol + step[1] * j);
                        if (ans == StepType.Success)				LegalSteps.AddLast( new int[] {fromRow + step[0] * j, fromCol + step[1] * j, 1} );
                        else if (ans == StepType.Capture){		    LegalSteps.AddLast( new int[] {fromRow + step[0] * j, fromCol + step[1] * j, 2} ); j = -1; }
                        else if (ans == StepType.CaptureKing){	    LegalSteps.AddLast( new int[] {fromRow + step[0] * j, fromCol + step[1] * j, 3} ); j = -1; }
                        else if (ans == StepType.Failure)		    j = -1;
                    }
                }
                break;

            case FigureType.Bishop:
                steps.AddLast( new int[] {1,	1,	0 } );
                steps.AddLast( new int[] {1,	-1,	0 } );
                steps.AddLast( new int[] {-1,	1,	0 } );
                steps.AddLast( new int[] {-1,	-1,	0 } );

                foreach (int[] step in steps)
                {
                    j = 0;
                    while (j >= 0)
                    {
                        ++j;
                        ans = Figure.isLegalStep(board, fromRow, fromCol, fromRow + step[0] * j, fromCol + step[1] * j);
                        if (ans == StepType.Success)				LegalSteps.AddLast( new int[] {fromRow + step[0] * j, fromCol + step[1] * j, 1} );
                        else if (ans == StepType.Capture){		    LegalSteps.AddLast( new int[] {fromRow + step[0] * j, fromCol + step[1] * j, 2} ); j = -1; }
                        else if (ans == StepType.CaptureKing){	    LegalSteps.AddLast( new int[] {fromRow + step[0] * j, fromCol + step[1] * j, 3} ); j = -1; }
                        else if (ans == StepType.Failure)		    j = -1;
                    }
                }
                break;

            case FigureType.Knight:

                steps.AddLast( new int[] { fromRow - 2, fromCol - 1, 0 } );
                steps.AddLast( new int[] { fromRow - 2, fromCol + 1, 0 } );
                steps.AddLast( new int[] { fromRow + 2, fromCol - 1, 0 } );
                steps.AddLast( new int[] { fromRow + 2, fromCol + 1, 0 } );
                steps.AddLast( new int[] { fromRow - 1, fromCol - 2, 0 } );
                steps.AddLast( new int[] { fromRow + 1, fromCol - 2, 0 } );
                steps.AddLast( new int[] { fromRow - 1, fromCol + 2, 0 } );
                steps.AddLast( new int[] { fromRow + 1, fromCol + 2, 0 } );

                foreach (int[] step in steps)
                {
                    ans = Figure.isLegalStep(board, fromRow, fromCol, step[0], step[1]);
                    if (ans == StepType.Success)
                    {
                        step[2] = 1;
                        LegalSteps.AddLast(step);
                    } else if (ans == StepType.Capture)
                    {
                        step[2] = 2;
                        LegalSteps.AddLast(step);
                    } if (ans == StepType.CaptureKing)
                    {
                        step[2] = 3;
                        LegalSteps.AddLast(step);
                    }
                }
                break;

            case FigureType.Pawn:
                int modifier = white ? -1 : 1;
                if (Figure.isLegalStep(board, fromRow, fromCol, fromRow + modifier, fromCol) == StepType.Success)
                    LegalSteps.AddLast(new int[] { fromRow + modifier, fromCol, 1 });

                ans = Figure.isLegalStep(board, fromRow, fromCol, fromRow + modifier, fromCol - 1);
                if (ans == StepType.Capture)
                    LegalSteps.AddLast(new int[] { fromRow + modifier, fromCol - 1, 2 });
                if (ans == StepType.CaptureKing)
                    LegalSteps.AddLast(new int[] { fromRow + modifier, fromCol - 1, 3 });

                ans = Figure.isLegalStep(board, fromRow, fromCol, fromRow + modifier, fromCol + 1);
                if (ans == StepType.Capture)
                    LegalSteps.AddLast(new int[] { fromRow + modifier, fromCol + 1, 2 });
                if (ans == StepType.CaptureKing)
                    LegalSteps.AddLast(new int[] { fromRow + modifier, fromCol + 1, 3 });
                break;
            }

               // Console.WriteLine(figure.getFigureType() + " " + figure.getRow() + " " + fromCheckTest);
            if (!fromCheckTest)
            {
                Board tBoard = board.Clone();
                for (int i = 0; i < LegalSteps.Count(); ++i)
                {
                    Console.WriteLine(figure.getFigureType() + " " + figure.getRow() + " " + fromCheckTest);
                    Console.WriteLine(i + " " + fromRow + " " + fromCol);
                    Console.WriteLine(1 + " " + tBoard.getFigureAt(fromRow, fromCol).getFigureType());
                    tBoard.Step(fromRow, fromCol, LegalSteps.ElementAt(i)[0], LegalSteps.ElementAt(i)[1]);

                    if (tBoard.checkTest(white))
                    {
                        tBoard.Step(LegalSteps.ElementAt(i)[0], LegalSteps.ElementAt(i)[1], fromRow, fromCol);
                        LegalSteps.Remove(LegalSteps.ElementAt(i));
                        --i;
                    } else
                        tBoard.Step(LegalSteps.ElementAt(i)[0], LegalSteps.ElementAt(i)[1], fromRow, fromCol);

                }
            }

            return LegalSteps;
        }
Esempio n. 20
0
 // Megadja, hogy adott figurához a másik figura ellenség-e
 protected static bool isEnemy(Board board, int fr, int fc, int r, int c)
 {
     return board.getFigureAt(r, c).isWhite() != board.getFigureAt(fr, fc).isWhite();
 }
Esempio n. 21
0
 public void setBoard(Board board)
 {
     _board = board;
 }
Esempio n. 22
0
        // egy lépés szimulálása
        public override IState SimulateStep(IState current, AbstractStep step)
        {
            if (!(step is QuartoStep))
                throw new Exception("Not proper step type!");
            QuartoStep cStep = (QuartoStep)step;
            Board returnBoard = new Board((Board)current);

            if (returnBoard.SelectedPiece == null)
            {
                returnBoard.SelectedPiece= cStep.P;
                returnBoard.UpdateActivePieces(returnBoard.ActivePieces, returnBoard.SelectedPiece);

            }
            else
            {

                   returnBoard.insertPiece(cStep.X, cStep.Y, returnBoard.SelectedPiece);
                   returnBoard.SelectedPiece = null;
                   returnBoard.checkWinningState();

            }

            if (returnBoard == (Board)current)
            {
                return null;
            }
            return returnBoard;
        }
Esempio n. 23
0
 private void UpdateGrid(Board board, SquareControl[,] grid)
 {
     // Map the current game board to the square controls.
     for (int i = 0; i < Board.GridMaxRow; i++)
     {
         for (int j = 0; j < Board.GridMaxCol; j++)
         {
             grid[i, j].Contents = board.GetSquareContents(i, j);
             grid[i, j].Refresh();
         }
     }
 }
Esempio n. 24
0
 public Quarto()
 {
     activeBoard = new Board();
 }
Esempio n. 25
0
 private void UpdateSquare(int row, int col, SquareControl[,] grid, Board board)
 {
     grid[row, col].Contents = board.GetSquareContents(row, col);
     grid[row, col].Refresh();
 }
Esempio n. 26
0
 public Board WithHeader(StateHeader Header)
 {
     var r = new Board(this);
     r.Data[0] = Header.Data;
     return r;
 }
Esempio n. 27
0
        // InGameMenu Events
        public void GoBackToMenu()
        {
            LockEverything();

            // Show loading effects
            _loading.BringToFront();
            _loading.Show();
            _loading.Refresh();

            // Remove gameMenu
            this.Controls.Remove(_gameMenu);

            // Set double-buffering
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.DoubleBuffer, true);

            // Remove grid
            for (int i = 0; i < Board.GridMaxRow; i++)
                for (int j = 0; j < Board.GridMaxCol; j++)
                    this.Controls.Remove(_grid[i, j]);

            // Remove window elements
            this.Controls.Remove(_actionMenu);
            this.Controls.Remove(_infoBox);
            this.Controls.Remove(_scenarioBox);
            this.Controls.Remove(_stats);
            this.Controls.Remove(_eventFlux);
            this.Controls.Remove(_actionsPanel);

            // Destroy Grid & Board
            _board = null;
            _grid = null;

            // Hide loading effects
            _loading.SendToBack();
            _loading.Hide();

            // Show HomePage
            _home.Show();
            gleipnir_logo.Show();
        }
Esempio n. 28
0
 public Board(Board Source)
 {
     fixed (byte* x = Data)
         for (var i = 0; i < 20; ++i)
             x[i] = Source.Data[i];
 }
Esempio n. 29
0
        // NewGame
        public void StartGame()
        {
            // Suspend Graphic Update
            this.SuspendLayout();

            // Hide home page
            _home.Visible = false;
            _home.Hide();
            _loading.BringToFront();
            _loading.Visible = true;
            _loading.Show();
            _loading.Refresh();

            // Restart Graphics Updates
            this.ResumeLayout();

            // Suspend Graphic Update
            this.SuspendLayout();

            // Create the game & objects
            _game = new Game.Game();
            _gameMenu = new InGameMenu(this);
            _stats = new InformationsUC(this);
            _eventFlux = new EventFluxUC();
            _scenarioBox = new ScenarioBox(this);
            _actionMenu = new TabIndex(this);
            _infoBox = new InformationBox(this);
            _actionsPanel = new ActionsPanel(this);
            _grid = new SquareControl[Board.GridMaxRow, Board.GridMaxCol];
            _board = _game.Villages[0].VillageGrid;
            options = new Options();

            #region Grid Generation
            // Set double-buffering
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.DoubleBuffer, true);

            for (int i = 0; i < Board.GridMaxRow; i++)
            {
                for (int j = 0; j < Board.GridMaxCol; j++)
                {
                    // Create
                    _grid[i, j] = new SquareControl(i, j);

                    // Hide & Configure
                    _grid[i, j].Visible = false;
                    _grid[i, j].SuspendLayout();
                    _grid[i, j].Left = 220 + (j * _grid[i, j].Width);
                    _grid[i, j].Top = 40 + (i * _grid[i, j].Height);
                    _grid[i, j].SendToBack();
                    this.Controls.Add(_grid[i, j]);
                    _grid[i, j].ResumeLayout();

                    // Add events
                    _grid[i, j].MouseMove += new MouseEventHandler(SquareControl_MouseMove);
                    _grid[i, j].MouseLeave += new EventHandler(SquareControl_MouseLeave);
                    _grid[i, j].Click += new EventHandler(SquareControl_Click);
                }
            }
            #endregion

            // Setting the grid
            _board.SetForNewGame(_game);
            _emptySquaresList = new List<SquareControl>();
            _emptySquaresList = SetEmptySquaresList(_emptySquaresList, _board, _grid);
            UpdateGrid(_board, _grid);

            #region Create, Hide and Configure objects
            // InGameMenu
            _gameMenu.SuspendLayout();
            _gameMenu.Anchor = (AnchorStyles.Top | AnchorStyles.Right);
            _gameMenu.BringToFront();
            this.Controls.Add(_gameMenu);
            _gameMenu.ResumeLayout();
            _gameMenu.Visible = false;
            _gameMenu.Hide();

            // Stats
            _stats.SuspendLayout();
            _stats.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
            _stats.SendToBack();
            PushGeneralGold(_game.TotalGold); //PushGeneralGold(_game.Villages[0].Gold);
            PushPopulation(_game.TotalPop);
            PushGeneralFaith(_game.Villages[0].Faith);
            PushGeneralHappiness(_game.Villages[0].Happiness);
            PushGeneralCoins(_game.Offerings);
            PushOfferingsPointsPerTick(_game.Villages[0].OfferingsPointsPerTick);
            this.Controls.Add(_stats);
            _stats.ResumeLayout();
            _stats.Visible = false;
            _stats.Hide();

            // EventFlux
            _eventFlux.Visible = false;
            _eventFlux.Hide();
            _eventFlux.SuspendLayout();
            _eventFlux.Anchor = (AnchorStyles.Top | AnchorStyles.Right);
            _eventFlux.SendToBack();
            this.Controls.Add(_eventFlux);
            _eventFlux.ResumeLayout();

            // ActionsPanel
            _actionsPanel.Visible = false;
            _actionsPanel.Hide();
            _actionsPanel.SuspendLayout();
            _actionsPanel.Anchor = (AnchorStyles.Top | AnchorStyles.Right);
            _actionsPanel.SendToBack();
            this.Controls.Add(_actionsPanel);
            _actionsPanel.ResumeLayout();

            // ScenarioBox
            _scenarioBox.Visible = false;
            _scenarioBox.Hide();
            _scenarioBox.SuspendLayout();
            _scenarioBox.Anchor = AnchorStyles.Bottom;
            _scenarioBox.SendToBack();
            this.Controls.Add(_scenarioBox);
            _scenarioBox.ResumeLayout();

            // ActionMenu
            _actionMenu.Visible = false;
            _actionMenu.Hide();
            _actionMenu.SuspendLayout();
            _actionMenu.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Top);
            _actionMenu.SendToBack();
            this.Controls.Add(_actionMenu);
            _actionMenu.ResumeLayout();
            _actionMenu.Refresh();

            // InfoBox
            _infoBox.Visible = false;
            _infoBox.Hide();
            _infoBox.SuspendLayout();
            _infoBox.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
            _infoBox.SetNothingSelected();
            this.Controls.Add(_infoBox);
            _infoBox.ResumeLayout();
            #endregion

            // Hide loading effects
            gleipnir_logo.Visible = false;
            gleipnir_logo.Hide();
            gleipnir_logo.Refresh();
            _loading.SendToBack();
            _loading.Visible = false;
            _loading.Hide();

            #region Show Elements
            _actionMenu.Visible = true;
            _actionMenu.Show();
            _stats.Visible = true;
            _stats.Show();
            _eventFlux.Visible = true;
            _eventFlux.Show();
            _scenarioBox.Visible = true;
            _scenarioBox.Show();
            _infoBox.Visible = true;
            _infoBox.Show();
            for (int i = 0; i < Board.GridMaxRow; i++)
            {
                for (int j = 0; j < Board.GridMaxCol; j++)
                {
                    _grid[i, j].Visible = true;
                    _grid[i, j].Show();
                }
            }
            #endregion

            #region Trace Window
            trace = new traceBox();
            //trace.Show();
            #endregion

            // Wait the scenario's end
            // LockEverything();
            PushText("","Bienvenue à Ragnar");
            // Timer
            if (_interval == 0)
                _timer = null;
            else
            {
                _timer = new System.Windows.Forms.Timer();
                _timer.Tick += (source, eventArgs) => { Step(); };
                _timer.Interval = _interval;
                _timer.Start();
            }
            GameStarted = true;

            // Restart Graphics Updates
            this.ResumeLayout();
        }
Esempio n. 30
0
        // Grid Events
        private void SquareControl_MouseMove(object sender, MouseEventArgs e)
        {
            SquareControl squareControl = (SquareControl)sender;

            // If the square is Empty and the player wants place a building
            #region Select Empty
            if (_board.IsValidSquare(squareControl.Row, squareControl.Col)
                && actionState == ActionState.InPlace)
            {
                // If the square is selected and his last content is empty
                if (!squareControl.IsActive && squareControl.PreviewContents == Board.EmptyInt)
                {
                    // If the show valid place option is active, mark the square
                    if (options.showValidPlaces)
                    {
                        squareControl.IsActive = true;

                        // If the preview place option is not active, update the square display now
                        if (!options.previewSquares)
                            squareControl.Refresh();
                    }

                    // If the preview place option is active, mark the appropriate squares
                    if (options.previewSquares)
                    {
                        // Create a temporary board to make the move on
                        Board copy_board = new Board(_board);

                        // Set up the move preview
                        for (int i = 0; i < Board.GridMaxRow; i++)
                        {
                            for (int j = 0; j < Board.GridMaxCol; j++)
                            {
                                if (copy_board.GetSquareContents(i, j) != _board.GetSquareContents(i, j))
                                {
                                    // Set and update the square display
                                    _grid[i, j].PreviewContents = copy_board.GetSquareContents(i, j);
                                    _grid[i, j].Refresh();
                                }
                            }
                        }
                    }
                }

                // Change the cursor
                squareControl.Cursor = Cursors.Hand;
            }
            #endregion
            // If the square is a building & the player wants repair building
            #region Select Building
            else if (_board.IsBuilding(squareControl.Row, squareControl.Col)
                && (actionState == ActionState.None || actionState == ActionState.SelectRepair))
            {
                // If the square is selected
                if (!squareControl.IsActive)
                {
                    // If the show valid place option is active, mark the square
                    if (options.showValidPlaces)
                    {
                        squareControl.IsActive = true;

                        // If the preview place option is not active, update the square display now
                        if (!options.previewSquares)
                            squareControl.Refresh();
                    }

                    // If the preview place option is active, mark the appropriate squares
                    if (options.previewSquares)
                    {
                        // Create a temporary board
                        Board copy_board = new Board(_board);

                        // Set up the move preview
                        for (int i = 0; i < Board.GridMaxRow; i++)
                        {
                            for (int j = 0; j < Board.GridMaxCol; j++)
                            {
                                if (copy_board.GetSquareContents(i, j) != _board.GetSquareContents(i, j))
                                {
                                    // Set and update the square display
                                    _grid[i, j].PreviewContents = copy_board.GetSquareContents(i, j);
                                    _grid[i, j].Refresh();
                                }
                            }
                        }
                    }
                }

                // Change the cursor
                squareControl.Cursor = Cursors.Hand;
            }
            #endregion
        }
Esempio n. 31
0
        // Megnézi, hogy adott figurával legális lépés-e
        public static StepType isLegalStep(Board board, int fromRow, int fromCol, int toRow, int toCol)
        {
            if (toRow < 0 || toRow >= board.getDimension()[1] || toCol < 0 || toCol >= board.getDimension()[0])
                return StepType.Failure;

            if (fromRow == toRow && fromCol == toCol)
                return StepType.Failure;

            Figure figure = board.getFigureAt(toRow, toCol);

            if (figure == null || figure.getFigureType() == FigureType.Nothing)
                return StepType.Success;

            if (Figure.isEnemy(board, fromRow, fromCol, toRow, toCol))
            {
                if (figure.getFigureType() == Figure.FigureType.King)
                    return StepType.CaptureKing;
                return StepType.Capture;
            }

            return StepType.Failure;
        }