[Game]Console War

Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Account Upgraded | Title Enabled! shadow-xx is offline
    MemberRank
    Jan 2007 Join Date
    MegatonLocation
    804Posts

    [Game]Console War

    First Application i made in c++
    might be a bit buggy but i just started
    learning 4 days ago im kinda n00b at it

    its a simple game enter the number of a weapon
    and it should atack

    if you run out of hp sooner then the pc you lose
    if the pc runs out of hp sooner then you you win
    if you used all weapons and the pc stil has hp its draw

    the damage of the weapons is random
    but each weapon has different minimum
    and maximum of damage it can deal

    Screenshots

    Screen1


    Screen2


    scan log from nod32
    http://img89.imageshack.us/img89/7119/scanco5.jpg

    New Version

    Quote Originally Posted by Change Log
    V1.1
    - Added Background color.
    - Changed text from green to white.
    - Fixed the negative healh number of user.
    - changed a few lines of text.
    - added a few lines of txt.
    - When atacking backgroun color changes to red.
    <renoved download cleariing traces>
    Last edited by shadow-xx; 26-12-08 at 10:20 PM.


  2. #2
    Gamma Daevius is offline
    MemberRank
    Jun 2007 Join Date
    NetherlandsLocation
    3,252Posts

    Re: [Game]Console War

    Looks nice :), good work :).

    To change background colour; I found this code:
    Code:
    #include <windows.h>
    
    void SetColor(int ForgC, int BackC)
    {
         WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);;
         SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);     
         return;
    }
    Usage:
    SetColor(1, 7); // foreground, background

    I dont know what the max number is, but I saw the author using it upto 15.

    -----

    textbackground(BLUE);
    works too, you will need the conio.h header file.

    C And C++ - An Urgent Help Requierd Regarding Console Background Color | DreamInCode.net

  3. #3
    Account Upgraded | Title Enabled! shadow-xx is offline
    MemberRank
    Jan 2007 Join Date
    MegatonLocation
    804Posts

    Re: [Game]Console War

    thnx^^

    but i just found a big bug type a letter instead
    of a number and it starts looping 1 line of text over and over again
    til the console is closed

    thnx for the snippet but i already found a easyer way to add a background color

    Code:
    // first number sets background seccond number sets txt color
    system("COLOR 21");
    // numbers 0  to 9 and a,b,c,d,e,f

  4. #4
    Account Upgraded | Title Enabled! passie is offline
    MemberRank
    Jan 2005 Join Date
    The NetherlandsLocation
    710Posts

    Re: [Game]Console War

    lol its kinda hard to ^^ lost 2 times

  5. #5
    Account Upgraded | Title Enabled! shadow-xx is offline
    MemberRank
    Jan 2007 Join Date
    MegatonLocation
    804Posts

    Re: [Game]Console War

    made a better version of it v1.1

    Quote Originally Posted by Change Log
    V1.1
    - Added Background color.
    - Changes text from green to white.
    - Fixed the negative healh number of user.
    - changes a few lines of text.
    - added a few lines of txt.
    - When atacking background color changes to red.

  6. #6
    Gamma Daevius is offline
    MemberRank
    Jun 2007 Join Date
    NetherlandsLocation
    3,252Posts

    Re: [Game]Console War

    I actually played the game now, was at school previously.

    I must say, nice work, and good that you done it in C ;).

    Bugs:
    - I once didnt see how many health I lost, it just displayed the enemies health and said twice that I had to press a key.
    - It says 'Enemy lost' and than Draw game. So the enemy didn't lose...and I couldnt view my own hitpoints.

    Improvements (in my opinion):
    - Only require users to press the number and than it will display both your and your enemies turn, so users dont have to tick the space bar twice ;). (use SDL? see bottom of my post)
    - Game is quite hard, you use random values to calculate turns right? What random function do you use? Pseudo-random functions are not really random ;).

    For improvement one, you can use SDL if you want. Its quite easy when it comes to user input and basic screen output. If you need some help with it, or a sample code, PM me ;)

    But nice work, keep going ;)

  7. #7
    Account Upgraded | Title Enabled! shadow-xx is offline
    MemberRank
    Jan 2007 Join Date
    MegatonLocation
    804Posts

    Re: [Game]Console War

    c?? its c++:P
    i dont think u like it if you see my messy code T_T

    i use random numbers for the damage
    when starting it puts random numbers in the aray of
    of the player and npc damage

    example
    (dmg of weapon 2)
    Sets player weapon dmg to 22
    sets enemy weapon dmg to 17

    if user inputs 2 select weapon 2
    atack with weapon 2 :enemy's hp = 100 - 22 enemy has 78 hp left
    select weapon 2 of enemy
    enemy deals 17 damage

    its like if you use weapon 2 enemy uses weapon 2


    dont know how to explain:P
    kinda hard for a beginner

    i use (rand()%30)+4
    but i dont rly understand how to use it
    Last edited by shadow-xx; 10-12-07 at 09:31 PM.

  8. #8
    Gamma Daevius is offline
    MemberRank
    Jun 2007 Join Date
    NetherlandsLocation
    3,252Posts

    Re: [Game]Console War

    To get better random numbers, use this:

    Code:
    srand(time(0));
    
    cout << rand() << endl;
    If you ever outputted your rand() script, it will give the same values each time you run the program, but the numbers look random at first (which they are not).

    C or C++, its for 98% the same thing ;), I mean if I say that you program in VB, you wouldn't say you programmed in VB6 instead of VB would you? ;)

    Why don't you make it open-source? Than people can correct your errors/messyness even more ;)

  9. #9
    Account Upgraded | Title Enabled! shadow-xx is offline
    MemberRank
    Jan 2007 Join Date
    MegatonLocation
    804Posts

    Re: [Game]Console War

    oh 1 sec leme post my messy source:P

    EDIT

    Code:
    #include <iostream>
    using namespace std;
    
    int main() {
    
    	system("TITLE Console War - Made by shadow-xx");
        system("COLOR 1F");
    
    	//txt
    cout << "Console War" << endl << endl;
    cout << "Made by Shadow-xx" << endl;
    cout << "Found a bug?  << endl;
    cout << "To your msn or just send a mail" << endl <<endl;
    cout << "version 1.1" << endl << endl;
    
    system("PAUSE");
    	
    // if user watns to play a new game
    newgame:
    
    	// user's weapon variables
    	int weapons[6];
    	weapons[0] = 1;
    	weapons[1] = 1;
    	weapons[2] = 1;
    	weapons[3] = 1;
    	weapons[4] = 1;
    	weapons[5] = 1;
    	weapons[6] = 1;
    	
    	// user's weapon input
    	int wepNumber;
    	wepNumber = 0;
    
    	// user's weapon deamage
    	int wDmg[6];
    	wDmg[0] = 0;
    	wDmg[1] = 0;
    	wDmg[2] = 0;
    	wDmg[3] = 0;
    	wDmg[4] = 0;
    	wDmg[5] = 0;
    	wDmg[6] = 0;
    	
    	// enemy's weapon deamage
    	int ewDmg[6];
    	ewDmg[0] = 0;
    	ewDmg[1] = 0;
    	ewDmg[2] = 0;
    	ewDmg[3] = 0;
    	ewDmg[4] = 0;
    	ewDmg[5] = 0;
    	ewDmg[6] = 0;
    
    	// enemy weapon variables
    	int eWep[6];
    	eWep[0] = 1;
    	eWep[1] = 1;
    	eWep[2] = 1;
    	eWep[3] = 1;
    	eWep[4] = 1;
    	eWep[5] = 1;
    	eWep[6] = 1;
    
    	// hit point variables
    	int playerHp = 100;
    	int npcHp = 100;
    
    	//replaced a gets by user (y/n)
    	char alp = 'a'; 
    	
    // weapons treu or false (on / off)
    // and assing damage to weapon in array wDmg
    startgame:
    	system("CLS");
    	cout << "Console War" << endl << endl;
    switch (weapons[0] == 1)
    case 1: cout << "0 - Sword" << endl;
    wDmg[0] = (rand()%30)+10;
    switch (weapons[1] == 1)
    case 1: cout << "1 - Bow" << endl;
    wDmg[1] = (rand()%20)+7;
    switch (weapons[2] == 1)
    case 1: cout << "2 - Knife" << endl;
    wDmg[2] = (rand()%14)+4;
    switch (weapons[3] == 1)
    case 1: cout << "3 - Throwing Star" << endl;
    wDmg[3] = (rand()%14)+4;
    switch (weapons[4] == 1)
    case 1: cout << "4 - Daggers" << endl;
    wDmg[4] = (rand()%19)+5;
    switch (weapons[5] == 1)
    case 1: cout << "5 - Scythe" << endl;
    wDmg[5] = (rand()%30)+10;
    switch (weapons[6] == 1)
    case 1: cout << "6 - Axe" << endl;
    wDmg[6] = (rand()%30)+10;
    cout << endl;
    
    // Enemy's weapon damage
    // weapons treu or fales (on / off)
    switch (eWep[0] == 1)
    case 1: ewDmg[0] = (rand()%30)+10;
    switch (eWep[1] == 1)
    case 1: ewDmg[1] = (rand()%20)+7;
    switch (eWep[2] == 1)
    case 1: ewDmg[2] = (rand()%14)+4;
    switch (eWep[3] == 1)
    case 1: ewDmg[3] = (rand()%14)+4;
    switch (eWep[4] == 1)
    case 1: ewDmg[4] = (rand()%19)+5;
    switch (eWep[5] == 1)
    case 1: ewDmg[5] = (rand()%30)+10;
    switch (eWep[6] == 1)
    case 1: ewDmg[6] = (rand()%30)+10;
    
    // User input of weapon number
    cout << "Please enter the number of the weapon you would like to use" << endl;
    cin >> wepNumber;
    cout << endl; 
    
    // checks witch number is entered by user and run code
    wepcheck:
    if (wepNumber == 0 && weapons[0] == 1){
    	npcHp = npcHp - wDmg[0];
    	weapons[0] = 0;
    	if (npcHp < 0){
    		npcHp = 0;
    	}
    	cout << "Enemy lost : " << wDmg[0] << " health and has : " << npcHp << " remaining" << endl;
    }
    else if (wepNumber == 1 && weapons[1] == 1) {
    	npcHp = npcHp - wDmg[1];
    	weapons[1] = 0;
    	if (npcHp < 0){
    		npcHp = 0;
    	}
    	cout << "Enemy lost : " << wDmg[1] << " health and has : " << npcHp << " remaining" << endl;
    }
    else if (wepNumber == 2 && weapons[2] == 1) {
    	npcHp = npcHp - wDmg[2];
    	weapons[2] = 0;
    	if (npcHp < 0){
    		npcHp = 0;
    	}
    	cout << "Enemy lost : " << wDmg[2] << " health and has : " << npcHp << " remaining" << endl;
    }
    else if (wepNumber == 3 && weapons[3] == 1) {
    	npcHp = npcHp - wDmg[3];
    	weapons[3] = 0;
    	if (npcHp < 0){
    		npcHp = 0;
    	}
    	cout << "Enemy lost : " << wDmg[3] << " health and has : " << npcHp << " remaining" << endl;
    }
    else if (wepNumber == 4 && weapons[4] == 1) {
    	npcHp = npcHp - wDmg[4];
    	weapons[4] = 0;
    	if (npcHp < 0){
    		npcHp = 0;
    	}
    	cout << "Enemy lost : " << wDmg[4] << " health and has : " << npcHp << " remaining" << endl;
    }
    else if (wepNumber == 5 && weapons[5] == 1) {
    	npcHp = npcHp - wDmg[5];
    	weapons[5] = 0;
    	if (npcHp < 0){
    		npcHp = 0;
    	}
    	cout << "Enemy lost : " << wDmg[5] << " health and has : " << npcHp << " remaining" << endl;
    }
    else if (wepNumber == 6 && weapons[6] == 1) {
    	npcHp = npcHp - wDmg[6];
    	weapons[6] = 0;
    	if (npcHp < 0){
    		npcHp = 0;
    	}
    	cout << "Enemy lost : " << wDmg[6] << " health and has : " << npcHp << " remaining" << endl;
    }
    else { // if a wrong number has been entered by the user
    	wepNumber = 0;
    	cout << "Wrong Number Please try again" << endl;
    	cin >> wepNumber;
    	cout << endl;
    	goto wepcheck;
    }
    
    // check if npc has 0 hp
    // check if user stil have a weapon left to use
    if (npcHp <= 0){ 
    	cout << "You Win" << endl << endl;
    	goto endgame;
    }
    else if (weapons[0] == 0 && weapons[1] == 0 && weapons[2] == 0 && weapons[3] == 0 && weapons[4] == 0 && weapons[5] == 0 && weapons[6] == 0){ 
    	cout <<"Draw Game" << endl <<endl;
    	goto endgame;
    }
    else {
    	// end of line
    	cout << endl;
    	cout << "Enemy's turn to atack" << endl << endl;
    	system("COLOR 4F");
    	system("PAUSE");
    	cout << endl;
    	// enemy atack
    	if (wepNumber == 0 && eWep[0] == 1) {
    		playerHp = playerHp - ewDmg[6];
    		eWep[0] = 0;
    		if (playerHp < 0){
    		playerHp = 0;
    	}
    		cout << "You lost : " << ewDmg[0] << " health and have : " << playerHp << " health left" << endl;
    	}
    	else if (wepNumber == 1 && eWep[1] == 1) {
    		playerHp = playerHp - ewDmg[1];
    		eWep[1] = 0;
    		if (playerHp < 0){
    		playerHp = 0;
    	}
    		cout << "You lost : " << ewDmg[1]<< " health and have : " << playerHp << " health left" << endl;
    	}
    	else if (wepNumber == 2 && eWep[2] == 1) {
    		playerHp = playerHp - ewDmg[2];
    		eWep[1] = 0;
    		if (playerHp < 0){
    		playerHp = 0;
    	}
    		cout << "You lost : " << ewDmg[2]<< " health and have : " << playerHp << " health left" << endl;
    	}
    	else if (wepNumber == 3 && eWep[3] == 1) {
    		playerHp = playerHp - ewDmg[3];
    		eWep[1] = 0;
    		if (playerHp < 0){
    		playerHp = 0;
    	}
    		cout << "You lost : " << ewDmg[3]<< " health and have : " << playerHp << " health left" << endl;
    	}
    	else if (wepNumber == 4 && eWep[4] == 1) {
    		playerHp = playerHp - ewDmg[4];
    		eWep[1] = 0;
    		if (playerHp < 0){
    		playerHp = 0;
    	}
    		cout << "You lost : " << ewDmg[4]<< " health and have : " << playerHp << " health left" << endl;
    	}
    	else if (wepNumber == 5 && eWep[5] == 1) {
    		playerHp = playerHp - ewDmg[5];
    		eWep[1] = 0;
    		if (playerHp < 0){
    		playerHp = 0;
    	}
    		cout << "You lost : " << ewDmg[5]<< " health and have : " << playerHp << " health left" << endl;
    	}
    	else if(wepNumber == 6 && eWep[6] == 1) {
    		playerHp = playerHp - ewDmg[6];
    		eWep[1] = 0;
    		if (playerHp < 0){
    		playerHp = 0;
    	}
    		cout << "You lost : " << ewDmg[6]<< " health and have : " << playerHp << " health left" << endl;
    	}
    }
    // end of line
    system("COLOR 1F");
    cout << endl;
    
    // Freeze console til key is entered 
    system("PAUSE");
    
    // check if the player's hp is 0
    if ( playerHp <= 0){
    	cout << "you lose" << endl;
    	goto endgame;
    }
    else {
    	goto startgame;
    }
    // endgame
    endgame:
    
    cout << "Would you like to play again? (Y/N)" << endl;
    selectexit:
    cin >> alp;
    
    if (alp == 'y') {
    	system("CLS");
    	goto newgame;
    }
    else if ( alp == 'Y'){
    	system("CLS");
    	goto newgame;
    }
    else if ( alp == 'n'){
    	system("CLS");
    	goto lastline;
    }
    else if ( alp == 'N'){
    	system("CLS");
    	goto lastline;
    }
    else {
    cout << "Wrong char type y or n" << endl;
    	goto selectexit;
    }
    
    
    //exit game
    lastline:
    // Freeze console til key is entered 
    // needs to be removed when script is completed
    //cout << endl;
    //system("PAUSE");
    return(0);
    }

    i think im goign to remake it from the ground up again if i watched the
    other vids of c++ i still need to see^^
    Last edited by shadow-xx; 26-12-08 at 10:20 PM.

  10. #10
    Account Upgraded | Title Enabled! passie is offline
    MemberRank
    Jan 2005 Join Date
    The NetherlandsLocation
    710Posts

    Re: [Game]Console War

    maybe you should add level like
    easy hp 75
    normal hp 100
    hard hp 150
    hope it give you new idea !

    greetz passie

  11. #11
    Gamma Daevius is offline
    MemberRank
    Jun 2007 Join Date
    NetherlandsLocation
    3,252Posts

    Re: [Game]Console War

    I think for easy you would need 150 hp and for hard 75 hp...lol. Else you have less chance to die in hard than in easy ^^

  12. #12
    Account Upgraded | Title Enabled! shadow-xx is offline
    MemberRank
    Jan 2007 Join Date
    MegatonLocation
    804Posts

    Re: [Game]Console War

    already working on a complete new one less messy

    only need to find some way of generating a number
    between 0 and 6 to make the enemy select a random weapon
    instead of the same one the user selects^^

  13. #13
    Gamma Daevius is offline
    MemberRank
    Jun 2007 Join Date
    NetherlandsLocation
    3,252Posts

    Re: [Game]Console War

    Code:
    srand(time(0));
    
    cout << (rand()%6) << endl;

  14. #14
    Account Upgraded | Title Enabled! shadow-xx is offline
    MemberRank
    Jan 2007 Join Date
    MegatonLocation
    804Posts

    Re: [Game]Console War

    srand(time(0));
    sets random to generate a number based on time with a minimum of 0?


    cout << (rand()%6) << endl;
    outputs the other line with a max of 6?


    sry i ask loads of questions
    just want to know what they do instead of copy and paste
    from copy and paste i wil learn nothing:P

  15. #15
    Gamma Daevius is offline
    MemberRank
    Jun 2007 Join Date
    NetherlandsLocation
    3,252Posts

    Re: [Game]Console War

    Quote Originally Posted by shadow-xx View Post
    srand(time(0));
    sets random to generate a number based on time with a minimum of 0?


    cout << (rand()%6) << endl;
    outputs the other line with a max of 6?


    sry i ask loads of questions
    just want to know what they do instead of copy and paste
    from copy and paste i wil learn nothing:P
    Ah yes, sorry :). Good point, I thought you knew how it worked:

    srand(); will set the seed for random numbers. We will base it on the time the application is running.

    rand(); gets a random number, it could be anything (you can get the max number, but I forgot how...RAND_MAX or something).

    The % operator is quite nice. It substracts the last number from the first one as long as the first number is not lower than the last one.

    12%6 = 0 because 12 - 6 = 6, 6 - 6 = 0

    13%6 = 1 because 13 - 6 = 7, 7 - 6 = 1 and is lower than 6

    17%9 = 8 because 17 - 9 = 8 ;)

    You get it? :)

    So the output is always lower than the second value (after the % symbol).
    rand()%6 will give you a random number from 0 to 5 ;).



Page 1 of 2 12 LastLast

Advertisement