Jump to content
  • Advertisement
Sign in to follow this  
Sria

Some trivial console programs for the C++ newb?

This topic is 4500 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all, I have been roamin around the forums and the site for a little while now and readin lot's of posts. So anyway, I just started programming C++ about a week and a half or so. At first I was teaching myself C# from a book but then after reading some people saying C++ was where the action is in game programming I switched over to teaching myself C++ from a book. Since then I have seen several mixed opinions on the C# v. C++ thing but I have committed to C++ and judging by how my little information with C# still helped me and translated well into C++ I think I will be alright learning C# later. So there is my life story, sorry you had to read that before I got to the point of this thread which is - What are some maybe idea's or typical programs that are above cout<<"Hello world!"; but Below some of the other typical starting programs that I am not ready for yet, such as Pong, Asteroids , Breakout and the like (involving graphics and what not). I have the book Beggining C++ Game Programming - by Michael Dawson and I am in the midst of Chapter 5 if that means anything to you guys :). Anyway I always try to add to or change the programs he shows because it helps me understand what's going on better but with these last few chapters I have had a difficult time making the code into something different then just copying the example out of the book. So if any of you had some idea's for something that might be within my skillset range I'd just like to use some of the little knowledge I have now and be familiar with it before I move on to far. I have a concept but not mastery (obviously) of: arrays vectors scopes functions loops (if, else, do , while and for) random numbers operators mostly just the beggining stuff. Well if you have made it this far then I must thank you simply for reading my post and thanks for the help in advance :)

Share this post


Link to post
Share on other sites
Advertisement
I know your not into the graphics stage yet, but if you did start to discover and learn to get some pixels on the screen, it would really give you a lot more options for small programs to practice and test basic programming concepts.
At least thats my take on it.

Or you could just make one of those little 'ski down hill' games, where the letter 'V' is the ski guy, and you have some trees 'A' move up the screen towards ski guy. Ski guy stays center of screen, but moves left and right, and all trees just move up, use your array skills to hold random tree placement for drawing and collision detection.

Share this post


Link to post
Share on other sites
I don't know how to do collision detection or how I would go about making the V move left to right but that is an interesting idea that I did not think of that maybe I could do with just a little more practice.

Thank you sir :)

Share this post


Link to post
Share on other sites
Well, just keep practicing with the console, you can practice making a character move by having a loop that draws a character 'V' with a certain ammound to spaces, to make it farther left or right.

Just to give you someting to play with

void main()
{
bool finish = false;
int spaces = 10;

do
{
//some command here that clears the console
int dir = //randome number from 0 to 2
switch (dir)
{
case 0: spaces--; if (spaces<0) spaces = 0;
break;
case 1:
break;
case 2: spaces++; if (spaces>20) spaces=20;
break;
}
//draw the player
//some type of clear screen command goes here
for(int n=0;n<spaces;n++) printf(" "); //or use cout
printf("V"); //draw the player, or use cout once again
//check for some sort of keypress to break the loop
//if (keypress == ESC) finish = true;
} while !finish;
}




This is just some sort of pseudo code off the top of my head, but it might inspire you somehow.

Share this post


Link to post
Share on other sites
Wow, thank you very much, I decided to persue trieng to atleast get some sort of random "mountain slope" with 'A's moving up it in a random order but the way I have it written so far seems very sloppy and unintuitive,

If that doesnt make sense ill try to show what I was thinking..


I don't know how to use the source code window thing but what i have is


const int ROWS = 30;
const int COLUMNS = 5;
char slope[ROWS][COLUMNS] = {{' ', ' ',' ',' ',' '}, etc. etc.

then i used a for loop with a nested for loop to display the board

then I planned on using

srand(time(0));
treeRow = (rand() % 30) + 1;
treeColumn = (rand() % 5) + 1;

slope[treeRow][treeColumn]= 'A';

but then I get stuck because the board is not constantly scrolling and I have no idea how to implement a V that goes back and forth.

Anyway I don't actually know why i posted all that but I will try working with what you posted :P

Thank you again

Share this post


Link to post
Share on other sites
A few programs you could try after hello world:

- Hello user:
Ask for the user's name, and then use it to say hello to the user.

- Guess my number:
This is a simple game where the user (player) needs to guess the number the computer is "thinking of". The computer should produce a random number between 1 and 10. If the user guesses a number that is higher or lower than the computer's number, they should be told "higher" or "lower" and allowed to guess again until they find the solution. When the player guesses the correct number they should be congratulated and asked if they would like to try again.
Extra Credit: Can you allow the player to exit at any time without having to guess the number, in case they get sick of it?
(Hint: Get the player to enter some value that would never be a valid input if they wish to exit without finishing the game.)
Challenge: Can you (using a switch statement) add a menu at the beginning allowing the player to choose from 3 difficulties? The difficulties would be as follows:
- 1: Guess a number between 1 and 10.
- 2: Guess a number between 1 and 20.
- 3: Guess a number between 1 and 30.
(Hint: Have the player input 1, 2 or 3 and use that to decide which choice has been made.)

- Hangman:
In this game, the player must guess leters in order to try to figure out what word the computer is thinking of. If the player doesn't guess the word within a certain number of turns they lose the game. The game should tell the player how many letters are in the word, and should display: how many turns are left; what letters have already been guessed, and where in the word correctly guessed letters are. Words should be stored in a text file, and the program will select one of these words randomly at the beginning of a game.
Extra Credit:
Can you use ASCII art to draw the typical hangman display piece by piece?
eg.

----------+---
| \|/
0 |
/|\ |
/\ |
|
----------+---

(Hint: You'll want to clear and redraw the entire console screen each time.)

- Tic-Tac-Toe:
Also known as naughts and crosses. The player must get 3 pieces in a row. This game can be represented using ASCII art and later re-done using graphics, I'm not going to explain the rules of play; if you don't know them and want to try it, you could look them up.

| |
--+--+--
| |
--+--+--
| |

(Hint: The numeric keypad is a good way of taking input for this game, as it has 9 keys that share the same layout as the game board.)
Extra Credit: Can you make this game with both a two-player mode and with a simple AI player?
Challenge: Can you create different levels of difficulty for the AI? You should be able to create a 'perfect' AI that cannot be beaten, as well as an easier one that is possible to beat but still challenging.


You could give those a try. Hangman and Tic-Tac-Toe can be quite tricky for a beginner but should be doable if you put in some effort and think about it carefully. If you can't manage those yet, some extra practice of the basics would probably be good, and I'm sure we could make some suggestions for simpler things. If those are too trivial I can also make some more difficult suggestions that should be possible in the console, but I'll leave that unless you ask for them in order to keep my post a reasonable length.

Hope those are of some use to you. [smile]

Share this post


Link to post
Share on other sites
Quote:
Original post by SelethD
I know your not into the graphics stage yet, but if you did start to discover and learn to get some pixels on the screen, it would really give you a lot more options for small programs to practice and test basic programming concepts.
At least thats my take on it.

Or you could just make one of those little 'ski down hill' games, where the letter 'V' is the ski guy, and you have some trees 'A' move up the screen towards ski guy. Ski guy stays center of screen, but moves left and right, and all trees just move up, use your array skills to hold random tree placement for drawing and collision detection.

You can create an ASCII tetris using quite similar techniques if you figure this one out by the way...

Share this post


Link to post
Share on other sites
Thank you very much Jason, I have made a guess my number and a non-interactive tic tac toe game and a hang man game but I have not made them like you said so it will pose a challenge.

But before I start on those I have almost completed my very first idea inspired by
SelethD (to just make a scrolling slope with random 'A's in random places throughout the board) but I am stuck at one very last part and that is; to my dissapointment keypress == ESC gives my compiler an error :P so I need some way to end my "do" loop without typing in 'quit' via cin>>

Share this post


Link to post
Share on other sites
Keyboard input is quite OS and compiler dependant. What OS are you writing on and which compiler are you using?

Share this post


Link to post
Share on other sites
You could make a text based pong game. like this:

_________________________________________________


# #
# #
# O #
# #




__________________________________________________

With ASCII symbols.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!