Example #1
0
 public Player(Color myColor)
 {
     this.MyColor = myColor;
     MyPawns = new Pawn[4];
     MyBases = new BaseField[4];
     MyHomes = new HomeField[4];
 }
Example #2
0
 public void AddHome(HomeField homef)
 {
     for (int i = 0; i < 4; i++)
     {
         if (MyHomes[i] == null)
         {
             MyHomes[i] = homef;
             break;
         }
     }
 }
Example #3
0
        public void BuildBoardFields(string[] lines)
        {
            Field currentField = null;
            Field previousField = null;
            Field continueOn = null;
            Player currentPlayer;
            for (int y = 1; y < lines.Length; y++)
            {
                for (int x = 0; x < lines[y].Length; x++)
                {
                    if (Origin != null)
                    {
                        previousField = currentField;
                    }
                    switch (y)
                    {
                        case 1: CurrentColor = Color.Yellow; break;
                        case 2: CurrentColor = Color.Green; break;
                        case 3: CurrentColor = Color.Red; break;
                        case 4: CurrentColor = Color.Blue; break;
                    }
                    if (x == 0)
                    {
                        currentField = new StartField(CurrentColor);
                        if (y == 1) { Origin = currentField; }
                        if (y > 1) { previousField = continueOn; previousField.Next = currentField; currentField.Previous = previousField; }
                        if (GetPlayerByColor(CurrentColor) != null)
                        {
                            currentPlayer = GetPlayerByColor(CurrentColor);
                            currentPlayer.MyStart = (StartField)currentField;
                        }

                    }
                    if (x > 0 && x < 9)
                    {
                        currentField = new Field();
                        currentField.Previous = previousField;
                        previousField.Next = currentField;
                    }
                    if (x == 9)
                    {
                        currentField = new EndField();
                        currentField.Previous = previousField;
                        previousField.Next = currentField;
                        continueOn = currentField;
                    }
                    if (x > 9)
                    {
                        Color previousColour = CurrentColor;
                        if (previousColour == Color.Yellow) CurrentColor = Color.Green;
                        if (previousColour == Color.Green) CurrentColor = Color.Red;
                        if (previousColour == Color.Red) CurrentColor = Color.Blue;
                        if (previousColour == Color.Blue) CurrentColor = Color.Yellow;
                        currentField = new HomeField(CurrentColor);
                        currentField.Previous = previousField;
                        previousField.NextHome = (HomeField)currentField;
                        if (GetPlayerByColor(CurrentColor) != null)
                        {
                            currentPlayer = GetPlayerByColor(CurrentColor);
                            currentPlayer.AddHome((HomeField)currentField);
                        }
                        CurrentColor = previousColour;
                    }
                    if (lines[y][x] != 'o')
                    {
                        BaseField current = OriginBaseField;
                        switch(lines[y][x])
                        {
                            case 'y': CurrentColor = Color.Yellow; break;
                            case 'g': CurrentColor = Color.Green; break;
                            case 'b': CurrentColor = Color.Blue; break;
                            case 'r': CurrentColor = Color.Red; break;
                            default: break;
                        }
                        int amount = 0;
                        int baseNr = 0;
                        while (current.MyColor == CurrentColor)
                        {
                            if (current.MyPawn != null)
                            {
                                amount++;
                            }
                            current = (BaseField)current.Next;
                        }
                        current = OriginBaseField;
                        while (current.Next != null)
                        {
                            if (current.MyColor == CurrentColor && current.MyPawn == null)
                            {
                                baseNr = current.MyNumber;
                                break;
                            }
                            current = (BaseField)current.Next;
                        }
                        if (GetPlayerByColor(CurrentColor) != null)
                        {
                            currentPlayer = GetPlayerByColor(CurrentColor);
                            currentField.MyPawn = new Pawn(current, CurrentColor, currentPlayer.GetNonUsedNumber());
                            currentField.MyPawn.MyField = currentField;
                            if(currentField.GetType() == typeof(HomeField))
                            {
                                currentField.IsLocked = true;
                                currentField.MyPawn.IsLocked = true;
                            }
                            currentPlayer.AddPawn(currentField.MyPawn);
                        }
                    }
                }
            }
            Origin.Previous = continueOn;
            continueOn.Next = Origin;
        }