required any type of game code

Questions regarding game mechanics and graphic programming should go here.

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

required any type of game code

Postby jonnitwo » Mon May 23, 2011 1:18 am

I want to made a simple game.

Any type please anyone give me the game code.

I am thankful to them.
jonnitwo
 
Posts: 28
Joined: Mon Apr 04, 2011 2:57 am
Location: uk

Re: required any type of game code

Postby Wizard » Tue May 24, 2011 7:17 am

When learning how to make a game, it's a good idea to start with something simple with very strict rules. Tic-Tac-Toe is very common place to start. Very small board, very simple rules, well understood AI.
Checkers is also pretty good. Still a small board, simple enough rules, and much more rewarding than tic-tac-toe.
The basic flow of a game will be pretty much the same regardless of the type. Once you've written a few very simple board-like games, and understand the basics of getting user input, calculating computer moves, displaying the results, and looping back to the start, you'll be ready to tackle something more interesting.
Good luck!
User avatar
Wizard
Site Admin
 
Posts: 3226
Joined: Mon Sep 22, 2003 4:52 pm
Location: ON, CA

Re: required any type of game code

Postby joshcschool » Wed May 09, 2012 6:32 pm

Here is code for a simple guessing game, I hope it helps you and makes you want to learn more of how it works.

Code: Select all
#include <iostream>
#include <time.h>

using namespace std;

int main()
{
    cout << "This is a very simple number guessing game. Each time you will be given a number of the range 0-10." << endl;
    cout << "The objective of the game is to guess whether the next number is going to be higher or not. As simple as that." << endl;
    cout << "You have the ability to make no more than 3 mistakes before you lose, so guess wisely." << endl << endl;
    cout << "You are starting with number 5. Is the next number higher(write H) or lower(write L) ?" << endl;

    int mistakes = 0;
    int correctGuesses;
    int prevNum = 5, nextNum;
    char choice;

    do
    {
        srand ( time(NULL) );
        do
            nextNum = rand() % 11;
        while (nextNum == prevNum);

        cin >> choice;

        if (choice == 'H')
        {
            if (prevNum < nextNum)
            {
                cout << "Correct ! The new number is " << nextNum << endl;
                correctGuesses++;
            }
            else if (prevNum > nextNum)
            {
                cout << "Wrong, you made a mistake ! The new number is " << nextNum << endl;
                mistakes++;
            }
        }

        if (choice == 'L')
        {
            if (prevNum > nextNum)
            {
                cout << "Correct ! The new number is " << nextNum << endl;
                correctGuesses++;
            }
            else if (prevNum < nextNum)
            {
                cout << "Wrong, you made a mistake ! The new number is " << nextNum << endl;
                mistakes++;
            }
        }

        prevNum = nextNum;
    }
    while(mistakes < 3);

    cout << "You've made 3 mistakes ! Game is now over !" << endl;
    cout << "You had " << correctGuesses << " correct guesses before the game was over" << endl;

    return 0;
}
joshcschool
 
Posts: 3
Joined: Wed May 09, 2012 6:12 pm

Re: required any type of game code

Postby jhon marvi » Thu Dec 20, 2012 11:56 pm

...I don't know what you want to do with the user input, but it shouldn't be too difficult. You will probably want to do a whole lot more in terms of managing the state of the falling text, such as speed up if the user enters incorrectly or slow down if the user enters correctly. You can modify the delay amount to fit your needs. There are a lot of other things that you can do, but this is very much non-standard C++ (in fact it uses a Borland C library), and I'm not very interested in dredging up detailed information on how to use it through a DOS-based interface that wants point and click when "man" would be so much nicer and quicker.
jhon marvi
 
Posts: 1
Joined: Mon Dec 03, 2012 11:54 pm


Return to Games and Graphics

Who is online

Users browsing this forum: No registered users and 1 guest