Welcome
Welcome to the forums of AntiRTFM's Absolute N00b Spoonfeed C++ Tutorials!

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. Registration is fast, simple, and absolutely free, so please, <a href="/profile.php?mode=register">join our community today</a>!

CONSOLE GRAPHICS INTERFACE project

Here are some projects of actual programs you can practice making.

CONSOLE GRAPHICS INTERFACE project

Postby glinka57 on Fri Oct 16, 2009 9:46 am

This Thread is for talking about and working to gether to create some neat ascii console graphics and interfaces.
NoobGrammer and i would like to face off with some graphics demos.

here is my sample:
http://cpptutorials.freeforums.org/space-combat-simulator-prototype-t567.html

ok that said,I wanted to ask about the console window, when its running you can rightclick and select properties
and change alot of stuff like : fullscreen' font sizes' etc etc is there a way or functions that can do that in the code itself.
like a system() command. i know u can use system to change the font color and also add a title to the window, but how about those other stuff. im sure there is
User avatar
glinka57
 
Posts: 195
Joined: Fri Feb 27, 2009 7:32 pm

Re: CONSOLE GRAPHICS INTERFACE project

Postby noobgrammer on Fri Oct 16, 2009 12:10 pm

This is a working program that at the moment doesn't do a thing.

I'm still in testing and getting things to work I also have to translate some of it since I copied some code from a game I made but then stripped down to make it with classes. I also may have some pointless stuff in there that hasn't been deleted yet this is still a work in progress

I told glinka that I'm making it graphical and I started toying with some just before he posted his and after seeing his I believe I can do what I want to do. I had already had my character drawn and a little animation to give me an idea of what needs to be done. I defiantly plan to do more and better with what I have but I decided to get the backbone of the program working. After that I will work my graphics in with monsters. I plan on adding a level class where you will be able to walk around and a more graphical shop but as I said I need a backbone to work with first. I like the idea of posting my work in progress so that I can get some advice on what and how to do better. I tried adding comments in for what I was thinking on in places. So it will be a work in progress post where I will probably bounce around with what I'm doing. I may stop coding and start creating my graphic ideas in the process.

to see what I have working comment out one and uncomment out the other to see what I have going

Code: Select all
//shop.CompareStats(Fists, Draw, LONG_SWORD,weaponAttack,weaponSpeed,weaponTwoHand,weaponMagic,weaponNames);

Draw.myCharacter();



glinka has pushed me to make a better intro than what I had. I think its still in my other project though. The character will be colored and it will be rated M there will be graphical blood spraying while they die. Hopefully I will have a better animation to show in a bit.
on line 312 in drawengine.cpp just add a 2 to dying to see another idea I was thinking on.


since this is a work in progress I will update by adding new links


10-16-09

EDIT: I guess I should elaborate on what I'm thinking on some parts

I want to create a new weapon and when I equipt another weaopn it will delete the other weapon(I'm thinking more as a larger picture as in if you had a couple hundred weapons to choose from not to mention armor which would be five times that size that would be a lot of wasted memory) but I will be able to keep the extra weapon in inventory but only a string name. I may just ditch the enum in inventory not sure yet. So I guess one question would be what is a good way to delete a old and create a new. I will probably add more to this as I go through my code.
I need a compiler with a can of RAID built into it

I added a msn messenger just for programming feel free to email or add yourself to it
User avatar
noobgrammer
 
Posts: 198
Joined: Tue Aug 25, 2009 10:44 am
Location: Orlando

Re: CONSOLE GRAPHICS INTERFACE project

Postby Vevix on Fri Oct 16, 2009 10:28 pm

glinka57 wrote:ok that said,I wanted to ask about the console window, when its running you can rightclick and select properties
and change alot of stuff like : fullscreen' font sizes' etc etc is there a way or functions that can do that in the code itself.
like a system() command. i know u can use system to change the font color and also add a title to the window, but how about those other stuff. im sure there is


There is better alternatives to 'system()'.

Color Text
---------
Code: Select all
#include <Windows.h>
#include <iostream>

// Function
std::ios_base& RedColor( std::ios_base& iosBase )
{
   HANDLE Console = GetStdHandle( STD_OUTPUT_HANDLE );
   SetConsoleTextAttribute( Console, FOREGROUND_RED | FOREGROUND_INTENSITY );
   return iosBase;
}

// Example Usage
std::cout << RedColor << "Hello World" << std::endl;


So this post isn't so massive here is a link to the colors: Red, Yellow, Cyan, White - http://vevix.privatepaste.com/0515Rbs3L0

FOREGROUND_ can be changed to BACKGROUND_ to achieve a background on certain words - You can read up on this @ http://msdn.microsoft.com/en-us/library/ms682088%28VS.85%29.aspx#_win32_character_attributes

With this you could easily create your own print class/functions that expand on 'std::cout' with color and backgrounds or whatever features you need - remember this is C++ don't dump everything into a single file - use classes and multiple files.

Fullscreen Console
---------
Code: Select all
void MaxWindow()
{
   // Get Console Info
   CONSOLE_SCREEN_BUFFER_INFO Info;
   GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &Info);

   // Calculate Coords for Max size
   SMALL_RECT Rect;
   Rect.Left = Rect.Top = 0;
   Rect.Right = min(Info.dwMaximumWindowSize.X, Info.dwSize.X) - 1;
   Rect.Bottom = min(Info.dwMaximumWindowSize.Y, Info.dwSize.Y) - 1;

   // Set new console info
   SetConsoleWindowInfo(GetStdHandle(STD_OUTPUT_HANDLE), true, &Rect);
}


Something like that should work

All of this can be found on MSDN.
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg. -- Bjarne Stroustrup
User avatar
Vevix
 
Posts: 142
Joined: Sat Oct 10, 2009 9:24 pm
Location: kernel32.dll

Re: CONSOLE GRAPHICS INTERFACE project

Postby noobgrammer on Sat Oct 17, 2009 5:29 am

Ok glinka heres a little idea of what I'm thinking for my game for graphics
I drew this up last night and finished it this morning so I may still edit it some more later. I'm thinking that this will be my intro with some other stuff in it.
I may also use it in parts of my game still working on all the details.

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

void gotoxy(short x, short y);
void DrawCastle();

int main()
{
   DrawCastle();
}

void DrawCastle()
{
   using std::cout;
   
   gotoxy(30,2);
   cout<< "/\\";
   gotoxy(29,3);
   cout<< "/,,\\";
   gotoxy(28,4);
   cout<< "/,,,,\\       /\\";
   gotoxy(27,5);
   cout<< "/,,,,,,\\     /,,\\";
   gotoxy(17,6);
   cout<< "|>       /________\\   /____\\";
   gotoxy(17,7);
   cout<< "|          |    |      |##|";
   gotoxy(17,8);
   cout<< "|          | ## |     /\\  |_";
   gotoxy(16,9);
   cout<< "/,\\        _| ## |_   /__\\--_|";
   gotoxy(15,10);
   cout<< "/,,,\\  /\\   |-------|  |__|  |";
   gotoxy(14,11);
   cout<< "/,,,,,\\/__\\  |       | /,,,,\\ |";
   gotoxy(13,12);
   cout<< "/_______|  |  | #   # |/,,,,,,\\|";
   gotoxy(14,13);
   cout<< "_|-----|  |--/\\      /,,,,,,,,\\";
   gotoxy(7,14);
   cout<< "/\\     |      |  | /,,\\#  #/__________\\";
   gotoxy(6,15);
   cout<< "/__\\    | #  # |  |/,,,,\\    |         |";
   gotoxy(5,16);
   cout<< "/|##|\\   |      |  /,,,,,,\\   |  #   #  |      /\\";
   gotoxy(6,17);
   cout<< "|  |----| #  # | /________\\  |   /\\    |__   /,,\\";
   gotoxy(6,18);
   cout<< "|  |    |      | |        |  |  /,,\\     _| /____\\";
   gotoxy(6,19);
   cout<< "\\ /     |   /\\-----------------/,,,,\\----|  | ## |";
   gotoxy(7,20);
   cout<< "|---------/,,\\               /______\\   |__|----|";
   gotoxy(7,21);
   cout<< "|        /,,,,\\   ##     ##  |  ##  |  #        |";
   gotoxy(7,22);
   cout<< "|  ##   /,,,,,,\\             |  ##  |           /";
   gotoxy(7,23);
   cout<< "|  ##  /________\\------------------------------|";
   gotoxy(7,24);
   cout<< "|      |        |        /\\        /\\          |------";
   gotoxy(7,25);
   cout<< "|      |        |       /__\\  /\\  /__\\         |_____|";
   gotoxy(7,26);
   cout<< "|  ##  | # ## # |  # #  |  |-/__\\-|  |   #    #      |";
   gotoxy(7,27);
   cout<< "|      |        |       |  |/####\\|  |               |";
   gotoxy(7,28);
   cout<< "|      |        |       |  |######|  |               |";
   gotoxy(7,29);
   cout<< "|______|________|_______|__|######|__|_______________|";
   gotoxy(15,31);
   
}

void gotoxy(short x, short y)
{
   COORD coord;
   coord.X = x;
   coord.Y = y;
   SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}


One problem I am having though is the max window size. I have tried multiple ways including the one Vevix just posted and they only work if I personally go to my command prompt window properties and change settings in there. Is there no way to set the properties through program code so you don't have to tell the user to change the properties first to see it fully.

on a side note I've change my weapon new and delete around and want to know if what I'm doing here is right or not.

Code: Select all
//inside main

Weapon *ptrWeapon = new Weapon;
   Weapon Fists(weaponAttack[0], weaponSpeed[0], weaponTwoHand[0], weaponMagic[0], FISTS);
   *ptrWeapon = Fists;

The caps are enums
Code: Select all
//inside Weapon.cpp

void Weapon::NewWeapons(eWEAPONS eChoose, Weapon *ptrWeapon, const short wepatt[], const short wepspeed[],const bool wepth[],const bool wepmag[])
{
   switch(eChoose)
   {

      case FISTS:
      {
         delete ptrWeapon;
         
         Weapon *ptrWeapon = new Weapon;
         Weapon Fists(wepatt[FISTS], wepspeed[FISTS], wepth[FISTS], wepmag[FISTS], FISTS);
         *ptrWeapon = Fists;
         
         break;
      }
      case DAGGER:
      {
         delete ptrWeapon;
         
         Weapon *ptrWeapon = new Weapon;
         Weapon Dagger(wepatt[DAGGER], wepspeed[DAGGER], wepth[DAGGER], wepmag[DAGGER], DAGGER);
         *ptrWeapon = Dagger;
         
         break;
      }
         
      case SHORT_SWORD:
      {
         delete ptrWeapon;
         
         Weapon *ptrWeapon = new Weapon;
         Weapon Short_Sword(wepatt[SHORT_SWORD], wepspeed[SHORT_SWORD], wepth[SHORT_SWORD], wepmag[SHORT_SWORD], SHORT_SWORD);
         *ptrWeapon = Short_Sword;
         
         break;
      }
      case LONG_SWORD:
      {
         delete ptrWeapon;
         
         Weapon *ptrWeapon = new Weapon;
         Weapon Long_Sword(wepatt[LONG_SWORD], wepspeed[LONG_SWORD], wepth[LONG_SWORD], wepmag[LONG_SWORD], LONG_SWORD);
         *ptrWeapon = Long_Sword;
         
         break;
      }
   }//end switch
}
I need a compiler with a can of RAID built into it

I added a msn messenger just for programming feel free to email or add yourself to it
User avatar
noobgrammer
 
Posts: 198
Joined: Tue Aug 25, 2009 10:44 am
Location: Orlando

Re: CONSOLE GRAPHICS INTERFACE project

Postby glinka57 on Sat Oct 17, 2009 11:12 pm

Vevix Thanks, I'll need to do alot of research into the console window functions. I dont know why msdn makes the explanations so
unnoobfriendly... etc. well thats why we have this forum anyway.. yea I will use that color function, color might add a whole new dimension.
NoobG, LOL! you should use the Sleep(); function to display the image of that house for a while. It looks good. Thats funny how you drew it with all those cout strings and \'s lol. If I may say , there are 2 main functions in the ascii graphics method:
gotoxy(); .... to pinpoint where to draw/erase
Sleep(); ..... so the viewer can have time to see it (and other things)

but that way of drawing the image with .........\\........\ etc lol reminds me I should give you something.
so here it is its a grid I made and numbered of the default console window. you can print a bunch of pages and sketch out your image displays on them , then it makes it so much easier to translate it into your code

http://www.meganetstudios.com/NoobInterface.zip

hey I'll post more tomorow
User avatar
glinka57
 
Posts: 195
Joined: Fri Feb 27, 2009 7:32 pm


Return to Projects

Who is online

Users browsing this forum: No registered users and 0 guests