Esempio n. 1
0
        public IGameSession SetPlayerAmount()
        {
            Console.Clear();
            Console.WriteLine("How many players will play ?");

            string[] avaliablePlayers = { "[   2   ]", "[   3   ]", "[   4   ]" };
            PlayerAmount = (2 + CreateInteractable.OptionMenu(true, avaliablePlayers, 0, 2));

            return(this);
        }
Esempio n. 2
0
        public IGameSession SetSessionData()
        {
            Console.Clear();

            string[]      tmpOptions   = Enum.GetNames(typeof(GameColors));
            List <string> colorOptions = new List <string>(tmpOptions);

            Console.WriteLine("Please type in your names");

            for (int i = 1; i <= PlayerAmount; i++)
            {
                DrawGFX.SetDrawPosition(0, 1);
                Console.Write($"Name player {i}: ");
                PlayerName = Console.ReadLine();
                while (string.IsNullOrEmpty(PlayerName))
                {
                    Console.Clear();
                    Console.WriteLine("Sorry. You have to fill in a name");
                    Console.Write($"Name player {i}: ");
                    PlayerName = Console.ReadLine();
                }

                DrawGFX.SetDrawPosition(0, 3);
                Console.WriteLine("Choose your player color:");

                int colorID = CreateInteractable.OptionMenu(true, colorOptions, 0, 5);

                string choosenColor = colorOptions[colorID];
                SessionPlayerData.Add(Tuple.Create(i, PlayerName, choosenColor));

                colorOptions.RemoveAt(colorID);
                DrawGFX.ClearDrawContent(0, 3);
                DrawGFX.ClearDrawContent(0, 1);
            }

            return(this);
        }
Esempio n. 3
0
        //this loop runs the game
        public void GameLoop()
        {
            Console.OutputEncoding = Encoding.UTF8;


            if (NewGame == true)
            {
                Console.Clear();
                Console.OutputEncoding = Encoding.UTF8;

                InitializeGame();

                //decide which player start
                IDictionary <int, int> playersRoll = new Dictionary <int, int>();
                for (int i = 1; i <= GamePlayerAmnt; i++)
                {
                    DrawGFX.SetDrawPosition(0, ConsolePosition.InfoPos);
                    Console.WriteLine("[GAME PROGRESS INFORMATION]");

                    DrawGFX.SetDrawPosition(0, ConsolePosition.SubInfoPos);
                    Console.WriteLine("Decide which player starts by rolling the dice. Highest number wins");

                    DrawGFX.SetDrawPosition(0, ConsolePosition.StatusPos);
                    Console.WriteLine($"Player {i} please roll the dice. Press[ENTER] to roll");

                    DrawGFX.SetDrawPosition(0, ConsolePosition.InteractablePos);
                    int diceValue = CreateInteractable.SingleButton(dice.Roll, "Roll");

                    DrawGFX.SetDrawPosition(0, ConsolePosition.ResultPos);
                    Console.WriteLine($"Player {i} rolls: {diceValue}");

                    playersRoll.Add(i, diceValue);
                }

                int playerIDStart = DecidePlayerStart(playersRoll);

                DrawGFX.SetDrawPosition(0, ConsolePosition.StatusPos);
                Console.WriteLine($"Player {playerIDStart} got the highest number and therefore start. Press[ENTER] to continue ");

                GamePlayers = SetPlayOrder(playerIDStart, GamePlayers);

                Console.ReadKey();

                Console.Clear();
            }
            else
            {
                InitializeBoardCoordinates();
                for (int i = 0; i < GamePlayerAmnt; i++)
                {
                    GamePlayers[i].GlobalStartPos = SetColorStartPositon(GamePlayers[i].Color);
                }
            }

            //continue gameloop until winner
            while (winner == "")
            {
                //all the gameplay here
                for (int i = 0; i < GamePlayerAmnt; i++)
                {
                    playerTextColor = DrawGFX.BrushColor(GamePlayers[i].Color);

                    /********************************************
                    *           GFX-POSITIONING STATUSTEXT
                    ********************************************/

                    //header
                    DrawGFX.SetDrawPosition(0, ConsolePosition.InfoPos);
                    Console.Write(new string("[GAME PROGRESS INFORMATION]").PadRight(35));

                    //position for dialogue
                    DrawGFX.ClearDrawContent(0, ConsolePosition.StatusPos);
                    DrawGFX.SetDrawPosition(0, ConsolePosition.StatusPos);
                    Console.ForegroundColor = playerTextColor;
                    Console.Write($"Player {GamePlayers[i].GamePlayerID}: {GamePlayers[i].Name}");
                    Console.ResetColor();
                    Console.WriteLine(" please roll the dice: ");

                    //position for consoledivider
                    DrawGFX.SetDrawPosition(0, ConsolePosition.DividerPos);
                    Console.Write("\r\n" + new string('=', Console.WindowWidth) + "\r\n");


                    /********************************************
                    *      GFX-POSITIONING GAME BOARD
                    ********************************************/

                    //positon for Game Board Title
                    DrawGFX.SetDrawPosition(0, ConsolePosition.GameBoardTitlePos);
                    Console.WriteLine("GAME BOARD");

                    //position for Game Board Pieces
                    DrawGFX.SetDrawPosition(0, ConsolePosition.GameBoardPiecePos);
                    var commonGameBoardPieces = DrawGFX.CreateBoard(40, BoardGFXItem.GameBoardPiecesGFX);

                    //get gameboardpieces position from CoordinateOuterPosition
                    List <Tuple <int, int, string> > tmp = new List <Tuple <int, int, string> >();
                    for (int y = 0; y < CoordinateOuterPosition.Count; y++)
                    {
                        if (CoordinateOuterPosition[y].IsOccupied == true)
                        {
                            var color = GamePlayers.Where(c => c.GamePlayerID == CoordinateOuterPosition[y].OccupiedPlayerID).Select(c => c.Color).FirstOrDefault();
                            tmp.Add(Tuple.Create(y, CoordinateOuterPosition[y].OccupiedPlayerID, color));
                        }
                    }
                    commonGameBoardPieces = DrawGFX.RenderGameBoardPieces(commonGameBoardPieces, tmp);

                    //position for Game Board
                    DrawGFX.SetDrawPosition(0, ConsolePosition.GameBoardPos);
                    var commonGameBoard = DrawGFX.CreateBoard(40, BoardGFXItem.GameBoardGFX);
                    commonGameBoard = DrawGFX.RenderGameBoard(commonGameBoard);


                    /********************************************
                    *        GFX-POSITIONING PLAYER-RELATED
                    ********************************************/

                    //player pieces
                    var piece1 = GamePlayers[i].Pieces.Where(s => s.PieceID == 1).FirstOrDefault();
                    var piece2 = GamePlayers[i].Pieces.Where(s => s.PieceID == 2).FirstOrDefault();
                    var piece3 = GamePlayers[i].Pieces.Where(s => s.PieceID == 3).FirstOrDefault();
                    var piece4 = GamePlayers[i].Pieces.Where(s => s.PieceID == 4).FirstOrDefault();

                    //position for playerboard title
                    DrawGFX.SetDrawPosition(0, ConsolePosition.PlayerBoardTitlePos);
                    Console.ForegroundColor = playerTextColor;
                    Console.WriteLine("PLAYER BOARD");

                    //position for playerboard info
                    DrawGFX.SetDrawPosition(0, ConsolePosition.PlayerInfoPos);
                    Console.Write(new string($"Player {GamePlayers[i].GamePlayerID}: {GamePlayers[i].Name}").PadRight(30));
                    Console.Write(new string("▲ = Player piece").PadRight(25));
                    Console.WriteLine("(▲) = Piece in Nest");
                    Console.ResetColor();

                    //position piece board 1
                    DrawGFX.SetDrawPosition(0, ConsolePosition.PieceBoard1Pos);
                    var playerBoard1 = DrawGFX.CreateBoard(46, BoardGFXItem.PieceBoardGFX);
                    Console.Write(new string("[Piece 1]: ").PadRight(10));

                    //update piece gfx and render pieceboard §
                    playerBoard1[piece1.CurrentPos] = DrawGFX.UpdatePlayerPieceGFXByPosition(piece1.CurrentPos);
                    playerBoard1 = DrawGFX.RenderPieceBoard(GamePlayers[i].Color, playerBoard1);

                    //position piece board 2
                    DrawGFX.SetDrawPosition(0, ConsolePosition.PieceBoard2Pos);
                    var playerBoard2 = DrawGFX.CreateBoard(46, BoardGFXItem.PieceBoardGFX);
                    Console.Write(new string("[Piece 2]: ").PadRight(10));

                    //update piece gfx and render pieceboard 2
                    playerBoard2[piece2.CurrentPos] = DrawGFX.UpdatePlayerPieceGFXByPosition(piece2.CurrentPos);
                    playerBoard2 = DrawGFX.RenderPieceBoard(GamePlayers[i].Color, playerBoard2);

                    //position piece board 3
                    DrawGFX.SetDrawPosition(0, ConsolePosition.PieceBoard3Pos);
                    var playerBoard3 = DrawGFX.CreateBoard(46, BoardGFXItem.PieceBoardGFX);
                    Console.Write(new string("[Piece 3]: ").PadRight(10));

                    //update piece gfx and render pieceboard 3
                    playerBoard3[piece3.CurrentPos] = DrawGFX.UpdatePlayerPieceGFXByPosition(piece3.CurrentPos);
                    playerBoard3 = DrawGFX.RenderPieceBoard(GamePlayers[i].Color, playerBoard3);

                    //position piece board 4
                    DrawGFX.SetDrawPosition(0, ConsolePosition.PieceBoard4Pos);
                    var playerBoard4 = DrawGFX.CreateBoard(46, BoardGFXItem.PieceBoardGFX);
                    Console.Write(new string("[Piece 4]: ").PadRight(10));

                    //update piece gfx and render pieceboard 4
                    playerBoard4[piece4.CurrentPos] = DrawGFX.UpdatePlayerPieceGFXByPosition(piece4.CurrentPos);
                    playerBoard4 = DrawGFX.RenderPieceBoard(GamePlayers[i].Color, playerBoard4);


                    /********************************************
                    *               DICE-RELATED
                    ********************************************/

                    //position for dice btn
                    DrawGFX.SetDrawPosition(0, ConsolePosition.InteractablePos);
                    int diceValue = CreateInteractable.SingleButton(dice.Roll, "Roll");

                    //position for dice roll text
                    DrawGFX.SetDrawPosition(0, ConsolePosition.ResultPos);
                    Console.WriteLine("Dice rolled: " + diceValue);

                    //dice-roll
                    IList <string> options       = new List <string>();
                    int            selectedPiece = 0;

                    //move a playerpiece based on dice value, method containing other methods
                    MovePieceOnDiceResult(i, options, selectedPiece, diceValue);


                    /********************************************
                    *               RE-RENDER GFX
                    ********************************************/

                    ////update piece gfx new position after movement
                    playerBoard1[piece1.CurrentPos] = DrawGFX.UpdatePlayerPieceGFXByPosition(piece1.CurrentPos);
                    playerBoard2[piece2.CurrentPos] = DrawGFX.UpdatePlayerPieceGFXByPosition(piece2.CurrentPos);
                    playerBoard3[piece3.CurrentPos] = DrawGFX.UpdatePlayerPieceGFXByPosition(piece3.CurrentPos);
                    playerBoard4[piece4.CurrentPos] = DrawGFX.UpdatePlayerPieceGFXByPosition(piece4.CurrentPos);

                    //re-render piece boards
                    DrawGFX.SetDrawPosition(0, ConsolePosition.PieceBoard1Pos);
                    Console.Write(new string("[Piece 1]: ").PadRight(10));
                    playerBoard1 = DrawGFX.RenderPieceBoard(GamePlayers[i].Color, playerBoard1);

                    DrawGFX.SetDrawPosition(0, ConsolePosition.PieceBoard2Pos);
                    Console.Write(new string("[Piece 2]: ").PadRight(10));
                    playerBoard2 = DrawGFX.RenderPieceBoard(GamePlayers[i].Color, playerBoard2);

                    DrawGFX.SetDrawPosition(0, ConsolePosition.PieceBoard3Pos);
                    Console.Write(new string("[Piece 3]: ").PadRight(10));
                    playerBoard3 = DrawGFX.RenderPieceBoard(GamePlayers[i].Color, playerBoard3);

                    DrawGFX.SetDrawPosition(0, ConsolePosition.PieceBoard4Pos);
                    Console.Write(new string("[Piece 4]: ").PadRight(10));
                    playerBoard4 = DrawGFX.RenderPieceBoard(GamePlayers[i].Color, playerBoard4);


                    //input to player to press enter
                    DrawGFX.SetDrawPosition(0, ConsolePosition.InteractableInfoPos);
                    Console.WriteLine("Please press [ENTER] to continue");
                    Console.ReadKey();


                    /********************************************
                    *               GFX-CLEANUP
                    ********************************************/

                    //cleaning up console before next player
                    DrawGFX.ClearDrawContent(0, ConsolePosition.SubInfoPos);
                    DrawGFX.ClearDrawContent(0, ConsolePosition.InteractableInfoPos);
                    DrawGFX.ClearDrawContent(0, ConsolePosition.ResultPos);

                    //Winner
                    var allPiecesFinished = GamePlayers[i].Pieces.All(p => p.PieceInGoal == true && p.CurrentPos == p.GoalPosIndex);
                    if (allPiecesFinished == true)
                    {
                        winner = GamePlayers[i].Name;
                    }
                }


                //Save Game or skip
                string[] saveOptions = { "Skip", "Save Game?" };
                saveOrSkip = CreateInteractable.OptionMenu(true, saveOptions, 40, ConsolePosition.InfoPos);
                if (saveOrSkip == 1)
                {
                    Console.Clear();
                    DrawGFX.SetDrawPosition(0, 0);
                    Console.WriteLine("Saving data, please wait...");
                    DrawGFX.SetDrawPosition(0, 2);
                    SaveGame();
                    Console.Clear();
                }
            }

            SaveWinner();
            DisplayWinner();
        }
Esempio n. 4
0
        /*===========================================================
        *                       DICE-LOGIC
        *  ===========================================================*/

        private void MovePieceOnDiceResult(int playerIndex, IList <string> options, int selectedPiece, int diceValue)
        {
            switch (diceValue)
            {
            case 1:
                DrawGFX.SetDrawPosition(0, ConsolePosition.InteractableInfoPos);
                Console.WriteLine("Choose a piece to move");

                options = CreatePieceBtnOptions(true, playerIndex);
                if (options.Count() != 0)
                {
                    selectedPiece = (CreateInteractable.OptionMenu(true, options, 0, ConsolePosition.InteractablePos));
                    string pieceName = options[selectedPiece];
                    int    pieceID   = int.Parse(pieceName.Last().ToString());

                    var pieceToMove = GetPieceByID(playerIndex, pieceID);
                    int pieceIndex  = GetPieceIndex(playerIndex, pieceToMove);

                    MovePiece(playerIndex, pieceIndex, pieceToMove, diceValue);
                }
                break;

            case 6:
                DrawGFX.SetDrawPosition(0, ConsolePosition.InteractableInfoPos);
                Console.WriteLine("You rolled 6. Please make a choice:");

                List <string> moveOptions  = new List <string>();
                var           piecesInNest = GamePlayers[playerIndex].Pieces.Where(p => p.CurrentPos == p.LocalStartPos);
                if (piecesInNest.Count() >= 2)
                {
                    moveOptions.Add("Move 1 piece 6 steps?");
                    moveOptions.Add("Move 2 pieces 1 step?");
                }
                else
                {
                    moveOptions.Add("Move 1 piece 6 steps?");
                }

                int selectMoveOption = CreateInteractable.OptionMenu(true, moveOptions, 0, ConsolePosition.InteractablePos);

                DrawGFX.ClearDrawContent(0, ConsolePosition.InteractableInfoPos);

                if (selectMoveOption == 0)
                {
                    DrawGFX.SetDrawPosition(0, ConsolePosition.InteractableInfoPos);
                    Console.WriteLine("Choose a piece to move");

                    options = CreatePieceBtnOptions(true, playerIndex);
                    if (options.Count() != 0)
                    {
                        selectedPiece = (CreateInteractable.OptionMenu(true, options, 0, ConsolePosition.InteractablePos));
                        string pieceName = options[selectedPiece];
                        int    pieceID   = int.Parse(pieceName.Last().ToString());

                        var pieceToMove = GetPieceByID(playerIndex, pieceID);
                        int pieceIndex  = GetPieceIndex(playerIndex, pieceToMove);

                        MovePiece(playerIndex, pieceIndex, pieceToMove, 6);
                    }
                }
                else
                {
                    for (int y = 1; y <= 2; y++)
                    {
                        DrawGFX.SetDrawPosition(0, ConsolePosition.InteractableInfoPos);
                        Console.WriteLine($"Choose piece {playerIndex} to move");

                        IList <string> pieceOptions = CreatePieceButtonOptionsInNest(playerIndex);
                        if (pieceOptions.Count() != 0)
                        {
                            selectedPiece = (CreateInteractable.OptionMenu(true, pieceOptions, 0, ConsolePosition.InteractablePos));
                            string pieceName = pieceOptions[selectedPiece];
                            int    pieceID   = int.Parse(pieceName.Last().ToString());

                            var pieceToMove = GetPieceByID(playerIndex, pieceID);
                            int pieceIndex  = GetPieceIndex(playerIndex, pieceToMove);

                            MovePiece(playerIndex, pieceIndex, pieceToMove, 1);
                        }
                    }
                }
                break;

            default:
                DrawGFX.SetDrawPosition(0, ConsolePosition.InteractableInfoPos);
                Console.WriteLine("Choose a piece to move");

                options = CreatePieceBtnOptions(false, playerIndex);
                if (options.Count() != 0)
                {
                    selectedPiece = (CreateInteractable.OptionMenu(true, options, 0, ConsolePosition.InteractablePos));
                    string pieceName = options[selectedPiece];
                    int    pieceID   = int.Parse(pieceName.Last().ToString());

                    var pieceToMove = GetPieceByID(playerIndex, pieceID);
                    int pieceIndex  = GetPieceIndex(playerIndex, pieceToMove);

                    MovePiece(playerIndex, pieceIndex, pieceToMove, diceValue);
                }
                break;
            }
        }