First Game.

This is a discussion on First Game. within the Game Programming forums, part of the General Programming Boards category; This is my first game. Its not really mine because its very strongly based on kirdra's ghost game. I wanted ...

  1. #1
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331

    First Game.

    This is my first game. Its not really mine because its very strongly based on kirdra's ghost game. I wanted to post it tho to demonstrate how i did some things a little differently, and because i have some questions.

    I want to implement monsters and random amounts taken away from "health" based on the action the user chooses, how might i go about this?

    Code:
    /*	Steven Billington
    	Caverns.cpp
    	September 27, 2002
    
    	This is my first game ever. Its a relativley simple program
    	as it should be cause its newbie made. Its a console based text RPG.
    
    	Welcome to Caverns, enjoy!
    
    */
    
    #include <iostream.h>
    #include <stdlib.h>
    #include <conio.h>
    
    int User_Location_X = 0;
    int User_Location_Y = 0;
    int underwear = 0;
    int DBZ = 0;
    int points = 0;
    int end_game = 100;
    
    char input;
    
    int main ()
    {
    
    	//Take user input and display opening messages
    	char name[20];
    
    	cout <<"Please enter your first name and press enter twice: ";
    	
    	cin >>name;
    
    	cout <<"Welcome to the caverns "<<name<<" . You are here because you are a non-conformist\n";
    	cout <<"to society. To get home you must complete a task..\n";
    	cout <<"This task is too find two items. These items will guide you home.\n";
    	cout <<"Many trials and horrors await thee..take the step into the darkness, \n"; 
    	cout <<"and find the Dragonball Z t-shirt, and my Dirty Underwear!\n";
    	cout <<"\n";
    	cout <<"You may quit at any time by entering (Q)\n";
    
    	getch(); //wait for key push and continue
    
    	
    	do//Start loop
    	{
    
    	// Check user position
    	if (User_Location_Y == 15)
    	{
    		cout <<"You cannot continue in this direction\n";
    		User_Location_Y = User_Location_Y--;
    		getch();
    	}
    
    	else if (User_Location_Y == -15)
    	{
    		cout <<"You cannot continue in this direction\n";
    		User_Location_Y = User_Location_Y++;
    		getch();
    	}
    
    	else if (User_Location_X == 15)
    	{
    		cout <<"You cannot continue in this direction\n";
    		User_Location_X = User_Location_X--;
    		getch();
    	}
    
    	else if (User_Location_X == -15)
    	{
    		cout <<"You cannot continue in this direction\n";
    		User_Location_X = User_Location_X++;
    	}
    
    	
    	//This decrements by 1 every loop, when it hits 0 game ends.
    	end_game = end_game--;
    
    	if (end_game == 0)
    	{
    
    		system("cls");
    		cout <<"You have used all your energy, GAME OVER!\n";
    		return 0;
    	}
    
    	//This displays every loop so user knows options
    	system("cls");
    
    	cout <<"North (1)\nSouth (2)\nEast (3)\nWest (4)\n\n";
    	cin >>input; //Store user choice
    	cout <<"\n";
    
    	//Does user want to quit? 
    	if (input == 'Q' || input == 'q')
    	{
    		system("cls");
    		cout <<"You have chosen to exit, goodbye!\n";
    		return 0;
    	}
    
    	//Update user position	
    	if (input == '1')
    	{
    		User_Location_Y = User_Location_Y++;
    	}
    
    	else if (input == '2')
    	{
    		User_Location_Y = User_Location_Y--;
    	}
    
    	else if (input == '3')
    	{
    		User_Location_X = User_Location_X++;
    	}
    
    	else if (input == '4')
    	{
    		User_Location_X = User_Location_X--;
    	}
    
    	
    	if (User_Location_X == 0 && User_Location_Y == 5)
    	{
    		if (underwear == 1)
    		{
    			cout <<"You have found some more dirty underwear.\n\n";
    			User_Location_X = 0;
    			User_Location_Y = 0;
    		
    		}
    
    		else if (underwear == 0)
    		{
    			cout <<"You found a pair of dirty underwear!\n\n";
    			underwear = 1;
    			points = points + 50;
    			User_Location_X = 0;
    			User_Location_Y = 0;
    		}
    	}
    
    	if (User_Location_X == 10 && User_Location_Y == 0)
    	{
    		if (DBZ == 1)
    		{
    			cout <<"You find another Dragonball Z t-shirt!\n\n";
    			User_Location_X = 0;
    			User_Location_Y = 0;
    		}
    
    		else if (DBZ == 0)
    		{
    			cout <<"You have aquired a Dragonball Z t-shirt, now your lost in style!\n\n";
    			DBZ = 1;
    			points = points + 50;
    			User_Location_X = 0;
    			User_Location_Y = 0;
    		}
    	}
    
    
    	if (points == 100)
    	{
    		cout <<"You have found both items and will now be freed!\n\n";
    
    		getch();
    
    		return 0;
    	}
    
    	
    
    	}
    
    	while(end_game!=1);
    
    	return 0;
    }

  2. #2
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    User_Location_X = User_Location_X++;

    should be

    User_Location_X++;
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  3. #3
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    hmm, i hadn't thought of doing it that way but that would be more efficent(sp).

  4. #4
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Ok i have added:

    Armor - protection system is in but not in use yet.

    Spell book - you can use spells, but there isn't yet a check to see if you have the book.

    Meaningful storyline and item names.

    Monsters.

    Points and Health system.

    Better Code and Comments.


    This game is very basic and under construction, but its my first release i'm proud of : )

    Caverns Version 1 release 2:

  5. #5
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    it wouldn't let me attach it all so above is the only cpp file and this is the release folder zipped.

  6. #6
    Registered User Kirdra's Avatar
    Join Date
    Aug 2002
    Posts
    105
    This may help, I made it a while ago I was a little less experinced

    It may answer a few questions and give you a few ideas.
    Attached Files Attached Files

  7. #7
    Registered User Kirdra's Avatar
    Join Date
    Aug 2002
    Posts
    105
    *edit*

    Good to see my programs going to good use. =)

    Do you have a map for that game, you defined a pretty big area. 30x30 = 900 spaces

    Have a look at my first game that used this style, v.01 The current version of the game is been made in graphics
    Attached Files Attached Files
    Last edited by Kirdra; 09-28-2002 at 10:20 PM.

  8. #8
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    I don't think i do have a map i jus started from scratch based on what you had lol.

    I want to be able to define it so that in some places you can't go certain directions but there has got to be a better way then if statements....


    Thanks for the examples!

    //edited: Does this use the same code?? How did you implement this map, etc.
    Last edited by RoD; 09-29-2002 at 07:28 AM.

  9. #9
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946

    Re: First Game.

    Originally posted by Ride -or- Die

    Code:
    		User_Location_Y = User_Location_Y++;
    		User_Location_X = User_Location_X--;
    		User_Location_X = User_Location_X++;
    	end_game = end_game--;
    		User_Location_Y = User_Location_Y++;
    		User_Location_Y = User_Location_Y--;
    	User_Location_X = User_Location_X++;
    		User_Location_X = User_Location_X--;
    these lines of code result in undefined behavior.
    hello, internet!

  10. #10
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    The locational setup of the game is really the only thing i don't really understand, the concept makes sense but beyond that...

  11. #11
    Registered User Kirdra's Avatar
    Join Date
    Aug 2002
    Posts
    105
    You can create areas that the user can't get to by using if statments:

    Lets say the user wanted to walk past location x = 10.

    Code:
    if(x > 10)
    {
         x--;
    }
    The if statment would see that x is greater than 10 thus the condition is true. therfore running the code.

    For example if you wanted an area in the middle not to be explorable if a certain condition was not met you could do this:

    Code:
    if(x < 3 && Access_Middle == 0)
    {
         x++;
    }
    
    if(y < 3 && Access_Middle == 0)
    {
         y++;
    }
    This code would stop the user from getting to the desire co-ordinates.

    if you wanted to define a certain location for instances the location of an item.

    here I'll show the method I use for unique items that can only be found once.

    Code:
    if(x == 4 && y ==5 && gold == 0)
    {
         cout << "You found gold!";
         gold++;
    }
    Now gold is equal to 1 this code will not run again. You can use this condition maybe to activate another location just as a NPC wanting to sell you something for your gold.

  12. #12
    Registered User Kirdra's Avatar
    Join Date
    Aug 2002
    Posts
    105
    Have a look at this Demo I made of one of my "possible future" creations I'll send you some basic source files of how it's all done if you want.

    *Edit* Changes files
    Attached Files Attached Files
    Last edited by Kirdra; 10-03-2002 at 03:39 PM.

  13. #13
    Registered User red_baron's Avatar
    Join Date
    May 2002
    Posts
    274
    you can check out my dungeon of moria game it uses character graphics...
    ¿Red Baron?

    "Imagination is more important than knowledge"
    -Albert Einstein (1879-1955)

    Check out my games!

    [code] /* dont forget code tags! */ [/code]

  14. #14
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    I'll send you some basic source files of how it's all done if you want.
    That would be great!

  15. #15
    Registered User
    Join Date
    Sep 2002
    Posts
    22
    im still pretty new, is this gui?? or DOS
    Laugh

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-07-2010, 11:08 PM
  2. Open Source / Semi Open source game idea. Help needed
    By CaptainPatent in forum Projects and Job Recruitment
    Replies: 10
    Last Post: 05-16-2007, 10:44 AM
  3. game engine advice?
    By stien in forum Game Programming
    Replies: 0
    Last Post: 01-23-2007, 02:46 PM
  4. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21