user input from keyboard

Ok so I am making this super mega crapy game, far from Gears or halo, but you have to start somewhere. I am trying to get input from the player and then see what key was pushed either x v or s and this will determine the attack type and minus this from the health of the really stupid bot that I made.
I am haveing problems with geting the input from the user and also geting the attack to subtrack from the enemy health points.
I worked with number input like 1 2 and 3 and that worked but did not damage the enemy health at all so there is also something wrong there too.
Thanks for any help


here is the code for one of the best games of E3 this year :)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "stdafx.h"
#include <iostream>
#include <string>
#include <windows.h>

using namespace System;
using namespace std;




//good guy ie player
class Player
{
public:
	int hp;
	int sp;
	int mp;
		
};

class Bot
{
public:
	int hp; //hit points for emeny
	int atk; //damage to player health
};

void atkTimer(){
	cout << "Player attacked please wait" << endl;
	//time guage for attack bar player cannot attck for 5 seconds
	Sleep(5000); //this is in milliseconds
}


	
int main()
{
	//attack related items and skills
	//attack bar
	 bool atb = true; //if false then player cannot attack 
	
	//amount of damage is abitray
	 int slash = 10;         //players pushs x does 10 in damage
	 int flameSlash = 20;    //player pushs s does 20 in damage
	 int shiningStrike = 30; //player pushs v does 30 in damage

	//skill wheel does x in damage
	 int powerDive = 15;
	 int powerCharge = 25;
	 int wildStrike = 35;
	 int renegade = 40;
	 int ShiningStars = 50;  
	
	//build player
	Player Maverick;
	Maverick.hp = 1220;
	Maverick.mp = 220;
	Maverick.sp = 100;
	//build bot
	Bot ninja;
	ninja.hp = 500;
	ninja.atk = 20;

	//print off player data
	cout << "Maverick" << endl;
	cout << "Health " << Maverick.hp <<endl;
	cout << "Magic " << Maverick.mp <<endl;
	cout << "Skill " << Maverick.sp <<endl;
	cout <<endl;

	//print off ninja
	cout << "Enemy Ninja Health " << ninja.hp <<endl;
	
	//player battle starts
	while(ninja.hp > 0) //fight until ninja dies
	{
		cout << "Attack!" << endl;
		char button; //input for button pressed
		cin >> button;
		//input is either x v or s on key board.
		if(button == x)
		{
			ninja.hp - slash;
		}else if(button == v)
		{
			ninja.hp - flameSlash;
		
		}else if(button == s)
		{
			ninja.hp - shiningStrike;
		
		}
		
			
		cout << "Enemy Ninja Health " << ninja.hp <<endl;
		atb = false;
		//ninja stricks like the flu
		Maverick.hp - ninja.atk;

		atkTimer();
		atb = true; //player can attack now

	
	}//end of while




    return 0;
}
You aren't assigning the remaining hp for the ninja back into the ninja's hp.

And you didn't make x,v or s a character literal. So, it was thinking x,v and s were variables.

1
2
3
4
5
6
7
8
9
10
11
12
if(button == 'x')
		{
			ninja.hp -= slash;
		}else if(button == 'v')
		{
			ninja.hp -= flameSlash;
		
		}else if(button == 's')
		{
			ninja.hp -= shiningStrike;
		
		}


Also, according to the notes on what the different attacks do, you have s and v mixed up.
Last edited on
Yeah, like oghma said - it's a good practice to remember that char literals should have single apostrophes surrounding it :)
Just curious from a design point of view is there a reason you went with sleep? Instead of turn based or some other mechanic for example?

Also as practice why don't you throw something in for invalid options? You did really good if this is your first "game".
Last edited on
Thank you oghma that fixed it just right. I see now that the code was treating it like a variable with out the little '' thingys around it.

For the design Computer i went with the sleep becuase I am thinking of having a realtime stratigy type attack method with player stamina in the later codeing so I can adjust the rate of attack based on the power of the attack and the players stamina. Something different than the standard Final Fantisy game tactics.

Soon I will have much more to this little dos game type very soon. Maybe even images when I get there :(
Topic archived. No new replies allowed.