コード例 #1
0
ファイル: RuleEngine.cs プロジェクト: hannahborje/Ludo
        /// <summary>
        /// This is the method that UI will call in order to get a status update
        /// </summary>
        /// <param name="gameEvent"></param>
        /// <returns></returns>
        public GameState parseEvent(GameEvent gameEvent)
        {
            // Game State not active, Decide who is going to start
            if (!ActiveGame)
            {
                return decideStartingPlayer(gameEvent);
            }
            // Game State active, make active game relevant choices
            else
            {
                Colors playerID = gameEvent.Player;
                piece chosenPieceID = gameEvent.Piece;
                Piece[][] pieces = (Piece[][]) ludoBoard.State["pieces"];
                Piece chosenPiece = pieces[(int)playerID][chosenPieceID];
                dice dice = gameEvent.Dice;
                Player[] players = (Player[]) ludoBoard.State["players"];
                Player player = players[(int)playerID];

                Debug.Write("\nDeciding action for player: " + player.PlayerID + ", with piece: " +
                            chosenPiece.PieceID + ", player rolled: " + dice);

                if (!chosenPiece.Active)
                {
                    bool isPieceActivated = tryActivate(playerID, dice);
                    Debug.Write(String.Format("\nTried activating new piece: {0}", isPieceActivated));
                }
                else
                {
                    Debug.Write("\nTrying to move piece.");
                    tryMove(chosenPiece, dice);
                }
            }
            return ludoBoard.ToArray(); // return updated state to UI
        }
コード例 #2
0
        /// <summary>
        /// This is the method that UI will call in order to get a status update
        /// </summary>
        /// <param name="gameEvent"></param>
        /// <returns></returns>
        public GameState parseEvent(GameEvent gameEvent)
        {
            Colors playerID = gameEvent.Player;
            piece chosenPieceID = gameEvent.Piece;
            Piece[][] pieces = (Piece[][]) ludoBoard.State["pieces"];
            Piece chosenPiece = pieces[(int)playerID][chosenPieceID];
            dice dice = gameEvent.Dice;
            Player[] players = (Player[]) ludoBoard.State["players"];
            Player player = players[(int)playerID];
            GameState gameState = new GameState();
            bool isPieceActivated = false;

            Nest[] nests = (Nest[]) ludoBoard.State["nests"];

            Debug.Write("\nRules: Deciding action for player: " + player.PlayerID + ", with piece: " +
                        chosenPiece.PieceID + ", player rolled: " + dice);

            if (!chosenPiece.Active)
            {
                isPieceActivated = tryActivate(playerID, dice, chosenPieceID);
                Debug.Write(String.Format("\nRules: Tried activating new piece: {0}", isPieceActivated));
                if (ludoBoard.Instruction != Instructions.CollisionWithSelf)
                {
                    ludoBoard.Instruction = (isPieceActivated) ? Instructions.Introduce : Instructions.NotIntroduce;
                }
            }
            else
            {
                Debug.Write("\nRules: Trying to move piece.");
                bool hasPieceMoved = tryMove(chosenPiece, dice);
            }
            Debug.WriteLine("\n Instruction = " + gameState.Instruction);
            return updateGameState(gameState, pieces);
        }
コード例 #3
0
ファイル: RuleEngine.cs プロジェクト: hannahborje/Ludo
        /// <summary>
        /// If there is a player with higher result than the others, make them the winner
        /// Otherwise, do nothing
        /// </summary>
        /// <param name="gameEvent"></param>
        /// <param name="winner"></param>
        /// <returns></returns>
        private GameState decideStartingPlayer(GameEvent gameEvent)
        {
            GameState gameState = new GameState();
            Colors winner;
            Dictionary<Colors, dice> diceResults = gameEvent.Dices;

            Debug.WriteLine("\ndiceResults check");
            // Create ordered List
            var orderedResults = diceResults.OrderBy(results => results.Value).ToList();
            // Check if there are two equally maximum results
            int last = orderedResults[numOfPlayers - 1].Value;
            int nextLast = orderedResults[numOfPlayers - 2].Value;
            bool isTie = (last == nextLast);

            if (isTie)
            {
                Debug.WriteLine("\n it's a Tie");
                gameState.StartingPlayer = -1;
            }
            else
            {
                winner = orderedResults[numOfPlayers - 1].Key;
                gameState.StartingPlayer = (int)winner;
                Debug.Write("\nWinner of round robin is: " + winner);
                ActiveGame = true;  // TODO: ???
            }
            return gameState;
        }
コード例 #4
0
 private void StartGame()
 {
     ruleEngine = new RuleEngine();
     gameState = new GameState();
     gameEvent = new GameEvent();
     pieces = new List<Piece>();
     hasGameStarted = true;
     createTurnString(ref turn);
     PlayerTurn = turn;
     gameEvent.Player = LudoRules.Colors.Blue;
     chooseTalkingBubble("/images/started.png");
     initializePieces();
 }