Closed Thread
Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 21

Thread: Project 1 - Game Network 1.0

  1. #11
    Lance is offline Programming Professional
    Join Date
    Dec 2008
    Posts
    276
    Rep Power
    13

    Re: Project 1 - Game Network 1.0

    We would be happy to of any help in your journey on OOP in C++.

    I guess it's a continous loop like

    Code:
        read -> think -> write +
          ^                    |
          |                    |
          +--------------------+
    Read good books/articles/forum discussions/actual code
    Think if it's really like what people claims. Could it be done better in a different way? etc
    Write, well you can write you game; apply the theory you learn on your actual work. Do not hesitate to reinvent wheels when learning a lauguage.

    But it could be too dull for a boy at your age. The most important thing should be to have fun. Good luck, Donovan.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #12
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: Project 1 - Game Network 1.0

    I agree that learning OOP in command-line first is probably the best way to go. It will help make GUI stuff make a LOT more sense, since GUI toolkits tend to be very heavily OOP, and not understanding the basics can make the journey much harder.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #13
    Join Date
    Oct 2008
    Location
    Pahrump, Nevada
    Posts
    787
    Blog Entries
    1
    Rep Power
    20

    Re: Project 1 - Game Network 1.0

    Alright, Thanks for the information

    +Friend Me | My Graphics | Forum Rules | Help Forum | Forum FAQ

  5. #14
    Feral is offline Programmer
    Join Date
    Jul 2008
    Posts
    163
    Rep Power
    15

    Re: Project 1 - Game Network 1.0

    Since i'm cheap and I actually like the books check out Thinking in C++ volumes 1 and 2 by Bruce Eckel's.

    He has made them freely available for download off of his site (the link).

    If you do want to carry on with game programming you would want to start with the game loop and then a user input system. networking would be one of the last things to actually consider learning for game programming. Basically because its like learning an entire system all by itself. Creating a network connection is pretty easy but optimizing your code and minimizing the amount of data sent over the network as to not kill your bandwidth but still give the clients enough info to work with is very hard.

  6. #15
    Join Date
    Oct 2008
    Location
    Pahrump, Nevada
    Posts
    787
    Blog Entries
    1
    Rep Power
    20

    Re: Project 1 - Game Network 1.0

    Quote Originally Posted by Feral View Post
    Since i'm cheap and I actually like the books check out Thinking in C++ volumes 1 and 2 by Bruce Eckel's.

    He has made them freely available for download off of his site (the link).

    If you do want to carry on with game programming you would want to start with the game loop and then a user input system. networking would be one of the last things to actually consider learning for game programming. Basically because its like learning an entire system all by itself. Creating a network connection is pretty easy but optimizing your code and minimizing the amount of data sent over the network as to not kill your bandwidth but still give the clients enough info to work with is very hard.
    Thank you for your contribute +rep

    +Friend Me | My Graphics | Forum Rules | Help Forum | Forum FAQ

  7. #16
    gon1387 is offline Newbie
    Join Date
    Jun 2009
    Posts
    17
    Rep Power
    0

    Re: Project 1 - Game Network 1.0

    deitel's "C++ How to Program, Fifth Edition" is a good book, it'll help you a lot with oop... I learned a lot from it, really, with OOP stuffs. it starts teaching you about OOP from the early chapters.

  8. #17
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: Project 1 - Game Network 1.0

    Deitel's book (3rd or 4th) was the one I started C++ with
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  9. #18
    gon1387 is offline Newbie
    Join Date
    Jun 2009
    Posts
    17
    Rep Power
    0

    Re: Project 1 - Game Network 1.0

    Bjarne Stroustrup's book was the first i've read about c++ and it makes me hate c++ before.. the reason, I can't understand a thing. Then I realized it might be written for seasoned pros so i started to look for other alternative and I found deitel's beginning in c++. It was the best beginner's book I've ever read. Anyway, this so much off topic...

  10. #19
    Zer033 is offline Learning Programmer
    Join Date
    Mar 2008
    Posts
    79
    Rep Power
    15

    Re: Project 1 - Game Network 1.0

    Hey Donovan I see you're interested in game programming. I would agree with the others that it is best to do command line stuff to get used to the language first. Here's an old command line maze game I made a long time ago that might be of some help to you. It is very basic, but that can be the best way to learn starting out. It isn't much of a game really it was more just to test stuff out.

    It shows a few game programming ideas in it like drawing of graphics, erasing of graphics, score keeping, time keeping, saving stats to a file, player character movement, collision detection, state changes, and most of all the game loop. The game loop is constantly running through all of the logic tests, drawing/erasing of graphics, and player input code you create for your game until it reaches some code that will tell it to end the game loop.

    A lot of this same stuff is used in any game you will create whether it be a 2D sprite game or fully 3D models, so simple command line programming can really be beneficial for setting up learning the more complex game programming stuff down the road.

    Code:
    /*
    I modified my maze game to use a finite state machine where the rooms are states and
    when a new state is entered information will be displayed on the screen.  Transition is the way to get back
    to another state by leaving the room and the state name is the room that you are currently in. Most of the new 
    finite state machine code is near the top.
    */
    
    #include "stdafx.h"
    #include <iostream>
    #include <windows.h>
    #include <string>
    #include <stdio.h>
    #include <time.h>
    #include <fstream>
    
    #define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
    #define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
    
    //states
    #define initialRoom 0
    #define northRoom	1
    #define southRoom	2
    #define westRoom	3
    #define eastRoom	4
    #define EXIT		5
    
    void gotoxy(short x, short y) 
    {
    	HANDLE hConsoleOutput;
    	COORD Cursor_Pos = {x, y};
    
    	hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
    	SetConsoleCursorPosition(hConsoleOutput, Cursor_Pos);
    }
    
    void setcolor(unsigned short color)                
    {                                                   
        HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
        SetConsoleTextAttribute(hcon,color);
    }
    
    using namespace std;
    
    string playerName;
    int selection;
    int score = 0;
    int row;
    int col;
    int x = 15;
    int y = 10;
    int exitFlag = 0;
    int finished = 0;
    const int MAZE_WIDTH = 30;
    const int MAZE_HEIGHT = 20;
    clock_t counter;
    int seconds = 0;
    int minutes;
    int smPebble;
    int lgPebble;
    time_t start, end;
    int menuTime;
    
    char maze[MAZE_HEIGHT][MAZE_WIDTH] =
    {
    {'|','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','|'},
    {'|','=','=','=','=','=','=','=','=','=','=','|',' ',' ',' ',' ',' ',' ',' ','|','=','=','=','=','=','=','=','=','=','|'},
    {'|','=','=','=','=','=','=','=','=','=','=','|',' ',' ',' ','O',' ',' ',' ','|','=','=','=','=','=','=','=','=','=','|'},
    {'|','=','=','=','=','=','=','=','=','=','=','|',' ',' ',' ','o',' ',' ',' ','|','=','=','=','=','=','=','=','=','=','|'},
    {'|','=','=','=','=','=','=','=','=','=','=','|',' ',' ',' ','o',' ',' ',' ','|','=','=','=','=','=','=','=','=','=','|'},
    {'|','=','=','=','=','=','=','=','=','=','=','|','=','=','=','o','=','=','=','|','=','=','=','=','=','=','=','=','=','|'},
    {'|','=','=','=','=','=','=','=','=','=','=',' ',' ',' ',' ',' ',' ',' ',' ',' ','=','=','=','=','=','=','=','=','=','|'},
    {'|','E','|',' ',' ',' ',' ',' ',' ',' ','|',' ',' ',' ',' ',' ',' ',' ',' ',' ','|',' ',' ',' ',' ',' ',' ',' ',' ','|'},
    {'|','X','|',' ',' ',' ',' ',' ',' ',' ','|',' ',' ',' ',' ',' ',' ',' ',' ',' ','|',' ',' ',' ',' ',' ',' ',' ',' ','|'},
    {'|',' ','|',' ',' ',' ',' ',' ',' ',' ','|',' ',' ',' ',' ',' ',' ',' ',' ',' ','|',' ',' ',' ',' ',' ',' ',' ',' ','|'},
    {'|',' ',' ',' ',' ',' ','O','o','o','o','o',' ',' ',' ',' ',' ',' ',' ',' ',' ','o','o','o','o','O',' ',' ',' ',' ','|'},
    {'|','I','|',' ',' ',' ',' ',' ',' ',' ','|',' ',' ',' ',' ',' ',' ',' ',' ',' ','|',' ',' ',' ',' ',' ',' ',' ',' ','|'},
    {'|','T','|',' ',' ',' ',' ',' ',' ',' ','|',' ',' ',' ',' ',' ',' ',' ',' ',' ','|',' ',' ',' ',' ',' ',' ',' ',' ','|'},
    {'|','=','=','=','=','=','=','=','=','=','=',' ',' ',' ',' ',' ',' ',' ',' ',' ','=','=','=','=','=','=','=','=','=','|'},
    {'|','=','=','=','=','=','=','=','=','=','=','|','=','=','=','o','=','=','=','|','=','=','=','=','=','=','=','=','=','|'},
    {'|','=','=','=','=','=','=','=','=','=','=','|',' ',' ',' ','o',' ',' ',' ','|','=','=','=','=','=','=','=','=','=','|'},
    {'|','=','=','=','=','=','=','=','=','=','=','|',' ',' ',' ','o',' ',' ',' ','|','=','=','=','=','=','=','=','=','=','|'},
    {'|','=','=','=','=','=','=','=','=','=','=','|',' ',' ',' ','O',' ',' ',' ','|','=','=','=','=','=','=','=','=','=','|'},
    {'|','=','=','=','=','=','=','=','=','=','=','|',' ',' ',' ',' ',' ',' ',' ','|','=','=','=','=','=','=','=','=','=','|'},
    {'|','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','|'}
    };
    
    //New state class
    class State
    {
    public:
    
    State();
    
    int state;
    string transition;
    string stateName;
    
    void InitialRoom();
    void NorthRoom();
    void SouthRoom();
    void WestRoom();
    void EastRoom();
    void FinalRoom();
    
    };
    
    State player;
    
    //constructor
    State::State()
    {
    	transition = "North, South, East, West";
    	stateName = "Initial Room";
    }
    
    //room state change functions
    void State::InitialRoom()
    {
    	transition = "North, South, East, West";
    	stateName = "Initial Room";
    }
    
    void State::NorthRoom()
    {
    	transition = "South                         ";
    	stateName = "North Room    ";
    }
    
    void State::SouthRoom()
    {
    	transition = "North                        ";
    	stateName = "South Room    ";
    }
    
    void State::WestRoom()
    {
    	transition = "East, West                      ";
    	stateName = "West Room    ";
    }
    
    void State::EastRoom()
    {
    	transition = "West                          ";
    	stateName = "East Room    ";
    }
    
    //exit game when final room is reached
    void State::FinalRoom()
    {
    	finished = 1;
    }
    
    //check nodes and set state accordingly
    void CheckStates()
    {
    	if ((x == 15 && y == 6) || (x == 15 && y == 13) || (x == 11 && y == 10) || (x == 19 && y == 10))
    	{
    		player.state = initialRoom;
    	}
    	if (x == 15 && y == 5)
    	{
    		player.state = northRoom;
    	}
    	if (x == 15 && y == 14)
    	{
    		player.state = southRoom;
    	}
    	if (x == 10 && y == 10)
    	{
    		player.state = westRoom;
    	}
    	if (x == 20 && y == 10)
    	{
    		player.state = eastRoom;
    	}
    	if (x == 1 && y == 10)
    	{
    		player.state = EXIT;
    	}
    }
    
    //call functions depending on state entered
    void ChangeStates()
    {
    	switch(player.state)
    	{
    	case initialRoom:
    		player.InitialRoom();
    		break;
    	case northRoom:
    		player.NorthRoom();
    		break;
    	case southRoom:
    		player.SouthRoom();
    		break;
    	case westRoom:
    		player.WestRoom();
    		break;
    	case eastRoom:
    		player.EastRoom();
    		break;
    	case EXIT:
    		player.FinalRoom();
    		break;
    	}
    }
    
    void DisplayStateInfo()
    {
    	gotoxy(44, 3);
    	setcolor(8);
    	cout << player.transition;
    
    	gotoxy(39, 5);
    	setcolor(8);
    	cout << player.stateName;
    }
    
    //---------------------------------------------------------
    // Function: DrawMaze()
    // Purpose:  Draws the character array to create the maze and colors it
    //---------------------------------------------------------
    void DrawMaze()
    {
    system("cls");
    
    	for (row = 0; row < MAZE_HEIGHT; row++)
    	{
    		for (col = 0; col < MAZE_WIDTH; col++)
    		{
    			if (maze[row][col] == '=' || maze[row][col] == '|')
    				setcolor(8);
    			else if (maze[row][col] == 'o')
    				setcolor(13);
    			else if (maze[row][col] == 'O')
    				setcolor(14);
    			else if (maze[row][col] == 'F')
    				setcolor(12);
    
    			cout << maze[row][col];
    		}
    		cout << "\n";
    	}//end for
    }//end DrawMaze()
    
    //---------------------------------------------------------
    // Function: CheckKeys()
    // Purpose:  Checks for user keyboard input and handles it
    //---------------------------------------------------------
    void CheckKeys()
    {
    		//move up
    		if (KEY_DOWN(VK_UP))
    			{
    				y = y - 1;//move position
    
    				if (maze[y][x] == ' ' || maze[y][x] == 'o' || maze[y][x] == 'O')//check to see if new position is traversable
    				{
    					Sleep(200);//delay so only one coord is moved
    
    					gotoxy(x, y + 1);//erase character as it is moved
    					cout << " ";
    				}
    				else if (maze[y][x] == '=' || maze[y][x] == '|')//if new position is a wall then reset position
    				{
    					y = y + 1;
    				}
    			}
    		//move down
    		else if (KEY_DOWN(VK_DOWN))
    			{			
    				y = y + 1;
    
    				if (maze[y][x] == ' ' || maze[y][x] == 'o' || maze[y][x] == 'O')
    				{
    					Sleep(200);
    
    					gotoxy(x, y - 1);
    					cout << " ";
    				}
    				else if (maze[y][x] == '=' || maze[y][x] == '|')
    				{
    					y = y - 1;
    				}
    				
    			}
    		//move left
    		else if (KEY_DOWN(VK_LEFT))
    			{
    				x = x - 1;
    
    				if (maze[y][x] == ' ' || maze[y][x] == 'o' || maze[y][x] == 'O')
    				{
    					Sleep(200);
    
    					gotoxy(x + 1, y);
    					cout << " ";
    				}
    				else if (maze[y][x] == '=' || maze[y][x] == '|')
    				{
    					x = x + 1;
    				}
    
    			}
    		//move right
    		else if (KEY_DOWN(VK_RIGHT))
    			{
    				x = x + 1;
    
    				if (maze[y][x] == ' ' || maze[y][x] == 'o' || maze[y][x] == 'O')
    				{
    					Sleep(200);
    
    					gotoxy(x - 1, y);
    					cout << " ";
    				}
    				else if (maze[y][x] == '=' || maze[y][x] == '|')
    				{
    					x = x - 1;
    				}
    			}
    		//escape = quit
    		else if (KEY_DOWN(VK_ESCAPE))
    			{
    				exitFlag = 1;//exit game
    				Sleep(200);
    			}
    }//end CheckKeys()
    
    //---------------------------------------------------------
    // Function: DisplayMenus()
    // Purpose:  Displays menu and handles menu branching
    //---------------------------------------------------------
    void DisplayMenus()
    {
    system("cls");
    
    cout << "Make Your Selection, " << playerName << ": \n\n";
    cout << "1 - Start Game\n";
    cout << "2 - Instructions\n";
    cout << "3 - About\n";
    cout << "4 - Quit\n\n";
    cout << "Selection: ";
    cin >> selection;
    
    	switch(selection)
    	{
    		case 1:
    			DrawMaze();
    			break;
    		case 2:
    			system("cls");
    			cout << "The objective of the game is to traverse the maze while picking up items to \nincrease your score, but hurry up time is ticking.";
    			cout << "\n\nGame Items:";
    			setcolor(12);
    			cout << "\n\nX - YOU, The Player";
    			setcolor(13);
    			cout << "\no - Adds 100 points to your score";
    			setcolor(14);
    			cout << "\nO - Adds 1000 points to your score";
    			setcolor(8);
    			cout << "\n= - Wall type 1 (cannot be passed through)";
    			cout << "\n| - Wall type 2 (cannot be passed through)";
    			setcolor(12);
    			cout << "\nF - Finish Line";
    			setcolor(3);
    			cout << "\n\nGame Controls:";
    			cout << "\n\nArrow Keys - Move left, right, up, down";
    			cout << "\nEscape     - Exit Game\n\n";
    			cout << "1 - Return to Main Menu\n\n";
    			cout << "Selection: ";
    			cin >> selection;
    			if (selection == 1)
    			{
    				DisplayMenus();
    			}
    			break;
    		case 3:
    			system("cls");
    			cout << "Written by:  BN \n\n";
    			cout <<	"Objective:   A MAZE GAME MADE FROM C++\n\n";
    			cout << "1 - Return to Main Menu\n\n";
    			cout << "Selection: ";
    			cin >> selection;
    			if (selection == 1)
    			{
    				DisplayMenus();
    			}
    			break;
    		case 4:
    			exitFlag = 1;
    			break;
    		default:
    			DisplayMenus();
    			break;
    	}//end switch
    }//end DisplayMenus()
    
    //---------------------------------------------------------
    // Function: ScoreKeeper()
    // Purpose:  Adds to the score when items are encountered 
    //			 in-game and displays the score to the screen
    //---------------------------------------------------------
    void ScoreKeeper()
    {
    	if (maze[y][x] == 'o')
    	{
    		maze[y][x] = ' ';
    		score = score + 100;
    		smPebble = smPebble + 1;
    	}
    	if (maze[y][x] == 'O')
    	{
    		maze[y][x] = ' ';
    		score = score + 1000;
    		lgPebble = lgPebble + 1;
    	}
    
    	gotoxy(39, 7);
    	setcolor(8);
    	cout << score;
    }//end ScoreKeeper()
    
    //---------------------------------------------------------
    // Function: SaveScore()
    // Purpose:  Allows the player to save their score to a file
    //---------------------------------------------------------
    void SaveScore()
    {
    	ofstream scoreFile;
    	scoreFile.open ("score.txt", ios::app);
    	scoreFile << playerName << "'s score card:";
    	scoreFile << "\nNumber of small pebbles recovered: " << smPebble;
    	scoreFile << "\nNumber of large pebbles recovered: " << lgPebble;
    	scoreFile << "\nBase score: " << score;
    	scoreFile << "\nSeconds elapsed: " << seconds;
    	scoreFile << "\nFinal score: " << score/seconds;
    	scoreFile << "\n\n";
    	scoreFile.close();
    }//end SaveScore()
    
    //---------------------------------------------------------
    // Function: BeatGame()
    // Purpose:  This code executes when the player reaches
    //           the end of the maze. Gives the player the
    //           option to save their score before quitting.
    //---------------------------------------------------------
    void BeatGame()
    {
    	system("cls");
    	setcolor(3);
    	cout << "You've beat the game, CONGRATULATIONS!";
    	cout << "\n\n\tScore Summary: ";
    	cout << "\n\n\tNumber of small pebbles recovered: " << smPebble;
    	cout << "\n\n\tNumber of large pebbles recovered: " << lgPebble;
    	cout << "\n\n\tBase score: " << score;
    	cout << "\n\n\tSeconds elapsed: " << seconds;
    	cout << "\n\n\tFinal score: " << score/seconds;
    	cout << "\n\n1 - Save score to a file and quit";
    	cout << "\n\n2 - Quit without saving score";
    	cout << "\n\nSelection: ";
    	cin >> selection;
    	switch (selection)
    	{
    	case 1:
    		SaveScore();
    		exitFlag = 1;
    		break;
    	case 2:
    		exitFlag = 1;
    		break;
    	default:
    		BeatGame();
    	}//end switch
    }//end BeatGame()
    
    //---------------------------------------------------------
    // Function: DisplayTimer()
    // Purpose:  Times and displays the time to the screen.
    //           Seconds taken is also used in score calculation.
    //---------------------------------------------------------
    void DisplayTimer()
    {
    	seconds = (clock()/1000) - menuTime + 1;
    
    	gotoxy(39, 9);
    	setcolor(8);
    	cout << seconds;
    }//end DisplayTimer()
    
    //---------------------------------------------------------
    // Main Module
    // The game starts here
    //---------------------------------------------------------
    int main()
    {
    time(&start);
    system("cls");
    
    setcolor(3);
    cout << "Welcome to MAZE GAME!\n\n";
    cout << "Please, Introduce yourself\n\n";
    cout << "What name would you like to go by? ";
    cin >> playerName;
    
    		DisplayMenus();
    
    	gotoxy(32, 1);
    	cout << playerName << "'s Maze";
    	gotoxy(32, 3);
    	cout << "Transition: ";
    	gotoxy(32, 5);
    	cout << "State: ";
    	gotoxy(32, 7);
    	cout << "Score:";
    	gotoxy(32, 9);
    	cout << "Time:";
    
    time(&end);
    menuTime = difftime(end, start);/*get menu run time so I can subtract from the game run time so my timer is accurate
    								  since it starts when the program starts*/
    
    	//game loop
    	while (exitFlag == 0)
    	{
    		CheckKeys();
    		ScoreKeeper();
    		DisplayTimer();
    		DisplayStateInfo();
    
    		CheckStates();
    		ChangeStates();
    
    		gotoxy(x, y);//Draw character as coords change
    		setcolor(12);
    		cout << "X";
    /*
    		if (maze[y][x] == 'F')
    		{
    			finished = 1;//reached finished line so finished is true
    		}
    */
    		if (finished == 1)//if finish line is reached exit game loop by going to the end of the game screen
    		{
    			BeatGame();
    		}
    	}//end while
    }//end main

  11. #20
    Join Date
    Jul 2008
    Location
    Somewhere that is shorter to write than "In the gloomy shadows of my personal namespace"
    Posts
    10,725
    Blog Entries
    2
    Rep Power
    90

    Re: Project 1 - Game Network 1.0

    Very cool Zer033, +rep
    Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Closed Thread
Page 2 of 3 FirstFirst 123 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Help with getting list of online plyers of network game
    By elirand in forum General Programming
    Replies: 3
    Last Post: 09-09-2010, 05:38 AM
  2. Network management project. HELP!
    By airborne in forum Visual Basic Programming
    Replies: 1
    Last Post: 05-03-2010, 05:22 AM
  3. Doing final year project, network based intrusion
    By it_is_pavan in forum Programming Theory
    Replies: 5
    Last Post: 03-21-2010, 11:05 AM
  4. Good network/game engines for c++?
    By laserdude45 in forum C and C++
    Replies: 2
    Last Post: 07-22-2007, 12:47 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts