示例#1
0
 public void FromChar(char charIn)
 {
     // Use a switch statement to parse characters.
     switch (charIn)
     {
         case 'W':
             _contentCode = SquareContent.Wall;
             break;
         case 'B':
             _contentCode = SquareContent.Brick;
             break;
         case 'H':
             _contentCode = SquareContent.Water;
             break;
         case 'C':
             _contentCode = SquareContent.Coin;
             break;
         case 'T':
             _contentCode = SquareContent.Tank;
             break;
         case 'L':
             _contentCode = SquareContent.Health;
             break;
         case ' ':
         default:
             _contentCode = SquareContent.Empty;
             break;
     }
 }
示例#2
0
        private bool TryPlayThreeInARowFor(SquareContent content, Game game)
        {
            Square[] emptySquares = game.EmptySquares();

            int length = emptySquares.Length;

            if (length == 0) // no empty squares left; should not occur, but test anyway
                return false;

            foreach (Square square in emptySquares)
            {
                Board tryBoard = game.BoardCopy; // gets a copy of the game board
                tryBoard[square] = content;
                Line[] linesForSquare = Board.LinesForSquare(square); // get a copy
                foreach (Line line in linesForSquare)
                {
                    if (tryBoard.LineSum(line, content) == Game.WinningLineSum)
                    {
                        game.Play(square);
                        return true;
                    };
                };
            };
            return false;
        }
示例#3
0
        private bool TryPlayThreeInARowFor(SquareContent content, Game game)
        {
            Square[] emptySquares = game.EmptySquares();

            int length = emptySquares.Length;

            if (length == 0) // no empty squares left; should not occur, but test anyway
            {
                return(false);
            }

            foreach (Square square in emptySquares)
            {
                Board tryBoard = game.BoardCopy;                      // gets a copy of the game board
                tryBoard[square] = content;
                Line[] linesForSquare = Board.LinesForSquare(square); // get a copy
                foreach (Line line in linesForSquare)
                {
                    if (tryBoard.LineSum(line, content) == Game.WinningLineSum)
                    {
                        game.Play(square);
                        return(true);
                    }
                    ;
                }
                ;
            }
            ;
            return(false);
        }
 /// <summary>
 /// Set all squares of the board to a given content
 /// </summary>
 /// <param name="content">Square content that should be written to all squares</param>
 public void Clear(SquareContent content)
 {
     for (var i = 0; i < 10 * 10; i++)
     {
         boardContent[i] = content;
     }
 }
示例#5
0
文件: Square.cs 项目: bburhans/vtank
 public CompleteSquare(int x, int y, int distanceSteps, bool isPath, SquareContent content)
 {
     X             = x;
     Y             = y;
     DistanceSteps = distanceSteps;
     IsPath        = isPath;
     ContentCode   = content;
 }
示例#6
0
 public CompleteSquare(int x, int y, int distanceSteps, bool isPath, SquareContent content)
 {
     X = x;
     Y = y;
     DistanceSteps = distanceSteps;
     IsPath = isPath;
     ContentCode = content;
 }
 public Square(Point point, SquareContent content, char value)
 {
     this.Point = point;
     this.SquareContent = content;
     this.Value = value;
     this.Distance = 0;
     this.DistanceUpToHere = 0;
     this.Visited = false;
 }
 public Square(Point point, SquareContent content, char value)
 {
     this.Point            = point;
     this.SquareContent    = content;
     this.Value            = value;
     this.Distance         = 0;
     this.DistanceUpToHere = 0;
     this.Visited          = false;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="BoardContent"/> type.
        /// </summary>
        /// <param name="initialContent">Initial content of all squares</param>
        public BoardContent(SquareContent initialContent) : this()
        {
            // In C#, we cannot rely on valid values for enums, we have to check. Read more are
            // https://docs.microsoft.com/en-us/dotnet/api/system.enum.isdefined

            if (!Enum.IsDefined(typeof(SquareContent), initialContent))
            {
                throw new ArgumentOutOfRangeException(nameof(initialContent));
            }

            Clear(initialContent);
        }
示例#10
0
 public void ChangeData(Position newDataSet, int width, int height, SquareContent type)
 {
     for (int i = (int)newDataSet.X; i < newDataSet.X + width; i++)
     {
         for (int j = (int)newDataSet.Y; j < newDataSet.Y + height; j++)
         {
             if (ValidCoordinates(i, j))
             {
                 _squares[i, j] = type;
             }
         }
     }
 }
示例#11
0
        } // note: a semicolon here is not allowed - we are at the end of an accessor block.

        public int LineSum(Line line, SquareContent content)
        {
            int sum = 0;
            Square[] currentLineSquares = lineSquares[(int)line];
            foreach (Square square in currentLineSquares)
            {
                if (this[square] == content)
                {
                    sum = sum + magicSquare3by3[(int)square];
                };
            };
            return sum;
        }
示例#12
0
        private void createBlocks(String[] theToken, int tokenIndex, SquareContent content)
        {
            String[] blockCoords = theToken[tokenIndex].Split(';');
            int      x, y;

            foreach (String coordinate in blockCoords)
            {
                x = int.Parse(coordinate.Split(',')[0]);
                y = int.Parse(coordinate.Split(',')[1]);

                Map.getMap.BoardBlocks[x, y] = new CompleteSquare(x, y, content);
                Map.getMap.BoardBlocks[x, y].ObstaclePresent = true;
                //Console.WriteLine(Map.getMap.BoardBlocks[x, y].ContentCode + " added at (" + Map.getMap.BoardBlocks[x, y].Coordinate.X+ " ," + Map.getMap.BoardBlocks[x, y].Coordinate.Y+")");
            }
        }
示例#13
0
        } // note: a semicolon here is not allowed - we are at the end of an accessor block.

        public int LineSum(Line line, SquareContent content)
        {
            int sum = 0;

            Square[] currentLineSquares = lineSquares[(int)line];
            foreach (Square square in currentLineSquares)
            {
                if (this[square] == content)
                {
                    sum = sum + magicSquare3by3[(int)square];
                }
                ;
            }
            ;
            return(sum);
        }
示例#14
0
        public static string ToText(SquareContent content)
        {
            // the ?: conditional operator is much more readable here
            // than a cascading if-statement...

            //return
            //    content == Content.Cross ? Cross :
            //    (content == Content.Nought ? Nought : None);

            // but a switch statement is even better:
            switch (content)
            {
                default:
                    return None;
                case SquareContent.Nought:
                    return Nought;
                case SquareContent.Cross:
                    return Cross;
            }
        }
        public static string ToText(SquareContent content)
        {
            // the ?: conditional operator is much more readable here
            // than a cascading if-statement...

            //return
            //    content == Content.Cross ? Cross :
            //    (content == Content.Nought ? Nought : None);

            // but a switch statement is even better:
            switch (content)
            {
            default:
                return(None);

            case SquareContent.Nought:
                return(Nought);

            case SquareContent.Cross:
                return(Cross);
            }
        }
示例#16
0
 public CompleteSquare(int x, int y, SquareContent content)
 {
     Coordinate  = new Point(x, y);
     DamageLevel = 0;
     ContentCode = content;
 }
示例#17
0
 public FieldContent(BoardIndex index, SquareContent content)
 {
     Index   = index;
     Content = content;
 }
示例#18
0
        public void Pathfind(Map map, Player player, int destinationX, int destinationY)
        {
            /*
             *
             * Find path from hero to monster. First, get coordinates
             * of hero.
             *
             * */
            Point startingPoint = new Point((int)player.Position.x / 64, -(int)player.Position.y / 64);

            startingX         = startingPoint.X;
            startingY         = startingPoint.Y;
            this.destinationX = destinationX / 64;
            this.destinationY = (destinationY / 64);

            // Initialize path.
            for (int y = 0; y < map.Height; ++y)
            {
                for (int x = 0; x < map.Width; ++x)
                {
                    SquareContent content = SquareContent.Empty;
                    Tile          tile    = map.GetTile(x, y);
                    if (!tile.IsPassable)
                    {
                        content = SquareContent.Wall;
                    }
                    else if (x == startingX && y == startingY)
                    {
                        content = SquareContent.Starting;
                    }

                    _squares[x, y] = new CompleteSquare()
                    {
                        X             = -1, Y = -1,
                        IsPath        = false,
                        ContentCode   = content,
                        DistanceSteps = 10000
                    };
                }
            }

            /*
             *
             * Hero starts at distance of 0.
             *
             * */
            _squares[startingPoint.X, startingPoint.Y].DistanceSteps = 0;

            while (true)
            {
                bool madeProgress = false;

                /*
                 *
                 * Look at each square on the board.
                 *
                 * */
                foreach (Point mainPoint in AllSquares())
                {
                    int x = mainPoint.X;
                    int y = mainPoint.Y;

                    /*
                     *
                     * If the square is open, look through valid moves given
                     * the coordinates of that square.
                     *
                     * */
                    Tile relevantTile = map.GetTile(x, y);
                    if (relevantTile.IsPassable)
                    {
                        int passHere = _squares[x, y].DistanceSteps;

                        foreach (Point movePoint in ValidMoves(x, y))
                        {
                            int newX    = movePoint.X;
                            int newY    = movePoint.Y;
                            int newPass = passHere + 1;

                            if (_squares[newX, newY].DistanceSteps > newPass)
                            {
                                _squares[newX, newY].DistanceSteps = newPass;
                                madeProgress = true;
                            }
                        }
                    }
                }
                if (!madeProgress)
                {
                    break;
                }
            }

            HighlightPath();
        }
 public static char SquareContentToChar(SquareContent sq)
 => sq switch
 {