Hi there!

I've tested your code and come up with the following:

  1. You might want to check your random values. According to Oracles documentation, Math.random() does the following:
    Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0.
    Less than 1.0 means that your maximum values will be less than 4. And by converting your double to int using (int) you simply cut all decimals, thus your maximum value will be 3. This means that you will only read at most 4 lines (0-3). A suggestion is to use:

    Random rnd = new Random(); // Do this once, generates a unique seed
    int myVal = rnd.nextInt(5); // Generates an integer [0, 4]
  2. I think what's actually causing your problem is that you increase c before checking if it's bigger or equal to check_phrase.

Regards,
Emil Olofsson

Hi there!

I need to see more code than this to be able to help you. To solve this problem I would use an array of coordinates like this:
[ (5, 5) (4, 5) (3, 5) (3, 6) ]
for example.

Then, when I move up for example, I take the first coordinate (5, 5) and decrease y by 1 and push it first in the queue so I get this:
[ (5, 4) (5, 5) (4, 5) (3, 5) (3, 6) ]

I then pop the last coordinate (3, 6) from the queue leaving this:
[ (5, 4) (5, 5) (4, 5) (3, 5) ].

This is your new snake.

Also, a proper game loop using old standards can look something like this:

1. While Not EndCondition = True do:
    2. If KeyPressed do:
        3. (char) c <= GetKey
        4. Handle movement
    5. End if
    6. Calculate stuff
    7. Draw stuff
    8. Sleep some
9. End while

I used this structure quite alot when I took my Pascal courses back in highschool. You should be able to find a similar way to implement this in your C++ code.

I hope this helps!

Regards,
Emil Olofsson

PeTo. commented: thank you so much i'm trying to that right now :) +0

You could add a member called name of type char*to your queue class. Then you could change the constructor to request a string that will be the name of your list:

public class queue
{
    public:
    queue();
    ~queue();
    bool Empty() const;
    void Enqueue(message^);
    void Dequeue();
    void DisplayAll() const;
    private:
    gcroot<String^> bindingkey;
    queue(queue const& obj);
    ListNode* head;
    ListNode* tail;
    char* name; // Added this
};

queue::queue(char* _name):head(nullptr), tail(nullptr), name(_name) {}

You can of course change it to some other string type if you would like that better. I hope it works!

SAM2012 commented: thanks +1

Hello! I don't really understand your question. Do you want to programatically get the name of the pointer that points to a certain queue object? I think that could be rather tricky. What are you gonna use this for? I'm sure there's another way to solve your problem.

Regards,
Emil Olofsson

You could convert the number into a string, then creating substrings of every two characters, and then parse them back to int and add them together?

Another approach would be using modulus, adding the rests of your value x mod 100, 10000 (then split by 100) and so on.

Good luck to you!
Emil Olofsson

Hi!

Math.Sin and Math.Cos takes angles measured in radians and not degrees. Try this:

double angleRadians = (Math.PI / 180.0) * angle;

Then use angleRadians instead.

Regards,
Emil Olofsson

Sahil89 commented: Quickly solved! +2

First of all, I'm not familiar to that particular book you mention, so I don't really know what you mean by T0 and T1. I can tell you however thet the code you wrote down indeed is a fetch cycle. Your program counter tells you on which line in your assembler program (or whatever you call your higher level language) you are. So first of all, you want to fetch that line from memory to your IR in order to decode and execute it. When that's done, and your micro code is finished, you want to restart your fetch cycle, but with the next line in your assembler memory. Right?

Also, you only want to increment your PC once. The logical to do this is in the second line (T1). This is because you are already reading/writing from your PC during the first line. If you would increment the PC simultaneously as you are reading from it, you never know wether you get PC or PC+1, right? So in order to avoid problems, it's better to increment it after you've read from it.

I hope I managed to answer your question. If not, please specify your question a little more.

Good luck to you!
Emil Olofsson

Hello there! May I ask what the meaning of these lines is?
[CODE]
if (userNumber < smallNumber){
smallNumber = userNumber;

                if (userNumber > largeNumber)
                largeNumber = userNumber;

            }

[/CODE]

It seems you are only looking for a larger number if the user number is the smallest number? I would like to suggest using [ICODE]else if[/ICODE] instead when looking for the largest number (Alternatively simply removing the brackets around your if-statement). It can't be both smaller and larger (unless you enter 0, but that case sorta handles itself already)

I hope this helps!
Emil Olofsson

Edit: Ah I see you beat me to it :)

What you really want to do is to copy the contents of the array:

[CODE=C++]
mydatastructure::mydatastructure(const mydatastructure& copystructure)
{
_numberData = new int [1000]; //Create a new array on the heap
for (int i = 0; i < 1000; i++)
_numberData[i] = copystructure._numberData[i];
}
[/CODE]

Good luck!
Emil Olofsson

AltF4me commented: Perfect answer. Just what I was looking for. +0

First, let's assume the center of your screen has the coordinate (0, 0) for simplicity. Then, you would always want to draw whatever object you are following at the coordinate (0, 0), placing it in the middle of the screen. Then you would want to draw everything else at their respective positions relative to the position of the object you are following.

I usually solve this by creating a camera class, keeping track of where the camera is pointed. Assume you have a grid of height 100 and width 100, and some objects are scattered around its surface. If, let's say, your camera points at (47, 93) you would like to centre that particular point of your grid to (0, 0) (in order for it to appear at the centre of your screen).

Before continuing, let's visualize this with some pseudo:
[code]
camera.Xpos -> 47
camera.Ypos -> 93
[/code]
The camera also happens to look at a car, that is positioned exactly at those coordinates:
[code]
car.Xpos -> 47
car.Ypos -> 93
[/code]

The camera is just an abstract object, and you will never draw it to the screen. The car however, will be drawn, and since your camera is looking directly at it, you will want to draw it at the centre of the screen. How do you do this? Well, let all your visual objects inherit a visualRepresentation class, which contains a method draw, which takes the camera as a parameter ([ICODE]draw(const Camera & camera)[/ICODE]). The draw method ...

Ouch my eyes hurt just by looking at your code. Please indent it and repost! Well, by going through your code once, I managed to extract some things that might be causing your problems.

You are trying to use a do .. while ... loop to make your program loop. This means that it will loop for as long as the condition after while equals true. Assuming all your brackets are in the right places and all, what your do-while statement says is
[CODE=Java]
do {
// Lots of stuff here
} while (bankroll <= 0);
[/CODE]
Take a look at that. You tell your program to repeat for as long as your bankroll has less than zero credits in it. That's not what you want, is it?

Cheers
Emil Olofsson

[CODE=C++]#define 'X' 'Y'[/CODE]

This is a pre compiler command, that tells the compiler to interpret all 'X' as 'Y'. This is a good way to define constants used in your program, and it really makes your code easier to understand.

Return points out what the return value of your function is.

In your case I strongly recommend looking for a beginners tutorial/book on C++. There is plenty of easy-to-understand literature online about trivial programming aspects such as how to use functions, operations, and how to plan and construct simple programs. Try google!

Emil Olofsson

It seems to me you assume the user already knows the answers to all those values?

Some relations you might want to define are:

[CODE=C++]

define PAINT_PER_SQFT (1/500)

define HOURS_PER_SQFT (8/500)

int myCeil(double d)
{
return (int) d + 0.99;
}

int myRound(double d)
{
return (int) d + 0.5;
}

int paintRequired(int area)
{
return myCeil(PAINT_PER_SQFT * area);
}

int hoursRequired(int area)
{
return myRound(HOURS_PER_SQFT * area);
}
[/CODE]

And so on.. You should get the hang of it.

I hope this helps!
Emil Olofsson

Well, I think it depends on what your intentions are. I personally have been playing around a little with some free game engines. Its fun, and they save you a lot of work, that's true. But I think the choice is up to one's personal taste. I get the feeling of cheating when using somebody elses engine, and you often encounter restrictions, especially if it's not an open source engine.

My recommendation to you is that you follow a book or tutorial and learn how to create your own engine first. You will learn a lot, and you will get a hang of what to expect out of other engines.

As for literature on the subject, I suggest you pick a language and graphics library, and then stick to it for a while. Use google and you will surely find a thorough tutorial covering everything you wish to know.

I've been using an OpenGL Library for Java called Jogl for quite a while now. [URL="

[QUOTE=jwenting;1148130]Sounds like what you really want is a single linked list.
That's fast for insert and iteration, slow for delete.[/QUOTE]

Well, why not a double-linked list then? Requires just a little more memory, but that shouldn't be a problem in the long run. This way deletion is just as fast as insertion.

As for the main question of this thread, I have the same problems. Although I don't have a solid answer to your question, my reasoning goes like this;

  • If all your moving objects fit into the screen at all times, storing everything in a vector and iterating over the entire vector is a good solution, since you still have to look at every object in order to find out where to draw them

  • If objects leave the screen you don't want to draw them, and therefore you want to skip iterating over them to save time. My theoretical solution to this is to store the objects in a search tree structure, where the keys are which X- and Y-block of the level the object is in. Now, based on the coordinates of your camera, you should be able to find the sub-tree containing the blocks that are currently visible on the screen, and iterate over the elements there. Whenever an object leaves a block, you have to reinsert it into the tree.

I haven't tried this out yet, but with large quantities of objects scattered over a large area, like a space-flying game, this method may ...