得分疯狂 [英] Scoring goes craaazy

查看:83
本文介绍了得分疯狂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们...我正在创建2D拼字游戏,但在刻苦方面存在得分问题.
以下是我的两个类可单击的字母"和级别",它们是我的点值" int唯一使用的地方,其总得分为
当玩家点击支票分数时,ATM的分数可以从0到42到135到213,疯狂的数字,而且每次尝试时似乎都不过分.
即使板上没有字母,也会发生这种情况,因此很明显出了点问题.请帮助...提前感谢

在我的级别类中寻找countScore方法,为了对问题进行排序,我在级别构造函数中将每个字母的所有点值都设置为"1"

Hi Guys...im creating a 2D scrabble board game and at the minute have a problem with the scoring.
Below are my two classes ''clickable letter'' and ''level'' which are the only places my ''point value'' int is used, and its this that totals the score
ATM when the player hits check score the score can go from 0 to 42 to 135 to 213, crazy numbers and there doesnt seem to too much of a pattern each time i try it.
This happens even with no letters on the board so clearly something is wrong. Please help...thanks in advance

look for the countScore method in my level class, for the sake of sorting the problem I have set all the point values of each letter to ''1'' inside the level constructor

namespace Scrabble 
{ 
    class ClickableLetter:ClickableGameplayObject 
    { 
        //Point value  
        public int PointValue; 
 
        Mouse mouse; 
 
        //Reference XNA framework 
        Game gameReference; 
 
        public int x; 
        public int y; 
 
        MouseState previousState, currentState; 
 
        public ContentManager Content 
        { 
            get { return content; } 
        } 
        ContentManager content; 
 
        Random random; 
        public Texture2D ClickedTexture 
        { 
            get; 
            set; 
        } 
 
        Texture2D saved; 
 
        public ClickableLetter(Game theGame, int points, int x, int y, string textureSource) 
            : base() 
        { 
            Alpha = 0.5f; 
            random = new Random((int)DateTime.Now.TimeOfDay.TotalMilliseconds); 
            content = theGame.Content; 
            Texture = Content.Load<texture2d>(textureSource); 
            this.gameReference = theGame; 
            PointValue = points; 
            Position = new Vector2(x, y); 
        } 
 
        public override void OnHover() 
        { 
            base.OnHover(); 
 
            //Alpha = 1.0f; 
 
            // Rotation += 0.01f; 
        } 
 
        public override void OnLeave() 
        { 
            base.OnLeave(); 
 
            Alpha = 0.5f; 
        } 
 
        public override void OnLeftClick() 
        { 
            base.OnLeftClick(); 
 
            Position = new Microsoft.Xna.Framework.Vector2(ActiveMouse.Position.X, ActiveMouse.Position.Y); 
        } 
 
        public override void OnHeldLeftClick() 
        { 
            base.OnHeldLeftClick(); 
 
            Position = new Microsoft.Xna.Framework.Vector2(ActiveMouse.Position.X, ActiveMouse.Position.Y); 
        } 
 
        protected override void UpdateGameplayObject(Microsoft.Xna.Framework.GameTime gameTime) 
        { 
 
        } 
 
        public void Update(GameTime gameTime, SpriteBatch spriteBatch) 
        { 
        } 
 
        public override void OnLeftRelease() 
        { 
            centerLetterOnTile(); 
        } 
 
        //this is used to center the letter when placed on board 
        private void centerLetterOnTile() 
        { 
            Level.x = Level.currentState.X; 
            Level.y = Level.currentState.Y; 
 
            if (Level.x >= 300 && Level.x <= 1050) 
            { 
                //find relative pos of tile (3,3) on overall screen, that will give pos on board 
                Level.x -= 300; 
                Level.x /= 50; 
                Level.y -= 1; 
                Level.y /= 50; 
                // / 50 is to know how many times you have to move - relative to tiles 
 
                //variable will now be stored as (0,1)(1,1) etc... so *50 to get tile pos, and + 25 to center 
                Level.x = (Level.x * 50) + 25; 
                Level.y = (Level.y * 50) + 25; 
 
                //find exact pos on board - on screen 
                Level.x += 300; 
                Level.y += 1; 
 
                Vector2 temp = new Vector2(Level.x, Level.y); 
                Position = temp; 
 
                x = Level.x; 
                y = Level.y; 
            } 
            else 
            { 
                x = Level.currentState.X; 
                y = Level.currentState.Y; 
            } 
        } 
    } 
} 
 


//and the level
namespace Scrabble 
{ 
    class Level 
    { 
        [DllImport("user32.dll", CharSet = CharSet.Auto)] 
        public static extern uint MessageBox(IntPtr hWndle, String text, String caption, int buttons); 
        
        Game gameReference; 
 
        //score 
        int player1Score, player2Score; 
 
        //textures 
        private Texture2D backgroundImage; 
        private Texture2D p1on, p1off, p2on, p2off; 
 
        //array for tiles displayed. 
        public static Tile[,] tiles; 
 
        //Add Pause 
        private Pause pause; 
 
        //Bools for pausing, resuming gameplay and drawing moving blocks  
        public bool paused = false; 
        public bool notPaused = true; 
        public static bool player1Turn = true; 
        public static bool player2Turn; 
        public static bool drawP1 = true; 
        public static bool drawP2 = false; 
        public bool cursorInsideScorebtn = false; 
        public bool press1; 
        public bool press2; 
 
 
        // The layer which entities are drawn on top of. 
        private const int EntityLayer = 2; 
 
        // Level game state & Camera for scroll screen 
        private Random random = new Random(354668); 
        public float cameraPosition; 
        public float cameraPositionY; 
 
        //Sound Effect for exit reached & Bonus collected. 
        private SoundEffect exitReachedSound; 
        private SoundEffect CollectBonus; 
 
        //Return Score 
        public int Score 
        { 
            get { return score; } 
        } 
        int score; 
        #region 
        //start of file from other game 
        public static int x; 
        public static int y; 
        public bool ScoreButtonPressed; 
 
        SpriteFont hudFont; 
 
        //clickable letter on screen 
        public static ClickableLetter letterA;  
        public static ClickableLetter letterB; 
        public static ClickableLetter letterC; 
        public static ClickableLetter letterD; 
        public static ClickableLetter letterE; 
        public static ClickableLetter letterF; 
        public static ClickableLetter letterT; 
        public static ClickableLetter letterH; 
        public static ClickableLetter letterI; 
        public static ClickableLetter letterJ; 
        public static ClickableLetter letterK; 
        public static ClickableLetter letterL; 
        public static ClickableLetter letterM; 
        public static ClickableLetter letterN; 
 
        //static mouse 
        public static Mouse mouse; 
 
       //ClickablePlayer 
        List<clickableletter> clickableObjects; 
        public static MouseState mouseState; 
 
        /// <summary> 
        /// The X, Y screen coordinates of the mouse 
        /// </summary> 
        public Vector2 Position//used for hud 
        { 
            get; 
            protected set; 
        } 
 
 
        public Vector2 Positionofc2//used for hud 
        { 
            get; 
            protected set; 
        } 
 
 
        //pos of tile on board 
        public Rectangle checkScoreBTN 
        { 
            get; 
            set; 
        } 
 
        public bool DIOC; 
 
        //Textures for images 
        private Texture2D TileA1; 
        private Texture2D checkScoreB; 
        private Texture2D checkScoreW; 
        private Texture2D shelf; 
        #endregion 
 
        //Call Content         
        public ContentManager Content 
        { 
            get { return content; } 
        } 
        ContentManager content; 
        #region Loading 
        /// <summary> 
        /// Constructs a new level. 
        /// The service provider that will be used to construct a ContentManager. 
        /// </summary><param name="serviceProvider"><param name="path"> 
        /// The absolute path to the level file to be loaded. 
        /// </param> 
        public Level(Game theGame, IServiceProvider serviceProvider, Stream fileStream, int levelIndex) 
   
        { 
            whosTurnIsIt(); 
 
            // Create a new content manager to load content used just by this level. 
            content = new ContentManager(serviceProvider, "Content"); 
 
            //Call Load tiles method 
            LoadTiles(fileStream); 
 
            backgroundImage = Content.Load<texture2d>("Images/backgroundImage"); 
            p1on = Content.Load<texture2d>("Player/p1on"); 
            p1off = Content.Load<texture2d>("Player/p1off"); 
            p2on = Content.Load<texture2d>("Player/p2on"); 
            p2off = Content.Load<texture2d>("Player/p2off"); 
 
            LoadPause(); 
 
            content = theGame.Content; 
            this.gameReference = theGame; 
 
            
            letterA = new ClickableLetter(theGame, 1, 148, 475, "Letters/a"); 
            letterB = new ClickableLetter(theGame, 1, 1125, 475, "Letters/b"); 
            letterC = new ClickableLetter(theGame, 1, 233, 475, "Letters/c"); 
            letterD = new ClickableLetter(theGame, 1, 1240, 475, "Letters/d"); 
            letterE = new ClickableLetter(theGame, 1, 1065, 475, "Letters/e"); 
            letterF = new ClickableLetter(theGame, 1, 61, 475, "Letters/t"); 
            letterT = new ClickableLetter(theGame, 1, 61, 475, "Letters/t"); 
            letterH = new ClickableLetter(theGame, 1, 148, 475, "Letters/a"); 
            letterI = new ClickableLetter(theGame, 1, 1125, 475, "Letters/b"); 
            letterJ = new ClickableLetter(theGame, 1, 233, 475, "Letters/c"); 
            letterK = new ClickableLetter(theGame, 1, 1240, 475, "Letters/d"); 
            letterL = new ClickableLetter(theGame, 1, 1065, 475, "Letters/e"); 
            letterM = new ClickableLetter(theGame, 1, 61, 475, "Letters/t"); 
            letterN = new ClickableLetter(theGame, 1, 61, 475, "Letters/t"); 
    
            LoadContent(); 
         
 
 
        }//End of Level Constructor 
 
 
        /// <summary> 
        /// Will load the pause class 
        /// </summary> 
        private void LoadPause() 
        { 
            pause = new Pause(this); 
 
        }//End of LoadPause 
 
        //bool to test collisin + colour 
        public static MouseState previousState, currentState; 
 
 
        private void LoadContent() 
        { 
            //load mouse 
            mouse = new Mouse(content); 
 
            shelf = Content.Load<texture2d>("Backgrounds/shelf"); 
            checkScoreB = Content.Load<texture2d>("Old/CheckScoreB"); 
            checkScoreW = Content.Load<texture2d>("Old/CheckScoreW"); 
            hudFont = content.Load<spritefont>("Old/Hud"); 
 
            //list for letters 
            clickableObjects = new List<clickableletter>(14); 
 
            //load letter as clickable object 
            clickableObjects.Add(letterA); 
            clickableObjects.Add(letterB); 
            clickableObjects.Add(letterC); 
            clickableObjects.Add(letterD); 
            clickableObjects.Add(letterE); 
            clickableObjects.Add(letterF); 
            clickableObjects.Add(letterT); 
            clickableObjects.Add(letterH); 
            clickableObjects.Add(letterI); 
            clickableObjects.Add(letterJ); 
            clickableObjects.Add(letterK); 
            clickableObjects.Add(letterL); 
            clickableObjects.Add(letterM); 
            clickableObjects.Add(letterN); 
        } 
 
 
        private void LoadTiles(Stream fileStream) 
        { 
            // Load the level and ensure all of the lines are the same length. 
            int width; 
            List<string> lines = new List<string>(); 
            using (StreamReader reader = new StreamReader(fileStream)) 
            { 
                string line = reader.ReadLine(); 
                width = line.Length; 
                while (line != null) 
                { 
                    lines.Add(line); 
                    if (line.Length != width) 
                        throw new Exception(String.Format("The length of line {0} is different from all preceeding lines.", lines.Count)); 
                    line = reader.ReadLine(); 
                } 
            } 
 
            // Allocate the tile grid. 
            //array used for tiles 
            tiles = new Tile[width, lines.Count]; 
 
            // Loop over every tile position, 
            for (int y = 0; y < Height; ++y) 
            { 
                for (int x = 0; x < Width; ++x) 
                { 
                    // To load each tile. 
                    char tileType = lines[y][x]; 
                    tiles[x, y] = LoadTile(tileType, x, y); 
                } 
            } 
 
        }//End of LoadTiles 
 
        private Tile LoadTile(char tileType, int x, int y) 
        { 
            switch (tileType) 
            { 
                //Blank space 
                case '.': 
                    return new Tile(null, TileCollision.Passable,0); 
 
 
                //Floating platform 
               // case '-': 
                 //   return LoadTile("Platform", TileCollision.Platform); 
 
                case '1': 
                    return LoadTile("1Centertile", TileCollision.Platform,1); 
                case '2': 
                    return LoadTile("2normal", TileCollision.Platform,2); 
                case '3': 
                    return LoadTile("3DoubleLetterScore", TileCollision.Platform,3); 
                case '4': 
                    return LoadTile("4TripleLetterScore", TileCollision.Platform,4); 
                case '5': 
                    return LoadTile("5DoubleWordScore", TileCollision.Platform,5); 
                case '6': 
                    return LoadTile("6TripleWordScore", TileCollision.Platform,6); 
 
                case '7': 
                    return LoadTile("2", TileCollision.Platform,7); 
               
                   default: 
                    return new Tile(null, TileCollision.Passable, 0 ); 
 
                    throw new NotSupportedException(String.Format("Unsupported tile type character '{0}' at position {1}, {2}.", tileType, x, y)); 
            }//End of Switch 
 
        }//End of Tile-LoadTile 
 
 
       
        private Tile LoadTile(string name, TileCollision collision, int type) 
        { 
            return new Tile(Content.Load<texture2d>("Tiles/" + name), collision, type); 
 
        }//End of Tile -LoadTile 
 
        /// <summary> 
        /// Unloads the level content. 
        /// </summary> 
        public void Dispose() 
        { 
            Content.Unload(); 
 
        }//End of Dispose 
        #endregion 
        #region Bounds and collision 
 
        /// <summary> 
        /// Gets the collision mode of the tile at a particular location. 
        /// This method handles tiles outside of the levels boundries by making it 
        /// impossible to escape past the left or right edges, but allowing things 
        /// to jump beyond the top of the level and fall off the bottom. 
        /// </summary> 
        public TileCollision GetCollision(int x, int y) 
        { 
            // Prevent escaping past the level ends. 
            if (x < 0 || x >= Width) 
                return TileCollision.Impassable; 
            //Allow jumping past the level top and falling through the bottom. 
            if (y < 0 || y >= Height) 
                return TileCollision.Passable; 
            return tiles[x, y].Collision; 
 
        }//End of TileCollision 
 
 
        /// <summary> 
        /// Gets the bounding rectangle of a tile in world space. 
        /// </summary>         
        public Rectangle GetBounds(int x, int y) 
        { 
            return new Rectangle(x * Tile.Width, y * Tile.Height, Tile.Width, Tile.Height); 
 
        }//End of GetBounds 
 
 
        /// <summary> 
        /// Width of level measured in tiles. 
        /// </summary> 
        public int Width 
        { 
            get { return tiles.GetLength(0); } 
 
        }//End of Width 
 
 
        /// <summary> 
        /// Height of the level measured in tiles. 
        /// </summary> 
        public int Height 
        { 
            get { return tiles.GetLength(1); } 
 
        }//End of Height 
 
        //MY CODE 
        #endregion 
        #region Update 
 
        /// <summary> 
        /// Updates all objects in the world, performs collision between them, 
        /// and handles the time limit with scoring. 
        /// </summary> 
        public void Update(GameTime gameTime, SpriteBatch spriteBatch) 
        { 
           // onLettersPlaced(); 
 
 
            //Allow keyboard input - used for pausing game 
            KeyboardState keyboardState = Keyboard.GetState(); 
 
            //If 'P' is pressed - Pause game 
            if (keyboardState.IsKeyDown(Keys.P)) 
            { 
                notPaused = false; 
                paused = true; 
 
            }//End of if 
 
            //If 'R' is pressed - Resume game 
            if (keyboardState.IsKeyDown(Keys.R)) 
            { 
                notPaused = true; 
                paused = false; 
 
            }//End of if 
 
 
            //If game is not paused 
            if (notPaused) 
            { 
                //methods to allow letters to be dragged and dropped 
                PerformMouseInteractions(gameTime); 
                PerformNormalUpdate(gameTime); 
 
 
                currentState = Microsoft.Xna.Framework.Input.Mouse.GetState();//mouse 
                mouse.Update(); 
                 
                //check score 
                checkScoreButton();          
 
            } 
             pause.Update(gameTime); 
 
        } 
 
 
                //method from mouse class to allow letter to be dragged and dropped 
        public void PerformNormalUpdate(GameTime gameTime) 
        { 
            foreach (ClickableGameplayObject cgo in clickableObjects) 
            { 
                if (cgo != mouse.ClickedObject) 
                { 
                    cgo.Update(gameTime); 
                } 
            } 
        } 
 
        //method from mouse class to allow letter to be dragged and dropped 
        public void PerformMouseInteractions(GameTime gameTime) 
        { 
            foreach (ClickableGameplayObject cgo in clickableObjects) 
            { 
                if (mouse.ClickedObject == null) 
                {   
                    cgo.Update(gameTime, mouse); 
                    if (cgo.ActiveMouse != null) 
                    { 
                        return; 
                    } 
                } 
                else if (mouse.ClickedObject != null) 
                { 
                    mouse.ClickedObject.Update(gameTime, mouse); 
 
                    return; 
                } 
            } 
        } 
 
         
        //check score button 
                public void checkScoreButton() 
                { 
                    //rect for 'check score' button 
                        checkScoreBTN = new Rectangle(87, 605, 163, 59); 
 
                        x = currentState.X; 
                        y = currentState.Y; 
                        mouseState = Microsoft.Xna.Framework.Input.Mouse.GetState();//mouse 
 
                    //if 'check score' button contains cursor return true                        
                            if (checkScoreBTN.Contains(x, y)) 
                            { 
                                cursorInsideScorebtn = true; 
                            } 
 
                            //if 'check score' button does NOT contain cursor return false   
                            if (!checkScoreBTN.Contains(x, y)) 
                            { 
                                cursorInsideScorebtn = false; 
                            } 
 
                             
                    //if it is player 1's turn and mouse is inside 'check score button' 
                            if (player1Turn & cursorInsideScorebtn) 
                            { 
                                //if mouse is pressed- run scount score 
                                if (mouseState.LeftButton == ButtonState.Pressed) 
                                { 
                                    //show light when button is pressed 
                                    ScoreButtonPressed = true; 
                                    countScore(); 
                                    //lights for players turn 
                                    press2 = false; 
                                    press1 = true; 
                                } 
 
                                else if (mouseState.LeftButton == ButtonState.Released) 
                                    { 
                                    //dont show light when button is released 
                                        ScoreButtonPressed = false; 
 
                                        if (press1) 
                                        { 
                                            //lights to show user whos turn it is 
                                            player1Turn = false; 
                                            player2Turn = true; 
                                        } 
 
 
                                    } 
                                } 
 
 
                        //if it is player 2's turn and mouse is inside 'check score button' 
                            else if (player2Turn & cursorInsideScorebtn) 
                            { 
                                //if mouse is pressed- run scount score 
                                if (mouseState.LeftButton == ButtonState.Pressed) 
                                {//show light when button is pressed 
                                    ScoreButtonPressed = true; 
 
                                    countScore(); 
                                    //lights to show user whos turn it is 
                                    press1 = false; 
                                    press2 = true; 
                 
                                } 
 
                            
                                if (mouseState.LeftButton == ButtonState.Released) 
                                {//dont show light when button is released 
                                    ScoreButtonPressed = false; 
 
                                    if (press2) 
                                    {//lights to show user whos turn it is 
                                        player1Turn = true; 
                                        player2Turn = false; 
                                    } 
 
                                } 
                            } 
                              
                         
                     
                } 
 
                public void countScore() 
                { 
                    int scoreThisTurn = 0; 
                    if (player1Turn) 
                    {//player 1's seven letters he can choose from 
                        for (int i = 0; i < 7; ++i) 
                        { 
                            //scoreThisTurn += addScore(clickableObjects[i]);                       
                            scoreThisTurn += 1;//just for testing 
                        } 
                        player1Score += scoreThisTurn; 
 
                    } 
                    else 
                    {//player 2's seven letter theycan choose from 
                        for (int i = 7; i < 14; ++i) 
                        { 
                            scoreThisTurn += addScore(clickableObjects[i]);//add parameter to addScore method 
                        } 
                    } 
                } 
 
        //this is used if letter is placed on bonus tiles 
               private int addScore(ClickableLetter letter) 
                { 
                    //inside board, otherwise return 0 points 
                    if (letter.x >= 300 && letter.x <= 1050) 
                    { 
                        //temp pos, then get (1,1) on board 
                        int tempX = letter.x; 
                        int tempY = letter.y; 
                        tempX -= 300; 
                        tempX /= 50; 
                        tempY -= 1; 
                        tempY /= 50; 
                         //actual tile on board/now check for bonus, Type is int in Tile, depending on bonus 
                        switch (tiles[tempX, tempY].Type) 
                        { 
                            case 3: 
                              //  return 2 * letter.PointValue;//case 3 =double 
                            case 4: 
                              //  return 3 * letter.PointValue;//case4 = triple 
                            default: 
                                return letter.PointValue;//no bonus so return just letter points 
                        } 
                         
                    } 
 
                    return 0; 
                } 
 
                public static void whosTurnIsIt() 
                { 
                    if (player1Turn) 
                    {//lights to draw, depending on whos go it is 
                        drawP1 = true; 
                        drawP2 = false; 
                    } 
 
                    else if (player2Turn) 
                    {//lights to show whose turn it is 
                        drawP1 = false; 
                        drawP2 = true; 
                    } 
 
                } 
 
 
        //draw all to screen 
        public void Draw(GameTime gameTime, SpriteBatch spriteBatch) 
        { 
 
            spriteBatch.End(); 
 
            ScrollCamera(spriteBatch.GraphicsDevice.Viewport); 
 
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend); 
 
 
            spriteBatch.Draw(backgroundImage, new Vector2(0, 0), null, Color.White, 0, Vector2.Zero, 1.0f, SpriteEffects.None, 1.0f); 
 
            spriteBatch.Draw(shelf, new Vector2(5, 496), null, Color.White, 0, Vector2.Zero, 1.0f, SpriteEffects.None, 1.0f); 
            spriteBatch.Draw(shelf, new Vector2(1062, 496), null, Color.White, 0, Vector2.Zero, 1.0f, SpriteEffects.None, 1.0f); 
 
            if (ClickableGameplayObject.OnLeaveTest) 
            { 
                spriteBatch.Draw(shelf, new Vector2(651, 300), null, Color.White, 0, Vector2.Zero, 1.0f, SpriteEffects.None, 1.0f); 
            } 
            if (ClickableGameplayObject.OnLeaveTestRect) 
            { 
                spriteBatch.Draw(shelf, new Vector2(651, 320), null, Color.White, 0, Vector2.Zero, 1.0f, SpriteEffects.None, 1.0f); 
            } 
 
            //rect to test from clickable object 
            spriteBatch.Draw(shelf, new Vector2(651, 372), null, Color.White, 0, Vector2.Zero, 1.0f, SpriteEffects.None, 1.0f); 
            spriteBatch.Draw(shelf, new Vector2(651, 422), null, Color.White, 0, Vector2.Zero, 1.0f, SpriteEffects.None, 1.0f); 
 
           if (drawP1) 
           { 
 
                spriteBatch.Draw(p1on, new Vector2(20, 100), null, Color.White, 0, Vector2.Zero, 1.0f, SpriteEffects.None, 1.0f); 
                spriteBatch.Draw(p2off, new Vector2(1060, 100), null, Color.White, 0, Vector2.Zero, 1.0f, SpriteEffects.None, 1.0f); 
            } 
 
            if (drawP2) 
            { 
 
                spriteBatch.Draw(p1off, new Vector2(20, 100), null, Color.White, 0, Vector2.Zero, 1.0f, SpriteEffects.None, 1.0f); 
                spriteBatch.Draw(p2on, new Vector2(1060, 100), null, Color.White, 0, Vector2.Zero, 1.0f, SpriteEffects.None, 1.0f); 
            } 
 
 
 
            //Method to Draw Tiles 
            DrawTiles(spriteBatch); 
 
            letterA.Draw(gameTime, spriteBatch); 
            //letterA.Draw( 
            letterB.Draw(gameTime, spriteBatch); 
            letterC.Draw(gameTime, spriteBatch); 
            letterD.Draw(gameTime, spriteBatch); 
            letterE.Draw(gameTime, spriteBatch); 
            letterT.Draw(gameTime, spriteBatch); 
 
 
            spriteBatch.Draw(checkScoreB, new Vector2(80, 600), null, Color.White, 0, Vector2.Zero, 1.0f, SpriteEffects.None, 1.0f); 
 
            if (ScoreButtonPressed) 
            { 
               // if (drawDiffScoreBTN) 
               // { 
                    spriteBatch.Draw(checkScoreW, new Vector2(80, 600), null, Color.White, 0, Vector2.Zero, 1.0f, 
                                     SpriteEffects.None, 1.0f); 
               // } 
            } 
 
 
 
            Vector2 hudLocation2 = new Vector2(180, 190); 
 
 
 
            //score ahs to be a string 
            string printStringP1; 
            string printStringP2; 
 
            printStringP1 = "Player 1: " + player1Score.ToString(); 
            printStringP2 = "Player 2: " + player2Score.ToString(); 
 
            spriteBatch.DrawString(hudFont, printStringP1, new Vector2(10.0f, 10.0f), 
                               Color.Black, 0, Vector2.Zero, 1, SpriteEffects.None, 0); 
 
            spriteBatch.DrawString(hudFont, printStringP2, new Vector2(10.0f, 40.0f), 
                                   Color.Black, 0, Vector2.Zero, 1, SpriteEffects.None, 0); 
 
 
 
            spriteBatch.End(); 
 
 
            mouse.Draw(spriteBatch); 
 
 
 
            if (paused) 
            { 
                pause.Draw(gameTime, spriteBatch, this); 
 
            } 
 
 
        }//End of if 
 
        /// <summary> 
        /// Method for Scroll Screen - Camera 
        /// </summary> 
        /// <param name="viewport"></param> 
        public void ScrollCamera(Viewport viewport) 
        { 
            //Float for margin 
            const float ViewMargin = 0.35f; 
 
            // Calculate the edges of the screen. 
            float marginWidth = viewport.Width * ViewMargin; 
            float marginLeft = cameraPosition + marginWidth; 
            float marginRight = cameraPosition + viewport.Width - marginWidth; 
 
            // Calculate the edges of the screen. 
            float marginHeight = viewport.Height * ViewMargin; 
 
 
            // Update the camera position, but prevent scrolling off the ends of the level. 
            float maxCameraPositionX = Tile.Width * Width - viewport.Width; 
            float maxCameraPositionY = Tile.Height * Height - viewport.Height; 
 
 
        }//End of Scroll Camera 
 
 
        /// <summary> 
        /// Draws each tile in the level. 
        /// </summary> 
        public void DrawTiles(SpriteBatch spriteBatch) 
        { 
            // Calculate the visible range of tiles. 
            int left = (int)Math.Floor(cameraPosition / Tile.Width); 
            int right = left + spriteBatch.GraphicsDevice.Viewport.Width / Tile.Width; 
            right = Math.Min(right, Width - 1); 
 
            // Calculate the visible range of tiles. 
            int top = (int)Math.Floor(cameraPositionY / Tile.Height); 
            int bottom = top + spriteBatch.GraphicsDevice.Viewport.Height / Tile.Height; 
            bottom = Math.Min(bottom, Height); 
 
            // For each tile position 
            for (int y = top; y <= bottom; ++y) 
            { 
                for (int x = left; x <= right; ++x) 
                { 
                    // If there is a visible tile in that position 
                    Texture2D texture = tiles[x, y].Texture; 
                    if (texture != null) 
                    { 
                        // Draw it in screen space. 
                        Vector2 position = new Vector2(x, y) * Tile.Size; 
                        spriteBatch.Draw(texture, position, Color.White); 
 
                    }//End of if 
 
                }//End of for 
 
            }//End of for 
 
        }//End of DrawTiles 
        #endregion 
    }//End of Level class 
 
}//End

推荐答案

xnaLearner,

After looking through what you passed in, its a whole lot of code and its hard to get a full picture of what is going on. I recommend placing a breakpoint in the countScore() and see who is calling it. I think that its getting called a lot more than you expected.

If that isn''t the issue, my next place to look would be the
xnaLearner,

After looking through what you passed in, its a whole lot of code and its hard to get a full picture of what is going on. I recommend placing a breakpoint in the countScore() and see who is calling it. I think that its getting called a lot more than you expected.

If that isn''t the issue, my next place to look would be the
private int addScore(ClickableLetter letter) 
{ 
    //inside board, otherwise return 0 points 
    if (letter.x >= 300 && letter.x <= 1050) 
    { 


addScore section. I''m wondering if the letter you are passing is the actual letter in the user''s tray, or one that they already scored. Maybe you are not removing them from the user''s collection correctly.

祝你好运!

霍根

EDIT HERE

xnaLearner,

Based on your first comment and the Solution 2, I think I see the issue now. When you click on countScore() you have the following code:


addScore section. I''m wondering if the letter you are passing is the actual letter in the user''s tray, or one that they already scored. Maybe you are not removing them from the user''s collection correctly.

Good luck!

Hogan

EDIT HERE

xnaLearner,

Based on your first comment and the Solution 2, I think I see the issue now. When you click on countScore() you have the following code:

//scoreThisTurn += addScore(clickableObjects[i]);                       
scoreThisTurn += 1;//just for testing 



You have the scoreThisTurn line commented out. That method is the one that does the validation to see if the pieces should be scored because they are on the board. So you should probably use that one and not the second line.

Addressing the score going up by 7 every time, currently, you are in a 7 iteration loop adding 1 to the overall score. Each time you click on score, you''re running the loop again and adding 7 to the previous score.

So you need to use the addScore() method and then remove the tiles that are used and get new ones. This should prevent the duplication of scores. I think you''re closer than you realize on this!!!

Good luck again!

Hogan



You have the scoreThisTurn line commented out. That method is the one that does the validation to see if the pieces should be scored because they are on the board. So you should probably use that one and not the second line.

Addressing the score going up by 7 every time, currently, you are in a 7 iteration loop adding 1 to the overall score. Each time you click on score, you''re running the loop again and adding 7 to the previous score.

So you need to use the addScore() method and then remove the tiles that are used and get new ones. This should prevent the duplication of scores. I think you''re closer than you realize on this!!!

Good luck again!

Hogan


Just an observation but countScore loops (internally) 7 times. Your scores are being multiplied by 7. Hmm: think there might be a connection? You are examining each tile and agregating the scores: is that what you meant to do? I would look more but I have my own code to stumble through and the only thing worse than looking at your own code, is to look at someone else''s. :-)
Just an observation but countScore loops (internally) 7 times. Your scores are being multiplied by 7. Hmm: think there might be a connection? You are examining each tile and agregating the scores: is that what you meant to do? I would look more but I have my own code to stumble through and the only thing worse than looking at your own code, is to look at someone else''s. :-)


这篇关于得分疯狂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆