예제 #1
0
        /// <summary>
        /// Converts MoveType enum object to Location object
        /// </summary>
        /// <returns></returns>
        private GameObjects.Location PerformLocationDelta(MoveType moveType, GameObjects.Location currentLocation, TeamColour team)
        {
            // is MoveUp the same for red and blue team? or if for red Up is +1 for blue should be -1 on OY???
            int dx = 0, dy = 0;

            switch (moveType)
            {
            case MoveType.right:
                dx = 1;
                break;

            case MoveType.left:
                dx = -1;
                break;

            case MoveType.down:
                dy = -1;
                break;

            case MoveType.up:
                dy = 1;
                break;
            }

            if (!ValidateFieldPosition(currentLocation.X, currentLocation.Y, team))
            {
                return(currentLocation);
            }
            else
            {
                return(new GameObjects.Location(currentLocation.X + dx, currentLocation.Y + dy));
            }
        }
예제 #2
0
        /// <summary>
        /// Sets info about discovered TaskField
        /// </summary>
        /// <param name="location"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="field"></param>
        /// <param name="TaskFieldList"></param>
        public void SetInfoAboutDiscoveredTaskField(GameObjects.Location location, int dx, int dy,
                                                    GameObjects.Field field, List <GameObjects.TaskField> TaskFieldList)
        {
            //basic information
            GameObjects.TaskField responseField = new GameObjects.TaskField(location.X + dx, location.Y + dy, DateTime.Now)
            {
                TimeStamp       = DateTime.Now,
                DistanceToPiece = (field as GameObjects.TaskField).DistanceToPiece
            };

            //anoter Player on the field
            if (field.HasPlayer())
            {
                responseField.PlayerId = (long)field.Player.ID;
                responseField.Player   = field.Player;
            }
            else
            {
                responseField.PlayerId = -1;
                responseField.Player   = null;
            }

            //piece on the field
            GameObjects.Piece piece = (field as GameObjects.TaskField).Piece;
            if (piece != null)
            {
                responseField.Piece = piece;
            }
            else
            {
                responseField.Piece = null;
            }

            TaskFieldList.Add(responseField);
        }
예제 #3
0
        ///// <summary>
        ///// Handles Player's request - move towards TaskField - fills response message with data about futureField
        ///// </summary>
        ///// <param name="location"></param>
        ///// <param name="playerGuid"></param>
        ///// <returns>Info about future field</returns>
        //public void TryMovePlayerToTaskField(Data response, Location futureLocation, string playerGuid,
        //                                    out Messages.Piece piece, out Messages.Field field)
        //{
        //    GameArea.TaskField fieldFromBoard = actualBoard.GetField(futureLocation.x, futureLocation.y) as GameArea.TaskField;
        //    field = new Messages.TaskField(futureLocation.x, futureLocation.y)
        //    {
        //        distanceToPiece = fieldFromBoard.Distance,
        //        timestamp = DateTime.Now,
        //    };

        //    // check if there is a piece on the filed
        //    fieldFromBoard = actualBoard.GetField(futureLocation.x, futureLocation.y) as GameArea.TaskField;
        //    piece = (fieldFromBoard as GameArea.TaskField).GetPiece;
        //    if (piece != null)
        //    {
        //        response.Pieces = new Messages.Piece[] { piece };
        //        (field as Messages.TaskField).pieceId = piece.id;
        //        (field as Messages.TaskField).pieceIdSpecified = true;
        //    }
        //    response.TaskFields = new Messages.TaskField[] { (field as Messages.TaskField) };
        //}

        ///// <summary>
        ///// Handles Player's request - move towards GoalField - fills response message with data about futureField
        ///// </summary>
        ///// <param name="location"></param>
        ///// <param name="playerGuid"></param>
        ///// <returns>Info about future field</returns>
        //public void TryMovePlayerToGoalField(Data response, Location futureLocation, string playerGuid,
        //                                    out Messages.Field field)
        //{
        //    GameArea.GoalField fieldFromBoard = actualBoard.GetField(futureLocation.x, futureLocation.y) as GameArea.GoalField;
        //    field = new Messages.GoalField(futureLocation.x, futureLocation.y, fieldFromBoard.GetOwner)
        //    {
        //        timestamp = DateTime.Now,
        //    };
        //    response.GoalFields = new Messages.GoalField[] { (field as Messages.GoalField) };
        //    response.TaskFields = null;
        //} // najprawdopodobniej do wyrzucenia

        /// <summary>
        /// Performs move action for an Player - called when action is valid
        /// </summary>
        /// <param name="currentLocation"></param>
        /// <param name="futureLocation"></param>
        /// <param name="playerGuid"></param>
        /// <param name="response"></param>
        public void PerformMoveAction(GameObjects.Location currentLocation, GameObjects.Location futureLocation,
                                      string playerGuid, DataMessage response)
        {
            var Player = actualBoard.GetField(currentLocation.X, currentLocation.Y).Player;

            actualBoard.GetField(currentLocation.X, currentLocation.Y).Player = null;
            actualBoard.GetField(futureLocation.X, futureLocation.Y).Player   = Player;
            response.PlayerLocation = futureLocation;
            Players.Where(q => q.GUID == playerGuid).First().SetLocation(futureLocation);
        }
예제 #4
0
        /// <summary>
        /// Handles Player's request - place a sham Piece on a GoalField
        /// </summary>
        /// <param name="location"></param>
        /// <param name="playerGuid"></param>
        /// <returns></returns>
        public GameObjects.GoalField[] TryPlaceShamPieceOnGoalField(GameObjects.Location location, string playerGuid)
        {
            var teamColour   = Players.Where(q => q.GUID == playerGuid).First().Team;
            var player       = Players.Where(q => q.GUID == playerGuid).First();
            var fieldMessage = new GameObjects.GoalField(location.X, location.Y, DateTime.Now, teamColour, GoalFieldType.unknown)
            {
                PlayerId = (long)player.ID,
            };

            return(new GameObjects.GoalField[] { fieldMessage });
        }
 public GoalDirectionInfo(List <GameArea.GameObjects.GoalField> goals, TeamColour team, GameArea.GameObjects.Location _PlayerLocation)
 {
     PlayerLocation = _PlayerLocation;
     Team           = team;
     if (team == TeamColour.red)
     {
         Goals = goals.OrderBy(q => q.Y).ThenBy(q => q.X).Where(q => q.Type == GoalFieldType.unknown).ToList();
     }
     else
     {
         Goals = goals.OrderByDescending(q => q.Y).ThenBy(q => q.X).Where(q => q.Type == GoalFieldType.unknown).ToList();
     }
 }
예제 #6
0
        /// <summary>
        /// Handles Player's request - place a normal Piece on a GoalField
        /// </summary>
        /// <param name="location"></param>
        /// <param name="playerGuid"></param>
        /// <returns></returns>
        public GameObjects.GoalField[] TryPlaceNormalPieceOnGoalField(GameObjects.Location location, string playerGuid)
        {
            var teamColour    = Players.Where(q => q.GUID == playerGuid).First().Team;
            var goalFieldType = actualBoard.GetGoalField(location.X, location.Y).Type;
            var Player        = Players.Where(q => q.GUID == playerGuid).First();
            var fieldMessage  = new GameObjects.GoalField(location.X, location.Y, DateTime.Now, teamColour, goalFieldType)
            {
                PlayerId = (long)Player.ID
            };

            // if GoalField is of type 'goal' we update data and notify point score
            var currentGoalField = actualBoard.GetField(location.X, location.Y) as GameObjects.GoalField;

            if (currentGoalField.Type == GoalFieldType.goal)
            {
                var goal = actualBoard.GetField(location.X, location.Y) as GameMasterGoalField;
                if (goal != null && !goal.IsFullfilled && State != GameMasterState.GameOver)
                {
                    switch (goal.Team)
                    {
                    case TeamColour.red:
                        GoalsRedLeft--;        // one goal less before the game is over
                        break;

                    case TeamColour.blue:
                        GoalsBlueLeft--;
                        break;
                    }
                    if (GoalsBlueLeft == 0 || GoalsRedLeft == 0)
                    {
                        if (IsGameFinished)
                        {
                            Console.WriteLine("!!!ACHTUNG!!!\nGame has ended.");
                        }
                        State       = GameMasterState.GameResolved;
                        GameEndDate = DateTime.Now;
                        PrintEndGameState();
                    }
                    Player.SetPiece(null); // the piece is no longer possesed by an Player
                }
            }

            return(new GameObjects.GoalField[] { fieldMessage });
        }
예제 #7
0
        /// <summary>
        /// Sets info about discovered GoalField
        /// </summary>
        /// <param name="location"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="field"></param>
        /// <param name="GoalFieldList"></param>
        public void SetInfoAboutDiscoveredGoalField(GameObjects.Location location, int dx, int dy,
                                                    GameObjects.Field field, List <GameObjects.GoalField> GoalFieldList)
        {
            GameObjects.GoalField responseField = new GameObjects.GoalField(location.X + dx, location.Y + dy, DateTime.Now, (field as GameObjects.GoalField).Team, GoalFieldType.unknown)
            {
                TimeStamp = DateTime.Now
            };

            if (field.HasPlayer())
            {
                responseField.PlayerId = (long)field.Player.ID;
                responseField.Player   = field.Player;
            }
            else
            {
                responseField.PlayerId = -1;
                responseField.Player   = null;
            }

            GoalFieldList.Add(responseField);
        }
예제 #8
0
        // ------------ additional methods
        #region addition api methods

        /// <summary>
        /// Handles Player's request - place a Piece on a TaskField
        /// </summary>
        public GameObjects.TaskField[] TryPlacePieceOnTaskField(GameObjects.Location location, string playerGuid)
        {
            GameObjects.TaskField fieldMessage = null;
            var currentTaskField = actualBoard.GetField(location.X, location.Y) as GameObjects.TaskField;
            var Player           = Players.Where(q => q.GUID == playerGuid).First();

            // if TaskField is not occupied
            if (currentTaskField.Piece == null)
            {
                fieldMessage = new GameObjects.TaskField(location.X, location.Y, DateTime.Now)
                {
                    PlayerId  = (long)Player.ID,
                    Piece     = Player.GetPiece,
                    TimeStamp = DateTime.Now
                };

                var piece = Player.GetPiece;
                piece.PlayerId         = 0;
                currentTaskField.Piece = piece; // the piece is put on the field
                Player.SetPiece(null);          // the piece is no longer possesed by an Player
                UpdateDistancesFromAllPieces();
            }
            return(new GameObjects.TaskField[] { fieldMessage }); // fieldMessage is null if TaskField is occupied
        }
 private int GetDistance(GameArea.GameObjects.Location goalLocation)
 {
     return(Math.Abs(goalLocation.X - PlayerLocation.X) + Math.Abs(goalLocation.Y - PlayerLocation.Y));
 }