Ejemplo n.º 1
0
 public Board(Player[] plist, Game game)
 {
     playerList = plist;
     first = null;
     last = null;
     theGame = game;
 }
Ejemplo n.º 2
0
        //Checks if ANY moves are possible
        public bool canMakeMove(Player p)
        {
            int moveablePawns = 0;
            bool stuck = true;

            foreach (Pawn pawn in p.pawns)
            {

                if (pawn.canMove(_diceRoll))
                {
                    moveablePawns++;
                }
            }
            if (moveablePawns == 0)
            {
                stuck = false;
            }

            return stuck;
        }
Ejemplo n.º 3
0
        public Pawn(Player p, Field firstField)
        {
            _player = p;
            _currentField = firstField;
            _onSpawn = true;

            bool inPawnList = false;

            for (int i = 0; i < _player.pawns.Length; i++)
            {
                if (!inPawnList)
                {
                    if (_player.pawns[i] == null)
                    {
                        _player.pawns[i] = this;
                        inPawnList = true;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private void firstRoll(Player[] players)
        {
            Player first = null;
            int highest = 0;

            foreach (Player p in players)
            {
                if (p != null)
                {
                    int temp = rollDice();
                    p.startRoll = temp;

                    if (p.startRoll > highest)
                    {
                        highest = p.startRoll;
                        first = p;
                    }
                }
            }

            _playersTurn = first;

            //place first pawn on board
            Field temporary = playersTurn.pawns[0].currentField;

            playersTurn.pawns[0].move(1 , this);

            //Won't draw
            sendFieldCode(temporary);
            sendFieldCode(_playersTurn.pawns[0].currentField);

            if (!_playersTurn.isHuman)
            {

                computerPrep(_playersTurn);
            }
            main.changePlayerTurn(playersTurn.color);
        }
Ejemplo n.º 5
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.º 6
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.º 7
0
        //Starts up the game
        public void createPlayers(int nrOfPlayers, int nrOfHumans)
        {
            _playerList = new Player[4];
            Player temp = null;
            //add players to player list & sets human or computer player
            for (int i = 0; i < nrOfPlayers; i++)
            {
                string color = "";
                switch (i)
                {
                    case 0:
                        color = PlayerColor.GREEN;
                        break;
                    case 1:
                        color = PlayerColor.RED;
                        break;
                    case 2:
                        color = PlayerColor.BLUE;
                        break;
                    case 3:
                        color = PlayerColor.YELLOW;
                        break;
                }

                if (i >= nrOfHumans)
                {
                    _playerList[i] = new Player(false, color);

                    if (temp != null)
                    {
                        temp.nextP = _playerList[i];
                    }

                }
                else
                {
                    _playerList[i] = new Player(true, color);
                    if (temp != null)
                    {
                        temp.nextP = _playerList[i];
                    }
                }

                temp = _playerList[i];
            }

            _playerList[nrOfPlayers -1].nextP = _playerList[0];
        }
Ejemplo n.º 8
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.º 9
0
 public Goal(Player p, string fieldC)
 {
     _player = p;
     _fieldCode = fieldC;
 }
Ejemplo n.º 10
0
        public void StartNewGame(int amountOfPlayers)
        {
            string pathString = "";
                string[] fileStrings = Directory.GetFiles(System.IO.Directory.GetCurrentDirectory() + @"\..\..\..\MEJN-Levels", "*.mejn");
                foreach (string s in fileStrings)
                {
                    if (amountOfPlayers == 4)
                    {
                        if (s.Contains("std.mejn"))
                        {
                            OriginPlayer = new Player(Color.Yellow);
                            Player currentPlayer = OriginPlayer;
                            currentPlayer.Next = new Player(Color.Green);
                            currentPlayer = currentPlayer.Next;
                            currentPlayer.Next = new Player(Color.Red);
                            currentPlayer = currentPlayer.Next;
                            currentPlayer.Next = new Player(Color.Blue);
                            currentPlayer = currentPlayer.Next;
                            currentPlayer.Next = OriginPlayer;

                            pathString = s;
                            buildLevel(pathString);
                            break;
                        }
                    }
                    if (amountOfPlayers == 3)
                    {
                        if (s.Contains("std3.mejn"))
                        {
                            OriginPlayer = new Player(Color.Yellow);
                            Player currentPlayer = OriginPlayer;
                            currentPlayer.Next = new Player(Color.Green);
                            currentPlayer = currentPlayer.Next;
                            currentPlayer.Next = new Player(Color.Red);
                            currentPlayer = currentPlayer.Next;
                            currentPlayer.Next = OriginPlayer;

                            pathString = s;
                            buildLevel(pathString);
                            break;
                        }
                    }
                    if (amountOfPlayers == 2)
                    {
                        if (s.Contains("std2.mejn"))
                        {
                            OriginPlayer = new Player(Color.Yellow);
                            Player currentPlayer = OriginPlayer;
                            OriginPlayer.Next = new Player(Color.Red);
                            currentPlayer = currentPlayer.Next;
                            currentPlayer.Next = OriginPlayer;

                            pathString = s;
                            buildLevel(pathString);
                            break;
                        }
                    }

                }
                CurrentTurn = OriginPlayer;
        }
Ejemplo n.º 11
0
        public void FirstTurns(int key)
        {
            ThrowDice();
            myBoard.MyView.UpdateDice();
            if (amountOfTurns == myBoard.AmountOfPlayers)
            {
                myBoard.CurrentTurn = highestPlayer;
                eyes = 0;
                myBoard.MyView.Dice.Content = " ";
                myBoard.MyView.UpdateDice();
            }
            if (eyes == highest)
            {
                twoHighest = true;
            }
            if (eyes > highest)
            {
                highest = eyes;
                twoHighest = false;
                highestPlayer = myBoard.CurrentTurn;

            }
            if (twoHighest == false)
            {
                amountOfTurns++;
            }
            if (twoHighest)
            {
                myBoard.CurrentTurn = myBoard.OriginPlayer;
                highest = 0;
                highestPlayer = null;
                amountOfTurns = 0;
                twoHighest = false;
            }
            currentTurnColor = myBoard.CurrentTurn.MyColor;
            myBoard.MyView.TurnLabel.Content = currentTurnColor;
        }
Ejemplo n.º 12
0
 public void CheckIfWon(Player current)
 {
     int total = 0;
      for(int i = 0; i < 4; i++)
      {
          if (current.MyPawns[i].IsLocked)
          {
              total++;
          }
      }
      if (total == 4)
      {
          myBoard.MyView.UpdateView();
          myBoard.MyView.ShowWinMessage(current.MyColor);
      }
 }
Ejemplo n.º 13
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
                }
            }
        }
Ejemplo n.º 14
0
        public void colorEllipses(Player[] players)
        {
            int g = 0;
            foreach(Player p in players)
            {

                if (p != null)
                {
                    foreach (Spawn sp in p.spawns)
                    {
                        spawns[g] = sp;
                        g++;
                    }
                }
            }
            //color all the spawns
            int i = 0;
            if(spawns!=null)
            while (i < spawns.Length)
            {
                if (spawns[i] != null)
                {

                    if (spawns[i].fieldCode.StartsWith("pgreen") && spawns[i].pawn != null)
                    {
                        getFieldEllipse(spawns[i].fieldCode).Fill = new SolidColorBrush(Colors.LawnGreen);
                    }
                    else if (spawns[i].fieldCode.StartsWith("pgreen") && spawns[i].pawn == null)
                    {
                        getFieldEllipse(spawns[i].fieldCode).Fill = new SolidColorBrush(Colors.Green);
                    }
                    else if (spawns[i].fieldCode.StartsWith("pred") && spawns[i].pawn != null)
                    {
                        getFieldEllipse(spawns[i].fieldCode).Fill = new SolidColorBrush(Colors.Red);
                    }
                    else if (spawns[i].fieldCode.StartsWith("pred") && spawns[i].pawn == null)
                    {
                        getFieldEllipse(spawns[i].fieldCode).Fill = new SolidColorBrush(Colors.DarkRed);
                    }
                    else if (spawns[i].fieldCode.StartsWith("pblue") && spawns[i].pawn != null)
                    {
                        getFieldEllipse(spawns[i].fieldCode).Fill = new SolidColorBrush(Colors.Blue);
                    }
                    else if (spawns[i].fieldCode.StartsWith("pblue") && spawns[i].pawn == null)
                    {
                        getFieldEllipse(spawns[i].fieldCode).Fill = new SolidColorBrush(Colors.DarkBlue);
                    }
                    else if (spawns[i].fieldCode.StartsWith("pyellow") && spawns[i].pawn != null)
                    {
                        getFieldEllipse(spawns[i].fieldCode).Fill = new SolidColorBrush(Colors.Yellow);
                    }
                    else if (spawns[i].fieldCode.StartsWith("pyellow") && spawns[i].pawn == null)
                    {
                        getFieldEllipse(spawns[i].fieldCode).Fill = new SolidColorBrush(Colors.Goldenrod);
                    }

                }
                i++;
            }
        }