Exemplo n.º 1
0
 private async Task UpdateBoard()
 {
     UpdateTurnLabel();
     foreach (Control c in BoardLayout.Controls)
     {
         if (c is Panel)
         {
             var pos = BoardLayout.GetPositionFromControl(c);
             var pic = (PictureBox)c.Controls.Find("pic", true)[0];
             if (board.fields[pos.Column, pos.Row].val == null)
             {
                 pic.Image = null;
             }
             else if (board[pos.Column, pos.Row].val.color == Color.Black && board[pos.Column, pos.Row].val is Pawn)
             {
                 pic.Image = Resources.black;
             }
             else if (board[pos.Column, pos.Row].val.color == Color.White && board[pos.Column, pos.Row].val is Pawn)
             {
                 pic.Image = Resources.red;
             }
             else if (board[pos.Column, pos.Row].val.color == Color.Black && board[pos.Column, pos.Row].val is King)
             {
                 pic.Image = Resources.blackking;
             }
             else
             {
                 pic.Image = Resources.redking;
             }
         }
     }
 }
Exemplo n.º 2
0
        private void Button_Save_Click(object sender, RoutedEventArgs e)
        {
            LayoutNameDialog layoutNameDialog = new LayoutNameDialog("保存布局", "布局名称");

            layoutNameDialog.OKButton.Click += (sender1, e1) =>
            {
                if (string.IsNullOrEmpty(layoutNameDialog.LayoutNameTextBox.Text))
                {
                    DialogWarning dialog = new DialogWarning("提示", "请输入布局名称。");
                    dialog.ShowDialog();
                    return;
                }

                BoardLayout newBoardLayout = mainSetting.BuildBoardLayout(this.canvasBorderList, layoutNameDialog.LayoutNameTextBox.Text);
                mainSetting.SaveBoardLayoutToJsonFile(newBoardLayout.LayoutName, newBoardLayout, true);
                mainSetting.savedBoardLayouts.Add(newBoardLayout);

                ComboBoxItem newItem = new ComboBoxItem();
                newItem.Content = newBoardLayout.LayoutName;
                this.ComboBox_BoardLayout.Items.Add(newItem);
                this.ComboBox_BoardLayout.SelectedItem = newItem;

                layoutNameDialog.Close();
            };

            layoutNameDialog.ShowDialog();
        }
Exemplo n.º 3
0
        public int SaveBoardLayoutToJsonFile(string fileName, BoardLayout boardLayout, bool isOverlay)
        {
            string filePath = System.IO.Path.Combine(BoardLayoutFilesFolder, fileName + ".json");

            string layoutJson = string.Empty;

            try
            {
                layoutJson = JsonConvert.SerializeObject(boardLayout);
            }
            catch (Exception)
            {
                return(-1);
            }

            if (!CalabashTools.FileIO.ExistFolder(BoardLayoutFilesFolder))
            {
                CalabashTools.FileIO.CreateFolder(BoardLayoutFilesFolder);
            }

            if (!isOverlay && CalabashTools.FileIO.ExistFile(filePath))
            {
                return(-2);
            }
            else
            {
                CalabashTools.FileIO.Write2File(filePath, layoutJson);
            }

            return(0);
        }
Exemplo n.º 4
0
 public override void Update()
 {
     base.Update();
     if (Input.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.A))
     {
         BoardLayout layout = BoardLayout.DefaultLayout;
         GameBoard.Instance.Load(layout);
     }
 }
Exemplo n.º 5
0
 private void CreatePiecesFromLayout(BoardLayout layout)
 {
     for (int i = 0; i < layout.GetPiecesCount(); i++)
     {
         Vector2Int squareCoords = layout.GetSquareCoordsAtindex(i);
         TeamColor  team         = layout.GetSquareTeamColorAtIndex(i);
         string     typeName     = layout.GetSquarePieceNameAtIndex(i);
         CreatePieceAndInitialize(squareCoords, team, typeName);
     }
 }
Exemplo n.º 6
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        BoardLayout board = (BoardLayout)target;

        EditorGUILayout.Separator();
        if (GUILayout.Button("Align Board"))
        {
            board.AlignBoard();
        }
    }
Exemplo n.º 7
0
        public override void OnStart()
        {
            base.OnStart();

            BoardLayout layout = BoardLayout.DefaultLayout;

            GameBoard.Instance.Load(layout);

            Camera.MinimumZoom = 0.2f;
            Camera.MaximumZoom = 30;
            Camera.ZoomOut(30);
            Camera.Position = new Vector2((float)layout.width / 2, (float)layout.height / 2) * Constants.CellSize;
        }
Exemplo n.º 8
0
        public int SaveBoardLayoutToJsonFile(string fileName, string layoutName, List <DraggableBorder> canvasBorders)
        {
            string filePath = System.IO.Path.Combine(BoardLayoutFilesFolder, fileName + ".json");

            BoardLayout boardLayout = this.BuildBoardLayout(canvasBorders, layoutName);

            if (boardLayout != null)
            {
                this.SaveBoardLayoutToJsonFile(fileName, boardLayout, true);
            }

            return(0);
        }
Exemplo n.º 9
0
        private void MPDSEditor_Load(object sender, EventArgs e)
        {
            byte[] numArray1 = Compression.LZ77Decompress(this.BoardData.Files[1].Data);
            byte[] numArray2 = Compression.LZ77Decompress(this.BoardData.Files[2].Data);
            byte[] numArray3 = Compression.LZ77Decompress(this.BoardData.Files[0].Data);
            byte[] array1    = ((IEnumerable <byte>)numArray1).ToList <byte>().GetRange(4, numArray1.Length - 4).ToArray();
            byte[] array2    = ((IEnumerable <byte>)numArray2).ToList <byte>().GetRange(4, numArray2.Length - 4).ToArray();
            byte[] array3    = ((IEnumerable <byte>)numArray3).ToList <byte>().GetRange(4, numArray3.Length - 4).ToArray();
            this.pictureBox1.Image = (Image)Graphic.ConvertData(array2, 0, 0, array1, array3, 256, 256, Graphic.GXTexFmt.GX_TEXFMT_PLTT16, Graphic.NNSG2dCharacterFmt.NNS_G2D_CHARACTER_FMT_CHAR);
            this.Layout            = new BoardLayout(Compression.LZ77Decompress(this.BoardData.Files[3].Data));
            int index1 = -1;
            int num    = 0;

            for (int index2 = 4; (long)index2 < (long)this.BoardData.NrFiles; ++index2)
            {
                int length = this.BoardData.Files[index2].Data.Length;
                if (length > num)
                {
                    num    = length;
                    index1 = index2;
                }
            }
            this.Model      = new HBDF(Compression.LZ77Decompress(this.BoardData.Files[index1].Data));
            this.Spaces     = new HBDF.TEXSBlock(Compression.LZ77Decompress(this.SystemData.Files[69].Data));
            this.Objects[0] = new HBDF(Compression.LZ77Decompress(this.SystemData.Files[32].Data));
            this.Objects[1] = new HBDF(Compression.LZ77Decompress(this.SystemData.Files[31].Data));
            this.Objects[2] = new HBDF(Compression.LZ77Decompress(this.SystemData.Files[33].Data));
            Gl.ReloadFunctions();
            Gl.glEnable(2896);
            Gl.glEnable(32826);
            Gl.glEnable(2903);
            Gl.glEnable(2929);
            Gl.glEnable(2977);
            Gl.glDisable(2884);
            Gl.glFrontFace(2305);
            Gl.glEnable(3553);
            Gl.glClearDepth(1.0);
            Gl.glEnable(3008);
            Gl.glEnable(3042);
            Gl.glBlendFunc(770, 771);
            Gl.glShadeModel(7425);
            Gl.glAlphaFunc(516, 0.0f);
            Gl.glClearColor(0.2f, 0.2f, 0.2f, 1f);
            GlNitro2.glNitroBindTextures(this.Model, 1);
            GlNitro2.glNitroBindTextures(this.Spaces, (int)this.Model.MDLFBlocks[0].NrTextures + 1);
            GlNitro2.glNitroBindTextures(this.Objects[0], (int)this.Model.MDLFBlocks[0].NrTextures + 1 + this.Spaces.TEXOBlocks.Length);
            GlNitro2.glNitroBindTextures(this.Objects[1], (int)this.Model.MDLFBlocks[0].NrTextures + 1 + this.Spaces.TEXOBlocks.Length + (int)this.Objects[0].MDLFBlocks[0].NrTextures);
            GlNitro2.glNitroBindTextures(this.Objects[2], (int)this.Model.MDLFBlocks[0].NrTextures + 1 + this.Spaces.TEXOBlocks.Length + (int)this.Objects[0].MDLFBlocks[0].NrTextures + (int)this.Objects[1].MDLFBlocks[0].NrTextures);
            this.Render();
        }
Exemplo n.º 10
0
        public List <BoardLayout> LoadBoardLayouts()
        {
            List <BoardLayout> layoutList  = new List <BoardLayout>();
            List <FileInfo>    layoutFiles = CalabashTools.FileIO.ListAllFiles(BoardLayoutFilesFolder);

            if (layoutFiles != null)
            {
                foreach (FileInfo layoutFile in layoutFiles)
                {
                    BoardLayout boardLayout = this.LoadBoardLayoutFromJsonFile(layoutFile.Name);
                    layoutList.Add(boardLayout);
                }
            }

            return(layoutList);
        }
Exemplo n.º 11
0
    public void initMe()
    {
        script = new SerializedObject(target);
        bl     = ((BoardLayout)target);

        if (bl.gm == null)
        {
            bl.gm = bl.GetComponent <GameManager>(); // assign gm ref if needed
        }

        // scripts to use
        scripts = bl.gm.panelManager.GetComponents <PanelDefinition>();
        pieces  = bl.gm.pieceManager.GetComponents <PieceDefinition>();

        // visual textures
        panelEditVisuals = script.FindProperty("panelEditVisuals");
        pieceEditVisuals = script.FindProperty("pieceEditVisuals");

        // weights
        colorWeight = script.FindProperty("colorWeight");

        // random on start boolean
        randomOnStart = script.FindProperty("randomOnStart");
        // show hex grid arrangement
        showHexGrid = script.FindProperty("showHexGrid");
        // use Selector boolean
        useSelector = script.FindProperty("useSelector");

        // max panels during randomization
        randomPanelLimit = script.FindProperty("randomPanelLimit");
        randomPanelCount = script.FindProperty("randomPanelCount");

        // gui usage booleans
        hidePanel1 = script.FindProperty("hidePanel1");
        hidePanel2 = script.FindProperty("hidePanel2");
        hidePanel3 = script.FindProperty("hidePanel3");

        // board GUI setups
        panelArray = script.FindProperty("panelArray"); // for the button arrays
        pStrength  = script.FindProperty("pStrength");  // for the strength fields
        pieceArray = script.FindProperty("pieceArray"); // for the piece types
        colorArray = script.FindProperty("colorArray"); // for the piece color type

        scrollPos  = script.FindProperty("scrollPos");  // for the scrollbar to conpensate for big boards
        scrollPos2 = script.FindProperty("scrollPos2"); // for the scrollbar to conpensate for big boards
        scrollPos3 = script.FindProperty("scrollPos3"); // for the scrollbar to conpensate for big boards
    }
Exemplo n.º 12
0
        private async Task Deselect()
        {
            if (selected == null)
            {
                return;
            }
            var pos = BoardLayout.GetPositionFromControl(selected);

            if ((pos.Column + pos.Row) % 2 == 0)
            {
                selected.BackColor = SystemColors.ControlDark;
            }
            else
            {
                selected.BackColor = SystemColors.ControlLight;
            }
        }
Exemplo n.º 13
0
    //TODO: make blueprint a interface or subclass

    // Use this for initialization
    void Start()
    {
        boardLayout = GetComponent <BoardLayout>();
        boardLayout.initBoardLayout();
        boardLayoutBgs = boardLayout.GetBoardLayoutBg();
        boardColumns   = boardLayoutBgs.GetLength(0);
        boardRows      = boardLayoutBgs.GetLength(1);
        boardOffX      = (boardColumns - 1) / 2f;
        boardOffY      = (boardRows - 1) / 2f;

        blueprint = GetComponent <Blueprint>().getBlueprint();
        //ValidateBoardLayout_withBlueprint(boardLayout, blueprint);

        cdTimer.gameObject.transform.localPosition = new Vector3(0f, boardOffY + 1f, 0f);
        cdTimer.gameObject.SetActive(false);

        InitBoardBG();
        //InitUnits ();
    }
Exemplo n.º 14
0
 private async Task DeselectAll()
 {
     selected = null;
     foreach (Control c in BoardLayout.Controls)
     {
         var pos = BoardLayout.GetPositionFromControl(c);
         if (c is Panel)
         {
             if ((pos.Column + pos.Row) % 2 == 0)
             {
                 c.BackColor = SystemColors.ControlDark;
             }
             else
             {
                 c.BackColor = SystemColors.ControlLight;
             }
         }
     }
 }
Exemplo n.º 15
0
    public void loadScene()
    {
        string path = Application.dataPath + "/LevelData/level1Board.json";

        if (File.Exists(path))
        {
            string levelString = File.ReadAllText(path);
            boardLayout = JsonUtility.FromJson <BoardLayout>(levelString);
            foreach (Tile tile in boardLayout.layout)
            {
                Vector3 position = new Vector3(tile.x, tile.y, 1);
                instantiateTile(position, tile.type);
            }
            enemyStartPosition = new Vector2(boardLayout.path.enemyStartPosition[0],
                                             boardLayout.path.enemyStartPosition[1]);
            enemyEndPosition = new Vector2(boardLayout.path.enemyEndPosition[0],
                                           boardLayout.path.enemyEndPosition[1]);
        }
    }
Exemplo n.º 16
0
    void OnGUI()
    {
        if (Selection.activeGameObject != null)
        {
            bl = Selection.activeGameObject.GetComponent <BoardLayout>();

            if (bl != null)
            {
                showChoices();
            }
            else
            {
                showErrorMsg();                 // tells user to select the GameManger object
            }
        }
        else
        {
            showErrorMsg();             // tells user to select the GameManger object
        }
    }
Exemplo n.º 17
0
        private async Task HighlightMoves()
        {
            if (selected == null)
            {
                return;
            }
            var pos = BoardLayout.GetPositionFromControl(selected);

            if (board[pos.Column, pos.Row].val != null)
            {
                HashSet <Move> list = board[pos.Column, pos.Row].val.GetMovesOrAttacks(board);
                foreach (Move move in list)
                {
                    var x = move.moveTo.x;
                    var y = move.moveTo.y;
                    var c = BoardLayout.GetControlFromPosition(x, y);
                    c.BackColor = SystemColors.Highlight;
                }
            }
        }
Exemplo n.º 18
0
        public BoardLayout BuildBoardLayout(List <DraggableBorder> canvasBorders, string layoutName = "")
        {
            BoardLayout boardLayout = null;

            List <ButtonDefinition> boardDefs = new List <ButtonDefinition>();

            foreach (DraggableBorder border in canvasBorders)
            {
                int              keyCode    = border.KeyCode;
                string           keyText    = border.KeyText;
                Rect             buttonRect = border.RectangleGeometry.Rect;
                ButtonDefinition buttonDef  = new ButtonDefinition(keyCode, keyText, buttonRect);

                boardDefs.Add(buttonDef);
            }

            if (boardDefs.Count > 0)
            {
                boardLayout = new BoardLayout(layoutName, boardDefs);
            }

            return(boardLayout);
        }
Exemplo n.º 19
0
    void OnGUI()
    {
        GameObject sel = Selection.activeGameObject;

        if (sel != null)
        {
            BoardLayout layout = sel.GetComponent <BoardLayout>();

            if (layout != null)
            {
                Editor editor = Editor.CreateEditor(layout);
                editor.OnInspectorGUI();
            }
            else
            {
                showErrorMsg();                 // tells user to select the GameManger object
            }
        }
        else
        {
            showErrorMsg();             // tells user to select the GameManger object
        }
    }
Exemplo n.º 20
0
        private async void HandleCellClick(object sender, EventArgs e)
        {
            Panel p;

            if (sender is PictureBox)
            {
                p = (Panel)((PictureBox)sender).Parent;
            }
            else
            {
                p = (Panel)sender;
            }
            if (selected != null &&
                board[BoardLayout.GetPositionFromControl(selected).Column, BoardLayout.GetPositionFromControl(selected).Row].val != null &&
                board[BoardLayout.GetPositionFromControl(selected).Column, BoardLayout.GetPositionFromControl(selected).Row].val.player == board.playersTurn &&
                board[BoardLayout.GetPositionFromControl(selected).Column, BoardLayout.GetPositionFromControl(selected).Row].val.player is Human)
            {
                var  pos      = BoardLayout.GetPositionFromControl(selected);
                var  fieldPos = BoardLayout.GetPositionFromControl(p);
                Move move     = board.playersTurn.GetAvailableMoves().FirstOrDefault(
                    (a) => a.piece.GetField(board) == board[pos.Column, pos.Row] && a.moveTo.x == fieldPos.Column && a.moveTo.y == fieldPos.Row);
                board.MakeMove(move);
                turn.Text = "Thinking...";
                if (!board.playersTurn.IsDefeated() && board.playersTurn is Computer)
                {
                    stopwatch.Restart();
                    board.MakeTurn(((Computer)board.playersTurn).GetBestTurn());
                    stopwatch.Stop();
                }
            }
            await DeselectAll();

            selected           = p;
            selected.BackColor = SystemColors.Highlight;
            await UpdateBoard();
            await HighlightMoves();
        }
Exemplo n.º 21
0
        public BoardLayout LoadBoardLayoutFromJsonFile(string fileName)
        {
            string      filePath      = System.IO.Path.Combine(BoardLayoutFilesFolder, fileName);
            BoardLayout currentLayout = null;

            if (CalabashTools.FileIO.ExistFile(filePath))
            {
                try
                {
                    string content = CalabashTools.FileIO.ReadFromFile(filePath);

                    if (!string.IsNullOrEmpty(content))
                    {
                        currentLayout = JsonConvert.DeserializeObject <BoardLayout>(content);
                    }
                }
                catch (Exception)
                {
                    return(null);
                }
            }

            return(currentLayout);
        }
Exemplo n.º 22
0
    void OnGUI()
    {
        if (Selection.activeGameObject != null)
        {
            bl = Selection.activeGameObject.GetComponent <BoardLayout>();

            if (bl != null)
            {
                if (script == null)
                {
                    script = new SerializedObject(bl);
                }
                showWeights();
            }
            else
            {
                showErrorMsg();                 // tells user to select the GameManger object
            }
        }
        else
        {
            showErrorMsg();             // tells user to select the GameManger object
        }
    }
        public void have_3_columns()
        {
            List <Column> columns = BoardLayout.Columns();

            Assert.That(columns.Count, Is.EqualTo(3));
        }
Exemplo n.º 24
0
 public void Clear()
 {
     BoardLayout.Fill(EPieces.NoPiece);
     OccupiedBySide.Fill(Zero);
     BoardPieces.Fill(Zero);
 }
        public void have_3_rows()
        {
            List <Row> rows = BoardLayout.Rows();

            Assert.That(rows.Count, Is.EqualTo(3));
        }
Exemplo n.º 26
0
 public void GameLogic(Rules m, int GhostHuman, int GhostAI, int PackPlayerHuman, int PackPlayerAI, Board b, BoardLayout bl)
 {
 }
Exemplo n.º 27
0
 void Start()
 {
     pos    = GetComponent <Transform>();
     layout = board.GetComponent <BoardLayout>();
     setPos();
 }
        public void have_2_diagonals()
        {
            List <Diagonal> diagonals = BoardLayout.Diagonals();

            Assert.That(diagonals.Count, Is.EqualTo(2));
        }
Exemplo n.º 29
0
 public void GameLogic(Rules m, int GhostHuman, int GhostAI, int PackPlayerHuman, int PackPlayerAI, Board b, BoardLayout bl)
 {
 }