Go Back   Flash Flash Revolution > General Discussion > Critical Thinking > Homework & Help

Reply
 
Thread Tools Display Modes
Old 09-5-2015, 01:38 PM   #21
Xayphon
sausage
FFR Simfile AuthorD7 Elite KeysmasherFFR Veteran
 
Xayphon's Avatar
 
Join Date: Nov 2008
Location: Germany
Posts: 1,630
Default Re: [University - C++ Programming] Help With Assignment (Very Basic Stuff)

Oh, yeah, totally missed that
Xayphon is offline   Reply With Quote
Old 09-5-2015, 09:31 PM   #22
sickufully
Sir Krisk
FFR Veteran
 
sickufully's Avatar
 
Join Date: Dec 2007
Location: Vic, Australia
Posts: 930
Default Re: [University - C++ Programming] Help With Assignment (Very Basic Stuff)

I'm pretty sure I know what I'm supposed to do, I just don't know how to code it. I'm going to assume I need to add in an if statement for both [row] and [col] to determine if the row or col value is at the first or last box of the array? Do I need to change the for loops to if loops?

This is what I have so far:
Code:
	if (unsigned int row = 0 && 20)
	{
		tileMap[MAP_WIDTH][row] = WALL;
	}
	else
	{
		tileMap[MAP_WIDTH][row] = EMPTY;
	}
	if (unsigned int col = 0 && 30)
	{
		tileMap[MAP_HEIGHT][col] = WALL;
	}
	else
	{
		tileMap[MAP_HEIGHT][col] = EMPTY;
	}
It doesn't seem to contain any errors but I'm pretty sure all I've done is assign a wall to array locations row[0] and [20] and col[0] and [30] (all the corners and that's it). It doesn't actually put a wall all the way around. But there's something else wrong with my code now and it breaks at (in the function: DrawMap):
Code:
rScreenBuffer[row][col].Char.AsciiChar = (char)TOKEN[rTile];
I think this has something to do with my previous question but I honestly don't know why it stuffs up. If someone could help me out with rectifying this?
__________________

Last edited by sickufully; 09-5-2015 at 10:10 PM..
sickufully is offline   Reply With Quote
Old 09-5-2015, 11:05 PM   #23
Xayphon
sausage
FFR Simfile AuthorD7 Elite KeysmasherFFR Veteran
 
Xayphon's Avatar
 
Join Date: Nov 2008
Location: Germany
Posts: 1,630
Default Re: [University - C++ Programming] Help With Assignment (Very Basic Stuff)

Can you show the complete code of the whole tileMap initialization function you have so far? Including the for-loops
Xayphon is offline   Reply With Quote
Old 09-5-2015, 11:23 PM   #24
AutotelicBrown
Under the scarlet moon
FFR Simfile AuthorD7 Elite KeysmasherFFR Veteran
 
AutotelicBrown's Avatar
 
Join Date: Jan 2014
Age: 31
Posts: 921
Default Re: [University - C++ Programming] Help With Assignment (Very Basic Stuff)

Just a reminder that the equality operator is '==' and not '='. You should have something like:
Code:
if (row == 0 || row == 20)

Last edited by AutotelicBrown; 09-5-2015 at 11:24 PM..
AutotelicBrown is offline   Reply With Quote
Old 09-5-2015, 11:24 PM   #25
sickufully
Sir Krisk
FFR Veteran
 
sickufully's Avatar
 
Join Date: Dec 2007
Location: Vic, Australia
Posts: 930
Default Re: [University - C++ Programming] Help With Assignment (Very Basic Stuff)

This is all that's in the initialisation of Tile Map. I took the for-loops out for some reason (clearly I know what I'm doing...) but I still have them saved in a notepad in case I still needed them (which I'm assuming I do since you mentioned it :P). Oh also, I may have been testing a few things with the if statements so that's why they probably contain a tonne of errors in them.

Code:
	/*************************************************************************
	* Initialise the tile map with appropriate ENTITY values
	*/
	MAP_BUFFER		tileMap;
	
	if (unsigned int row = 0 && 20) //values in row 0 and 20 are set to WALL
	{
		tileMap[MAP_WIDTH][row] = WALL; //not sure whether I'm supposed to assign an Ascii Code or just set it to WALL
	}
	else
	{
		tileMap[MAP_WIDTH][row] = EMPTY; //any other row set to EMPTY
	}
	if (unsigned int col = 0 && 30) //values in col 0 and 30 are set to WALL
	{
		tileMap[MAP_HEIGHT][col] = WALL;
	}
	else
	{
		tileMap[MAP_HEIGHT][col] = EMPTY; //any other col set to EMPTY
	}
Code:
for (unsigned int row = 0; row < MAP_HEIGHT; row++)
	{
		for (unsigned int col = 0; col < MAP_WIDTH; col++)
		{
			tileMap[row][col] = WALL;
		}
	}
__________________
sickufully is offline   Reply With Quote
Old 09-5-2015, 11:32 PM   #26
AutotelicBrown
Under the scarlet moon
FFR Simfile AuthorD7 Elite KeysmasherFFR Veteran
 
AutotelicBrown's Avatar
 
Join Date: Jan 2014
Age: 31
Posts: 921
Default Re: [University - C++ Programming] Help With Assignment (Very Basic Stuff)

Also, if is not a loop, when you have something like:

Code:
if (unsigned int row = 0 && 20) //values in row 0 and 20 are set to WALL
	{
		tileMap[MAP_WIDTH][row] = WALL; //not sure whether I'm supposed to assign an Ascii Code or just set it to WALL
	}
else
	{
		tileMap[MAP_WIDTH][row] = EMPTY; //any other row set to EMPTY
	}
You are:
-Declaring a new int named row with value being '0 && 20', && being logical and (should evaluate to 0)
-Assigning to tileMap[MAP_WIDTH][row], aka tileMap[MAP_WIDTH][0] the value of EMPTY (because 0 evaluates to false).

Last edited by AutotelicBrown; 09-5-2015 at 11:32 PM..
AutotelicBrown is offline   Reply With Quote
Old 09-5-2015, 11:48 PM   #27
sickufully
Sir Krisk
FFR Veteran
 
sickufully's Avatar
 
Join Date: Dec 2007
Location: Vic, Australia
Posts: 930
Default Re: [University - C++ Programming] Help With Assignment (Very Basic Stuff)

Is this any closer to the answer? Also, am I supposed to keep the for-loops in the code and the if statements lie somewhere within the loop?
In (row == 0 || row == 20), the first 'row' is underlined as being undefined and same with col in it's statement.
Code:
	if (row == 0 || row == 20) //values in row 0 and 20 are set to WALL
	{
		tileMap[MAP_WIDTH][1] = WALL; //not sure whether I'm supposed to assign an Ascii Code or just set it to WALL
	}
	else
	{
		tileMap[MAP_HEIGHT][0] = EMPTY; //any other row set to EMPTY
	}
	if (col == 0 || col == 30) //values in col 0 and 30 are set to WALL
	{
		tileMap[MAP_HEIGHT][1] = WALL;
	}
	else
	{
		tileMap[MAP_HEIGHT][0] = EMPTY; //any other col set to EMPTY
	}
__________________

Last edited by sickufully; 09-5-2015 at 11:50 PM..
sickufully is offline   Reply With Quote
Old 09-5-2015, 11:57 PM   #28
AutotelicBrown
Under the scarlet moon
FFR Simfile AuthorD7 Elite KeysmasherFFR Veteran
 
AutotelicBrown's Avatar
 
Join Date: Jan 2014
Age: 31
Posts: 921
Default Re: [University - C++ Programming] Help With Assignment (Very Basic Stuff)

Yeah, those should be inside the for loop, and note that you should have in all of them something of the form:
Code:
tileMap[row][col] = WALL;
or:

Code:
tileMap[row][col] = EMPTY;
Actually, you should assign EMPTY at first, and only check for the 'true' block of the ifs to change to WALL if necessary. Logically, you are checking all positions of the matrix and, if the position corresponds to a border you assigning a WALL instead of EMPTY.

Last edited by AutotelicBrown; 09-6-2015 at 12:01 AM..
AutotelicBrown is offline   Reply With Quote
Old 09-6-2015, 12:21 AM   #29
sickufully
Sir Krisk
FFR Veteran
 
sickufully's Avatar
 
Join Date: Dec 2007
Location: Vic, Australia
Posts: 930
Default Re: [University - C++ Programming] Help With Assignment (Very Basic Stuff)

Well, I've done it backwards. I think. I'm assuming I'm pretty close now but I'm not sure what I need to change around.


Here's my code:
Code:
	* Initialise the tile map with appropriate ENTITY values
	*/
	MAP_BUFFER		tileMap;
	for (unsigned int row = 0; row < MAP_HEIGHT; row++)
	{
		if (row == 0 || row == 20) 
		{
			tileMap[row][0] = EMPTY; 
		}
		else
		{
			tileMap[row][1] = WALL;
		}

		for (unsigned int col = 0; col < MAP_WIDTH; col++)
		{
			if (col == 0 || col == 30) 
			{
				tileMap[row][col] = EMPTY;
			}
			else
			{
				tileMap[row][col] = WALL; 
			}
		}
	}
__________________
sickufully is offline   Reply With Quote
Old 09-6-2015, 01:49 AM   #30
sickufully
Sir Krisk
FFR Veteran
 
sickufully's Avatar
 
Join Date: Dec 2007
Location: Vic, Australia
Posts: 930
Default Re: [University - C++ Programming] Help With Assignment (Very Basic Stuff)

Alright guys, I cannot thank each of you who helped me out on this enough. Without the help I received here, I would've surely achieved no higher than 10-20%. I've handed the assignment in (it was due last Friday but I chose to sacrifice 10% to try and attain another 20-30% worth of marks) but I'm still not expecting to pass. There was still another entire section to complete that I didn't even touch.

I can say that I have a slightly better understanding of certain terms and what they mean and do. C++ is A LOT HARDER than I originally thought (cannot emphasis enough on 'A LOT HARDER'). Maybe it's not that hard, maybe I just overthink things or my brain just doesn't seem to grasp the understanding of the language, but one thing is for certain: I need to study a shit tonne more of this if I want to pass the exam in a month or two.

If anyone who helped me out wants some credits, just post in here and I'll give you a few. Once again, thank you.

p.s I'll probably make another thread for the next assignment (which I've been told is on another level) so keep your eyes peeled. Mostly likely in the next fortnight.
__________________

Last edited by sickufully; 09-6-2015 at 01:51 AM..
sickufully is offline   Reply With Quote
Old 09-6-2015, 04:48 AM   #31
AutotelicBrown
Under the scarlet moon
FFR Simfile AuthorD7 Elite KeysmasherFFR Veteran
 
AutotelicBrown's Avatar
 
Join Date: Jan 2014
Age: 31
Posts: 921
Default Re: [University - C++ Programming] Help With Assignment (Very Basic Stuff)

You got it slightly backwards, here is what should've been (at this point I don't think there is a problem giving it solved). Note the comments after the code explaining what is being done.

Code:
1   MAP_BUFFER  tileMap;
2   for (int row = 0; row < MAP_HEIGHT; ++row)  {
3     for (int col = 0; col < MAP_WIDTH; ++col) {
4       if ( row == 0 || row == MAP_HEIGHT - 1 || col == 0 || col == MAP_WIDTH - 1 ) {
5         tileMap[row][col] = WALL;
6       } else
7         tileMap[row][col] = EMPTY;
8       }
9     }
10  }
Comments by line:
Line 2 and 3 - unsigned for loop index don't make any difference most of the time, so int is cleaner. Not going into the details of it, but using ++row is the preferrable practice in C++ (but not in C).
Line 4 - The whole logical check can be done together and it is a chain of logical OR ('||' operand), which means if any of those four conditions is true, you execute the if block. The nested for loops makes the pair (row, col) go through all possible map indexes [0..19][0..29], so you want to check if they are on the border which is the beginning and end of the respective indexes. Note that C arrays are 0 indexed, so an array of size 20 goes from [0] to [19], which is why you need the -1 there and why the for loop test uses '<' and not '<='.
Line 5 - Tile is indeed border, assign WALL to it.
Line 6 - You get into else block if none of the tests inside the if evaluates to true which means it is not a border tile.
Line 7 - Tile is not border, assign EMPTY to it.

Would normally omit those brackets to make things cleaner but chose the explicit way to make it more obvious what is being done.

And my piece of advice for future programming assignments: the program will do exactly what you tell it to, so be always sure what each line you write is doing instead of simply guessing its meaning. All the basic syntax is easily available in any C/C++ documentation and if you need more nuanced explanation you should search on stackoverflow.com.

I usually use this for C/C++ reference and in your case it might be useful to check the tutorial with all the basic language structures here. I know that some details might not be so easy to understand without grasping the computer architecture behind the language abstraction but you should be able to handle all the basic programming without that knowledge.

Last edited by AutotelicBrown; 09-6-2015 at 04:49 AM..
AutotelicBrown is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 07:07 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright FlashFlashRevolution