Ejemplo n.º 1
0
 public Player(Color myColor)
 {
     this.MyColor = myColor;
     MyPawns = new Pawn[4];
     MyBases = new BaseField[4];
     MyHomes = new HomeField[4];
 }
Ejemplo n.º 2
0
        public void recieveClickedEllipse(string p)
        {
            if (_diceRoll != 0)
            {

                Field current = null;

                current = board.getFieldFromPath(p);

                if (current != null)
                {

                    if (current.nextF != null)

                        if (current.pawn != null)
                        {
                            if (current.pawn.player == playersTurn && current.pawn.canMove(_diceRoll))
                            {
                                _selected = current.pawn;
                                handleTurn(playersTurn);
                            }
                        }
                }
            }
        }
Ejemplo n.º 3
0
        public void playerPrep(Player p)
        {
            if (!canMakeMove(p))
            {

                _playersTurn = _playersTurn.nextP;
                if (!_playersTurn.isHuman)
                {
                    computerPrep(_playersTurn);
                }

                _diceRoll = 0;
            }
            else
            {
                _selected = null;
                main.rollButton.IsEnabled = false;
            }
            main.changePlayerTurn(playersTurn.color);
        }
Ejemplo n.º 4
0
        public void handleTurn(Player p)
        {
            Field start = _selected.currentField;
            _selected.move(_diceRoll , this);
            if (diceRoll == 0)
                return;
            if (p.pawnsInGoal == 4)
            {
                main.showEndMessage();
                // end the game here
            }
            else if (_diceRoll == 6)
            {
                _playersTurn = p;
                _diceRoll = -0;
            }
            else
            {
                _playersTurn = p.nextP;
            }

            if (!_playersTurn.isHuman)
            {
                sendFieldCode(start);
                sendFieldCode(_selected.currentField);
                _selected = null;
                _diceRoll = 0;
                computerPrep(_playersTurn);
            }
            else
            {
                //null soms

                sendFieldCode(start);
                //sendFieldCode(_selected.currentField);

                _selected = null;
                _diceRoll = 0;

                main.rollButton.IsEnabled = true;

            }

            main.changePlayerTurn(playersTurn.color);
        }
Ejemplo n.º 5
0
        //Prepares a turn for the computer
        public void computerPrep(Player p)
        {
            Pawn temp = null;
            main.changeDice(rollDice());
            bool select = false;

            if (canMakeMove(p))
            {

                while (!select)
                {
                    foreach (Pawn pawn in p.pawns)
                    {

                        if (pawn.canMove(_diceRoll))
                        {
                            if (pawn.canHit)
                            {
                                _selected = pawn;
                                select = true;
                                sendFieldCode(_selected.currentField);
                            }
                        }
                    }

                    if (_selected == null)
                    {
                        foreach (Pawn pawn in p.pawns)
                        {

                            if (pawn.canMove(_diceRoll))
                            {

                                if (pawn.currentField.GetType() == typeof(Goal))
                                {
                                    temp = pawn;
                                }
                                else
                                {
                                    _selected = pawn;
                                }
                            }

                            if (_selected == null)
                            {
                                if (temp != null)
                                {
                                    _selected = temp;
                                }

                            }

                            select = true;

                        }
                    }

                    select = true;
                }

                handleTurn(p);

            }  // end if
            else
            {
                //computer cant move, next players turn
                _playersTurn = p.nextP;

                if (!_playersTurn.isHuman)
                {
                    _selected = null;
                    computerPrep(_playersTurn);
                }
                else
                {
                    main.rollButton.IsEnabled = true;

                }

                _selected = null;
                _diceRoll = 0;
            }
            main.changePlayerTurn(playersTurn.color);
        }
Ejemplo n.º 6
0
        public void pawnToSpawn(Pawn p , Game g)
        {
            bool placed = false;

              for (int i = 0; i < _spawns.Length; i++)
              {
                if (!placed)
                {
                   if (_spawns[i].pawn == null)
                    {
                        _spawns[i].pawn = p;
                        p.currentField = _spawns[i];
                        placed = true;
                        p.onSpawn = true;
                        g.sendFieldCode(_spawns[i]);

                    }
                }
            }
        }
Ejemplo n.º 7
0
 public ImageSource SetPawnImage(Pawn myPawn)
 {
     ImageSource img = null;
     switch (myPawn.MyColor)
     {
         case Color.Red:
             switch(myPawn.MyNumber)
             {
                 case 1: img = pawnRed1; break;
                 case 2: img = pawnRed2; break;
                 case 3: img = pawnRed3; break;
                 case 4: img = pawnRed4; break;
                 default: break;
             }
             break;
         case Color.Yellow:
             switch (myPawn.MyNumber)
             {
                 case 1: img = pawnYellow1; break;
                 case 2: img = pawnYellow2; break;
                 case 3: img = pawnYellow3; break;
                 case 4: img = pawnYellow4; break;
                 default: break;
             }
             break;
         case Color.Blue:
             switch (myPawn.MyNumber)
             {
                 case 1: img = pawnBlue1; break;
                 case 2: img = pawnBlue2; break;
                 case 3: img = pawnBlue3; break;
                 case 4: img = pawnBlue4; break;
                 default: break;
             }
             break;
         case Color.Green:
             switch (myPawn.MyNumber)
             {
                 case 1: img = pawnGreen1; break;
                 case 2: img = pawnGreen2; break;
                 case 3: img = pawnGreen3; break;
                 case 4: img = pawnGreen4; break;
                 default: break;
             }
             break;
         default: break;
     }
     return img;
 }
Ejemplo n.º 8
0
 public void AddPawn(Pawn pawn)
 {
     MyPawns[pawn.MyNumber - 1] = pawn;
 }
Ejemplo n.º 9
0
        public void SixAndBaseNotFull(Pawn currentPawn)
        {
            if (currentPawn.MyField.GetType() == typeof(BaseField))
            {

            }
            else if (currentPawn.MyField.GetType() == typeof(StartField))
            {
                Move(currentPawn, eyes, currentPawn.MyField);
            }
            else if(currentPawn.MyField.GetType() == typeof(Field))
            {
                Move(currentPawn, eyes, currentPawn.MyField);
            }
        }
Ejemplo n.º 10
0
 public void PlayTurn(int key)
 {
     if (amountOfTurns < myBoard.AmountOfPlayers + 1)
     {
         FirstTurns(key);
         if (amountOfTurns != 0 && amountOfTurns != myBoard.AmountOfPlayers + 1) { myBoard.CurrentTurn = myBoard.CurrentTurn.Next; currentTurnColor = myBoard.CurrentTurn.MyColor; myBoard.MyView.TurnLabel.Content = currentTurnColor; }
         if (amountOfTurns == myBoard.AmountOfPlayers + 1)
         {
             currentPawn = myBoard.CurrentTurn.GetPawnByNumber(1);
             if (currentPawn.MyField.GetType() == typeof(BaseField))
             {
                 currentField = currentPawn.MyField;
                 currentField.MyPawn = null;
                 currentField = myBoard.CurrentTurn.MyStart;
                 currentPawn.MyField = currentField;
                 currentField.MyPawn = currentPawn;
                 myBoard.CurrentTurn.MyStart.MyPawn = currentPawn;
                 myBoard.MyView.UpdateView();
             }
             SpaceToRethrow = true;
             WaitForSpaceInput = false;
             amountOfTurns += 2;
         }
     }
     else
     {
         if (SpaceToRethrow && !WaitForNumberInput && !WaitForSpaceInput)
         {
             SpaceToRethrow = false;
             ThrowDice();
             myBoard.MyView.UpdateDice();
             if (eyes == 6)
             {
                 WaitForNumberInput = true;
             }
             else
             {
                 if (myBoard.CurrentTurn.FullBase())
                 {
                     myBoard.CurrentTurn = myBoard.CurrentTurn.Next;
                     currentTurnColor = myBoard.CurrentTurn.MyColor;
                     myBoard.MyView.TurnLabel.Content = currentTurnColor;
                     WaitForSpaceInput = true;
                 }
                 else
                 {
                     WaitForNumberInput = true;
                 }
             }
         }
         else if (WaitForSpaceInput && !SpaceToRethrow && !WaitForNumberInput)
         {
             WaitForSpaceInput = false;
             ThrowDice();
             myBoard.MyView.UpdateDice();
             if (eyes == 6)
             {
                 WaitForNumberInput = true;
             }
             else
             {
                 if (myBoard.CurrentTurn.FullBase())
                 {
                     myBoard.CurrentTurn = myBoard.CurrentTurn.Next;
                     currentTurnColor = myBoard.CurrentTurn.MyColor;
                     myBoard.MyView.TurnLabel.Content = currentTurnColor;
                     WaitForSpaceInput = true;
                 }
                 else
                 {
                     WaitForNumberInput = true;
                 }
             }
         }
         else if (WaitForNumberInput && !WaitForSpaceInput && !SpaceToRethrow)
         {
             if (!myBoard.CurrentTurn.GetPawnByNumber(key).IsLocked)
             {
                 WaitForNumberInput = false;
                 if (myBoard.CurrentTurn.GetPawnByNumber(key).MyField.GetType() == typeof(BaseField))
                 {
                     if (eyes == 6)
                     {
                         currentPawn = myBoard.CurrentTurn.GetPawnByNumber(key);
                         currentField = currentPawn.MyField;
                         currentField.MyPawn = null;
                         currentField = myBoard.CurrentTurn.MyStart;
                         CheckIfCollision(currentField);
                         currentPawn.MyField = currentField;
                         currentField.MyPawn = currentPawn;
                         myBoard.CurrentTurn.MyStart.MyPawn = currentPawn;
                         myBoard.MyView.UpdateView();
                         SpaceToRethrow = true;
                     }
                     else
                     {
                         WaitForNumberInput = true;
                         //output
                     }
                 }
                 else
                 {
                     WaitForNumberInput = false;
                     currentPawn = myBoard.CurrentTurn.GetPawnByNumber(key);
                     currentField = currentPawn.MyField;
                     currentField.MyPawn = currentPawn;
                     Move(currentPawn, eyes, currentField);
                     if (eyes == 6)
                     {
                         SpaceToRethrow = true;
                     }
                     else
                     {
                         myBoard.CurrentTurn = myBoard.CurrentTurn.Next;
                         currentTurnColor = myBoard.CurrentTurn.MyColor;
                         myBoard.MyView.TurnLabel.Content = currentTurnColor;
                         WaitForSpaceInput = true;
                     }
                 }
             }
             else
             {
                 WaitForNumberInput = true;
             }
         }
     }
 }
Ejemplo n.º 11
0
 public void Move(Pawn currentPawn, int eyes, Field currentField)
 {
     if (currentField != null)
     {
         bool setToPrevious = false;
         currentField.MyPawn = null;
         for (int i = 0; i < eyes; i++)
         {
             if ((currentField.GetType() == typeof(EndField) && currentField.NextHome.MyColor == currentPawn.MyColor) || (currentField.GetType() == typeof(HomeField)))
             {
                 if (i == eyes - 1)
                 {
                     if (currentField.NextHome != null)
                     {
                         if (setToPrevious)
                         {
                             currentField = currentField.Previous;
                         }
                         else
                         {
                             currentField = currentField.NextHome;
                         }
                     }
                     else
                     {
                         setToPrevious = true;
                         currentField = currentField.Previous;
                     }
                     if (currentField.IsLocked)
                     {
                         while (currentField.IsLocked)
                         {
                             currentField = currentField.Previous;
                         }
                     }
                 }
                 else
                 {
                     if (setToPrevious)
                     {
                         currentField = currentField.Previous;
                     }
                     else
                     {
                         if (currentField.NextHome != null)
                         {
                             currentField = currentField.NextHome;
                         }
                         else
                         {
                             setToPrevious = true;
                             currentField = currentField.Previous;
                         }
                     }
                 }
             }
             else
             {
                 if (setToPrevious)
                 {
                     currentField = currentField.Previous;
                 }
                 else
                 {
                     currentField = currentField.Next;
                 }
             }
         }
         CheckIfCollision(currentField);
         currentPawn.MyField = currentField;
         currentField.MyPawn = currentPawn;
         if (currentField.GetType() == typeof(HomeField))
         {
             currentField.IsLocked = true;
             currentPawn.IsLocked = true;
             CheckIfWon(myBoard.CurrentTurn);
         }
         myBoard.MyView.UpdateView();
         setToPrevious = false;
     }
 }
Ejemplo n.º 12
0
        public void newCreateField(string[] field , Player[] players)
        {
            playerList = players;
            //Field creation prep
            char[] normalF = new char[field[3].Length];
            char[] greenG = new char[4];
            char[] redG = new char[4];
            char[] blueG = new char[4];
            char[] yellowG = new char[4];

            normalF = field[3].ToCharArray();
            greenG = field[4].ToCharArray();
            redG = field[5].ToCharArray();
            blueG = field[6].ToCharArray();
            yellowG = field[7].ToCharArray();

            int yellowPawns = 0, greenPawns = 0, bluePawns = 0, redPawns = 0;

            Field previous = null;
            Field current = null;
            first = null;
            Pawn tempPawn = null;

            //create spawns
            foreach (Player p in players)
            {
                if (p != null)
                {
                    for (int s = 0; s < p.spawns.Length; s++)
                    {
                        string spwnCode = "p" + p.color + "spawn" + s;
                        p.spawns[s] = new Spawn(spwnCode);
                    }
                }
            }

            //create field & goal
            for (int i = 0; i < normalF.Length; i++)
            {

                tempPawn = null;
                //the normal fieldcreation
                switch (normalF[i])
                {
                    // empty field
                    case 'O':
                        current = new Field();
                        current.fieldCode = "field" + i;
                        break;

                     // green on board
                    case 'G':
                        current = new Field();
                        current.fieldCode = "field" + i;
                        tempPawn = new Pawn(players[0], current);
                        current.pawn = tempPawn;
                        theGame.sendFieldCode(current);
                        //add pawn
                        if (players[0].pawns[greenPawns] == null)
                        {
                            tempPawn.onSpawn = false;
                            players[0].pawns[greenPawns] = tempPawn;
                            greenPawns++;
                        }
                        break;

                    //Red on board
                    case 'R':
                        current = new Field();
                        current.fieldCode = "field" + i;
                        tempPawn = new Pawn(players[1], current);
                        current.pawn = tempPawn;
                        theGame.sendFieldCode(current);

                        //add pawn
                        if (players[1].pawns[redPawns] == null)
                        {
                            tempPawn.onSpawn = false;
                            players[1].pawns[redPawns] = tempPawn;
                            redPawns++;
                        }
                        break;

                     // blue on board
                    case 'B':
                        current = new Field();
                        current.fieldCode = "field" + i;
                        tempPawn = new Pawn(players[2], current);
                        current.pawn = tempPawn;
                        theGame.sendFieldCode(current);

                        //add pawn
                        if (players[2].pawns[bluePawns] == null)
                        {
                            tempPawn.onSpawn = false;
                            players[2].pawns[bluePawns] = tempPawn;
                            bluePawns++;
                        }
                        break;

                    //yellow on board
                    case 'Y':
                        current = new Field();
                        current.fieldCode = "field" + i;
                        tempPawn = new Pawn(players[3], current);
                        current.pawn = tempPawn;
                        theGame.sendFieldCode(current);

                        //add pawn
                        if (players[3] != null)
                        {
                            if (players[3].pawns[yellowPawns] == null)
                            {
                                tempPawn.onSpawn = false;
                                players[3].pawns[yellowPawns] = tempPawn;
                                yellowPawns++;
                            }
                        }
                        break;

                }

                //special steps
                switch (i)
                {

                        //startingfields
                    case 0:
                        first = current;

                        players[0].startingField = current;
                        foreach (Spawn sp in players[0].spawns)
                        {
                            sp.nextF = current;
                        }
                        break;
                    case 10:
                        players[1].startingField = current;
                        foreach (Spawn sp in players[1].spawns)
                        {
                            sp.nextF = current;
                        }
                        break;
                    case 20:
                        if (players[2] != null)
                        {
                            players[2].startingField = current;
                            foreach (Spawn sp in players[2].spawns)
                            {
                                sp.nextF = current;
                            }
                        }
                        break;

                    case 30:

                        if (players[3] != null)
                        {
                            players[3].startingField = current;
                            foreach (Spawn sp in players[3].spawns)
                            {
                                sp.nextF = current;
                            }
                        }
                        break;

                        //switchpoints + goal creation
                    case 9:
                        Goal rTemp = null;
                        Goal rPrev = null;

                        for (int g = 0; g < redG.Length; g++)
                        {
                            string fc = "goal" + players[1].color + g;
                            if (redG[g].Equals('R'))
                            {
                                rTemp = new Goal(players[1], fc);
                                rTemp.pawn = new Pawn(players[1], rTemp);
                                players[1].pawnsInGoal += 1;
                                theGame.sendFieldCode(rTemp);
                                if (players[1].pawns[redPawns] == null)
                                {
                                    tempPawn.onSpawn = false;
                                    players[1].pawns[redPawns] = tempPawn;
                                    redPawns++;
                                }
                            }
                            else
                            {
                                rTemp = new Goal(players[1], fc);
                            }

                            if (g == 0)
                            {
                                current.switchF = rTemp;
                                rTemp.previousF = current;
                            }
                            else
                            {
                                rTemp.previousF = rPrev;
                                rPrev.nextF = rTemp;

                            }
                            rPrev = rTemp;
                        }
                        break;

                    case 19:
                        if (players[2] != null)
                        {

                            Goal bTemp = null;
                            Goal bPrev = null;

                            for (int g = 0; g < blueG.Length; g++)
                            {
                                string fc = "goal" + players[2].color + g;
                                if (blueG[g].Equals('B'))
                                {
                                    bTemp = new Goal(players[2], fc);
                                    bTemp.pawn = new Pawn(players[2], bTemp);
                                    players[2].pawnsInGoal += 1;
                                    theGame.sendFieldCode(bTemp);
                                    if (players[2].pawns[bluePawns] == null)
                                    {
                                        tempPawn.onSpawn = false;
                                        players[2].pawns[bluePawns] = tempPawn;
                                        bluePawns++;
                                    }
                                }
                                else
                                {
                                    bTemp = new Goal(players[2], fc);
                                }

                                if (g == 0)
                                {
                                    current.switchF = bTemp;
                                    bTemp.previousF = current;
                                }
                                else
                                {
                                    bTemp.previousF = bPrev;
                                    bPrev.nextF = bTemp;

                                }
                                bPrev = bTemp;
                            }
                        }
                        break;

                    case 29:
                        Goal yTemp = null;
                        Goal yPrev = null;

                        if (players[3] != null)
                        {

                            for (int g = 0; g < yellowG.Length; g++)
                            {
                                string fc = "goal" + players[3].color + g;
                                if (yellowG[g].Equals('Y'))
                                {
                                    yTemp = new Goal(players[3], fc);
                                    yTemp.pawn = new Pawn(players[3], yTemp);
                                    players[3].pawnsInGoal += 1;
                                    theGame.sendFieldCode(yTemp);
                                    if (players[3].pawns[yellowPawns] == null)
                                    {
                                        tempPawn.onSpawn = false;
                                        players[3].pawns[yellowPawns] = tempPawn;
                                        yellowPawns++;
                                    }
                                }
                                else
                                {
                                    yTemp = new Goal(players[3], fc);
                                }

                                if (g == 0)
                                {
                                    current.switchF = yTemp;
                                    yTemp.previousF = current;
                                }
                                else
                                {
                                    yTemp.previousF = yPrev;
                                    yPrev.nextF = yTemp;

                                }
                                yPrev = yTemp;
                            }

                        }
                    break;
                    case 39:

                        if (players[0] != null)
                        {
                            Goal gTemp = null;
                            Goal gPrev = null;

                            for (int g = 0; g < greenG.Length; g++)
                            {
                                string fc = "goal" + players[0].color + g;
                                if (greenG[g].Equals('G'))
                                {
                                    gTemp = new Goal(players[0], fc);
                                    gTemp.pawn = new Pawn(players[0], gTemp);
                                    players[0].pawnsInGoal += 1;
                                    theGame.sendFieldCode(gTemp);
                                    if (players[0].pawns[greenPawns] == null)
                                    {
                                        tempPawn.onSpawn = false;
                                        players[0].pawns[greenPawns] = tempPawn;
                                        greenPawns++;
                                    }
                                }
                                else
                                {
                                    gTemp = new Goal(players[0], fc);
                                }

                                if (g == 0)
                                {
                                    current.switchF = gTemp;
                                    gTemp.previousF = current;
                                }
                                else
                                {
                                    gTemp.previousF = gPrev;
                                    gPrev.nextF = gTemp;

                                }
                                gPrev = gTemp;
                            }
                            //link ends

                            previous.nextF = current;
                            current.previousF = previous;

                            current.nextF = first;
                            first.previousF = current;
                        }
                        break;

                }

                //link the list
                if (i != 0 && i != 39)
                {
                    previous.nextF = current;
                    current.previousF = previous;
                }

                previous = current;

            } // end for

            //create pawns if not created yet:
            foreach (Player p in players)
            {
                if (p != null)
                {
                    for (int counter1 = 0; counter1 < 4; counter1++)
                    {
                        if (p.pawns[counter1] == null)
                        {
                            bool placed = false;
                            while (!placed)
                            {
                                for (int counter2 = 0; counter2 < p.spawns.Length; counter2++)
                                {

                                    if (p.pawns[counter2] == null)
                                    {
                                        p.pawns[counter1] = new Pawn(p, p.spawns[counter2]);
                                        p.spawns[counter2].pawn = p.pawns[counter1];
                                        placed = true;
                                    }
                                } // last for
                            }
                        }
                    } // first for
                }
            }
        }