• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
bean.

ATM Project for School

3 posts in this topic

Hey everybody. I'm in my intro to programming class in College (Computer Science Major). We're learning C++ at the moment. So, our first big project of the semester is to make an ATM (Automated Teller Machine) Simulation Program, using the console for input and output. We haven't gotten to Classes or anything like that yet, but I wanted to try and implement them anyway (I've got a bit of past experience in Java, not a lot, but enough to know the basics of OOP). My teacher said it was fine to use anything in C++ if we knew about content that we haven't learned about yet. Point. I wrote the program today, and I was hoping that if I posted my thought process (as concise as possible), and how I implemented everything, I could get a few critiques and suggestions on my coding style. Why waste a learning opportunity, right?

I approached the program similar to how I've learned to think about a game. I made a big, state driven loop. I used enums to control the states, and just used a boolean value (exit) to control the loop.

First, the user selects the language after they insert their card (card is 'inserted' automatically, there is a cout statement that tells the user they inserted it.) So, we have to have the rest of the program's output in 2 languages. I chose English and Spanish. I implemented this by setting any output that is given to the console as variables. I set constants, for example,

[code]const string ENGLISH_PIN_MENU_TEXT = "Please enter your pin Number.";
const string SPANISH_PIN_MENU_TEXT = "BLAH BLAH BLAH EL BLAH";
string pinMenuText;
while (!exit)
switch (currentState)
{
case SELECT_LANGUAGE:
if (input == 1) //english
pinMenuText = ENGLISH_PIN_MENU_TEXT;
else if (input == 2) //spanish
pinMenuText = SPANISH_PIN_MENU_TEXT;
break;
case PIN_MENU:
int input;
cout << pinMenuText;
cin >> input;
etc...[/code]

Is this a good way to implement language localization? I was trying to avoid writing to the hard drive cause I'm not extremely comfortable with file parsing and all that yet.

So yeah. The language implementation is one of the big things I would appreciate criticism on.

The other big question I have is about my menu implementation. I created a class ATMMenu that I used to make formatting the output text for each state in the program a little bit easier.

[code]class ATMMenu {
public:
void SetText(std::string txtdisplayed);
void AddOption(int option, std::string optiontext);
void SetMaxTries(int maxtries);

int GetMaxTries();
int GetInput();

void Display();

private:
std::string _MenuText;
static const int MAX_OPTIONS = 5;
std::string _Options[MAX_OPTIONS];
int _MaxTries = 50;
std::string _Error;
};
[/code]

Did I implement all of this alright? The general idea is that I use SetText to set the Menu's Text, AddOption to add options for the user to select, and then Display() outputs both of them together in a formatted cout state. GetInput then uses cin statements so that in my main() method I can put GetInput into a switch statement and then handle the user's input from there. Max Tries are there so that in the main() method I can use a for loop to let the user go through a menu more than once if incorrect input is entered (if the input is correct, the for loop breaks, if not, it loops again and gets more user input). How is this looking?

Those are my big 3 questions about everything I coded. The Language Implementation, The State Driven Design, and the ATMMenu class. What could I have done differently? How could I have added more classes and simplified the design? Is my coding style alright? How could I have taken advantage of pointers?

Here is one more excerpt from my actual program that shows the usage of the ATMMenu class and also the for loop I was talking about.

[code] // Select account to display or withdraw from
case SELECT_ACCOUNT:
{
ATMMenu selAcct;
selAcct.SetText(accountSelect);
// Adds the options, checking and savings are both //string variables that are set in the SELECT_LANGUAGE state of //the loop
selAcct.AddOption(1, checking);
selAcct.AddOption(2, savings);


// allows the user multiple chances to enter correct
//input
for (int i = 0; i < selAcct.GetMaxTries(); i++)
{
selAcct.Display();
switch (selAcct.GetInput())
{
case 1:
//activeAccount is an enum
activeAccount = CHECKING;
curBal = CheckingBalance;
curState = BALANCE_OR_WITHDRAW;
break;
case 2:
activeAccount = SAVINGS;
curBal = SavingsBalance;
curState = BALANCE_OR_WITHDRAW;
break;
// 0 is used to exit the program.
case 0:
exit = true;
break;
default:
// handles all other entered numbers
cout << endl << invalidNumberError << endl;
break;
}

// If the correct input is received, break out of the for loop.
if (curState == BALANCE_OR_WITHDRAW || exit == true)
{
break;
}
}
break;
}[/code]

Thanks for any help I'm given.
0

Share this post


Link to post
Share on other sites
You could implement the menus as a state, if you then initialise them all at the begining of the application you can do a state change by just making a different state the current active state. Here is some psuedocode that shows the idea.

[code]
class MenuState //Interface for all the menus
{
public:
virtual void initialise(const LanguageChoice currentLanguage);
virtual void display();
virtual void handleInput();
virtual NextMenuStateType getNextMenuTransition();
}

class MainMenuState : public MenuState
{
...
}

class SecondMenuState : public MenuState
{
...
}

void main()
{
//Initialise all the menus you need here

MenuState* currentActiveMenu = getMainMenu(); //This gets the first menu state somehow
while(runApp)
{
currentActiveMenu->display();
currentActiveMenu->handleInput();
NextMenuStateType nextMenu = currentActiveMenu->getNextMenuTransition();
currentActiveMenu = getNextMenuFromTransitionType(nextMenu);
}
}
[/code]

The benefit of this is that you don't have a massive state machine in your main loop and if you decide to have to add an additional menu, you can just add the state, initialise it, add a link in to a previous state, add a new NextMenuStateType or look up of this new state and it will work, all without having to add a new case label and case in the switch.
1

Share this post


Link to post
Share on other sites
Alright. That makes sense. Is it okay to make a new class for every menu I have? For example, have a class FirstMenu, SecondMenu, ThirdMenu, all the way up to like 10 menus, that all extend the abstract class? I didn't want to go overboard with classes, so I avoided that, but I thought of doing something similar. My main method is quite bloated as of right now as a result.
0

Share this post


Link to post
Share on other sites
[quote name='bean.' timestamp='1331141032' post='4920124']
Alright. That makes sense. Is it okay to make a new class for every menu I have? For example, have a class FirstMenu, SecondMenu, ThirdMenu, all the way up to like 10 menus, that all extend the abstract class? I didn't want to go overboard with classes, so I avoided that, but I thought of doing something similar. My main method is quite bloated as of right now as a result.
[/quote]

Yeah thats fine thats what specialisation in inheritance is for, but you should try to push common functionality to the base class still if possible. I wouldn't name them as you just suggested though I'd call them that because it was an example only. Names like MainMenu, OptionsMenu, GraphicsMenu are far better, I am using a game as example here only.

And what I mean with common functionality is stuff like the strings for a screen can be stored in a vector in the base class, the display function doesn't nessecarily need to be virtual as a likely implementation would be this in the base class:
[code]
void MenuState::display()
{
for(std::vector<std::string>::iterator it = m_strings.begin(); it != m_strings.end(); ++it)
{
std::cout << *it << std::endl; //Output all the strings in the string vector line by line.
}
}
[/code]
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0