Jump to content


Photo
- - - - -

Easy game to create using C++


  • This topic is locked This topic is locked
9 replies to this topic

#1 wazUPfoo

wazUPfoo

    Young Padawan

  • Members
  • Pip
  • 25 posts

Posted 11 June 2005 - 06:36 PM

I created this very simple game using Dev-C++, which is a free program that is easy to use! Download here:http://www.bloodshed...dev/devcpp.html

So here's the code, it explains everything in there:
#include <iostream>//Includes common functions and such
 using namespace std;//Use the std namespace
  
 int main()//Program entry point
 {
 bool done=false;//loop quit variable
 while(done!=true)//The main program loop.
 {
  cout << "1 - Play the number game.\n 2 - Play the letter game.\n3 - Quit.\n";//This is the menu
   int choice=0; //Declare the variable choice and set its value to 0
   cin >> choice;//Get the user input and put it in choice
   switch(choice)
  {
  case 1: //This is the number game, where who ever is playing chooses a number between 1 and 10, and then puts it in!
             int theNum;
             cout << "Welcome to the Number Game!  Enter a number between 1 and 10!\n:";
             cin >> theNum; //This is were the person puts in the number, "theNum" refers to the number
             if (theNum >=1 && theNum <=10) //This means that if the number is greater then 1 and less then 10, it is true
             {
                 cout << "Your number was " << theNum << "\n"; //If the number is greater then 1 and less then 10, this is the message you'll get
             }
             else
             {
                 cout << " " << theNum << " is greater then 10 smartass!!\n"; //This is what happens if the number is greater then 10
             }
    break;
     case 2: //This is what you get is you press 2 in then menu, which is the letter game, basically the same thing as the number game!
            char theChar;
            cout << "This is the letter game! \n Enter one letter, only 1, or the game will go into a never ending loop!!!\n:";
            cin >> theChar;  //The person puts in the character here, "theChar" refers to the charater
            cout << "Your letter was " << theChar << "!\n"; //If the person puts in 1 letter, then you get thus screen.  If the person puts 2 or more letters the game will go into an infinate loop
   break;
   case 3:
   done=true;//quits the loop
         break;
  default: //This is what you get if you pressed a number you put in the menu wasn't choice 1, 2, or 3
   cout << "That wasn't one of the choices!\n";
	}
   cout << "\n\n\n";//You can put a few new lines in right here!!
 } // End the while loop
 }//end the program
There it is!
If you have any questions, ask them here, and I'll do my best to answer them since I'm also relatively new! ;) :google:
Click here to try the game

Edited by wazUPfoo, 14 June 2005 - 07:15 PM.


#2 raenef

raenef

    Code Enforcer

  • Members
  • PipPipPip
  • 540 posts
  • Location:Battle Creek, Michigan
  • Interests:Web Development and Graphic Design

Posted 11 June 2005 - 10:05 PM

Interesting 'game' compiled it, tried it. Not too bad. All it does really is repeat your choice back to ya though. perhaps a suggestion: Have the computer pick a random number (or letter) then the player try and guess it. :P

#3 wazUPfoo

wazUPfoo

    Young Padawan

  • Members
  • Pip
  • 25 posts

Posted 12 June 2005 - 12:57 AM

alright, I'll try and figure that out tomarrow =)

#4 raenef

raenef

    Code Enforcer

  • Members
  • PipPipPip
  • 540 posts
  • Location:Battle Creek, Michigan
  • Interests:Web Development and Graphic Design

Posted 13 June 2005 - 06:36 AM

Here, try experimenting around with this code: It should get ya started:

// Guess My Number
// The classic number guessing game

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;
int main()
{
    srand(time(0)); // seed random number generator

    int theNumber = rand() % 100 + 1;  //random number between 1 and 100
    int tries = 0, guess;

    cout << "\tWelcome to Guess My Number\n\n";

//Guessing Loop
do
{

   cout << "Enter a guess:";
   cin >> guess;
   ++tries;

   if (guess > theNumber)
       cout << "Too high!\n\n";

   if (guess < theNumber)
       cout << "Too low!\n\n";
} while (guess != theNumber);
cout << "\nThat's it! You got it in" << tries << "guesses!\n";

return 0;
}

Source=
Beginning C++ Game Programming
Michael Dawson
Premier Press

Sidenote: Premier Press makes a ton of good game-programming books if you're intested in that genre.

#5 wazUPfoo

wazUPfoo

    Young Padawan

  • Members
  • Pip
  • 25 posts

Posted 13 June 2005 - 07:38 PM

Hey thanks I'll try that out!
I think I'll look up some of the books too =)

#6 Smarty

Smarty

    Young Padawan

  • Members
  • Pip
  • 67 posts

Posted 13 June 2005 - 09:42 PM

could you post the game so we can see it?the people who don't have C++

#7 wazUPfoo

wazUPfoo

    Young Padawan

  • Members
  • Pip
  • 25 posts

Posted 13 June 2005 - 09:49 PM

Sure, but first I need to know a site were you can upload files like this or.zips

#8 Smarty

Smarty

    Young Padawan

  • Members
  • Pip
  • 67 posts

Posted 13 June 2005 - 10:19 PM

try http://www.FreeFileHosting.net They might let you!

#9 wazUPfoo

wazUPfoo

    Young Padawan

  • Members
  • Pip
  • 25 posts

Posted 14 June 2005 - 06:55 PM

I found a file uploader =)
Click here!

Edited by wazUPfoo, 14 June 2005 - 07:07 PM.


#10 Bryn

Bryn

    Spammer

  • Members
  • PipPipPipPip
  • 2,019 posts
  • Gender:Male
  • Location:South Wonston, Winchester, UK
  • Interests:Music, Philosophy, Design, History, Reading, Writing, The Weekend etc...

Posted 19 November 2005 - 07:12 PM

^^ It's now de-hosted.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users