Jump to content

  • Log In with Google      Sign In   
  • Create Account

Squared'D's Journal

A Complete Graphics-less Game #3

Posted by , 25 May 2013 - - - - - - · 685 views
prototyping, prototype, text and 4 more...
More Design and the First Basic Prototype
In this journal entry, I'll talk about the prototype that I have written. Prototyping is a way to test concepts without committing to anything. Many like to use prototypes to test potential features. I think this is a good idea and I also do it. I also like to prototype code. Sometimes I do this in conjunction with UML to establish relationships and make sure the code structure makes sense. I think it's pointless to just start making the "final" production code right away unless you're working with an established framework or you're a crazy genius. Otherwise you'll end up re-factoring a lot. Re-factoring isn't always bad, but if I have to re-factor I rather find problems and do it earlier.

In my opinion, every prototype should have a clear and well defined purpose. The code doesn't have to be pretty and the same goes for the output, but after the prototype, I should learn something. I'm always careful about using code from a prototype. Usually the code sucks and at best should only be used as a guideline.

In this prototype, I want to quickly make a sample text-based game just so I can get a feel for what I'm about to make. I want to show 4 main things: the main menu, the world map, the battle system, and dialog. To prototype this, I'll make a simple function for each one. I'll code the real game in C++, but for this prototype at least, I'll use more of a C-style code. Why? For me, it's just easier to prototype simple console apps in C.

I'll explain some of the things I did in the code.

WARNING: The code you're about to read is bad. Proceed with caution

I'll start with some forward function declarations.
#include <conio.h>

/* declare our forward definitions. */
void DoMainMenu();
void DoWorldMap();
void DoBattleSystem();
void DoDialog();

bool DoTownOne(); /* true - goto next town */
bool DoTownTwo(); /* false - quit world map */

int main()
{
    DoMainMenu();
}



As you can see, I'm using separate functions to handle the game states and places. In a real game some sort of a state system should be used, but remember, I'm not making a "real" game yet.

Here's the main menu code. It's very simple. Just a few loops for checking input.
void DoMainMenu()
{
    bool finished = false;

    while(finished != true)
    {
        /* display the menu */
        printf("\n============================================================================\n");
        printf("You Got Punk'd\n\n");
        printf("1) Play\n");
        printf("2) Quit\n");
        printf("\n");
        printf("\n============================================================================\n");

        /* get the user's input */
        char input = _getch();

        /* check for valid input */
        bool valid;
        do
        {
            /* initialize valid for this loop */
            valid = true;

            /* the user wants to play */
            if(input == '1')
            {
                DoWorldMap();
            }

            /* the user wants to quit */
            else if(input == '2')
            {
                finished = true;
            }

            /* invalid input */
            else
            {
                printf("Invalid Input\n");
            }
        }  while(valid == false);
    }
}


The world map is also just a loop and it goes back and forth between the towns.
void DoWorldMap()
{
    // the current town
    int cur_town = 0;

    // the return value from the town function
    bool town_return;

    printf("\nYou enter a strange new world.\n");

    do
    {
        /* go to the town */
        if(cur_town == 0) town_return = DoTownOne();
        else town_return = DoTownTwo();

        /* set to the next town */
        cur_town = 1 - cur_town; 
    } while (town_return == true);
}
Here's the code for the two towns.
bool DoTownOne()
{
    while(true)
    {
        /* display the menu */
        printf("\n============================================================================\n");
        printf("Welcome to Bean Town\n\n");
        printf("1) Talk to a stranger. \n");
        printf("2) Go to Gotham City\n");
        printf("3) Quit\n");
        printf("\n");

        /* get the user's input */
        char input = _getch();

        /* check for valid input */
        bool valid;
        do
        {
            /* initialize valid for this loop */
            valid = true;

            /* the user wants to talk */
            if(input == '1')
            {
                DoDialog();
            }

            /* the user wants to go to the other city */
            else if(input == '2')
            {
                return true;
            }

            /* the user wants to quit */
            else if(input == '3')
            {
                return false;
            }

            /* invalid input */
            else
            {
                printf("Invalid Input\n");
            }
        }  while(valid == false);
    }
}

bool DoTownTwo()
{
    while(true)
    {
        /* display the menu */
        printf("\n============================================================================\n");
        printf("Welcome to Gotham City\n\n");
        printf("1) Fight for your life\n");
        printf("2) Run to Bean Town\n");
        printf("3) Quit\n");
        printf("\n");

        /* get the user's input */
        char input = _getch();

        /* check for valid input */
        bool valid;
        do
        {
            /* initialize valid for this loop */
            valid = true;

            /* the user wants to talk */
            if(input == '1')
            {
                DoBattleSystem();
            }

            /* the user wants to go to the other city */
            else if(input == '2')
            {
                return true;
            }

            /* the user wants to quit */
            else if(input == '3')
            {
                return false;
            }

            /* invalid input */
            else
            {
                printf("Invalid Input\n");
            }
        }  while(valid == false);
    }
}

I think it's very easy to see a lot of redundancy in the code. Noticing this will help me decide on a future code architecture.

And for lazy ones like me that never feel like downloading zips to look at code:
void DoBattleSystem()
{
    int my_hp = 200;
    int enemy_hp = 400;

    char input = 0;

    printf("\n\nWelcome to the fight of your life.\n");
  
    while ((my_hp > 0) && (enemy_hp > 0))
    {
        printf("Your HP: %i\n", my_hp);
        printf("Enemy HP: %i\n\n", enemy_hp);
        printf("What will you do?\n");
        printf("1) Use a gun. \n");
        printf("2) Use a knife. \n");
        printf("3) punch him. \n");
        printf("4) Scream\n");
        printf("\n============================================================================\n");

        input = _getch();
        if(input == '1')
        {
            printf("Stranger: You don\'t have a gun.\n");
            printf("You idiot. Stop pointing at me.\n");
            printf("Super Uppercut\n");
            printf("You -75\n");
            my_hp -= 75;
        }
        else if(input == '2')
        {
            printf("Crap. No knife.\n");
            printf("Kill him with a spoon.\n");
            printf("Stranger -199\n");
            printf("\nYou are very powerful.\n");
            enemy_hp -= 199;
        }
        else if(input == '3')
        {
            printf("Stranger: You hit like my sister.\n");
            printf("You: I know your sister well.\n");
            printf("Stranger: Mother #&@ Die.\n");
            printf("You -150\n");
            my_hp -= 150;
        }
        else if(input == '4')
        {
            printf("Stranger: What? You\'re so weak.\n");
            printf("You stab the stranger with a spoon as he walks away.\n");
            printf("Stranger -399\n");
            printf("\nStranger: It hurts a lot.\n");
            enemy_hp -= 399;
        }
        else
        {
            printf("Stranger: What are you trying to do?\n");
            printf("You -15\n");
            my_hp -= 15;
        }

    }

    if(my_hp > 0)
    {
        printf("Stranger: I'm so sorry. Take some money.\n");
    }
    else
    {
        printf("Stranger: I'll let you live because the programmer was too lazy to program a way to end the game here.\n");
    }

    _getch();
}

void DoDialog()
{
    bool finished = false;

    printf("\n============================================================================\n");
    printf("Stranger: What's up?\n");
    printf("1) Nothing much.\n");
    printf("2) The Sky.\n");
    printf("3) I don't know. I'm lost.\n");

    char input = _getch();
    if(input != '2')
    {
        printf("Stranger: I'll kill you!");
        DoBattleSystem();
    }
    else
    {
        printf("Stranger: Ha.Ha. Here's some money.");
        _getch();
    }
}

I'd explain the code more, but I think it's pretty self-explanatory. Even though this is a text based game, I hope readers have a working knowledge of C and C++. If you have any questions though, feel free to leave a comment. In my next entry, I'll analyze this prototype some more and I'll also introduce some things that are missing from it.

Attached Files




A Complete Graphics-less Game #2

Posted by , in A Complete Graphics-less Game 22 May 2013 - - - - - - · 627 views
design, beginner, programming and 2 more...
Part 2 - The Preliminary Design / Concept
I'm going to start this project by doing a little design work first. When I used to work at the USDA, I would review proposals from companies bidding on IT projects. Their concepts and specs had to be good because they wanted get the contract and get money. What I'm doing now is nothing like that. This isn't going to be a major project and any docs that I make will only be used by me so I don't need a complete design document. I do feel that I'll need something to help my stay on task. I need a goal and a defined scope.

My goal is to make a game not a text-based game engine; though I will try to organize things into reusable parts. I will make an adventure rpg game. Adventure games work will with just text and that's basically the type of game we used to make in middle school.

Before I can go any further, I need to define the game a little bit more. I should decide on what the game will be about.


Game Name: The Next Tomorrow (the working title)

Setting: This game will be in a steam punk setting on a post-apocalyptic Earth.

Story: After a war that nearly destroyed the planet, humans have started to rebuild. Over the past 75 years after the apocalypse humans have cities again, but the former countries no longer exist. City-states are the only types of governments that still exist.

Goal of the player:
The player by his actions can achieve these goals
  • The player can remain a mercenary and perform quest for money.
  • The player can attempt to build his own city-state.
  • The player can attempt to rise up through the ranks and become the leader of a city-state.
My game will have these features:
  • A pregame menu system
  • A World Map
  • Towns
  • Quest
  • A Battle System
  • multiple character classes
  • an inventory system
  • dialogue
Internally, the game will have the following:
  • Load the world from disk
  • save and load game features game
  • scripted AI (using Angel Script)
This is it for the design. It's not complicated right? Are all the details there? No, not yet. Next time I'll build a quick prototype of some of the features that I want to implement. After I make the first prototype, I'll be able to understand what I need to build better and I may be able to think of some new features.


A Complete Graphics-less Game #1

Posted by , in A Complete Graphics-less Game 22 May 2013 - - - - - - · 693 views
beginner, text based, game and 1 more...
The Idea
What's the first thing that the we often notice when playing video games? Most of us see the graphics first and games that look good and have a lot of eye-candy make people immediately interested. Because of this, many (myself included) have been focusing on making good looking games. While I think good graphics are necessary, focusing on graphics too much can cause new programmers especially to not take the time to develop other needed skills. We can't all be graphics programmers right? How about organizing entities? How about loading data or integrating with a scripting language? These are some issues that I will tackle in this journal.

How will I do it without worrying about graphics? When I was in middles school, we used to have old Apple II computers in the computer lab. Some of us used to make simple text games which were just a really long nest of if statements. So that gave me the idea to make a text based from start to finish and I will document my progress using this journal. I will not use any of my old code. I will start from scratch and try to use only standard C++.

I've used console applications before to test code before, but this will be my first full-scale text-based game. I'll try to post at least once a week. I'll start with a quick a dirty game design. Then I'll do some prototyping, then I'll design a little more. This will not be a tutorial per se, as I don't want to show people how to make a text-based game. I want to show how it can be useful to step away from the graphics and concentrate on other things.






Recent Comments

May 2013 »

S M T W T F S
   1234
567891011
12131415161718
19202122232425
262728293031