Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


C# Conditionals and reference help please

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Sat Nov 14, 2009 1:25 am    Post subject: C# Conditionals and reference help please Reply with quote

it was working not a long time ago but I'm not sure what I changed and now every time I go to
BASE.posX == 1 & PASE.posZ == 1
it crashes with a NullReference exception

Code:

spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.BackToFront, SaveStateMode.SaveState);

            Ray cursorRay = CalculateCursorRay(cameraProjectionMatrix, cameraViewMatrix);

            if (RayIntersectsModel(cursorRay, BaseTop))
            {

                Matrix world = Matrix.CreateFromYawPitchRoll(
                    BaseTop.rotation.Y,
                    BaseTop.rotation.X,
                    BaseTop.rotation.Z) *
                    Matrix.CreateScale(BaseTop.scale) *
                    Matrix.CreateTranslation(BaseTop.position);

                Vector2 textPosition =
                    new Vector2(cursorstate.X, cursorstate.Y - 60);


                Vector2 stringCenter =
                    font.MeasureString("test") / 2;


                Vector2 shadowOffset = new Vector2(3, 2);

                spriteBatch.DrawString(font, "Test",
                    textPosition + shadowOffset, Color.Black, 0.0f,
                    stringCenter, 1.0f, SpriteEffects.None, 1.0f);


                spriteBatch.DrawString(font, "Test",
                    textPosition, Color.White, 0.0f,
                    stringCenter, 1.0f, SpriteEffects.None, 0.0f);
                LoadBoard();

                if (BASE.posZ == 1)
                {
                    if (BASE.posX == 1)
                    {
                        CellSpace[BASE.posX, BASE.posZ + 1].position = Cell[BASE.posX,
                        BASE.posZ + 1].position + new Vector3(0.0f, 0.1f, 0.0f);
                        CellSpace[BASE.posX + 1, BASE.posZ].position = Cell[BASE.posX + 1,
                        BASE.posZ].position + new Vector3(0.0f, 0.1f, 0.0f);

                    }
                    if (BASE.posX == 10)
                    {
                        CellSpace[BASE.posX, BASE.posZ + 1].position = Cell[BASE.posX,
                        BASE.posZ + 1].position + new Vector3(0.0f, 0.1f, 0.0f);
                        CellSpace[BASE.posX - 1, BASE.posZ].position = Cell[BASE.posX - 1,
                        BASE.posZ].position + new Vector3(0.0f, 0.1f, 0.0f);
                        CellSpace[BASE.posX - 1, BASE.posZ + 1].position = Cell[BASE.posX - 1,
                        BASE.posZ + 1].position + new Vector3(0.0f, 0.1f, 0.0f);
                    }
                    if (BASE.posX >=2 & BASE.posX <= 9)  {
                        CellSpace[BASE.posX - 1, BASE.posZ + 1].position = Cell[BASE.posX - 1,
                        BASE.posZ + 1].position + new Vector3(0.0f, 0.1f, 0.0f);
                        CellSpace[BASE.posX - 1, BASE.posZ].position = Cell[BASE.posX - 1,
                        BASE.posZ].position + new Vector3(0.0f, 0.1f, 0.0f);
                        CellSpace[BASE.posX, BASE.posZ + 1].position = Cell[BASE.posX,
                        BASE.posZ + 1].position + new Vector3(0.0f, 0.1f   , 0.0f);
                        CellSpace[BASE.posX + 1, BASE.posZ].position = Cell[BASE.posX + 1,
                        BASE.posZ].position + new Vector3(0.0f, 0.1f, 0.0f);

                    }
                }
             
            }
           
            if (click == true)
            {
                if (BASE.posZ == 1)
                {
                    if (BASE.posX == 1)
                    {
                        //C
                        if (RayIntersectsModel(cursorRay, CellSpace[BASE.posX, BASE.posZ + 1]))
                        {
                            resetcells();
                            click = false;
                            BaseBottom.position = Cell[BASE.posX, BASE.posZ + 1].position + new Vector3(0.0f, 1.0f, 0.0f);
                            BaseTop.position = Cell[BASE.posX, BASE.posZ + 1].position + new Vector3(0.0f, 1.0f, 0.0f);
                            BASE.posZ = BASE.posZ + 1;

                        }
                        //D
                        if (RayIntersectsModel(cursorRay, CellSpace[BASE.posX + 1, BASE.posZ]))
                        {
                            resetcells();
                            click = false;
                            BaseBottom.position = Cell[BASE.posX + 1, BASE.posZ].position + new Vector3(0.0f, 1.0f, 0.0f);
                            BaseTop.position = Cell[BASE.posX + 1, BASE.posZ].position + new Vector3(0.0f, 1.0f, 0.0f);
                            BASE.posX = BASE.posX + 1;

                        }
                        else
                        {
                            click = false;
                        }

                    }
                    if (BASE.posX == 10)
                    {
                        //A
                        if (RayIntersectsModel(cursorRay, CellSpace[BASE.posX - 1, BASE.posZ]))
                        {
                            resetcells();
                            click = false;
                            BaseBottom.position = Cell[BASE.posX - 1, BASE.posZ].position + new Vector3(0.0f, 1.0f, 0.0f);
                            BaseTop.position = Cell[BASE.posX - 1, BASE.posZ].position + new Vector3(0.0f, 1.0f, 0.0f);
                            BASE.posX = BASE.posX - 1;

                        }
                        //B
                        if (RayIntersectsModel(cursorRay, CellSpace[BASE.posX - 1, BASE.posZ + 1]))
                        {
                            resetcells();
                            click = false;
                            BaseBottom.position = Cell[BASE.posX - 1, BASE.posZ + 1].position + new Vector3(0.0f, 1.0f, 0.0f);
                            BaseTop.position = Cell[BASE.posX - 1, BASE.posZ + 1].position + new Vector3(0.0f, 1.0f, 0.0f);
                            BASE.posX = BASE.posX - 1;
                            BASE.posZ = BASE.posZ + 1;
                        }
                        //C
                        if (RayIntersectsModel(cursorRay, CellSpace[BASE.posX, BASE.posZ + 1]))
                        {
                            resetcells();
                            click = false;
                            BaseBottom.position = Cell[BASE.posX, BASE.posZ + 1].position + new Vector3(0.0f, 1.0f, 0.0f);
                            BaseTop.position = Cell[BASE.posX, BASE.posZ + 1].position + new Vector3(0.0f, 1.0f, 0.0f);
                            BASE.posZ = BASE.posZ + 1;

                        }
                        else
                        {
                            click = false;
                        }
                    }
                    if (BASE.posX >= 2 & BASE.posX <= 9)
                    {
                        //A
                        if (RayIntersectsModel(cursorRay, CellSpace[BASE.posX - 1, BASE.posZ]))
                        {
                            resetcells();
                            click = false;
                            BaseBottom.position = Cell[BASE.posX - 1, BASE.posZ].position + new Vector3(0.0f, 1.0f, 0.0f);
                            BaseTop.position = Cell[BASE.posX - 1, BASE.posZ].position + new Vector3(0.0f, 1.0f, 0.0f);
                            BASE.posX = BASE.posX - 1;

                        }
                        //B
                        if (RayIntersectsModel(cursorRay, CellSpace[BASE.posX - 1, BASE.posZ + 1]))
                        {
                            resetcells();
                            click = false;
                            BaseBottom.position = Cell[BASE.posX - 1, BASE.posZ + 1].position + new Vector3(0.0f, 1.0f, 0.0f);
                            BaseTop.position = Cell[BASE.posX - 1, BASE.posZ + 1].position + new Vector3(0.0f, 1.0f, 0.0f);
                            BASE.posX = BASE.posX - 1;
                            BASE.posZ = BASE.posZ + 1;
                        }
                        //C
                        if (RayIntersectsModel(cursorRay, CellSpace[BASE.posX, BASE.posZ + 1]))
                        {
                            resetcells();
                            click = false;
                            BaseBottom.position = Cell[BASE.posX, BASE.posZ + 1].position + new Vector3(0.0f, 1.0f, 0.0f);
                            BaseTop.position = Cell[BASE.posX, BASE.posZ + 1].position + new Vector3(0.0f, 1.0f, 0.0f);
                            BASE.posZ = BASE.posZ + 1;

                        }
                        //D
                        if (RayIntersectsModel(cursorRay, CellSpace[BASE.posX + 1, BASE.posZ]))
                        {
                            resetcells();
                            click = false;
                            BaseBottom.position = Cell[BASE.posX + 1, BASE.posZ].position + new Vector3(0.0f, 1.0f, 0.0f);
                            BaseTop.position = Cell[BASE.posX + 1, BASE.posZ].position + new Vector3(0.0f, 1.0f, 0.0f);
                            BASE.posX = BASE.posX + 1;

                        }
                        else
                        {
                            click = false;
                        }

                       }


                }

            }
               
            spriteBatch.End();
Back to top
View user's profile Send private message MSN Messenger
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sat Nov 14, 2009 1:33 am    Post subject: Reply with quote

oh my god

hint: step through with the debugger.
because you honestly wish anyone is reading through your messes
Back to top
View user's profile Send private message
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Sat Nov 14, 2009 1:38 am    Post subject: Reply with quote

Code:
System.NullReferenceException was unhandled
  Message="Object reference not set to an instance of an object."
  Source="WoWminis"
  StackTrace:
       at WoWminis.Game1.RayIntersectsModel(Ray ray, GameObject gameobject) in C:\Users\Gonzalo Diaz\Documents\Visual Studio 2008\Projects\WoWminis\WoWminis\WoWminis\Game1.cs:line 344
       at WoWminis.Game1.DrawModelNames() in C:\Users\Gonzalo Diaz\Documents\Visual Studio 2008\Projects\WoWminis\WoWminis\WoWminis\Game1.cs:line 556
       at WoWminis.Game1.Draw(GameTime gameTime) in C:\Users\Gonzalo Diaz\Documents\Visual Studio 2008\Projects\WoWminis\WoWminis\WoWminis\Game1.cs:line 303
       at Microsoft.Xna.Framework.Game.DrawFrame()
       at Microsoft.Xna.Framework.Game.Tick()
       at Microsoft.Xna.Framework.Game.HostIdle(Object sender, EventArgs e)
       at Microsoft.Xna.Framework.GameHost.OnIdle()
       at Microsoft.Xna.Framework.WindowsGameHost.ApplicationIdle(Object sender, EventArgs e)
       at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FDoIdle(Int32 grfidlef)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at Microsoft.Xna.Framework.WindowsGameHost.Run()
       at Microsoft.Xna.Framework.Game.Run()
       at WoWminis.Program.Main(String[] args) in C:\Users\Gonzalo Diaz\Documents\Visual Studio 2008\Projects\WoWminis\WoWminis\WoWminis\Program.cs:line 14
  InnerException:


thats all the info it is giving me and its not really helpful xP

and it says that the error is at the ray intersect function which is not because why would there be a problem only when I go to BASE.posX == 1 & BASE.posZ == 1, I can move through all the other cells

this is my function

Code:

private static bool RayIntersectsModel(Ray ray, GameObject gameobject)
        {

            foreach (ModelMesh mesh in gameobject.model.Meshes)
            {

                Matrix world = Matrix.CreateFromYawPitchRoll(
                        gameobject.rotation.Y,
                        gameobject.rotation.X,
                        gameobject.rotation.Z) *
                        Matrix.CreateScale(gameobject.scale) *
                        Matrix.CreateTranslation(gameobject.position);
                   

                BoundingSphere sphere =
                    TransformBoundingSphere(mesh.BoundingSphere, world);

                if (sphere.Intersects(ray) != null)
                {
                    return true;
                }
            }

            return false;
        }
Back to top
View user's profile Send private message MSN Messenger
Fendaril
Cheater
Reputation: 0

Joined: 08 Nov 2009
Posts: 27

PostPosted: Sat Nov 14, 2009 7:10 am    Post subject: Reply with quote

h ttp://it.toolbox.co m/blogs/paytonbyrd/java-c-vb-prevent-null-pointer-and-null-reference-exceptions-12174

without h and c spaced.
Back to top
View user's profile Send private message
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Sat Nov 14, 2009 8:37 am    Post subject: Reply with quote

Thanks Fendaril but I tried that and cant seem to make it work...

here is the whole code if anyone is willing to help
game.cs
[code]
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace WoWminis
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
public MouseState cursorstate;

GameObject terrain = new GameObject();
GameObject BaseTop = new GameObject();
GameObject BaseBottom = new GameObject();

Vector3 cameraPosition = new Vector3(0.0f, 130.0f, 50.0f);
Vector3 cameraLookAt = new Vector3(0.0f, 0.0f, 7.5f);
Matrix cameraProjectionMatrix;
Matrix cameraViewMatrix;

KeyboardState oldState;

SpriteFont font;
double posX;
double posZ;
Vector2 debugDrawpointX = new Vector2(0.01f, 0.01f);
Vector2 debugDrawpointZ = new Vector2(0.01f, 0.05f);
Rectangle viewportRect;

BoardCells[,] Cell = new BoardCells[11, 12];

sprite2D cursor;


GameObject[,] CellSpace = new GameObject[11, 12];

Ubase BASE = new Ubase();

bool click = false;
bool pressed = false;









public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
this.graphics.PreferredBackBufferWidth = 1280;
this.graphics.PreferredBackBufferHeight = 720;

//this.graphics.IsFullScreen = true;

}

/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here

base.Initialize();
}

/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);



terrain.model = Content.Load<Model>("Models\\Map");
terrain.rotation = new Vector3(-1 * MathHelper.ToRadians(90.0f), 0.0f, -1 * MathHelper.ToRadians(90.0f));
BaseTop.model = Content.Load<Model>("Models\\BaseTop");
BaseTop.rotation = new Vector3(-1 * MathHelper.ToRadians(90.0f), 0.0f, -1 * MathHelper.ToRadians(0.0f));
BaseTop.scale = 0.15f;
BaseBottom.model = Content.Load<Model>("Models\\BaseBottom");
BaseBottom.rotation = new Vector3(-1 * MathHelper.ToRadians(90.0f), 0.0f, -1 * MathHelper.ToRadians(90.0f));
BaseBottom.scale = 0.15f;

BaseTop.position = new Vector3(0.0f, 1.0f, 0.0f);
BaseBottom.position = new Vector3(0.0f, 1.0f, 0.0f);



font = Content.Load<SpriteFont>("Fonts\\GameFont");
viewportRect = new Rectangle(0, 0,
graphics.GraphicsDevice.Viewport.Width,
graphics.GraphicsDevice.Viewport.Height);
LoadBoard();

BaseTop.position = Cell[1, 1].position + new Vector3(0.0f, 1.0f, 0.0f);
BaseBottom.position = Cell[1, 1].position + new Vector3(0.0f, 1.0f, 0.0f);
BASE.posX = 1;
BASE.posZ = 1;
BASE.name = "Test";
BASE.turn = 1;

cursor = new sprite2D(Content.Load<Texture2D>("Sprites\\Cursor"));
cursor.position = Vector2.Zero;

//test
for (int i = 1; i < 11; i++)
{
for (int x = 1; x < 12; x++)
{
CellSpace[i, x] = new GameObject();
CellSpace[i, x].model = Content.Load<Model>("Models\\CellSpace");
CellSpace[i, x].rotation = new Vector3(-1 * MathHelper.ToRadians(90.0f), 0.0f, -1 * MathHelper.ToRadians(90.0f));
CellSpace[i, x].position = Cell[i, x].position - new Vector3(0.0f, 1.0f, 0.0f);
CellSpace[i, x].scale = 0.4f;
}
}







// TODO: use this.Content to load your game content here
}

/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}

/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();

// TODO: Add your update logic here
//cursor
mouseload();
cursorstate = Mouse.GetState();
cursor.position.X = cursorstate.X;
cursor.position.Y = cursorstate.Y;
//camera

cameraViewMatrix = Matrix.CreateLookAt(
cameraPosition,
cameraLookAt,
Vector3.Up);

cameraProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(45.0f),
graphics.GraphicsDevice.Viewport.AspectRatio,
1.0f,
10000.0f);

// Debug
posX = Math.Round(BaseTop.position.X, 3);
posZ = Math.Round(BaseTop.position.Z, 3);


//keys

KeyboardState keyboardState = Keyboard.GetState();

if (keyboardState.IsKeyUp(Keys.C))
{
cameraPosition = new Vector3(0.0f, 130.0f, 50.0f);
cameraLookAt = new Vector3(0.0f, 0.0f, 7.5f);

}
if (keyboardState.IsKeyDown(Keys.C))
{
cameraPosition = new Vector3(0.0f, 10.0f, BaseTop.position.Z + 20f);
cameraLookAt = BaseTop.position;

}

if (keyboardState.IsKeyDown(Keys.Escape))
{
this.Exit();

}

UpdateInput();

base.Update(gameTime);
}

private void UpdateInput()
{
KeyboardState newState = Keyboard.GetState();

// Is the SPACE key down?
if (newState.IsKeyDown(Keys.Space))
{
// If not down last update, key has just been pressed.
if (!oldState.IsKeyDown(Keys.Space))
{
BaseBottom.rotation.Z += MathHelper.ToRadians(36.0f);
}
}

/*else if (oldState.IsKeyDown(Keys.Space))
{
// Key was down last update, but not down now, so
// it has just been released.
}*/

// Update saved state.
oldState = newState;
}


/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);

DrawGameObject(terrain);
DrawGameObject(BaseTop);
DrawGameObject(BaseBottom);

for (int i = 1; i < 11; i++)
{
for (int x = 1; x < 12; x++)
{
DrawGameObject(CellSpace[i, x]);

}
}



spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.BackToFront, SaveStateMode.SaveState);
spriteBatch.DrawString(font, " PositionX: " + BASE.posX.ToString(),
new Vector2(
debugDrawpointX.X * viewportRect.Width,
debugDrawpointX.Y * viewportRect.Height),
Color.Yellow);
spriteBatch.DrawString(font, " PositionZ: " + BASE.posZ.ToString(),
new Vector2(
debugDrawpointZ.X * viewportRect.Width,
debugDrawpointZ.Y * viewportRect.Height),
Color.Yellow);
spriteBatch.DrawString(font, " Debug: " + Cell[1, 1].position.X.ToString(),
new Vector2(
debugDrawpointZ.X * viewportRect.Width,
(debugDrawpointZ.Y + 0.1f) * viewportRect.Height),
Color.Yellow);
spriteBatch.Draw(cursor.sprite,
cursor.position,
null,
Color.White,
cursor.rotation,
cursor.center, 1.0f,
SpriteEffects.None, 0
);

spriteBatch.End();
// TODO: Add your drawing code here
DrawModelNames();


base.Draw(gameTime);
}



void DrawGameObject(GameObject gameobject)
{
foreach (ModelMesh mesh in gameobject.model.Meshes)
{


foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.PreferPerPixelLighting = true;
effect.FogEnabled = false;


effect.World = Matrix.CreateFromYawPitchRoll(
gameobject.rotation.Y,
gameobject.rotation.X,
gameobject.rotation.Z) *
Matrix.CreateScale(gameobject.scale) *
Matrix.CreateTranslation(gameobject.position);

effect.Projection = cameraProjectionMatrix;
effect.View = cameraViewMatrix;
}
mesh.Draw();



}
}

private static bool RayIntersectsModel(Ray ray, GameObject gameobject)
{

foreach (ModelMesh mesh in gameobject.model.Meshes)
{

Matrix world = Matrix.CreateFromYawPitchRoll(
gameobject.rotation.Y,
gameobject.rotation.X,
gameobject.rotation.Z) *
Matrix.CreateScale(gameobject.scale) *
Matrix.CreateTranslation(gameobject.position);


BoundingSphere sphere =
TransformBoundingSphere(mesh.BoundingSphere, world);

if (sphere.Intersects(ray) != null)
{
return true;
}
}

return false;
}

private static BoundingSphere TransformBoundingSphere(BoundingSphere sphere,
Matrix transform)
{
BoundingSphere transformedSphere;

Vector3 scale3 = new Vector3(sphere.Radius, sphere.Radius, sphere.Radius);

scale3 = Vector3.TransformNormal(scale3, transform);

transformedSphere.Radius = Math.Max(scale3.X, Math.Max(scale3.Y, scale3.Z));

transformedSphere.Center = Vector3.Transform(sphere.Center, transform);


return transformedSphere;
}

public Ray CalculateCursorRay(Matrix projectionMatrix, Matrix viewMatrix)
{

Vector3 nearSource = new Vector3(cursorstate.X, cursorstate.Y, 0f);
Vector3 farSource = new Vector3(cursorstate.X, cursorstate.Y, 1f);

Vector3 nearPoint = GraphicsDevice.Viewport.Unproject(nearSource,
projectionMatrix, viewMatrix, Matrix.Identity);

Vector3 farPoint = GraphicsDevice.Viewport.Unproject(farSource,
projectionMatrix, viewMatrix, Matrix.Identity);

Vector3 direction = farPoint - nearPoint;
direction.Normalize();


return new Ray(nearPoint, direction);
}

private void DrawModelNames()
{

spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.BackToFront, SaveStateMode.SaveState);

Ray cursorRay = CalculateCursorRay(cameraProjectionMatrix, cameraViewMatrix);

if (RayIntersectsModel(cursorRay, BaseTop))
{

Matrix world = Matrix.CreateFromYawPitchRoll(
BaseTop.rotation.Y,
BaseTop.rotation.X,
BaseTop.rotation.Z) *
Matrix.CreateScale(BaseTop.scale) *
Matrix.CreateTranslation(BaseTop.position);

Vector2 textPosition =
new Vector2(cursorstate.X, cursorstate.Y - 60);


Vector2 stringCenter =
font.MeasureString("test") / 2;


Vector2 shadowOffset = new Vector2(3, 2);

spriteBatch.DrawString(font, "Test",
textPosition + shadowOffset, Color.Black, 0.0f,
stringCenter, 1.0f, SpriteEffects.None, 1.0f);


spriteBatch.DrawString(font, "Test",
textPosition, Color.White, 0.0f,
stringCenter, 1.0f, SpriteEffects.None, 0.0f);


if (BASE.posZ == 1)
{
if (BASE.posX == 1 & BASE.posZ == 1)
{
resetcells();
CellSpace[BASE.posX, BASE.posZ + 1].position = Cell[BASE.posX,
BASE.posZ + 1].position + new Vector3(0.0f, 0.1f, 0.0f);
CellSpace[BASE.posX + 1, BASE.posZ].position = Cell[BASE.posX + 1,
BASE.posZ].position + new Vector3(0.0f, 0.1f, 0.0f);

}
if (BASE.posX == 10)
{
resetcells();
CellSpace[BASE.posX, BASE.posZ + 1].position = Cell[BASE.posX,
BASE.posZ + 1].position + new Vector3(0.0f, 0.1f, 0.0f);
CellSpace[BASE.posX - 1, BASE.posZ].position = Cell[BASE.posX - 1,
BASE.posZ].position + new Vector3(0.0f, 0.1f, 0.0f);
CellSpace[BASE.posX - 1, BASE.posZ + 1].position = Cell[BASE.posX - 1,
BASE.posZ + 1].position + new Vector3(0.0f, 0.1f, 0.0f);
}
if (BASE.posX >= 2 & BASE.posX <= 9)
{
resetcells();
CellSpace[BASE.posX - 1, BASE.posZ + 1].position = Cell[BASE.posX - 1,
BASE.posZ + 1].position + new Vector3(0.0f, 0.1f, 0.0f);
CellSpace[BASE.posX - 1, BASE.posZ].position = Cell[BASE.posX - 1,
BASE.posZ].position + new Vector3(0.0f, 0.1f, 0.0f);
CellSpace[BASE.posX, BASE.posZ + 1].position = Cell[BASE.posX,
BASE.posZ + 1].position + new Vector3(0.0f, 0.1f, 0.0f);
CellSpace[BASE.posX + 1, BASE.posZ].position = Cell[BASE.posX + 1,
BASE.posZ].position + new Vector3(0.0f, 0.1f, 0.0f);

}
}
else
{
//
}

}

if (click == true)
{
if (BASE.posZ == 1)
{
if (BASE.posX == 1)
{
//C
if (RayIntersectsModel(cursorRay, CellSpace[BASE.posX, BASE.posZ + 1]))
{
resetcells();
click = false;
BaseBottom.position = Cell[BASE.posX, BASE.posZ + 1].position + new Vector3(0.0f, 1.0f, 0.0f);
BaseTop.position = Cell[BASE.posX, BASE.posZ + 1].position + new Vector3(0.0f, 1.0f, 0.0f);
BASE.posZ = BASE.posZ + 1;

}
//D
if (RayIntersectsModel(cursorRay, CellSpace[BASE.posX + 1, BASE.posZ]))
{
resetcells();
click = false;
BaseBottom.position = Cell[BASE.posX + 1, BASE.posZ].position + new Vector3(0.0f, 1.0f, 0.0f);
BaseTop.position = Cell[BASE.posX + 1, BASE.posZ].position + new Vector3(0.0f, 1.0f, 0.0f);
BASE.posX = BASE.posX + 1;

}
else
{
click = false;
}

}
if (BASE.posX == 10)
{
//A
if (RayIntersectsModel(cursorRay, CellSpace[BASE.posX - 1, BASE.posZ]))
{
resetcells();
click = false;
BaseBottom.position = Cell[BASE.posX - 1, BASE.posZ].position + new Vector3(0.0f, 1.0f, 0.0f);
BaseTop.position = Cell[BASE.posX - 1, BASE.posZ].position + new Vector3(0.0f, 1.0f, 0.0f);
BASE.posX = BASE.posX - 1;

}
//B
if (RayIntersectsModel(cursorRay, CellSpace[BASE.posX - 1, BASE.posZ + 1]))
{
resetcells();
click = false;
BaseBottom.position = Cell[BASE.posX - 1, BASE.posZ + 1].position + new Vector3(0.0f, 1.0f, 0.0f);
BaseTop.position = Cell[BASE.posX - 1, BASE.posZ + 1].position + new Vector3(0.0f, 1.0f, 0.0f);
BASE.posX = BASE.posX - 1;
BASE.posZ = BASE.posZ + 1;
}
//C
if (RayIntersectsModel(cursorRay, CellSpace[BASE.posX, BASE.posZ + 1]))
{
resetcells();
click = false;
BaseBottom.position = Cell[BASE.posX, BASE.posZ + 1].position + new Vector3(0.0f, 1.0f, 0.0f);
BaseTop.position = Cell[BASE.posX, BASE.posZ + 1].position + new Vector3(0.0f, 1.0f, 0.0f);
BASE.posZ = BASE.posZ + 1;

}
else
{
click = false;
}
}
if (BASE.posX >= 2 & BASE.posX <= 9)
{
//A
if (RayIntersectsModel(cursorRay, CellSpace[BASE.posX - 1, BASE.posZ]))
{
resetcells();
click = false;
BaseBottom.position = Cell[BASE.posX - 1, BASE.posZ].position + new Vector3(0.0f, 1.0f, 0.0f);
BaseTop.position = Cell[BASE.posX - 1, BASE.posZ].position + new Vector3(0.0f, 1.0f, 0.0f);
BASE.posX = BASE.posX - 1;

}
//B
if (RayIntersectsModel(cursorRay, CellSpace[BASE.posX - 1, BASE.posZ + 1]))
{
resetcells();
click = false;
BaseBottom.position = Cell[BASE.posX - 1, BASE.posZ + 1].position + new Vector3(0.0f, 1.0f, 0.0f);
BaseTop.position = Cell[BASE.posX - 1, BASE.posZ + 1].position + new Vector3(0.0f, 1.0f, 0.0f);
BASE.posX = BASE.posX - 1;
BASE.posZ = BASE.posZ + 1;
}
//C
if (RayIntersectsModel(cursorRay, CellSpace[BASE.posX, BASE.posZ + 1]))
{
resetcells();
click = false;
BaseBottom.position = Cell[BASE.posX, BASE.posZ + 1].position + new Vector3(0.0f, 1.0f, 0.0f);
BaseTop.position = Cell[BASE.posX, BASE.posZ + 1].position + new Vector3(0.0f, 1.0f, 0.0f);
BASE.posZ = BASE.posZ + 1;

}
//D
if (RayIntersectsModel(cursorRay, CellSpace[BASE.posX + 1, BASE.posZ]))
{
resetcells();
click = false;
BaseBottom.position = Cell[BASE.posX + 1, BASE.posZ].position + new Vector3(0.0f, 1.0f, 0.0f);
BaseTop.position = Cell[BASE.posX + 1, BASE.posZ].position + new Vector3(0.0f, 1.0f, 0.0f);
BASE.posX = BASE.posX + 1;

}
else
{
click = false;
}

}


}

}

spriteBatch.End();
}

void mouseload()
{
if (cursorstate.LeftButton == ButtonState.Pressed)
pressed = true;

if (cursorstate.LeftButton == ButtonState.Released && pressed)
{
click = true;
pressed = false;
}
}

void resetcells()
{
for (int i = 1; i < 11; i++)
{
for (int x = 1; x < 12; x++)
{
if (CellSpace[i, x] == null)
{
CellSpace[i, x] = new GameObject();
CellSpace[i, x].model = Content.Load<Model>("Models\\CellSpace");
CellSpace[i, x].rotation = new Vector3(-1 * MathHelper.ToRadians(90.0f), 0.0f, -1 * MathHelper.ToRadians(90.0f));
CellSpace[i, x].position = Cell[i, x].position - new Vector3(0.0f, 1.0f, 0.0f);
CellSpace[i, x].scale = 0.4f;

}
CellSpace[i, x].position = Cell[i, x].position - new Vector3(0.0f, 1.0f, 0.0f);

}
}
}
void LoadBoard()
{
//Board positions
Cell[1, 1] = new BoardCells();
Cell[1, 2] = new BoardCells();
Cell[1, 3] = new BoardCells();
Cell[1, 4] = new BoardCells();
Cell[1, 5] = new BoardCells();
Cell[1, 6] = new BoardCells();
Cell[1, 7] = new BoardCells();
Cell[1, 8] = new BoardCells();
Cell[1, 9] = new BoardCells();
Cell[1, 10] = new BoardCells();
Cell[1, 11] = new BoardCells();
Cell[2, 1] = new BoardCells();
Cell[2, 2] = new BoardCells();
Cell[2, 3] = new BoardCells();
Cell[2, 4] = new BoardCells();
Cell[2, 5] = new BoardCells();
Cell[2, 6] = new BoardCells();
Cell[2, 7] = new BoardCells();
Cell[2, 8] = new BoardCells();
Cell[2, 9] = new BoardCells();
Cell[2, 10] = new BoardCells();
Cell[2, 11] = new BoardCells();
Cell[3, 1] = new BoardCells();
Cell[3, 2] = new BoardCells();
Cell[3, 3] = new BoardCells();
Cell[3, 4] = new BoardCells();
Cell[3, 5] = new BoardCells();
Cell[3, 6] = new BoardCells();
Cell[3, 7] = new BoardCells();
Cell[3, 8] = new BoardCells();
Cell[3, 9] = new BoardCells();
Cell[3, 10] = new BoardCells();
Cell[3, 11] = new BoardCells();
Cell[4, 1] = new BoardCells();
Cell[4, 2] = new BoardCells();
Cell[4, 3] = new BoardCells();
Cell[4, 4] = new BoardCells();
Cell[4, 5] = new BoardCells();
Cell[4, 6] = new BoardCells();
Cell[4, 7] = new BoardCells();
Cell[4, 8] = new BoardCells();
Cell[4, 9] = new BoardCells();
Cell[4, 10] = new BoardCells();
Cell[4, 11] = new BoardCells();
Cell[5, 1] = new BoardCells();
Cell[5, 2] = new BoardCells();
Cell[5, 3] = new BoardCells();
Cell[5, 4] = new BoardCells();
Cell[5, 5] = new BoardCells();
Cell[5, 6] = new BoardCells();
Cell[5, 7] = new BoardCells();
Cell[5, 8] = new BoardCells();
Cell[5, 9] = new BoardCells();
Cell[5, 10] = new BoardCells();
Cell[5, 11] = new BoardCells();
Cell[6, 1] = new BoardCells();
Cell[6, 2] = new BoardCells();
Cell[6, 3] = new BoardCells();
Cell[6, 4] = new BoardCells();
Cell[6, 5] = new BoardCells();
Cell[6, 6] = new BoardCells();
Cell[6, 7] = new BoardCells();
Cell[6, 8] = new BoardCells();
Cell[6, 9] = new BoardCells();
Cell[6, 10] = new BoardCells();
Cell[6, 11] = new BoardCells();
Cell[7, 1] = new BoardCells();
Cell[7, 2] = new BoardCells();
Cell[7, 3] = new BoardCells();
Cell[7, 4] = new BoardCells();
Cell[7, 5] = new BoardCells();
Cell[7, 6] = new BoardCells();
Cell[7, 7] = new BoardCells();
Cell[7, 8] = new BoardCells();
Cell[7, 9] = new BoardCells();
Cell[7, 10] = new BoardCells();
Cell[7, 11] = new BoardCells();
Cell[8, 1] = new BoardCells();
Cell[8, 2] = new BoardCells();
Cell[8, 3] = new BoardCells();
Cell[8, 4] = new BoardCells();
Cell[8, 5] = new BoardCells();
Cell[8, 6] = new BoardCells();
Cell[8, 7] = new BoardCells();
Cell[8, 8] = new BoardCells();
Cell[8, 9] = new BoardCells();
Cell[8, 10] = new BoardCells();
Cell[8, 11] = new BoardCells();
Cell[9, 1] = new BoardCells();
Cell[9, 2] = new BoardCells();
Cell[9, 3] = new BoardCells();
Cell[9, 4] = new BoardCells();
Cell[9, 5] = new BoardCells();
Cell[9, 6] = new BoardCells();
Cell[9, 7] = new BoardCells();
Cell[9, 8] = new BoardCells();
Cell[9, 9] = new BoardCells();
Cell[9, 10] = new BoardCells();
Cell[9, 11] = new BoardCells();
Cell[10, 1] = new BoardCells();
Cell[10, 2] = new BoardCells();
Cell[10, 3] = new BoardCells();
Cell[10, 4] = new BoardCells();
Cell[10, 5] = new BoardCells();
Cell[10, 6] = new BoardCells();
Cell[10, 7] = new BoardCells();
Cell[10, 8] = new BoardCells();
Cell[10, 9] = new BoardCells();
Cell[10, 10] = new BoardCells();
Cell[10, 11] = new BoardCells();


Cell[1, 1].position = new Vector3(-42.5f, 0.1f, 50.3f);
Cell[1, 2].position = new Vector3(-36.75f, 0.1f, 40.3f);
Cell[1, 3].position = new Vector3(-42.5f, 0.1f, 30.3f);
Cell[1, 4].position = new Vector3(-36.75f, 0.1f, 20.3f);
Cell[1, 5].position = new Vector3(-42.5f, 0.1f, 10.3f);
Cell[1, 6].position = new Vector3(-36.75f, 0.1f, 0.3f);
Cell[1, 7].position = new Vector3(-42.5f, 0.1f, -10.3f);
Cell[1, 8].position = new Vector3(-36.75f, 0.1f, -20.3f);
Cell[1, 9].position = new Vector3(-42.5f, 0.1f, -30.3f);
Cell[1, 10].position = new Vector3(-36.75f, 0.1f, -40.3f);
Cell[1, 11].position = new Vector3(-42.5f, 0.1f, -50.3f);
Cell[2, 1].position = new Vector3(-31f, 0.1f, 50.3f);
Cell[2, 2].position = new Vector3(-25.25f, 0.1f, 40.3f);
Cell[2, 3].position = new Vector3(-31f, 0.1f, 30.3f);
Cell[2, 4].position = new Vector3(-25.25f, 0.1f, 20.3f);
Cell[2, 5].position = new Vector3(-31f, 0.1f, 10.3f);
Cell[2, 6].position = new Vector3(-25.25f, 0.1f, 0.3f);
Cell[2, 7].position = new Vector3(-31f, 0.1f, -10.3f);
Cell[2, 8].position = new Vector3(-25.25f, 0.1f, -20.3f);
Cell[2, 9].position = new Vector3(-31f, 0.1f, -30.3f);
Cell[2, 10].position = new Vector3(-25.25f, 0.1f, -40.3f);
Cell[2, 11].position = new Vector3(-31f, 0.1f, -50.3f);
Cell[3, 1].position = new Vector3(-19.5f, 0.1f, 50.3f);
Cell[3, 2].position = new Vector3(-13.5f, 0.1f, 40.3f);
Cell[3, 3].position = new Vector3(-19.5f, 0.1f, 30.3f);
Cell[3, 4].position = new Vector3(-13.5f, 0.1f, 20.3f);
Cell[3, 5].position = new Vector3(-19.5f, 0.1f, 10.3f);
Cell[3, 6].position = new Vector3(-13.5f, 0.1f, 0.3f);
Cell[3, 7].position = new Vector3(-19.5f, 0.1f, -10.3f);
Cell[3, 8].position = new Vector3(-13.5f, 0.1f, -20.3f);
Cell[3, 9].position = new Vector3(-19.5f, 0.1f, -30.3f);
Cell[3, 10].position = new Vector3(-13.5f, 0.1f, -40.3f);
Cell[3, 11].position = new Vector3(-19.5f, 0.1f, -50.3f);
Cell[4, 1].position = new Vector3(-7.5f, 0.1f, 50.3f);
Cell[4, 2].position = new Vector3(-1.75f, 0.1f, 40.3f);
Cell[4, 3].position = new Vector3(-7.5f, 0.1f, 30.3f);
Cell[4, 4].position = new Vector3(-1.75f, 0.1f, 20.3f);
Cell[4, 5].position = new Vector3(-7.5f, 0.1f, 10.3f);
Cell[4, 6].position = new Vector3(-1.75f, 0.1f, 0.3f);
Cell[4, 7].position = new Vector3(-7.5f, 0.1f, -10.3f);
Cell[4, 8].position = new Vector3(-1.75f, 0.1f, -20.3f);
Cell[4, 9].position = new Vector3(-7.5f, 0.1f, -30.3f);
Cell[4, 10].position = new Vector3(-1.75f, 0.1f, -40.3f);
Cell[4, 11].position = new Vector3(-7.5f, 0.1f, -50.3f);
Cell[5, 1].position = new Vector3(4f, 0.1f, 50.3f);
Cell[5, 2].position = new Vector3(10f, 0.1f, 40.3f);
Cell[5, 3].position = new Vector3(4f, 0.1f, 30.3f);
Cell[5, 4].position = new Vector3(10f, 0.1f, 20.3f);
Cell[5, 5].position = new Vector3(4f, 0.1f, 10.3f);
Cell[5, 6].position = new Vector3(10f, 0.1f, 0.3f);
Cell[5, 7].position = new Vector3(4f, 0.1f, -10.3f);
Cell[5, 8].position = new Vector3(10f, 0.1f, -20.3f);
Cell[5, 9].position = new Vector3(4f, 0.1f, -30.3f);
Cell[5, 10].position = new Vector3(10f, 0.1f, -40.3f);
Cell[5, 11].position = new Vector3(4f, 0.1f, -50.3f);
Cell[6, 1].position = new Vector3(15.75f, 0.1f, 50.3f);
Cell[6, 2].position = new Vector3(21.75f, 0.1f, 40.3f);
Cell[6, 3].position = new Vector3(15.75f, 0.1f, 30.3f);
Cell[6, 4].position = new Vector3(21.75f, 0.1f, 20.3f);
Cell[6, 5].position = new Vector3(15.75f, 0.1f, 10.3f);
Cell[6, 6].position = new Vector3(21.75f, 0.1f, 0.3f);
Cell[6, 7].position = new Vector3(15.75f, 0.1f, -10.3f);
Cell[6, 8].position = new Vector3(21.75f, 0.1f, -20.3f);
Cell[6, 9].position = new Vector3(15.75f, 0.1f, -30.3f);
Cell[6, 10].position = new Vector3(21.75f, 0.1f, -40.3f);
Cell[6, 11].position = new Vector3(15.75f, 0.1f, -50.3f);
Cell[7, 1].position = new Vector3(27.5f, 0.1f, 50.3f);
Cell[7, 2].position = new Vector3(33.5f, 0.1f, 40.3f);
Cell[7, 3].position = new Vector3(27.5f, 0.1f, 30.3f);
Cell[7, 4].position = new Vector3(33.5f, 0.1f, 20.3f);
Cell[7, 5].position = new Vector3(27.5f, 0.1f, 10.3f);
Cell[7, 6].position = new Vector3(33.5f, 0.1f, 0.3f);
Cell[7, 7].position = new Vector3(27.5f, 0.1f, -10.3f);
Cell[7, 8].position = new Vector3(33.5f, 0.1f, -20.3f);
Cell[7, 9].position = new Vector3(27.5f, 0.1f, -30.3f);
Cell[7, 10].position = new Vector3(33.5f, 0.1f, -40.3f);
Cell[7, 11].position = new Vector3(27.5f, 0.1f, -50.3f);
Cell[8, 1].position = new Vector3(39.25f, 0.1f, 50.3f);
Cell[8, 2].position = new Vector3(45f, 0.1f, 40.3f);
Cell[8, 3].position = new Vector3(39.25f, 0.1f, 30.3f);
Cell[8, 4].position = new Vector3(45f, 0.1f, 20.3f);
Cell[8, 5].position = new Vector3(39.25f, 0.1f, 10.3f);
Cell[8, 6].position = new Vector3(45f, 0.1f, 0.3f);
Cell[8, 7].position = new Vector3(39.25f, 0.1f, -10.3f);
Cell[8, 8].position = new Vector3(45f, 0.1f, -20.3f);
Cell[8, 9].position = new Vector3(39.25f, 0.1f, -30.3f);
Cell[8, 10].position = new Vector3(45f, 0.1f, -40.3f);
Cell[8, 11].position = new Vector3(39.25f, 0.1f, -50.3f);
Cell[9, 1].position = new Vector3(51f, 0.1f, 50.3f);
Cell[9, 2].position = new Vector3(56.75f, 0.1f, 40.3f);
Cell[9, 3].position = new Vector3(51f, 0.1f, 30.3f);
Cell[9, 4].position = new Vector3(56.75f, 0.1f, 20.3f);
Cell[9, 5].position = new Vector3(51f, 0.1f, 10.3f);
Cell[9, 6].position = new Vector3(56.75f, 0.1f, 0.3f);
Cell[9, 7].position = new Vector3(51f, 0.1f, -10.3f);
Cell[9, 8].position = new Vector3(56.75f, 0.1f, -20.3f);
Cell[9, 9].position = new Vector3(51f, 0.1f, -30.3f);
Cell[9, 10].position = new Vector3(56.75f, 0.1f, -40.3f);
Cell[9, 11].position = new Vector3(51f, 0.1f, -50.3f);
Cell[10, 1].position = new Vector3(62.6f, 0.1f, 50.3f);
Cell[10, 2].position = new Vector3(68.5f, 0.1f, 40.3f);
Cell[10, 3].position = new Vector3(62.6f, 0.1f, 30.3f);
Cell[10, 4].position = new Vector3(68.5f, 0.1f, 20.3f);
Cell[10, 5].position = new Vector3(62.6f, 0.1f, 10.3f);
Cell[10, 6].position = new Vector3(68.5f, 0.1f, 0.3f);
Cell[10, 7].position = new Vector3(62.6f, 0.1f, -10.3f);
Cell[10, 8].position = new Vector3(68.5f, 0.1f, -20.3f);
Cell[10, 9].position = new Vector3(62.6f, 0.1f, -30.3f);
Cell[10, 10].position = new Vector3(68.5f, 0.1f, -40.3f);
Cell[10, 11].position = new Vector3(62.6f, 0.1f, -50.3f);
//Board Mountains
Cell[1, 1].isMountain = false;
Cell[1, 2].isMountain = false;
Cell[1, 3].isMountain = false;
Cell[1, 4].isMountain = false;
Cell[1, 5].isMountain = false;
Cell[1, 6].isMountain = false;
Cell[1, 7].isMountain = false;
Cell[1, 8].isMountain = false;
Cell[1, 9].isMountain = false;
Cell[1, 10].isMountain = false;
Cell[1, 11].isMountain = false;
Cell[2, 1].isMountain = false;
Cell[2, 2].isMountain = false;
Cell[2, 3].isMountain = false;
Cell[2, 4].isMountain = false;
Cell[2, 5].isMountain = false;
Cell[2, 6].isMountain = false;
Cell[2, 7].isMountain = false;
Cell[2, 8].isMountain = false;
Cell[2, 9].isMountain = false;
Cell[2, 10].isMountain = false;
Cell[2, 11].isMountain = false;
Cell[3, 1].isMountain = false;
Cell[3, 2].isMountain = false;
Cell[3, 3].isMountain = false;
Cell[3, 4].isMountain = false;
Cell[3, 5].isMountain = false;
Cell[3, 6].isMountain = false;
Cell[3, 7].isMountain = false;
Cell[3, 8].isMountain = false;
Cell[3, 9].isMountain = false;
Cell[3, 10].isMountain = false;
Cell[3, 11].isMountain = false;
Cell[4, 1].isMountain = false;
Cell[4, 2].isMountain = false;
Cell[4, 3].isMountain = false;
Cell[4, 4].isMountain = false;
Cell[4, 5].isMountain = false;
Cell[4, 6].isMountain = false;
Cell[4, 7].isMountain = false;
Cell[4, 8].isMountain = false;
Cell[4, 9].isMountain = false;
Cell[4, 10].isMountain = false;
Cell[4, 11].isMountain = false;
Cell[5, 1].isMountain = false;
Cell[5, 2].isMountain = false;
Cell[5, 3].isMountain = false;
Cell[5, 4].isMountain = false;
Cell[5, 5].isMountain = false;
Cell[5, 6].isMountain = false;
Cell[5, 7].isMountain = false;
Cell[5, 8].isMountain = false;
Cell[5, 9].isMountain = false;
Cell[5, 10].isMountain = false;
Cell[5, 11].isMountain = false;
Cell[6, 1].isMountain = false;
Cell[6, 2].isMountain = false;
Cell[6, 3].isMountain = false;
Cell[6, 4].isMountain = false;
Cell[6, 5].isMountain = false;
Cell[6, 6].isMountain = false;
Cell[6, 7].isMountain = false;
Cell[6, 8].isMountain = false;
Cell[6, 9].isMountain = false;
Cell[6, 10].isMountain = false;
Cell[6, 11].isMountain = false;
Cell[7, 1].isMountain = false;
Cell[7, 2].isMountain = false;
Cell[7, 3].isMountain = false;
Cell[7, 4].isMountain = false;
Cell[7, 5].isMountain = false;
Cell[7, 6].isMountain = false;
Cell[7, 7].isMountain = false;
Cell[7, 8].isMountain = false;
Cell[7, 9].isMountain = false;
Cell[7, 10].isMountain = false;
Cell[7, 11].isMountain = false;
Cell[8, 1].isMountain = false;
Cell[8, 2].isMountain = false;
Cell[8, 3].isMountain = false;
Cell[8, 4].isMountain = false;
Cell[8, 5].isMountain = false;
Cell[8, 6].isMountain = false;
Cell[8, 7].isMountain = false;
Cell[8, 8].isMountain = false;
Cell[8, 9].isMountain = false;
Cell[8, 10].isMountain = false;
Cell[8, 11].isMountain = false;
Cell[9, 1].isMountain = false;
Cell[9, 2].isMountain = false;
Cell[9, 3].isMountain = false;
Cell[9, 4].isMountain = false;
Cell[9, 5].isMountain = false;
Cell[9, 6].isMountain = false;
Cell[9, 7].isMountain = false;
Cell[9, 8].isMountain = false;
Cell[9, 9].isMountain = false;
Cell[9, 10].isMountain = false;
Cell[9, 11].isMountain = false;
Cell[10, 1].isMountain = false;
Cell[10, 2].isMountain = false;
Cell[10, 3].isMountain = false;
Cell[10, 4].isMountain = false;
Cell[10, 5].isMountain = false;
Cell[10, 6].isMountain = false;
Cell[10, 7].isMountain = false;
Cell[10, 8].isMountain = false;
Cell[10, 9].isMountain = false;
Cell[10, 10].isMountain = false;
Cell[10, 11].isMountain = false;
//Board Forest
Cell[1, 1].isForest = false;
Cell[1, 2].isForest = false;
Cell[1, 3].isForest = false;
Cell[1, 4].isForest = false;
Cell[1, 5].isForest = false;
Cell[1, 6].isForest = false;
Cell[1, 7].isForest = false;
Cell[1, 8].isForest = false;
Cell[1, 9].isForest = false;
Cell[1, 10].isForest = false;
Cell[1, 11].isForest = false;
Cell[2, 1].isForest = false;
Cell[2, 2].isForest = false;
Cell[2, 3].isForest = false;
Cell[2, 4].isForest = false;
Cell[2, 5].isForest = false;
Cell[2, 6].isForest = false;
Cell[2, 7].isForest = false;
Cell[2, 8].isForest = false;
Cell[2, 9].isForest = false;
Cell[2, 10].isForest = false;
Cell[2, 11].isForest = false;
Cell[3, 1].isForest = false;
Cell[3, 2].isForest = false;
Cell[3, 3].isForest = false;
Cell[3, 4].isForest = false;
Cell[3, 5].isForest = false;
Cell[3, 6].isForest = false;
Cell[3, 7].isForest = false;
Cell[3, 8].isForest = false;
Cell[3, 9].isForest = false;
Cell[3, 10].isForest = false;
Cell[3, 11].isForest = false;
Cell[4, 1].isForest = false;
Cell[4, 2].isForest = false;
Cell[4, 3].isForest = false;
Cell[4, 4].isForest = false;
Cell[4, 5].isForest = false;
Cell[4, 6].isForest = false;
Cell[4, 7].isForest = false;
Cell[4, 8].isForest = false;
Cell[4, 9].isForest = false;
Cell[4, 10].isForest = false;
Cell[4, 11].isForest = false;
Cell[5, 1].isForest = false;
Cell[5, 2].isForest = false;
Cell[5, 3].isForest = false;
Cell[5, 4].isForest = false;
Cell[5, 5].isForest = false;
Cell[5, 6].isForest = false;
Cell[5, 7].isForest = false;
Cell[5, 8].isForest = false;
Cell[5, 9].isForest = false;
Cell[5, 10].isForest = false;
Cell[5, 11].isForest = false;
Cell[6, 1].isForest = false;
Cell[6, 2].isForest = false;
Cell[6, 3].isForest = false;
Cell[6, 4].isForest = false;
Cell[6, 5].isForest = false;
Cell[6, 6].isForest = false;
Cell[6, 7].isForest = false;
Cell[6, 8].isForest = false;
Cell[6, 9].isForest = false;
Cell[6, 10].isForest = false;
Cell[6, 11].isForest = false;
Cell[7, 1].isForest = false;
Cell[7, 2].isForest = false;
Cell[7, 3].isForest = false;
Cell[7, 4].isForest = false;
Cell[7, 5].isForest = false;
Cell[7, 6].isForest = false;
Cell[7, 7].isForest = false;
Cell[7, 8].isForest = false;
Cell[7, 9].isForest = false;
Cell[7, 10].isForest = false;
Cell[7, 11].isForest = false;
Cell[8, 1].isForest = false;
Cell[8, 2].isForest = false;
Cell[8, 3].isForest = false;
Cell[8, 4].isForest = false;
Cell[8, 5].isForest = false;
Cell[8, 6].isForest = false;
Cell[8, 7].isForest = false;
Cell[8, 8].isForest = false;
Cell[8, 9].isForest = false;
Cell[8, 10].isForest = false;
Cell[8, 11].isForest = false;
Cell[9, 1].isForest = false;
Cell[9, 2].isForest = false;
Cell[9, 3].isForest = false;
Cell[9, 4].isForest = false;
Cell[9, 5].isForest = false;
Cell[9, 6].isForest = false;
Cell[9, 7].isForest = false;
Cell[9, 8].isForest = false;
Cell[9, 9].isForest = false;
Cell[9, 10].isForest = false;
Cell[9, 11].isForest = false;
Cell[10, 1].isForest = false;
Cell[10, 2].isForest = false;
Cell[10, 3].isForest = false;
Cell[10, 4].isForest = false;
Cell[10, 5].isForest = false;
Cell[10, 6].isForest = false;
Cell[10, 7].isForest = false;
Cell[10, 8].isForest = false;
Cell[10, 9].isForest = false;
Cell[10, 10].isForest = false;
Cell[10, 11].isForest = false;

for (int i = 1; i < 11; i++)
{
for (int x = 1; x < 12; x++)
{
Cell[i, x].posX = i;
Cell[i, x].posZ = x;
}
}



}
}
}

[\code]

GameObject.cs
[code]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace WoWminis
{
class GameObject
{
public Model model = null;
public Vector3 position = Vector3.Zero;
public Vector3 rotation = Vector3.Zero;
public float scale = 1.0f;
}
}
[/code]
BoardCells.cs
[code]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace WoWminis
{
class BoardCells
{
public bool isMountain = false;
public bool isForest = false;
public Vector3 position = Vector3.Zero;
public int posX;
public int posZ;


}
}
[/code]
Ubase.cs
[code]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace WoWminis
{
class Ubase
{
public int posX;
public int posZ;
public string name;
public int turn;
}
}
[/code]
[code]
not working?[/code]
Back to top
View user's profile Send private message MSN Messenger
Odecey
Master Cheater
Reputation: 1

Joined: 19 Apr 2007
Posts: 259
Location: Scandinavia

PostPosted: Sat Nov 14, 2009 1:50 pm    Post subject: Reply with quote

From what I can see, the variables contained within BASE are first assigned in LoadContent. Are you sure that LoadContent is called before any logic is used on the variables? In any case I think it would be a good idea to assign these variables when the Ubase instance is initialized, like this :
Code:

class Ubase
{
private int _x;
private int _z;
private string _name;
private int _turn;
public Ubase ()
{
_posX = 0;
_posZ = 0;
_name = "";
_turn = 0;
}
public Ubase (int x, int z, string name)
{
_x = x;
_x = z;
_name = name;
_turn = 0;
}
public int X {get{return _x;}set{_x = value;}}
public int Z {get{return _z;}set{_z = value;}}
public string Name{get{return _name;}set{_name = value;}}
public int Turn {get{return _turn;}set{_turn = value;}}
}

That way you're sure that if BASE is initialized, so are all its members.

_________________
Never confuse activity with productivity. You can be busy without a purpose, but what's the point?- Rick Warren
Back to top
View user's profile Send private message MSN Messenger
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Sat Nov 14, 2009 2:13 pm    Post subject: Reply with quote

thanks, I havent implemented it yet because I quite dont understand it sorry

_ stands for an expression? if so could you please explain how it works for me please?
Back to top
View user's profile Send private message MSN Messenger
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sat Nov 14, 2009 3:22 pm    Post subject: Reply with quote

Oh merciful Christ. Pick up an object oriented design book, and learn to use a fucking pastebin.
Back to top
View user's profile Send private message
Fendaril
Cheater
Reputation: 0

Joined: 08 Nov 2009
Posts: 27

PostPosted: Sat Nov 14, 2009 3:26 pm    Post subject: Reply with quote

How about being nice. We need less people like you clogging up legit topics.
Back to top
View user's profile Send private message
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Sat Nov 14, 2009 4:18 pm    Post subject: Reply with quote

the base was initialized correctly but still I'm getting that odd error ..
x_x

this is what is going on
Link


solved.

I didn;t notice the array was being initialized at [0,0] and started initializing it at [1,1] not I changed it to initialize it from [0,0] and no more RefNull
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites