C++ Help please . .

Soldato
Joined
14 Apr 2004
Posts
11,897
Location
UK
Hey guys, i'm making a 'pacman' style game for my uni assignment. I passed and successfully created a decent game a while back but I failed the exam so I have to do refferal work. Now the problem is, I can't rip my previous work, I have to use the structure we're given.

Now I've been stumped for a few hours and I can't work it out :(

I've deleted a fair amount of code but here's what I have so far:

PHP:
.

All I want is the sweet to appear, I can figure out the rest.
 
Last edited:
Hi there, sorry I should have been more specific.

I've managed to overcome a few issues however I'm experiencing a very strange problem.

Basically I sent my code to a friend and it worked for him in VS 05. I compiled my program using remote desktop on Uni's server using C++ 6, now when I compiled the application it fired up but when I had pressed a key, the program keeps crashing (debugging).

Now I've just installed VS and I get the following error:

1>d:\software engineering\fundementals of programming\visual studio 2005\projects\assigment 2 re-work\assigment 2\assigment 2\assigment 2.cpp(169) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?

Yes, stdafx.h is in the header and source. I'd really appreciate it if someone could help as I can't finish program till this is solved and I only have 2 days remaining :(
 
Ladforce said:
You only need to # include it in the cpp file. Can you post your cpp file here please. Have you tried cleaning the solution and then rebuilding as the pch file may have been corrupted or something causing that error.
Right it seems that problem is gone. It doesn't want to include my libraries it seems:



Feel free to add me to msn :)
 
Ladforce said:
So at the top of your Assignment2.cpp you have a #include for each of the 4 header files? And your still getting identifier not found?
Indeed, I have the following:

PHP:
//---------------------------------


#include <iostream>         //for output and input: getch() & cout << 
#include <conio.h>           //for kbhit 
#include <iomanip>           //for formatted output in 'cout' 
#include <fstream>           //for files 
#include <string>            //for string 
#include "RandomUtils.h"     //for Seed, Random, 
#include "ConsoleUtils.h"    //for Clrscr, Gotoxy, etc.
#include "stdafx.h"
using namespace std;


//---------------------------------
 
Ladforce said:
There is no include for TimeUtils.h but I assume those functions are not found in that header? Also, why are your function prototypes inside main()?
I've had no use for TimeUtils.h, I shall delete that.

That's the structure of the program that I have to follow as per specification.

I suspect that it's not including even the basics such iostream etc :\

Have I stored it in the correct directory?
 
Ladforce said:
try #include "stdafx.h" before any other header is included at the top of the .cpp file. seems like something stupid in the include order is screwing it.
That gave me 16 errors as opposed to 9 but every message is the same:

1>d:\software engineering\fundementals of programming\visual studio 2005\projects\assigment 2 re-work\assigment 2\assigment 2\consoleutils.h(56) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
 
I'd also like to add, when I connect to remote desktop at uni, when it crashes and then debugs the yellow arrow points at the last line of the following function:

PHP:
void placeSweetsOnGrid ( char grid[][SIZEX+1], int sweets[][2])

{ 
		for ( int swno(1); swno <= NUMSWEETS; ++swno) //for each sweet
		{ 
			int dy = sweets[swno][0]; 
			int dx = sweets[swno][1]; 
			if (! (( dy == 0) && (dx == 0)))
			grid[dy][dx] = SWEET;
		} 
}
Which is strange as it's valid.
 
Same errors with /wd4430 with clr : pure I 4 errors and 3 warnings:

1>.\Assigment 2.cpp(11) : warning C4653: compiler option 'Optimizations (one or more of /Oawstgp[y]) or debug checks (one or more of /GZ, /RTCcsu)' inconsistent with precompiled header; current command-line option ignored
1>.\Assigment 2.cpp(11) : warning C4652: compiler option 'C++ Exception Handling Unwinding' inconsistent with precompiled header; current command-line option will override that defined in the precompiled header
1>.\Assigment 2.cpp(11) : error C2855: command-line option '/clr' inconsistent with precompiled header
1>.\Assigment 2.cpp(11) : error C2855: command-line option '/clr : pure' inconsistent with precompiled header
1>.\Assigment 2.cpp(11) : error C2855: command-line option '/Gm' inconsistent with precompiled header
1>.\Assigment 2.cpp(11) : warning C4651: '/D__MSVC_RUNTIME_CHECKS' specified for precompiled header but not for current compile
1>.\Assigment 2.cpp(11) : fatal error C1903: unable to recover from previous error(s); stopping compilation

And all the errors I get take me to ConsoleUtils.h specifically where the colours all. I commented them out I got 44 errors.

This is not going well. I've been here trying for 7 hours and I've got a killer headache. I feel like i'm cracking up :(
 
Ladforce said:
ok change the comom runtime support back. after building it again go through each of the errors and make sure that everything in that file has a type.
Could you explain what you mean when you say that 'everything in the file has a type'?

Sorry, I've barely used VS for c++.
 
I really am stumped :mad: :(

PHP:
1>.\Assigment 2.cpp(3) : warning C4653: compiler option 'Optimizations (one or more of /Oawstgp[y]) or debug checks (one or more of /GZ, /RTCcsu)' inconsistent with precompiled header; current command-line option ignored
1>.\Assigment 2.cpp(3) : warning C4652: compiler option 'C++ Exception Handling Unwinding' inconsistent with precompiled header; current command-line option will override that defined in the precompiled header
1>.\Assigment 2.cpp(3) : error C2855: command-line option '/clr' inconsistent with precompiled header
1>.\Assigment 2.cpp(3) : error C2855: command-line option '/clr:pure' inconsistent with precompiled header
1>.\Assigment 2.cpp(3) : error C2855: command-line option '/Gm' inconsistent with precompiled header
1>.\Assigment 2.cpp(3) : warning C4651: '/D__MSVC_RUNTIME_CHECKS' specified for precompiled header but not for current compile
1>.\Assigment 2.cpp(3) : fatal error C1903: unable to recover from previous error(s); stopping compilation
 
I've reverted back to using remote desktop as VS is just being an arse.

no the strange thing is when I add the array values instead of swno the program fires up. SW stands for sweet numbers so it adds a sweet to the defined const int of 3 sweets. That's how it worked in my previous program without any problems.
 
Shoseki said:
Sometimes I don't understand other peoples' C++ code or habits at all. Why do you have "prototypes" in the main, and not before the main? Why are you using compiler macro "defines" instead of const static variables?

You are also doing some weird things with those arrays. You are passing by value the array into a function, and then manipulating the array, does that even update the original array? I'd expect it to if you passed by reference (using &) or by pointer.

Lots of things I don't understand about your code...

EDIT : Instead of storing all of your game items into a single array, why not create a few simple structs (one for a position, then one for each type of game item with position, character to be displayed, etc etc) and recompose the final drawing grid each frame. You could then have a vector<fruit> for example and have as many as you wanted on screen, detect collision against game objects rather than a grid etc etc.
In a nutshell, I have to do it to the speicfication given in the skeleton. It's also how I've been taught. It's not matter of go away and do it, we have adopt what's been given to us.

I got most of the other parts sorted such as a scoreboard etc, i'm just having problems setting the sweets in manual co-ordinates (4-6,5-6,7-7).
 
Back
Top Bottom