Need Help With Programming a Game

Questions regarding game mechanics and graphic programming should go here.

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

Need Help With Programming a Game

Postby abshelt » Fri Feb 29, 2008 10:01 pm

I have been trying to make a snowball fight game but cant seem to get it to work. I want for it to be a two player game without graphics, that player one picks where to aim and where to block then the screen clears and player two picks where they want to aim and block. Then I want it to display what each player selected and give the stats on that player. Until one of them is frozen. (They would be frozen after being hit 5 times.) Then I want for them to be asked if they'd like to play again. If someone could help that would be great! I just can't seem to get the code right!
abshelt
 
Posts: 3
Joined: Fri Feb 29, 2008 9:46 pm

Postby MXP » Sat Mar 01, 2008 2:59 am

What problems are you encountering?
Need information on a function I've posted? Chances are it's at the MSDN.
MXP
 
Posts: 6506
Joined: Mon Sep 22, 2003 5:27 pm

Postby abshelt » Sat Mar 01, 2008 4:16 pm

I have been having problems with figuring out what code to use to make it count down when one person is hit. I have it working up until the point of where it is supposed to display who was hit and/or who blocked the shots. Everything I have tried doesn't seem to work. I don't know what to do to get it to count down the number of times each player is hit and display what the players status is. I want them to each start out at 5 and each hit takes away one and displays their status as like 5 dry 4 damp 3 soggy 2 wet 1 drenched and 0 frozen. But once one of them hits 0 frozen for it to then display game over would you like to play again?.
abshelt
 
Posts: 3
Joined: Fri Feb 29, 2008 9:46 pm

Postby MXP » Sat Mar 01, 2008 4:29 pm

What have you tried so far? Can you show us some code?
Need information on a function I've posted? Chances are it's at the MSDN.
MXP
 
Posts: 6506
Joined: Mon Sep 22, 2003 5:27 pm

Postby abshelt » Sat Mar 01, 2008 10:31 pm

Code: Select all


#include<iostream>
#include<cmath>
using namespace std;



int main()
{
   int factor1, factor2;
   char status1, status2, aim1, aim2, block1, block2, m, M, L, l, H, h;

   cout << "Welcome to the Snowball Fight Game!\n\n\n";
   cout << "The game is about to begin.";
   cout << endl << endl << "Player one is " << factor1 << status1 << endl;
   cout << "Player two is " << factor2 << status2 << endl;
   
   cout << endl << endl << endl << "Player 1 please choose where you will aim:\n"
      << "(H for high, M for middle, or L for low)\n";
   cin >> aim1;   
   cout << endl << "Player 1 please choose where you will block:\n"
      <<"(H for high, M for middle, or L for low)\n";
   cin >> block1;
   system("cls");

   cout << "Player 2 please choose where you will aim :\n"
      << "(H for high, M for middle, or L for low)\n";
   cin >> aim2;
   cout << endl << "Player 2 please choose where you will block:\n"
      <<"(H for high, M for middle, or L for low)\n";
   cin >> block2;
   system("cls");
   
   while (block2 != H || block2 != h || block2 != l || block2 != L || block2 != M || block2 != m)
   {
      cout << "Your entry is invalid!";
      cout << endl << "Player 2 please choose where you will block:\n"
      <<"(H for high, M for middle, or L for low)\n";
   cin >> block2;
   }
   cout << endl << "Player 1 chose to aim " << aim1 << " and chose to block " << block1 << "!"
   << endl << "Player 2 chose to aim " << aim2   << " and chose to block " << block2 << "!";
}
abshelt
 
Posts: 3
Joined: Fri Feb 29, 2008 9:46 pm

Postby Wizard » Mon Mar 03, 2008 6:53 am

Several problems, but we'll start with this one:
while (block2 != H || block2 != h || block2 != l || block2 != L || block2 != M || block2 != m)
you've declared H, h, l, L, M, and m as variables. Variables are just names in program and probably don't mean what you want them to. To compare against the actual character, put it in single quotes, like this:
while (block2 != 'H' || block2 != 'h' || block2 != 'l' || block2 != 'L' || block2 != 'M' || block2 != 'm')
Now, instead of asking the compiler if the two variables block2 and H are the same (which they probably aren't since you never tell it what H is) you're asking it if block2 is the character 'H' or not.
You can then get rid of the H, h, L, l, M, and m variables that you declared.
User avatar
Wizard
Site Admin
 
Posts: 3226
Joined: Mon Sep 22, 2003 4:52 pm
Location: ON, CA


Return to Games and Graphics

Who is online

Users browsing this forum: No registered users and 2 guests