Example #1
0
 public GoalField(GoalField field) : base(field.ToBase())
 {
     Type = field.Type;
     Team = field.Team;
     if (field.Player != null)
     {
         Player = new Player(field.Player);
     }
 }
        /// <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 });
        }
        /// <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 });
        }
        /// <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);
        }
Example #5
0
 public GameBoard(int width, int taskAreaHeight, int goalAreaHeight, GoalFieldType defaultGoalType = GoalFieldType.unknown)
 {
     Width          = width;
     TaskAreaHeight = taskAreaHeight;
     GoalAreaHeight = goalAreaHeight;
     fields         = new Field[width, taskAreaHeight + 2 * goalAreaHeight];
     for (int i = 0; i < GoalAreaHeight; i++)
     {
         for (int j = 0; j < Width; j++)
         {
             fields[j, i] = new GoalField(j, i, DateTime.Now, TeamColour.blue, defaultGoalType);
             fields[j, i + taskAreaHeight + goalAreaHeight] = new GoalField(j, i + taskAreaHeight + goalAreaHeight, DateTime.Now, TeamColour.red, defaultGoalType);
         }
     }
     for (int i = GoalAreaHeight; i < Height - GoalAreaHeight; i++)
     {
         for (int j = 0; j < Width; j++)
         {
             fields[j, i] = new TaskField(j, i, DateTime.Now);
         }
     }
 }
        private MoveType GetDirectionToGoal(GameArea.GameObjects.GoalField goal)
        {
            MoveType direction = MoveType.left;

            if (goal == null)
            {
                ConsoleWriter.Warning("Null goal in getdirectiontogoal");
                return(Team == TeamColour.blue ? MoveType.down : MoveType.up);
            }
            long xDiff = Math.Abs(goal.X - PlayerLocation.X);
            long yDiff = Math.Abs(goal.Y - PlayerLocation.Y);

            if (xDiff < yDiff) //move in y axis
            {
                if (goal.Y - PlayerLocation.Y > 0)
                {
                    direction = MoveType.up;
                }
                else
                {
                    direction = MoveType.down;
                }
            }
            else
            {
                if (goal.X - PlayerLocation.X > 0)
                {
                    direction = MoveType.right;
                }
                else
                {
                    direction = MoveType.left;
                }
            }

            return(direction);
        }