Quick Search for:  in language:    
Simulates,game,must,wipeout,enemy,before,they
   Code/Articles  |  Newest/Best  |  Community  |  Jobs  |  Other  |  Goto  | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
C/ C++ Stats

 Code: 728,035. lines
 Jobs: 116. postings

 How to support the site

 
Sponsored by:

 
You are in:
 
Login





Latest Code Ticker for C/ C++.
socket
By Muhammad Ahmed Siddiqui on 3/6


Click here to see a screenshot of this code!Flexible Screen Designer Classes
By John Indigo on 3/6

(Screen Shot)

Click here to see a screenshot of this code!Basic 2D Transformation with Simulation
By Siva Chandran.P on 3/6

(Screen Shot)

Message Digest (LINUX) 1.0
By Vikram Shinde on 3/6


Windows Application with modified Message Loop
By Rockwell on 3/5


Inheritance of CBox
By Rockwell on 3/5


Click here to see a screenshot of this code!Awesome Screen Shot System For OpenGL And Direct3D
By James Dougherty on 3/5

(Screen Shot)

Process Killer
By Ruud Koolen on 3/5


Click here to see a screenshot of this code!Get The PIII Processor Serial Number Like Intel Format
By haitham hamed housin on 3/5

(Screen Shot)

Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites



 
 
   

Space Attack

Print
Email
 
VB icon
Submitted on: 2/16/2004 10:22:20 PM
By: Daniel Bjorndahl  
Level: Beginner
User Rating: Unrated
Compatibility:C++ (general)

Users have accessed this code 303 times.
 
 
     Simulates a war game. You must wipe-out the enemy before they wipe-out you...
 

INCLUDE files:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!

//**************************************
//     
//INCLUDE files for :Space Attack
//**************************************
//     
N/A
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

//**************************************
//     
// Name: Space Attack
// Description:Simulates a war game. You
//     must wipe-out the enemy before they wipe
//     -out you...
// By: Daniel Bjorndahl
//
// Inputs:Integers.
//
// Returns:N/A
//
// Assumes:It's boring
(my first game)
//
// Side Effects:If you enter a character
//     instead of a number, it goes bizerk, for
//     tunateyl it doesn't mess up any files or
//     anything, and is easy to recover from.
//
//This code is copyrighted and has// limited warranties.Please see http://
//     www.Planet-Source-Code.com/vb/scripts/Sh
//     owCode.asp?txtCodeId=7627&lngWId;=3//for details.//**************************************
//     

//--------------------------------------
//     ------------------------------|
// This program is property of Daniel Bj
//     orndahl, and no one else...
// ...unless he says so...
// So, please, don't steal my code
//--------------------------------------
//     ------------------------------|
#include <iostream>
using namespace std;
int attack_defend = 0;
int damage = 0;
int p_buildings = 100;//player buildings
int e_buildings = 100;//A.I. buildings
int random_ai_choice();//how the A.I. chooses moves/first loop of program
int attack_menu();//options for attack
int attack_menu2();
int defend_menu2();
int defend_menu();//options for defense
int main2();//main loop of program is actually here
int main3();
int main()
    {
    random_ai_choice();
    while(1 < 2)
        {
        main2();
        if(p_buildings < 1)
            {
            cout << "You lose!!!" << endl;
            cout << e_buildings << " to " << p_buildings << endl;
            system("PAUSE");
            return 0;
        }

if(e_buildings < 1) { cout << "You win!!!" << endl; cout << p_buildings << " to " << e_buildings << endl; system("PAUSE"); return 0; }
main3(); if(p_buildings < 1) { cout << "You lose!!!" << endl; system("PAUSE"); return 0; }
if(e_buildings < 1) { cout << "You win!!!" << endl; system("PAUSE"); return 0; }
}
if(p_buildings > e_buildings) { cout << "You win!!!" << endl; system("PAUSE"); }
if(p_buildings < e_buildings) { cout << "You lose!!!" << endl; system("PAUSE"); }
return 0; }
int random_ai_choice() { char buffer[3]; int i, r, temp; int nums[100]; srand(time(NULL)); for(i = 1; i < 100; i++) nums[i] = i; for(i = 1; i < 10; i++) { r = (rand() % 9) + 1; temp = nums[i]; nums[i] = nums[r]; nums[r] = temp; }
if(nums[1] > 5) { cout << "\nYou have the opportunity to attack\n" << endl; int choice = attack_menu(); if(choice == 1)//human choice { if(nums[2] > 5)//the random computer choice { damage = 0; e_buildings = e_buildings - damage; cout << damage << " enemy buildings destroyed" << endl; cout << "Enemy's new building count: " << e_buildings << endl; return e_buildings; main3(); }
if(nums[2] < 6)//the random computer choice { damage = 20; e_buildings = e_buildings - damage; cout << damage << " enemy buildings destroyed" << endl; cout << "Enemy's new building count: " << e_buildings << endl; return e_buildings; main3(); }
}
if(choice == 2) { if(nums[2] > 5)//the random computer choice { damage = 5; e_buildings = e_buildings - damage; cout << damage << " enemy buildings destroyed" << endl; cout << "Enemy's new building count: " << e_buildings << endl; return e_buildings; main3(); }
if(nums[2] < 6)//the random computer choice { damage = 10; e_buildings = e_buildings - damage; cout << damage << " enemy buildings destroyed" << endl; cout << "Enemy's new building count: " << e_buildings << endl; return e_buildings; main3(); }
}
if(choice == 3) { if(nums[2] > 5)//the random computer choice { damage = 2; e_buildings = e_buildings - damage; cout << damage << " enemy buildings destroyed" << endl; cout << "Enemy's new building count: " << e_buildings << endl; return e_buildings; main3(); }
if(nums[2] < 6)//the random computer choice { damage = 12; e_buildings = e_buildings - damage; cout << damage << " enemy buildings destroyed" << endl; cout << "Enemy's new building count: " << e_buildings << endl; return e_buildings; main3(); }
}
if(choice == 4) { if(nums[2] > 5)//the random computer choice { damage = 5; e_buildings = e_buildings - damage; cout << damage << " enemy buildings destroyed" << endl; cout << "Enemy's new building count: " << e_buildings << endl; return e_buildings; main3(); }
if(nums[2] < 6)//the random computer choice { damage = 5; e_buildings = e_buildings - damage; cout << damage << " enemy buildings destroyed" << endl; cout << "Enemy's new building count: " << e_buildings << endl; return e_buildings; main3(); }
}
}
if(nums[1] < 6) { cout << "\nYou must defend your planet\n" << endl; int choice = defend_menu(); if(choice == 1)//human choice { if(nums[2] > 8)//the random computer choice { damage = 2; p_buildings = p_buildings - damage; cout << damage << " of your buildings destroyed" << endl; cout << "Player's new building count: " << p_buildings << endl; return p_buildings; main2(); }
if(2 < nums[3] < 6)//the random computer choice { damage = 0; p_buildings = p_buildings - damage; cout << damage << " of your buildings destroyed" << endl; cout << "Player's new building count: " << p_buildings << endl; return p_buildings; main2(); }
if(nums[3] < 3)//the random computer choice { damage = 5; p_buildings = p_buildings - damage; cout << damage << " of your buildings destroyed" << endl; cout << "Player's new building count: " << p_buildings << endl; return p_buildings; main2(); }
if(9 > nums[3] > 5)//the random computer choice { damage = 10; p_buildings = p_buildings - damage; cout << damage << " of your buildings destroyed" << endl; cout << "Player's new building count: " << p_buildings << endl; return p_buildings; main2(); }
}
if(choice == 2) { if(nums[2] > 5)//the random computer choice { damage = 2; p_buildings = p_buildings - damage; cout << damage << " of your buildings destroyed" << endl; cout << "Player's new building count: " << p_buildings << endl; return p_buildings; main2(); }
if(nums[2] < 6)//the random computer choice { damage = 12; p_buildings = p_buildings - damage; cout << damage << " of your buildings destroyed" << endl; cout << "Player's new building count: " << p_buildings << endl; return p_buildings; main2(); }
if(nums[2] > 5)//the random computer choice { damage = 5; p_buildings = p_buildings - damage; cout << damage << " of your buildings destroyed" << endl; cout << "Player's new building count: " << p_buildings << endl; return p_buildings; main2(); }
if(nums[2] < 6)//the random computer choice { damage = 5; p_buildings = p_buildings - damage; cout << damage << " of your buildings destroyed" << endl; cout << "Player's new building count: " << p_buildings << endl; return p_buildings; main2(); }
}
}
}
int attack_menu() { int choice; cout << "\nEnter 1 to use the \"Alpha Fighter\"" << endl; cout << "Enter 2 to use the \"Beta Fighter\"" << endl; cout << "Or\nSend missles in to do the work" << endl; cout << "Enter 3 to use the Alpha \"Atom\" missle" << endl; cout << "Enter 4 to use the Beta Bomb" << endl; cin >> choice; if(choice == 2) { cout << "\nPicture of the Beta Fighter\n\n"; cout << "/\\" << endl; cout << " /-:::\\" << endl; cout << " \\-::: \\" << endl; cout << "+--->" << endl; cout << " /-::: /" << endl; cout << " \\-:::/" << endl; cout << "\\/" << endl << endl; }
if(choice == 1) { cout << "\nPicture of the Alpha Fighter\n\n"; cout << " <:--+" << endl; cout << "+" << endl; cout << " ++++-\\" << endl; cout << " ++++-/" << endl; cout << "+" << endl; cout << " <:--+" << endl << endl; }
if(choice == 3) { cout << "\nPicture of the Alpha \"Atom\" missle" << endl; cout << " !" << endl; cout << " (:)" << endl; cout << " ^^^" << endl; }
if(choice == 4) { cout << "\nPicture of the Beta Bomb" << endl; cout << ":" << endl; cout << "/:\\" << endl; cout << " --+--" << endl; cout << "/ \\" << endl; cout << " /\\" << endl; }
return choice; }
int attack_menu2() { int choice; cout << "\nEnter 1 to use the \"Alpha Fighter\"" << endl; cout << "Enter 2 to use the \"Beta Fighter\"" << endl; cout << "Or\nSend missles in to do the work" << endl; cout << "Enter 3 to use the Alpha \"Atom\" missle" << endl; cout << "Enter 4 to use the Beta Bomb" << endl; cin >> choice; if(choice == 2) { cout << "\nPicture of the Beta Fighter\n\n"; cout << "/\\" << endl; cout << " /-:::\\" << endl; cout << " \\-::: \\" << endl; cout << "+--->" << endl; cout << " /-::: /" << endl; cout << " \\-:::/" << endl; cout << "\\/" << endl << endl; }
if(choice == 1) { cout << "\nPicture of the Alpha Fighter\n\n"; cout << " <:--+" << endl; cout << "+" << endl; cout << " ++++-\\" << endl; cout << " ++++-/" << endl; cout << "+" << endl; cout << " <:--+" << endl << endl; }
if(choice == 3) { cout << "\nPicture of the Alpha \"Atom\" missle" << endl; cout << " !" << endl; cout << " (:)" << endl; cout << " ^^^" << endl; }
if(choice == 4) { cout << "\nPicture of the Beta Bomb" << endl; cout << ":" << endl; cout << "/:\\" << endl; cout << " --+--" << endl; cout << "/ \\" << endl; cout << " /\\" << endl; }
return choice; }
int defend_menu() { int choice; cout << "\nEnter 1 to defend your base with the Foxtrot \"Falcon\" missle\n"; cout << "Enter 2 to defend your base with the Epsilon \"Eagle\" missle\n"; cin >> choice; if(choice == 1) { cout << "\nPicture of the Foxtrot \"Falcon\" missle" << endl; cout << " :" << endl; cout << " :" << endl; cout << " /:\\" << endl; }
if(choice == 2) { cout << "\nPicture of the Epsilon \"Eagle\" missle" << endl; cout << " ^" << endl; cout << " <:>" << endl; cout << " :" << endl; cout << " ^" << endl; }
return choice; }
int defend_menu2() { int choice; cout << "\nEnter 1 to defend your base with the Foxtrot \"Falcon\" missle\n"; cout << "Enter 2 to defend your base with the Epsilon \"Eagle\" missle\n"; cin >> choice; if(choice == 1) { cout << "\nPicture of the Foxtrot \"Falcon\" missle" << endl; cout << " :" << endl; cout << " :" << endl; cout << " /:\\" << endl; }
if(choice == 2) { cout << "\nPicture of the Epsilon \"Eagle\" missle" << endl; cout << " ^" << endl; cout << " <:>" << endl; cout << " :" << endl; cout << " ^" << endl; }
return choice; }
int main2() { int changer = 0; char buffer[3]; int i, r, temp; int nums[100]; srand(time(NULL)); for(i = 1; i < 100; i++) nums[i] = i; for(i = 1; i < 10; i++) { r = (rand() % 9) + 1; temp = nums[i]; nums[i] = nums[r]; nums[r] = temp; }
changer++; cout << "\nYou have the opportunity to attack\n" << endl; int choice = attack_menu(); if(choice == 1)//human choice { if(nums[changer] > 5)//the random computer choice { damage = 0; e_buildings = e_buildings - damage; cout << damage << " enemy buildings destroyed" << endl; cout << "Enemy's new building count: " << e_buildings << endl; return e_buildings; }
if(nums[changer] < 6)//the random computer choice { damage = 20; e_buildings = e_buildings - damage; cout << damage << " enemy buildings destroyed" << endl; cout << "Enemy's new building count: " << e_buildings << endl; return e_buildings; }
}
if(choice == 2) { if(nums[changer] > 5)//the random computer choice { damage = 5; e_buildings = e_buildings - damage; cout << damage << " enemy buildings destroyed" << endl; cout << "Enemy's new building count: " << e_buildings << endl; return e_buildings; }
if(nums[changer] < 6)//the random computer choice { damage = 10; e_buildings = e_buildings - damage; cout << damage << " enemy buildings destroyed" << endl; cout << "Enemy's new building count: " << e_buildings << endl; return e_buildings; }
}
if(choice == 3) { if(nums[changer] > 5)//the random computer choice { damage = 2; e_buildings = e_buildings - damage; cout << damage << " enemy buildings destroyed" << endl; cout << "Enemy's new building count: " << e_buildings << endl; return e_buildings; }
if(nums[changer] < 6)//the random computer choice { damage = 12; e_buildings = e_buildings - damage; cout << damage << " enemy buildings destroyed" << endl; cout << "Enemy's new building count: " << e_buildings << endl; return e_buildings; }
}
if(choice == 4) { if(nums[changer] > 5)//the random computer choice { damage = 5; e_buildings = e_buildings - damage; cout << damage << " enemy buildings destroyed" << endl; cout << "Enemy's new building count: " << e_buildings << endl; return e_buildings; }
if(nums[changer] < 6)//the random computer choice { damage = 5; e_buildings = e_buildings - damage; cout << damage << " enemy buildings destroyed" << endl; cout << "Enemy's new building count: " << e_buildings << endl; return e_buildings; }
}
}
int main3() { int changer = 0; char buffer[3]; int i, r, temp; int nums[100]; srand(time(NULL)); for(i = 1; i < 100; i++) nums[i] = i; for(i = 1; i < 10; i++) { r = (rand() % 9) + 1; temp = nums[i]; nums[i] = nums[r]; nums[r] = temp; }
changer++; cout << "\nYou must defend your planet\n" << endl; int choice = defend_menu(); if(choice == 1)//human choice { if(nums[changer] > 8)//the random computer choice { damage = 2; p_buildings = p_buildings - damage; cout << damage << " of your buildings destroyed" << endl; cout << "Player's new building count: " << e_buildings << endl; return p_buildings; }
if(nums[changer] > 5)//the random computer choice { damage = 0; p_buildings = p_buildings - damage; cout << damage << " of your buildings destroyed" << endl; cout << "Player's new building count: " << p_buildings << endl; return p_buildings; }
if(nums[changer] > 2)//the random computer choice { damage = 5; p_buildings = p_buildings - damage; cout << damage << " of your buildings destroyed" << endl; cout << "Player's new building count: " << p_buildings << endl; return p_buildings; }
if(nums[changer] > 0)//the random computer choice { damage = 10; p_buildings = p_buildings - damage; cout << damage << " of your buildings destroyed" << endl; cout << "Player's new building count: " << p_buildings << endl; return p_buildings; }
}
if(choice == 2) { if(nums[changer] > 8)//the random computer choice { damage = 2; p_buildings = p_buildings - damage; cout << damage << " of your buildings destroyed" << endl; cout << "Player's new building count: " << p_buildings << endl; return p_buildings; }
if(nums[changer] > 5)//the random computer choice { damage = 12; p_buildings = p_buildings - damage; cout << damage << " of your buildings destroyed" << endl; cout << "Player's new building count: " << p_buildings << endl; return p_buildings; }
if(nums[changer] > 2)//the random computer choice { damage = 5; p_buildings = p_buildings - damage; cout << damage << " of your buildings destroyed" << endl; cout << "Player's new building count: " << p_buildings << endl; return p_buildings; }
if(nums[changer] < 0)//the random computer choice { damage = 5; p_buildings = p_buildings - damage; cout << damage << " of your buildings destroyed" << endl; cout << "Player's new building count: " << p_buildings << endl; return p_buildings; }
}
}

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments

 There are no comments on this submission.
 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | C/ C++ Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.