コード例 #1
0
ファイル: Genome.cs プロジェクト: caillou15/Cell-Lab-Remake
    static Genome()
    {
        Genome genome = new Genome();

        genome.InitialModeIndex = 0;
        CellMode mode1 = new CellMode(0);

        genome.AddMode(mode1);
    }
コード例 #2
0
ファイル: Genome.cs プロジェクト: caillou15/Cell-Lab-Remake
 public Genome(int count)
 {
     InitialModeIndex = 0;
     modes            = new CellMode[count];
     for (int i = 0; i < count; i++)
     {
         modes[i] = new CellMode(i);
     }
 }
コード例 #3
0
    public CellMode AddMode()
    {
        CellMode mode = new CellMode(CurrentGenome.ModeCount);

        CurrentGenome.AddMode(mode);

        CallGenomeModeAdded(mode);
        return(mode);
    }
コード例 #4
0
ファイル: Genome.cs プロジェクト: caillou15/Cell-Lab-Remake
 internal void AddMode(CellMode mode)
 {
     CellMode[] newarr = new CellMode[ModeCount + 1];
     for (int i = 0; i < ModeCount; i++)
     {
         newarr[i] = modes[i];
     }
     newarr[ModeCount] = mode;
     modes             = newarr;
 }
コード例 #5
0
    //Instancie des cell aléatoires pour compléter la map
    private List <CellMode> finishMapWithRandomCells()
    {
        List <CellMode> cellModeNotInPaths = new List <CellMode>();

        for (int i = 0; i < indexsOfCellsNotInPath.Count; i++)
        {
            int      randomCellMode = UnityEngine.Random.Range(0, 15);//Valeur brut pour le moment mais doit correspondre au nb de choix possibles dans l'enum
            CellMode typeOfCell     = All_choices[randomCellMode];
            cellModeNotInPaths.Add(typeOfCell);
        }
        return(cellModeNotInPaths);
    }
コード例 #6
0
        void OnCustomCellAppearance(object sender, PivotCustomCellAppearanceEventArgs e)
        {
            bool columnSelected = e.RowIndex == pivotGrid.FocusedCell.Y;
            bool rowSelected    = e.ColumnIndex == pivotGrid.FocusedCell.X;

            if (columnSelected && !rowSelected || !columnSelected && rowSelected)
            {
                CellMode mode = CellMode.Selected;
                if (e.RowValueType > 0 || e.ColumnValueType > 0)
                {
                    mode = mode | CellMode.Tolal;
                }
                e.Background = GetActualCellBackgroundBrush(mode);
                e.Foreground = GetActualCellForegroundBrush(mode);
            }
        }
コード例 #7
0
ファイル: Genome.cs プロジェクト: caillou15/Cell-Lab-Remake
    public object Clone()
    {
        Genome other = new Genome();

        foreach (CellMode mode in modes)
        {
            CellMode clone = new CellMode(mode);
            other.modes.Add(clone);
        }
        for (int i = 0; i < modes.Count; i++)
        {
            CellMode local  = modes[i];
            CellMode remote = other.modes[i];
            remote.Child1 = other.modes[modes.IndexOf(local.Child1)];
            remote.Child2 = other.modes[modes.IndexOf(local.Child2)];
        }
        return(other);
    }
コード例 #8
0
        Brush GetActualCellBackgroundBrush(CellMode actualMode)
        {
            switch (actualMode)
            {
            case CellMode.None:
                return(pivotGrid.CellBackground);

            case CellMode.Selected:
                return(pivotGrid.CellSelectedBackground);

            case CellMode.Tolal:
                return(pivotGrid.CellTotalBackground);

            case CellMode.TotalSelected:
                return(pivotGrid.CellTotalSelectedBackground);

            default:
                throw new Exception("CellMode");
            }
        }
コード例 #9
0
ファイル: GameField.cs プロジェクト: SergeyKoz/Dashes
        public GameCell(int x, int y, CellMode Horizontal, CellMode Vertical, WinMode WinMode)
        {
            this.x = x;
            this.y = y;

            Canvas FieldCanvas = ((MainWindow)(App.Current.MainWindow)).GameFieldCanvas;

            FieldItem = new Line();
            FieldCanvas.Children.Add(FieldItem);

            HorizontalFieldItem = new Line();
            FieldCanvas.Children.Add(HorizontalFieldItem);

            VerticalFieldItem = new Line();
            FieldCanvas.Children.Add(VerticalFieldItem);

            FillFieldItem = new Rectangle();
            FieldCanvas.Children.Add(FillFieldItem);

            SetCell(Horizontal, Vertical);
        }
コード例 #10
0
 public void nucleusDone()
 {
     currentMode = CellMode.Other;
 }
コード例 #11
0
ファイル: GameField.cs プロジェクト: SergeyKoz/Dashes
 public CellSave(CellMode Horizontal, CellMode Vertical, WinMode WinMode)
 {
     this.Horizontal = Horizontal;
     this.Vertical   = Vertical;
     this.WinMode    = WinMode;
 }
コード例 #12
0
 private void CallGenomeModeAdded(CellMode mode)
 {
     BroadcastMessage("GenomeModeAdded", mode);
     BroadcastMessage("GenomeModesChanged");
 }
コード例 #13
0
    /*
     *  Intantiate cell from cellmode
     */
    private void instantiateFor(CellMode mode, int index)
    {
        GameObject cell;
        int        random = 0;

        switch (mode)
        {
        case CellMode.RB:
            random = Random.Range(0, RBCells.Length);
            cell   = RBCells[random];
            break;

        case CellMode.RBL:
            random = Random.Range(0, RBLCells.Length);
            cell   = RBLCells[random];
            break;

        case CellMode.BL:
            random = Random.Range(0, BLCells.Length);
            cell   = BLCells[random];
            break;

        case CellMode.TRB:
            random = Random.Range(0, TRBCells.Length);
            cell   = TRBCells[random];
            break;

        case CellMode.TRBL:
            random = Random.Range(0, TRBLCells.Length);
            cell   = TRBLCells[random];
            break;

        case CellMode.TBL:
            random = Random.Range(0, TBLCells.Length);
            cell   = TBLCells[random];
            break;

        case CellMode.TR:
            random = Random.Range(0, TRCells.Length);
            cell   = TRCells[random];
            break;

        case CellMode.TRL:
            random = Random.Range(0, TRLCells.Length);
            cell   = TRLCells[random];
            break;

        case CellMode.TL:
            random = Random.Range(0, TLCells.Length);
            cell   = TLCells[random];
            break;

        case CellMode.R:
            random = Random.Range(0, RCells.Length);
            cell   = RCells[random];
            break;

        case CellMode.L:
            random = Random.Range(0, LCells.Length);
            cell   = LCells[random];
            break;

        case CellMode.RL:
            random = Random.Range(0, RLCells.Length);
            cell   = RLCells[random];
            break;

        case CellMode.TB:
            random = Random.Range(0, TBCells.Length);
            cell   = TBCells[random];
            break;

        case CellMode.T:
            random = Random.Range(0, TCells.Length);
            cell   = TCells[random];
            break;

        case CellMode.B:
            random = Random.Range(0, BCells.Length);
            cell   = BCells[random];
            break;

        default:
            cell = RBCells[0];
            break;
        }

        int x = index % LEVEL_WIDTH;
        int y = (int)(index / LEVEL_WIDTH);

        Instantiate(cell, new Vector3(x * CELL_WIDTH, -y * CELL_HEIGHT, 0), Quaternion.identity);
    }
コード例 #14
0
ファイル: GameField.cs プロジェクト: SergeyKoz/Dashes
        public void SetCell(CellMode Horizontal, CellMode Vertical)
        {
            int CellSize       = ((App)(Application.Current)).Game.CellSize;
            int DasheThickness = ((App)(Application.Current)).Game.DasheThickness;


            FieldItem.X1 = x * CellSize;
            FieldItem.Y1 = y * CellSize;
            FieldItem.X2 = x * CellSize + 1;
            FieldItem.Y2 = y * CellSize;
            FieldItem.StrokeThickness = 1;
            FieldItem.Stroke          = Brushes.Black;

            HorizontalFieldItem.X1 = x * CellSize;
            HorizontalFieldItem.Y1 = y * CellSize;
            HorizontalFieldItem.X2 = x * CellSize + CellSize + 1;
            HorizontalFieldItem.Y2 = y * CellSize;
            HorizontalFieldItem.StrokeThickness = DasheThickness;

            switch (Horizontal)
            {
            case CellMode.Border:
                HorizontalFieldItem.Stroke = Brushes.Black;
                break;

            case CellMode.Player1:
                HorizontalFieldItem.Stroke = Brushes.Blue;
                break;

            case CellMode.Player2:
                HorizontalFieldItem.Stroke = Brushes.Green;
                break;

            case CellMode.Computer:
                HorizontalFieldItem.Stroke = Brushes.Red;
                break;

            case CellMode.Empty:
                HorizontalFieldItem.Stroke = Brushes.Transparent;
                break;
            }
            this.Horizontal = Horizontal;

            VerticalFieldItem.X1 = x * CellSize;
            VerticalFieldItem.Y1 = y * CellSize;
            VerticalFieldItem.X2 = x * CellSize;
            VerticalFieldItem.Y2 = y * CellSize + CellSize + 1;
            VerticalFieldItem.StrokeThickness = DasheThickness;

            switch (Vertical)
            {
            case CellMode.Border:
                VerticalFieldItem.Stroke = Brushes.Black;
                break;

            case CellMode.Player1:
                VerticalFieldItem.Stroke = Brushes.Blue;
                break;

            case CellMode.Player2:
                VerticalFieldItem.Stroke = Brushes.Green;
                break;

            case CellMode.Computer:
                VerticalFieldItem.Stroke = Brushes.Red;
                break;

            case CellMode.Empty:
                VerticalFieldItem.Stroke = Brushes.Transparent;
                break;
            }
            this.Vertical = Vertical;
        }
コード例 #15
0
 public void cellOrganesDone()
 {
     currentMode = CellMode.Membrane;
 }
コード例 #16
0
ファイル: Genome.cs プロジェクト: caillou15/Cell-Lab-Remake
 public Genome()
 {
     modes       = new List <CellMode>();
     InitialMode = null;
 }
コード例 #17
0
    private void PlacePortal(List <CellMode> proceduralGeneration)
    {
        Mode gameMode = LevelModeSetup.mode;

        if (gameMode == Mode.Wfc)
        {
            // FROM procedural generation
            // Find the longest path and place portal
            //portal.transform.position = new Vector3(0, -CELL_HEIGHT*(LEVEL_HEIGHT - 1), 0);

            bool      findEnd           = false;
            int       currentCellIndex  = 0;
            Direction previousDirection = Direction.left;

            List <Direction> availableDirections = new List <Direction> {
                Direction.top, Direction.right, Direction.bottom, Direction.left
            };

            while (!findEnd)
            {
                CellMode         currentCell = proceduralGeneration[currentCellIndex];
                List <Direction> currentCellAvailableDirections = getDirections(currentCell, currentCellIndex);
                currentCellAvailableDirections.Remove(previousDirection);

                // Get an available direction from current cell
                Direction direction;
                if (currentCellAvailableDirections.Count > 0)
                {
                    int random = Random.Range(0, currentCellAvailableDirections.Count - 1);
                    direction = currentCellAvailableDirections[random];
                }
                else
                {
                    direction = Direction.right;
                }

                previousDirection = getOpposite(direction);

                // Move to the next cell
                int nextCellIndex = GetNextCellIndex(currentCellIndex, direction);
                if (nextCellIndex < 0 || nextCellIndex > LEVEL_WIDTH * LEVEL_HEIGHT - 1)
                {
                    findEnd = true;
                    break;
                }

                // If the algorithm find a path we can continue
                if (IsPathAvailable(proceduralGeneration, direction, nextCellIndex))
                {
                    visitedCellsIndex.Add(currentCellIndex);
                    currentCellIndex = nextCellIndex;
                }
                else
                {
                    findEnd = true;
                }
            }

            portalIndex = currentCellIndex;
        }


        // Place the portal where this algorithm tells us
        int cellXPosition = portalIndex % LEVEL_WIDTH;
        int cellYPosition = portalIndex / LEVEL_WIDTH;

        portal.transform.position = new Vector3(cellXPosition * CELL_WIDTH, -cellYPosition * CELL_HEIGHT, 0);
    }
コード例 #18
0
ファイル: Genome.cs プロジェクト: caillou15/Cell-Lab-Remake
 /// <summary>
 /// Copies the value parameters from other to the new mode.
 /// Does not copy child references.
 /// </summary>
 /// <param name = "other" > the mode to copy from</param>
 internal CellMode(CellMode other)
 {
     Type      = other.Type;
     SplitMass = other.SplitMass;
 }
コード例 #19
0
    /*
     *  Get all the directions for a cellmode
     */
    private List <Direction> getDirections(CellMode cm, int index)
    {
        List <Direction> directions = new List <Direction>();

        switch (cm)
        {
        case CellMode.RB:
            directions.Add(Direction.right);
            directions.Add(Direction.bottom);
            break;

        case CellMode.RBL:
            directions.Add(Direction.right);
            directions.Add(Direction.bottom);
            directions.Add(Direction.left);
            break;

        case CellMode.BL:
            directions.Add(Direction.bottom);
            directions.Add(Direction.left);
            break;

        case CellMode.TRB:
            directions.Add(Direction.top);
            directions.Add(Direction.right);
            directions.Add(Direction.bottom);
            break;

        case CellMode.TRBL:
            directions.Add(Direction.top);
            directions.Add(Direction.right);
            directions.Add(Direction.bottom);
            directions.Add(Direction.left);
            break;

        case CellMode.TBL:
            directions.Add(Direction.top);
            directions.Add(Direction.bottom);
            directions.Add(Direction.left);
            break;

        case CellMode.TR:
            directions.Add(Direction.top);
            directions.Add(Direction.right);
            break;

        case CellMode.TRL:
            directions.Add(Direction.top);
            directions.Add(Direction.right);
            directions.Add(Direction.left);
            break;

        case CellMode.TL:
            directions.Add(Direction.right);
            directions.Add(Direction.left);
            break;

        case CellMode.R:
            directions.Add(Direction.right);
            break;

        case CellMode.L:
            directions.Add(Direction.left);
            break;

        case CellMode.RL:
            directions.Add(Direction.right);
            directions.Add(Direction.left);
            break;

        default:
            break;
        }

        if (index != -1)
        {
            int x = index % LEVEL_WIDTH;
            int y = index / LEVEL_WIDTH;

            if (x == 0)
            {
                directions.Remove(Direction.left);
            }
            if (x == LEVEL_WIDTH)
            {
                directions.Remove(Direction.right);
            }
            if (y == 0)
            {
                directions.Remove(Direction.top);
            }
            if (y == LEVEL_HEIGHT)
            {
                directions.Remove(Direction.bottom);
            }
        }

        return(directions);
    }
コード例 #20
0
    //En fonction du code créé pour la cell, on définit le type de cell à instancier et on l'instancie
    private CellMode createCellModeWithCode(int cellCode, int posInIndexsOfCellsInPath)
    {
        CellMode typeOfCell = CellMode.TRBL;
        //int typeOfCell = 0;
        int rand;

        switch (cellCode)
        {
        case 10:        //1 déplacement vers la droite -> L
            rand       = UnityEngine.Random.Range(0, 8);
            typeOfCell = L_choices[rand];
            break;

        case 20:        //1 déplacement vers le bas -> B
            rand       = UnityEngine.Random.Range(0, 8);
            typeOfCell = T_choices[rand];
            break;

        case 30:        //1 déplacement vers le haut -> T
            rand       = UnityEngine.Random.Range(0, 8);
            typeOfCell = T_choices[rand];
            break;

        case 40:        //1 déplacement vers la gauche -> R
            rand       = UnityEngine.Random.Range(0, 8);
            typeOfCell = R_choices[rand];
            break;

        case 1:        //1 déplacement vers la droite -> R
            rand       = UnityEngine.Random.Range(0, 8);
            typeOfCell = R_choices[rand];
            break;

        case 2:        //1 déplacement vers le bas -> B
            rand       = UnityEngine.Random.Range(0, 8);
            typeOfCell = B_choices[rand];
            break;

        case 3:        //1 déplacement vers le haut -> T
            rand       = UnityEngine.Random.Range(0, 8);
            typeOfCell = T_choices[rand];
            break;

        case 4:        //1 déplacement vers la gauche -> L
            rand       = UnityEngine.Random.Range(0, 8);
            typeOfCell = L_choices[rand];
            break;

        case 11:        //2 déplacement vers la droite -> LR
            rand       = UnityEngine.Random.Range(0, 4);
            typeOfCell = LR_choices[rand];
            break;

        case 12:        //1 déplacement vers la droite puis 1 vers le bas -> LB
            rand       = UnityEngine.Random.Range(0, 4);
            typeOfCell = BL_choices[rand];
            break;

        case 13:        //1 déplacement vers la droite puis 1 vers le haut -> LT
            rand       = UnityEngine.Random.Range(0, 4);
            typeOfCell = TL_choices[rand];
            break;

        case 14:        //1 déplacement vers la droite puis 1 vers la gauche -> Normalement impossible
            Debug.Log("Case 14, normalement pas possible");
            // rand = UnityEngine.Random.Range(0, 4);
            // typeOfCell = LB_choices[rand];
            break;

        case 21:        //1 déplacement vers le bas puis 1 vers la droite -> TR
            rand       = UnityEngine.Random.Range(0, 4);
            typeOfCell = TR_choices[rand];
            break;

        case 22:        //2 déplacement vers le bas -> TB
            rand       = UnityEngine.Random.Range(0, 4);
            typeOfCell = BT_choices[rand];
            break;

        case 23:        //1 déplacement vers le bas puis 1 vers le haut -> Normalement impossible
            Debug.Log("case 23, normalement impossible");
            // rand = UnityEngine.Random.Range(0, 4);
            // typeOfCell = LB_choices[rand];
            break;

        case 24:        //1 déplacement vers le bas puis 1 vers la gauche -> TL
            rand       = UnityEngine.Random.Range(0, 4);
            typeOfCell = TL_choices[rand];
            break;

        case 31:        //1 déplacement vers le haut puis 1 vers la droite -> BR
            rand       = UnityEngine.Random.Range(0, 4);
            typeOfCell = BR_choices[rand];
            break;

        case 32:        //1 déplacement vers le haut puis un vers le bas -> Normalement impossible
            Debug.Log("case 32, normalement impossible");
            // rand = UnityEngine.Random.Range(0, 4);
            // typeOfCell = TB_choices[rand];
            break;

        case 33:        //2 déplacements vers le haut -> BT
            rand       = UnityEngine.Random.Range(0, 4);
            typeOfCell = BT_choices[rand];
            break;

        case 34:        //1 déplacement vers le haut puis 1 vers la gauche -> BL
            rand       = UnityEngine.Random.Range(0, 4);
            typeOfCell = BL_choices[rand];
            break;

        case 41:        //1 déplacement vers la gauche puis 1 vers la droite -> Normalement impossible
            Debug.Log("case 41, normalement impossible");
            // rand = UnityEngine.Random.Range(0, 4);
            // typeOfCell = BR_choices[rand];
            break;

        case 42:        //1 déplacement vers la gauche puis un vers le bas -> BR
            rand       = UnityEngine.Random.Range(0, 4);
            typeOfCell = BR_choices[rand];
            break;

        case 43:        //1 déplacement vers la gauche puis un vers le haut -> TR
            rand       = UnityEngine.Random.Range(0, 4);
            typeOfCell = TR_choices[rand];
            break;

        case 44:        //2 déplacements vers la gauche -> LR
            rand       = UnityEngine.Random.Range(0, 4);
            typeOfCell = LR_choices[rand];
            break;
        }
        return(typeOfCell);
    }
コード例 #21
0
ファイル: GameField.cs プロジェクト: SergeyKoz/Dashes
        public void SetStep(object sender, MouseEventArgs e)
        {
            CellMode StepModeHorizontal = CellMode.Empty;
            CellMode StepModeVertical   = CellMode.Empty;

            if (GameCursor.InGameField)
            {
                GameCursor.CursorPosition.SetPosition(e);

                GameCell Cell = fileldArray[GameCursor.CursorPosition.X, GameCursor.CursorPosition.Y];

                bool IsEnable = false;

                if (GameCursor.CursorLineMode == LineMode.Horizontal && Cell.Horizontal == CellMode.Empty)
                {
                    switch (PlayerMode)
                    {
                    case PlayerMode.Player1:
                        StepModeHorizontal = CellMode.Player1;
                        break;

                    case PlayerMode.Player2:
                        StepModeHorizontal = CellMode.Player2;
                        break;

                    case PlayerMode.Computer:
                        StepModeHorizontal = CellMode.Computer;
                        break;
                    }
                    StepModeVertical = Cell.Vertical;
                    IsEnable         = true;
                }

                if (GameCursor.CursorLineMode == LineMode.Vertical && Cell.Vertical == CellMode.Empty)
                {
                    StepModeHorizontal = Cell.Horizontal;
                    switch (PlayerMode)
                    {
                    case PlayerMode.Player1:
                        StepModeVertical = CellMode.Player1;
                        break;

                    case PlayerMode.Player2:
                        StepModeVertical = CellMode.Player2;
                        break;

                    case PlayerMode.Computer:
                        StepModeVertical = CellMode.Computer;
                        break;
                    }
                    IsEnable = true;
                }

                if (IsEnable)
                {
                    Cell.SetCell(StepModeHorizontal, StepModeVertical);

                    if (!Cell.CheckWinCells())
                    {
                        if (GameMode == GameMode.Player1Player2)
                        {
                            switch (PlayerMode)
                            {
                            case PlayerMode.Player1:
                                PlayerMode = PlayerMode.Player2;
                                break;

                            case PlayerMode.Player2:
                                PlayerMode = PlayerMode.Player1;
                                break;
                            }
                        }

                        if (GameMode == GameMode.Player1Computer)
                        {
                            PlayerMode = PlayerMode.Computer;
                            SetComputerStep();
                            PlayerMode = PlayerMode.Player1;

                            /*switch (PlayerMode)
                             * {
                             *  case PlayerMode.Player1:
                             *      PlayerMode = PlayerMode.Computer;
                             *      break;
                             *  case PlayerMode.Computer:
                             *      PlayerMode = PlayerMode.Player1;
                             *      break;
                             * }*/
                        }
                    }

                    SaveGame();
                }
            }
        }