SgtMe 46 Veteran Poster Featured Poster

These won't fix your issue, but they will clean up your code a bit.

In main.cpp:
-Change lines 8-10 to:

float mypointx, mypointy, Answer;

-After line 22 add:

system("pause");

In XYPoint.h:
-Change lines 13-17 to:

float mypointx, mypointy, pointpx, pointpy, mydistance;

In XYPoint.cpp:
-Remove lines 6-10 (Variables already zero. For one run, you won't need to set them. Keep though if looping program).

-------------------------------

Not sure why you are getting the answer in scientific notation.
When you are testing your program, make the (actual) distance between points "0", as to say that both sets of coordinates are the same. If it does not turn out zero, something is wrong.

When that is working, you will need to test the logic of your program with a 3-4-5 triangle. From your fixed point (eg [0, 0]), you will go out 3 on the x, and up 4 on the y, giving you [3, 4]. The hypotenuse (the distance) of which will be "5".
http://www.tpub.com/math1/20f.htm

Hope this helps :) (If so, then please upvote!)

SgtMe 46 Veteran Poster Featured Poster

Sorry double post by accident.

SgtMe 46 Veteran Poster Featured Poster
SgtMe 46 Veteran Poster Featured Poster

Eeeeek...sounds nasty. I think education globally is going to waste. I keep hearing on this site of people who are stuck on homework, not because they can't do it, but because they have a poor tutor, or the tutor is too vague or whatever. The fact that there are lots of functions doesn't really help.

My brain is trying to figure out a way of doing it without classes. For movement, I would suggest that you in your 10x10 grid, you have blank spaces as '0' and ships as 's'. Then, when you come to print, you would find all the ships in the array, get their direction, and print, say, [^] [>] [v] [<] to show the direction.

With regards to armour and range and the like, I would have an array called, eg., ArmourStats of length 'n=ships'. Therefore, ArmourStats[0] would be the value of the armour of ship one, ArmourStats[1] of ship two and so forth. Repeat for the other mass-variable storage mabobs.

You could reduce the amount of functions quite easily. Have ONE function for move, which takes a variable of where the ship you want to move is, and where to. Then you can just recycle this. Obviously, repeat with the other functions. The more of this you do, the more your tutor will/should be impressed.

Good luck again :)

SgtMe 46 Veteran Poster Featured Poster

So classes are banned? Awwwww shucks...if it wasn't banned you could sure learn that easily...
I guess you'll just have to use lots of functions and variables then. Go through the logic of your program, get a piece of paper, and work out what variables and functions you need. Organize the basic structure, then start to code in the finer details.

Tell your tutor that they should have taught you classes before getting you to make a game.

SgtMe 46 Veteran Poster Featured Poster

Have a look at classes. Make a class for your frigate/each type of ship. Then it should have functions such as one for movement, firing etc. You'll need to be careful about what variables you need and passing them backwards and forwards between your main program and the classes.
http://www.cplusplus.com/doc/tutorial/classes/

The movement idea of your program should be considerable maths-based (ie. calculating whether a move is legal, how far should they move etc.). It appears that the logic is not too difficult, but there is a lot of it.

Good luck :)

SgtMe 46 Veteran Poster Featured Poster
SgtMe 46 Veteran Poster Featured Poster

Ah apologies. My fault :)

SgtMe 46 Veteran Poster Featured Poster

Please could you post what the exercise is so that we have a better idea of what's going on. Thanks :)

SgtMe 46 Veteran Poster Featured Poster

OK. I still can't figure out how to get your code working :/ I'll keep looking around though.

SgtMe 46 Veteran Poster Featured Poster

I don't think 5 lines is much effort. Sorry.

SgtMe 46 Veteran Poster Featured Poster

Firstly, I am getting this error when I run into the top of the screen. It crashes the program.

Traceback (most recent call last):
  File "C:\Users\Mark\Downloads\game\Game.py", line 34, in <module>
    GameMain()
  File "C:\Users\Mark\Downloads\game\Game.py", line 30, in GameMain
    player.Move()
  File "C:\Users\Mark\Downloads\game\Handlers.py", line 95, in Move
    gfx.BlitBackground(self.X, self.Y) #Blit background again
  File "C:\Users\Mark\Downloads\game\Handlers.py", line 13, in BlitBackground
    self.surf = pygame.surface.Surface((X, Y))
error: Invalid resolution for Surface

Still looking through...

SgtMe 46 Veteran Poster Featured Poster

OK. Just keep us updated :)

SgtMe 46 Veteran Poster Featured Poster

Well let's see your attempt and we will help you out with it.

SgtMe 46 Veteran Poster Featured Poster

It's YOUR exam. Not ours. If you show some effort, we can help you, BUT, we won't write it for you.

SgtMe 46 Veteran Poster Featured Poster

http://www.koders.com/c/fidAFD244F63A431E188774EE14C972A5B3FD8F433D.aspx?s=ftp
That has a download link.
Looking through the code...
You may need this as well (features.h)
http://www.koders.com/c/fid4B72990CAFE31EDE806801FF5F38AEBC9B04D1AA.aspx?s=ftp
Have a look and see what you think :)

SgtMe 46 Veteran Poster Featured Poster

What's your current problem?
You could upload your game files in a zip and I could have a look and try to get it working.

WildBamaBoy commented: Very nice to offer +1
SgtMe 46 Veteran Poster Featured Poster

Problem solved yet?

SgtMe 46 Veteran Poster Featured Poster

Make sure the header is in your include directory of the compiler/IDE. If you don't have the file, don't use it.

SgtMe 46 Veteran Poster Featured Poster

OK, so you need your background image to be replaced in the dirty areas that have been updated? If you made a new pygame surface and blitted the background image onto it, you could use that. BUT, you must make sure that when you blit it, you blit the background image with negative x and y coordinates, so that it lines up properly with where you want it to go.

eg.

- Updated rectangle (5, 5, 10, 10)
- Make new 5*5 surface (surf)
- Blit background to surf (-5, -5)
- Blit surf to screen, BEFORE blitting the character.

SgtMe 46 Veteran Poster Featured Poster

What do you mean when you take out drawing the rectangles? Of course if you don't draw them a trail will be left.

SgtMe 46 Veteran Poster Featured Poster
SgtMe 46 Veteran Poster Featured Poster

No, it's not just the sprite. The dirty rectangle should be around the sprite, AND around the area the sprite was last in. If you only update the character, the rest of the screen won't be updated, hence you will get this trail.

SgtMe 46 Veteran Poster Featured Poster

You could use a seperate IDE. Dev-C++ (though no longer in development) makes it easy to install libraries. You literally choose what you want from a list and it will download and install it.

SgtMe 46 Veteran Poster Featured Poster

C++
Allegro (easy): Keep using it until you are confident to move on.
OpenGL (intermediate): Can be used for 2D. Don't get frustrated and stick with it.
Direct2D (hard): Specially built 2D library, but DirectX is hard to code.

Python
PyGame (easy): Same as allegro really.
PyOpenGL (intermediate): Use it for 2D first, then 3D. Needs to be used through PyGame.

As for sharing it on the internet, why don't you upload it to sourceforge when you are done? Then people can join you if you want an extra pair of hands, report bugs easily and it's just generally great for project hosting.

SgtMe 46 Veteran Poster Featured Poster

Sweet sprites! It looks fine on my computer. I'm guessing it would be to do with the time it takes to redraw the scene? Have a look into dirty-rectangles and dirty-sprites. These only update the parts of the screen or the sprites that need updating, without redrawing the whole scene.

Dirty Rectangles:
http://www.pygame.org/docs/ref/display.html#pygame.display.flip (PyGame Doc)
http://muagames.com/tutorials/pygame-3-pong/pygame-3-pong-step-1/ (An example I found, do page search for "dirty" or "dirty rectangles")
http://www.pygame.org/docs/tut/newbieguide.html (Another example)

Dirty Sprites:
http://www.pygame.org/docs/ref/sprite.html#pygame.sprite.DirtySprite (PyGame Doc)
Couldn't find so much for this one. Have a look round yourself if your interested.

I'd say dirty rectangles would be the best way to go for now.

SgtMe 46 Veteran Poster Featured Poster

Well a simple fix would be to multiply everything by 10. Ie:

import os
print float(1+1+1-3)/10
os.system("pause")
SgtMe 46 Veteran Poster Featured Poster

Please mark solved. Thanks.

SgtMe 46 Veteran Poster Featured Poster

Code tags please.

SgtMe 46 Veteran Poster Featured Poster

Well this may help you out on the first error. Not sure about the seconds one. Which lines are they on?
http://www.gamedev.net/community/forums/topic.asp?topic_id=149452

SgtMe 46 Veteran Poster Featured Poster

Please post the error you get (the whole error report)

SgtMe 46 Veteran Poster Featured Poster

Please don't bump old threads.
Note: This is not a bump of an old thread, this was top of the forum anyway, so it won't make much difference.

SgtMe 46 Veteran Poster Featured Poster

So you don't get any chance to enter input or anything in between the prints, and it's just wildly looping? It appears that your main game loop will always be true. You should use couts to check the values of variables and the expected output as you go. Use "system("pause")" [if your on windows] to pause the program after each loop and see what has happened.

You also appear to have something funny going on at line 83 (in your latest full code). You have

while (moveIsValid (Move) != true);

and then all the bits for changing who's turn it is. This would suggest that if the move is not valid, you change turn, therefore you will keep changing turn as the input is not valid.

SgtMe 46 Veteran Poster Featured Poster

Could you copy and paste the output (just one line of the repeating bit)? Even if the "else if" didn't work, it's still more conventional and would be better if you had more if statements.

SgtMe 46 Veteran Poster Featured Poster

LOL I never knew that! It's still in full development, so I guess it's becoming better with age.

SgtMe 46 Veteran Poster Featured Poster

So it keeps printing "Computer Moves"?
It would appear that your block of "if" statements are constantly going to the "else" option. Try this:
At line 72:
Change

else (Whose_Turn == 2);

To

else if (Whose_Turn == 2);

However, if that is the case, it will probably keep reverting to the "else if" and we will have another problem.

SgtMe 46 Veteran Poster Featured Poster

Which line is the print statement on? Please repost the code.

SgtMe 46 Veteran Poster Featured Poster

Please upvote my post that helped you. Thanks.
Which part is it that gets printer constantly?
PS. I'll be back later I'm going to the fish and chip shop :D

SgtMe 46 Veteran Poster Featured Poster

Well Ruby isn't so popular these days, but Ruby on Rails is used a fair bit for the web, but again it's not Ruby as such. Yeah I'm trying to learn a bit of Ruby at the moment, just to broaden my horizons.

SgtMe 46 Veteran Poster Featured Poster

Python has growing support for things like OpenGL, which are huge in the sofware/games development industry. Also, there are several Python modules enabling the use of web apps or sites. There are a surprising amount of desktop programs that were programmed in Python, Blender being just one of them. So yes, I think they have space to go. Python is a much simpler language than C++, for example, but it still has great capabilities. With a bit of luck, Python could become a great language for indie game dev.

SgtMe 46 Veteran Poster Featured Poster

What is the problem you are having?

SgtMe 46 Veteran Poster Featured Poster

The error is around lines 70 and 75. The user input changes the value of "Move" and the computer random value writes to the value of "move". Notice the difference?
Now look at lines 88 to 98. This is where you execute the moves. They both use "Move", which will always be the user input. Change line 75 to:

Move = rand () % 8;

Also:
http://www.cplusplus.com/reference/clibrary/cstdlib/rand/
Here is a reference to rand.
Have a look through.
You should reseed the random value:

#include <time.h>
//...............
//Between current lines 74 and 75
srand (time(NULL));

This should hopefully sort it :)

SgtMe 46 Veteran Poster Featured Poster

Is this thread solved? If so, mark solved and upvote the posts that helped. Thanks :)

SgtMe 46 Veteran Poster Featured Poster

Here's a page with a short, decent description. Should help you out a little. It's got a point or two that we haven't covered.
http://www.wikihow.com/Tell-if-a-Proper-Fraction-Is-Simplified

PS. Haven't seen you around lately Lerner :)
PPS. Who likes my new avatar?!

SgtMe 46 Veteran Poster Featured Poster

Please press the code tags button before pasting code. So you would code simplification? The first thing you should probably do is to test whether the fraction is prime. If the test returns false, then you should check what numbers can divide into it. Use while/for loops to test. Obviously, if either the top or bottom number is one, then you won't be able to divide, so you don't need to do all the tests. Again, you should use loops to keep dividing until you get to a prime.

SgtMe 46 Veteran Poster Featured Poster

Sweet code! May I recommend adding getchar(); at the end to pause? Just makes it a little easier for the user :)

SgtMe 46 Veteran Poster Featured Poster

Please mark solved.

SgtMe 46 Veteran Poster Featured Poster

If you want some practice exercises, head over to this thread:
http://www.daniweb.com/forums/thread32007.html
It's for python beginner projects, but you can use the same ideas in C++ as well :)

SgtMe 46 Veteran Poster Featured Poster

Thanks :) I shall be back later

SgtMe 46 Veteran Poster Featured Poster

OK. Sorry I can't write out much more code for you 'cos I've got a 3D modeling project to sort out. Here are some links to get you help on this.
Arrays
Time Value Of Money (Just take a glance)

Please can you upvote my posts seeing as I have helped you out :)