# C++ Workshop - Project 1

## Recommended Posts

JWalsh    498
Table 3.1 - Weapons
Unarmed Strike  	1d3 (20/x2)
Brass Knuckles	        1d4 (20/x2)		1g
Dagger			1d4 (19-20/x2)	        2g
Mace			1d6 (20/x2)		5g
Handaxe		        1d6 (20/x3)		6g
Shortsword		1d6 (19-20/x2)	        6.5g
Scimitar		1d6 (18-20/x2)	        7g
Morningstar		1d8 (20/x2)		8g
Spear			1d8 (20/x3)		9g
Longsword		1d8 (19-20/x2)	        9.5g
Greatclub		1d10 (20/x2)		11g
Halberd		        1d10 (20/x3)		12g
Bastard Sword		1d10 (19-20/x2)	        12.5g
Greataxe		1d12 (20/x3)		16.0g
Greatsword		2d6 (19-20/x2)	        20.0g

Table 3.2 - Armor
Unarmored		AC: +0		Max Dex: INF
Padded Armor		AC: +1		Max Dex: +8		5g
Leather Armor		AC: +2		Max Dex: +6		10g
Hide Armor		AC: +3 	        Max Dex: +4		15g
Studded Leather	        AC: +3		Max Dex: +5		25g
Scale Mail		AC: +4		Max Dex: +3		50g
Chain Shirt		AC: +4		Max Dex: +4		100g
Chainmail		AC: +5		Max Dex: +2		150g
Breastplate		AC: +5		Max Dex: +3		200g
Splint Mail		AC: +6		Max Dex: +0		225g
Banded Mail		AC: +6		Max Dex: +1		250g
Half-Plate		AC: +7		Max Dex: +0		600g
Full Plate		AC: +8		Max Dex: +1		1000g

4. If the user selects “View Stats” he will be shown a screen that displays the character’s stats. If no character has been created or if the character was killed in the arena, the output is simply “No Character Found.” After the stats or ‘no character’ message is displayed the player will be prompted to press any key. Doing so clears the screen and returns the player to the main menu. How the stats are displayed are up to the developer, but the following stats should be shown:
Name 		// Name of the Character
Level		// Level of the Character (1-20)
Strength	// Strength of the Character (8-20)
Dexterity	// Dexterity of the Character (8-20)
Constitution	// Constitution of the Character (8-20)
Hit Point	// The hit points of the character
Experience	// How many experience points the character has earned
Gold		// The amount of gold the character has earned through victorious battles

5. If the user selects “Fight!” at the main menu he will be taken to another menu which allows the user to select which level of opponent he wants to fight, in the range of 1 to 20, depending on whether or not he’s defeated an opponent of the previous level. For example, the first time the user enters the menu, “Level 1” will be the only choice. After he defeats a “Level 1” opponent and returns to the menu, “Level 1” and “Level 2” will both be options. Similarly, after the player defeats a level 15 opponent, the level 16 opponent will become available…and the pattern continues with level 20 being the most difficult opponent. Since the user can decide whether to fight an opponent of his level or less difficult, the choice he makes will determine how much experience and gold the player will get if he wins the battle. Listed below is a table that shows how much gold and experience a character gets for fighting mobs – relative to his own level.
Table 5.1 – Experience Rewards based on Opponent Level
Character Level: 300xp
Character Level - 1: 150xp
Character Level - 2: 75xp
Character Level – 3: 35xp
Character Level – 4: 15xp
Character Level – 5: 5xp
More than 5 levels below is 5xp

Table 5.2 – Treasure Rewards based on Opponent Level
Character Level: 25g
Character Level – 1: 12g
Character Level – 2 : 6g
Character Level – 3 : 3g
Character Level – 4 : 1g
Character Level – 5 : 0.5g
More than 5 levels below is 0.5g

Table 5.3 – Total Experience Points Required at each level
Level 1 - 0
Level 2 – 1,000
Level 3 – 3,000
Level 4 – 6,000
Level 5 – 10,000
….


##### Share on other sites
Zahlman    1682
Observations:

1) I'm assuming you don't actually intend for people to make any attempts to colour the output text?

2) You might want to provide a bit more guidance in terms of design.

Otherwise, looks like a fun project.

##### Share on other sites
JWalsh    498
Quote:
 Original post by ZahlmanObservations:1) I'm assuming you don't actually intend for people to make any attempts to colour the output text?2) You might want to provide a bit more guidance in terms of design.Otherwise, looks like a fun project.

1. Yes. Color the output. They learned how in a previous exercise.

2. If people have specific questions about design they can ask. Otherwise, I provided more than enough info to determine relevant classes, attributes, and behaviors.

Cheers!

##### Share on other sites
Deyja    920
This is actually somewhat more complex than I expected.

##### Share on other sites
Mordt    138
ohh looks like fun, I'll make a start tonight:)

##### Share on other sites
RinusMaximus    122
It also is more complex than I had expected, but I'm really happy about that. Cool execise Jeromy, keep up the good work!

##### Share on other sites
Deyja    920
So far, the biggest problem I've had writing up a design for this thing is not using language features that the book hasn't covered yet. :/

I won't give specifics because I don't want to design it for the students. :P[/edit]

[Edited by - Deyja on August 17, 2006 9:17:35 PM]

##### Share on other sites
JWalsh    498
As indicated in the project decription, it may be necessary to use things we will cover in the next few weeks, during the duration of the project.

Cheers!

##### Share on other sites
RinusMaximus    122
Quote:
 Original post by DeyjaSo far, the biggest problem I've had writing up a design for this thing is not using language features that the book hasn't covered yet. :/I won't give specifics because I don't want to design it for the students. :P[/edit]

I had the same thing. While I was reading the assignment I kept thinking: "Oh, I hope I learn how to do 'such and such' before the end of the project."

##### Share on other sites
eektor    182
Just curious what are the other chapters we will be covering in the next 4 weeks? It will help to know what we are covering so I can plan on utilizing the new stuff for the project.

Also, to me this seems like a big project (makes Pong look small and easy), so how do I start? What you gave us is kind of like a design document, right? Should I figure out the game states and what classes I use first? Should I just try to get the combat working first or should I try to get the main menus up first?

Thanks for the idea on the first project. It sounds like its going to be a lot of fun and I hope I would be able to finish it on time.

##### Share on other sites
IronGryphon    324
Looks like an excellent project proposal. A lot of features that can be used in quite a few games. Thanks for the work!

##### Share on other sites
Regano    122
Quote:
 Original post by jwalsh1. Yes. Color the output. They learned how in a previous exercise.

Can anyone point me to that excercise? I'm having trouble finding it. Thanks

##### Share on other sites
ChurchSkiz    1101
I was thinking of following along even though I don't have the book. One question I have, do you recommend storing the items and monsters in a text file and importing them into the game or is everything stored inside the code itself in a vector/array?

Great idea on the workshop, if people stick with it I think they are really going to be surprised at how much they learn.

##### Share on other sites
Deyja    920
Quote:
 Also, to me this seems like a big project (makes Pong look small and easy), so how do I start? What you gave us is kind of like a design document, right? Should I figure out the game states and what classes I use first? Should I just try to get the combat working first or should I try to get the main menus up first?

You are faced with the choice between top-down and bottom-up design. You have a choice to start with either to top of the system - the main menu - or the very bottom of the system - the combat. It doesn't really matter where you start. The finer points of system design are a bit outside the scope of this workshop, yeah?

For those who don't have the book; for text color you need to use conio.h. You can find out more about it on MSDN.

##### Share on other sites
Wow this is a really cool project. I havent been participating in the workshop but I would definatly like to try out this project.

##### Share on other sites
Iced_Eagle    349
I'm definetely in on the project ;) Just started a few mins ago (already had a silly semi-colon mistake too! :( Great start eh?)

*Edit* Woot, just got my menu system up and running :) Next up is the Character and Monster classes. :) I may end up doing that later tonight or tomorrow though... Oh well, decent progress for only like an hour of work.

[Edited by - Iced_Eagle on August 19, 2006 4:01:02 PM]

##### Share on other sites
Deyja    920
Great start is right. All I've got left to do is the actual combat. Except I'm writing it in vanilla C. This way, I can post code without worrying about students stealing it. If their code looks like mine, they fail the project. Genius, eh?

##### Share on other sites
kingIZZZY    122
How can I manipulate my text so that it looks neat during runtime? I need more than just \t and \n. I would like to know how to:

- Clear the screen (\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n....no thanx!)
- Place a particular character or string (or white-space) at a particular point in the screen (for example: row 2 column 47 print "Strength: 30")
- The above obviously should allow me to REplace characters/strings at will (for example: row 2 column 58 print "35" when strength increases)

With this power, I could think of many more games which could be made...

##### Share on other sites
Deyja    920
Check this out then. Clicky

##### Share on other sites
Guest Anonymous Poster
Thanx, though it looks A bit advanced, I hope ill be able to figure out what I need from it.

Otherwise, could you (or anyone) just post the bare basic instructions for how to place text at desired point on console screen? (much like the way the instructions for random numbers and colored text were posted, just the bottom line how to.)

##### Share on other sites
kingIZZZY    122
(Last post was mine, dunno why it signed out of my account)

##### Share on other sites
Deyja    920
That's right at the very top of the article.

##### Share on other sites
Iced_Eagle    349
To clear the screen

Include StdLib.h
#include <stdlib.h>

Then simply
system("cls");

Not sure if it's the best way to do it, but it's certainly the way to do it with the least number of lines :)

Quote:
 Otherwise, could you (or anyone) just post the bare basic instructions for how to place text at desired point on console screen? (much like the way the instructions for random numbers and colored text were posted, just the bottom line how to.)

Read the first code block in the article :) Fairly simple once you get the console handle.

##### Share on other sites
CondorMan    145
I've seen comments on other C++ sites that say the use of system calls should be avoided. I'll be interested to know the feelings of the experts here.

I came across a function which clears the console. It's not been covered in the book so far, so suspect that the simple \n\n\n\n\n ... approach might be what's expected.

void clrscr(void){    COORD                       coordScreen = { 0, 0 };    DWORD                       cCharsWritten;    CONSOLE_SCREEN_BUFFER_INFO  csbi;    DWORD                       dwConSize;    HANDLE                      hConsole = GetStdHandle(STD_OUTPUT_HANDLE);    GetConsoleScreenBufferInfo(hConsole, &csbi);    dwConSize = csbi.dwSize.X * csbi.dwSize.Y;    FillConsoleOutputCharacter(hConsole, TEXT(' '),                                dwConSize, coordScreen, &cCharsWritten);    GetConsoleScreenBufferInfo(hConsole, &csbi);    FillConsoleOutputAttribute(hConsole, csbi.wAttributes,                                dwConSize, coordScreen, &cCharsWritten);    SetConsoleCursorPosition(hConsole, coordScreen);}

##### Share on other sites
Deyja    920
That's unnecesarily complex. And also it's C.

This does it fine.
char buffer[50*80] = { ' ' };WriteConsole( GetStdHandle(STD_OUTPUT_HANDLE), buffer, 50*80, 0, 0 );

Of course, it assumes your window is 80 * 50. (Unless you change it, it is.)