It is currently Fri May 31, 2024 6:17 am
DarkMortar wrote:If you copied and pasted this in notepad, you may be a nerd. If you just highlighted this, you may be intelligent. If you read this like it is, you may become blind.







if((action != 'A') || (action != 'a'))
&&((action != 'D') || (action !='d'))
&&((action != 'W') || (action != 'w'))
{
cout << endl
<< "Invalid input."
<< endl;
input();
}
if((action != 'A') && (action != 'a')
&&(action != 'D') && (action != 'd')
&&(action != 'W') && (action != 'w'))
{
cout << endl
<< "Invalid input."
<< endl;
input();
}

int timesTwo(int number) {
return number * 2;
}
int main()
{
// here the number is delcared.
int someNumberToBeMultiplied;
int newNumber;
... // other code here
// here the number is initialized.
cin >> someNumberToBeMultiplied;
// here the number is 'passed' in as a parameter.
newNumber = timesTwo(someNumberToBeMultiplied);
... // other code here
}
// Ett medival spel
#include <iostream>
#include <ctime>
#include <iomanip>
#include <cstdlib>
#include <time.h>
using namespace std;
void input();
void attack();
void defend();
void wait();
srand(time(0));
// The following variables are global. they are accessable by
// any method including main. in this case however, main
// does not need to access these.
// Allied Starting Forces
int FootSoldiers = 500;
int HorseMen = 100;
int Cannons = 50;
int Citizen = 400;
// Enemy Starting Forces
int EneSold = 1000;
int EneHors = 500;
int EneCans = 100;
// Allied Killing Dices
int SoldDice = rand() % 250; // Dice for allied soldiers dying
int HorsDice = rand() % 50; // Allied Horse Men diying
int CanDice = rand() % 5; // Allied Cannon destroyed
// Gold Dices
int GoldDice = rand() % 20000;
int GoldDiceDefend = rand() % 2000;
int SpyGoldDice = rand() % 200000;
int WaitGold = rand() % 20000;
// Enemy Killing Dices
int KillDiceSold = rand() % 400;
int KillDiceHors = rand() % 200;
int KillDiceCan = rand() % 50;
int main()
{
cout << endl
<< "Hi and welcome to this Medival Game." << endl
<< "You will be starting with 500 Footsoldiers, 100 Horse Men, 50 Cannons," << endl
<< "400 citizens and 1000 gold." << endl
<< "Throughout the game you can take the following actions:" << endl
<< endl << endl //Give some space
<< "Attack:" << endl
<< "Attack your enemy to steal gold and capture prisoners." << endl << endl << endl //More space
<< "Defend:" << endl
<< "Defend your castle and send out spy's." << endl << endl << endl
<< "Wait:" << endl
<< "Wait for your citizens to train and join ur army, but be carefull you will be -" << endl
<< "vurnable against attacks."
<< endl;
input();
return 0;
}
//***************************************************************
// input()
// the method that gets called when input is needed.
//***************************************************************
void input()
{
cout << endl
<< "What would u like to do next?" << endl
<< "A = Attack." << endl
<< "D = Defend." << endl
<< "W = Wait." << endl
<< "Q = Quit." << endl
<< endl;
cin >> action2;
if((action != 'A') && (action != 'a') &&
(action != 'D') && (action != 'd') &&
(action != 'W') && (action != 'w') &&
(action != 'Q') && (action != 'q'))
{
cout << endl << "The input was invalid. Please try again.";
input();
}
if((action2 == 'A') || (action2 == 'a'))
{
attack();
}
if((action2 == 'D') || (action2 == 'd'))
{
defend();
}
if((action2 == 'W') || (action2 == 'w'))
{
wait();
}
else
{
return 0;
}
}
//***************************************************************
// attack()
// the method that gets called when the player chooses to attack.
//***************************************************************
void attack()
{
srand(time(0)); // Initialize random number generator.
int SoldDice = rand() % 250; // Dice for allied soldiers dying
int HorsDice = rand() % 50; // Allied Horse Men diying
int CanDice = rand() % 5; // Allied Cannon destroyed
int GoldDice = rand() % 20000; // Gold Gained
int KillDiceSold = rand() % 500; // Enemy Soldiers Killed
int KillDiceHors = rand() % 100; // Enemy Horse Men killed
int KillDiceCan = rand() % 20; // Enemy Cannons Destoyed
cout << endl
<< "Your army attacks the enemy." << endl << endl
<< "===============================================================================" << endl
<< "You loose: " << SoldDice << " Footsoldiers, " << HorsDice << " Horse Men and " << CanDice << " Cannons." << endl
<< "===============================================================================" << endl
<< endl
<< endl
<< "===============================================================================" << endl
<< "You gained: "<< GoldDice << " gold from the enemy." << endl
<< "===============================================================================" << endl
<< "You killed: " << KillDiceSold << " enemy Footsoldiers, " << KillDiceHors << " enemy Horse Men and " << KillDiceCan << " enemy Cannons" << endl
<< "===============================================================================" << endl
<< endl; // To make some space
int NewSold = FootSoldiers - SoldDice;
int NewHorse = HorseMen - HorsDice;
int NewCan = Cannons - CanDice;
int NewGold = Gold + GoldDice;
cout << endl
<< "===============================================================================" << endl
<< "Now you've got " << NewSold << " Footsoldiers, " << NewHorse << " Horse Men and " << NewCan << " Cannons." << endl
<< "===============================================================================" << endl
<< "Now you've got " << NewGold << " coins of gold." << endl
<< "==============================================================================="
<< endl;
input();
}
//***************************************************************
// wait()
// the method that gets called when the player chooses to wait.
//***************************************************************
void wait()
{
srand(time(0)); // Initialize random number generator.
int SoldDice = rand() % 50; // Dice for allied soldiers dying
int HorsDice = rand() % 10; // Allied Horse Men diying
int CanDice = rand() % 10; // Allied Cannon destroyed
int GoldDice = rand() % 20000; // Gold Gained
int KillDiceSold = rand() % 10; // Enemy Soldiers Killed
int KillDiceHors = rand() % 5; // Enemy Horse Men killed
int KillDiceCan = rand() % 1; // Enemy Cannons Destoyed
cout << endl
<< "Your army waits for recruits." << endl
<< "===============================================================================" << endl
<< "You loose: " << endl
<< SoldDice << " Footsoldiers, " << endl
<< HorsDice << " Horse Men and " << endl
<< CanDice << " Cannons." << endl
<< "===============================================================================" << endl
<< endl
<< "===============================================================================" << endl
<< "You gained: "<< GoldDice << " gold from different taxes." << endl
<< "===============================================================================" << endl
<< "You killed: " << KillDiceSold << " enemy Footsoldiers, " << KillDiceHors << " enemy Horse Men and " << KillDiceCan << " enemy Cannons" << endl
<< "==============================================================================="
<< endl; // To make some space
int NewSold = FootSoldiers - SoldDice;
int NewHorse = HorseMen - HorsDice;
int NewCan = Cannons - CanDice;
int NewGold = Gold + GoldDice;
cout << endl
<< "===============================================================================" << endl
<< "Now you've got " << NewSold << " Footsoldiers, " << NewHorse << " Horse Men and " << NewCan << " Cannons." << endl
<< "===============================================================================" << endl
<< "Now you've got " << NewGold << " coins of gold." << endl
<< "==============================================================================="
<< endl;
input();
}
//***************************************************************
// defend()
// the method that gets called when the player chooses to defend.
//***************************************************************
void defend()
{
srand(time(0)); // Initialize random number generator.
int SoldDice = rand() % 100; // Dice for allied soldiers dying
int HorsDice = rand() % 10; // Allied Horse Men diying
int CanDice = rand() % 10; // Allied Cannon destroyed
int GoldDice = rand() % 20000; // Gold Gained
int KillDiceSold = rand() % 750; // Enemy Soldiers Killed
int KillDiceHors = rand() % 200; // Enemy Horse Men killed
int KillDiceCan = rand() % 5; // Enemy Cannons Destoyed
cout << endl
<< "Your army defends the castle." << endl
<< "===============================================================================" << endl
<< "You loose: " << endl
<< SoldDice << " Footsoldiers, " << endl
<< HorsDice << " Horse Men and " << endl
<< CanDice << " Cannons." << endl
<< "===============================================================================" << endl
<< endl
<< "===============================================================================" << endl
<< "You gained: "<< GoldDice << " gold from the enemy." << endl
<< "===============================================================================" << endl
<< "You killed: " << KillDiceSold << " enemy Footsoldiers, " << KillDiceHors << " enemy Horse Men and " << KillDiceCan << " enemy Cannons" << endl
<< "==============================================================================="
<< endl; // To make some space
int NewSold = FootSoldiers - SoldDice;
int NewHorse = HorseMen - HorsDice;
int NewCan = Cannons - CanDice;
int NewGold = Gold + GoldDice;
cout << endl
<< "===============================================================================" << endl
<< "Now you've got " << NewSold << " Footsoldiers, " << NewHorse << " Horse Men and " << NewCan << " Cannons." << endl
<< "===============================================================================" << endl
<< "Now you've got " << NewGold << " coins of gold." << endl
<< "==============================================================================="
<< endl;
input();
}



jaddorii wrote:Hmm shouldn't all the methods return all the values of Soldiers killed, Gold gained etc. and store it in the main or something ?

longshanks wrote:BTW Why don't we have a programming forum on Interlopers? There are enough people here who understand this stuff.






Users browsing this forum: No registered users