Beispiel #1
0
 /// <summary>
 /// Given a JellyCode, x coordinate, y coordinate, and a name,
 /// this will build a Tile which will store all of the necessary
 /// information for representing the tile on the screen.
 /// </summary>
 /// <param name="code">A code representing the tile</param>
 /// <param name="x">the x position to draw to the screen</param>
 /// <param name="y">the y position to draw to the screen</param>
 /// <param name="name">the name in the image resources file to draw</param>
 public Tile(JellyCode code, int x, int y, string name)
 {
     Code = code;
     X    = x;
     Y    = y;
     Name = name;
 }
        /// <summary>
        /// Swaps two jelly icons on the board if they are next to each other.
        /// Each coordinate needs to be an index position into the array and not
        /// a mouse click location (because that's different).
        ///
        /// </summary>
        /// <param name="i">x coordinate of first jelly</param>
        /// <param name="j">y coordinate of first jelly</param>
        /// <param name="p">x coordinate of second jelly</param>
        /// <param name="q">y coordinate of second jelly</param>
        /// <returns>True if the two jellies are next to each other and the swap is successful, false otherwise</returns>
        public bool Swap(int i, int j, int p, int q)
        {
            int diffip = i - p;
            int diffjq = j - q;

            if ((diffip == 0 && (diffjq == -1 || diffjq == 1)) || (diffjq == 0 && (diffip == -1 || diffip == 1)))
            {
                JellyCode temp = Board[i, j];
                Board[i, j] = Board[p, q];
                Board[p, q] = temp;
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Gets the name of a image based on the JellyCode.
        /// </summary>
        /// <param name="code">A Jelly code</param>
        /// <returns>The string representation of the code.</returns>
        private String GetName(JellyCode code)
        {
            switch (code)
            {
            case JellyCode.BLACK: return("black");

            case JellyCode.BLUE: return("blue");

            case JellyCode.GREEN: return("green");

            case JellyCode.PINK: return("pink");

            case JellyCode.RED: return("red");

            case JellyCode.YELLOW: return("yellow");
            }

            return("empty");
        }