You're checking if "toby" is true in the second statement. Duplicate the playerName ==
[editline]15th September 2011[/editline]
Ie. [cpp]if (playerName == "Toby" || playerName == "toby")[/cpp]
[QUOTE=esalaka;32292670]You're checking if "toby" is true in the second statement. Duplicate the playerName ==
[editline]15th September 2011[/editline]
Ie. [cpp]if (playerName == "Toby" || playerName == "toby")[/cpp][/QUOTE]
Oohhh, I feel dumb. Thank you though, I didn't catch that.
[QUOTE=Werem00se;32292930]Oohhh, I feel dumb. Thank you though, I didn't catch that.[/QUOTE]
Instead of doing two checks, you can do something such as this:
if( tolower(playerName) == "toby" )
This way, any capital letters will be switched to their lower-case so you don't have to worry about case-sensitivity.
[QUOTE=ief014;32293241]Instead of doing two checks, you can do something such as this:
if( tolower(playerName) == "toby" )
This way, any capital letters will be switched to their lower-case so you don't have to worry about case-sensitivity.[/QUOTE]
Oh wow, I never thought of applying toLower or toUpper like that. Thank you.
Could someone recommend me some software?
Sometimes when I code, something goes wrong, and I think "Oh fuck, what did I break this time?" and then after trying to fix it countless times: "I wish I could just go back to the version of my code where it wasn't broken yet ;_;"
I'm pretty sure there is something for that, but what?
Version control.
Before I get laughed at for having an incredibly easy problem, I have only just recently started my computer science course at school. In this program I have a java class, and I need to make a program that takes a 3-Digit number the user types in and displays it after as - "Num1 + num2 + num3 = Sum"
AKA if someone types in 457, it displays the message "4 + 5 + 7 = 16"
[code]import javax.swing.JOptionPane;
import java.util.Scanner;
public class number
{
public static void main(String args[])
{
String input;
int firstNumber, secondNumber, thirdNumber, answer;
char number1, number2, number3;
input = JOptionPane.showInputDialog("Enter 3 numbers of your choice!");
\\ Stuff goes here
answer = firstNumber + secondNumber + thirdNumber;
JOptionPane.showMessageDialog(null, firstNumber + " + " + secondNumber + " + " + thirdNumber + " = " + answer);
System.exit(0);
}
}
[/code]
I did have things in the middle before, but I've been trying to figure it out for a while but I just can't get it right.
I know I have to parse the "Input" string to an integer, but then how do I get each individual character and then use them in calculations?
I tried using "input.charAt();", I guess I'm just making a stupid mistake.
[QUOTE=Nikita;32295377]Could someone recommend me some software?
Sometimes when I code, something goes wrong, and I think "Oh fuck, what did I break this time?" and then after trying to fix it countless times: "I wish I could just go back to the version of my code where it wasn't broken yet ;_;"
I'm pretty sure there is something for that, but what?[/QUOTE]
Revision Control software.
git, mercurial, svn, cvs, bazaar, etc. Take your pick.
I'm quite partial to git, but I'm a Linux user and it's really a *nix program at its core.
[editline]15th September 2011[/editline]
Also github is epic.
Thanks for the help guys, it's working much better now.
Javascript:
How can I search for text in a webpage and get the element the text is on?
Can anyone tell me what exactly is happening here?
[cpp]
int (*minus)(int,int) = subtraction;
[/cpp]
Full source code from C++ Documentation:
[cpp]
#include <iostream>
using namespace std;
int addition (int a, int b)
{ return (a+b); }
int subtraction (int a, int b)
{ return (a-b); }
int operation (int x, int y, int (*functocall)(int,int))
{
int g;
g = (*functocall)(x,y);
return (g);
}
int main ()
{
int m,n;
int (*minus)(int,int) = subtraction;
m = operation (7, 5, addition);
n = operation (20, m, minus);
cout <<n;
cin.get();
return 0;
}
[/cpp]
return_type (*pFunction)(arg1, arg2) = function;
It's a function-pointer. Stuff is more readable with typedefs
[cpp]typedef int (*mathfunction)(int, int);
mathfunction minus = subtraction;[/cpp]
or std::function
[cpp]std::function<int (int, int)> minus = subtraction[/cpp]
[editline]15th September 2011[/editline]
If you just need the type (e.g. for an unnamed argument or casting or something) you still need all parenthesis, so int *(int, int) would be invalid, but int (*)(int, int) is what you want.
So what exactly is *functocall doing there?
So, I'm having a logic issue with this game.
[url]http://www.text-upload.com/read.php?id=138968&c=4025067[/url] (Please keep in mind I'm working on it)
When the players health drops to 0, it should output a message saying that you have died. And in this fun little loop
[cpp]do
{
cout << "Wrong. You are beaten with a whip.\n";
takeDamage(playerHealth);
cout << "\nYour name is Toby. Got that, boy?(y/n): ";
cin >> gotThat;
switch (gotThat)
{
case 'y' : cout << "Okay, good. Glad we got that settled.\n";
}
}while(gotThat == 'n' && playerHealth >=10);
[/cpp] it should repeat and make you take damage until you have died. But I'm running into this problem when I run it,[img]http://s1.postimage.org/f31o17f1l/halp.png[/img]
where the loop continues even after the player is dead. Which is why I tried to stop it with the
&& playerHealth >=10);
Which you can tell it isn't working. So, my question? What am I doing wrong? Why is the loop still running again after it shouldn't have?
[QUOTE=Asgard;32300637]So what exactly is *functocall doing there?[/QUOTE]
"functocall" is a function pointer. In operation(), it is being used as a [url=http://en.wikipedia.org/wiki/Callback_function]callback function[/url].
Can someone explain to me how PGP Full disk runs under windows? It almost runs like a root kit. Im not sure how it can do that from the 'Boot loader'
I'm guessing a driver is installed into windows that allows this to happen but what happens before this driver is loaded how does windows even work? Can you run code in the background while somthing like windows is running if you hijack the bootloader?
[editline]15th September 2011[/editline]
I guess my question is that is it possible to run code 'under' windows with out driver installation?
[QUOTE=Nikita;32295377]Could someone recommend me some software?
Sometimes when I code, something goes wrong, and I think "Oh fuck, what did I break this time?" and then after trying to fix it countless times: "I wish I could just go back to the version of my code where it wasn't broken yet ;_;"
I'm pretty sure there is something for that, but what?[/QUOTE]
Gonna butt in late again and say I really like using mercurial through hg workbench/[URL="http://tortoisehg.bitbucket.org/"]TortoiseHg[/URL] and a free account on [URL="www.bitbucket.org"]www.bitbucket.org[/URL].
(Mostly because I'm slightly allergic to command lines.)
And an overview of source control systems to get you up to speed: [URL="http://thedailywtf.com/Articles/Source-Control-Done-Right.aspx"]http://thedailywtf.com/Articles/Source-Control-Done-Right.aspx[/URL]
It took me far too long to realize that I didn't need a server for Mercurial. I tried to set up some Python server on my Windows machine :suicide:
Anyway, I'm trying to render some labels in the background of my data control:
[IMG]http://dl.dropbox.com/u/5013896/forum/Facepunch/What%20do%20you%20need%20help%20with/LabelGlitch.png[/IMG]
-wrong code-
The labels are supposed to begin every 7 bytes starting at 0 and to cover 3 bytes each. RenderPosition returns the top-left edge for a column/row position. RenderEmpty merges the rectangles and formats the beginning and end of the label.
What's the best way to calculate the columns and rows of the beginning and end?
Edit: Fixed:
[img]http://dl.dropbox.com/u/5013896/forum/Facepunch/What%20do%20you%20need%20help%20with/LabelsFixed.png[/img]
[csharp]
private void RenderLabels(DrawingContext drawingContext)
{
foreach (var l in Labels)
{
var start = l.Offset - Offset;
var end = start + l.Length;
if (start >= Columns * Rows || end <= 0)
{
continue;
}
var firstLine = start / Columns;
var lastLine = end / Columns;
var areas = new List<Rect>();
for (long i = firstLine; i <= lastLine; i++)
{
Point topLeft;
if (i == firstLine)
{
topLeft = RenderPosition(start % Columns, i);
}
else
{
topLeft = RenderPosition(0, i);
}
Point bottomRight;
if (i == lastLine)
{
if (i > firstLine && end % Columns == 0)
{
break;
}
bottomRight = RenderPosition(end % Columns, i + 1);
}
else
{
bottomRight = RenderPosition(Columns, i + 1);
}
areas.Add(new Rect(topLeft, bottomRight));
}
l.RenderEmpty(drawingContext, areas.ToArray());
}
}
[/csharp]
In C++, if I include some standard header files before I include a header file for one of my classes which also requires those standard header files (like below), would this work or would I have to include the standard files again in my class's header?
[code]
#include <stdio.h>
#include <hypothetical.h>
#include "ClassWhichRequiresTheAboveFiles.h"
int main(int argc, char * argv[])
{
return 0;
}
[/code]
[QUOTE=AMD 32;32302610]In C++, if I include some standard header files before I include a header file for one of my classes which also requires those standard header files (like below), would this work or would I have to include the standard files again in my class's header?
[code]
#include <stdio.h>
#include <hypothetical.h>
#include "ClassWhichRequiresTheAboveFiles.h"
int main(int argc, char * argv[])
{
return 0;
}
[/code][/QUOTE]
It would work, but I'd recommend including files in other files that require them, that makes your system a bit more modular.
[QUOTE=Werem00se;32300770]So, I'm having a logic issue with this game.
[url]http://www.text-upload.com/read.php?id=138968&c=4025067[/url] (Please keep in mind I'm working on it)
When the players health drops to 0, it should output a message saying that you have died. And in this fun little loop
[cpp]do
{
cout << "Wrong. You are beaten with a whip.\n";
takeDamage(playerHealth);
cout << "\nYour name is Toby. Got that, boy?(y/n): ";
cin >> gotThat;
switch (gotThat)
{
case 'y' : cout << "Okay, good. Glad we got that settled.\n";
}
}while(gotThat == 'n' && playerHealth >=10);
[/cpp] it should repeat and make you take damage until you have died. But I'm running into this problem when I run it, *pic*
where the loop continues even after the player is dead. Which is why I tried to stop it with the
&& playerHealth >=10);
Which you can tell it isn't working. So, my question? What am I doing wrong? Why is the loop still running again after it shouldn't have?[/QUOTE]
So you want the player to get beaten by a whip until he's dead? Could you give an example of how it should look & work?
Hey i'm having some trouble with C++/SFML any help is appreciated...
So i have this code, and I'm trying to take input in a class before it is declared in main(), is there any way to do this? or a possible BETTER way of doing this?
[code]
#include <iostream>
#include <SFML/Graphics.hpp>
using namespace std;
class Player
{
public:
Player(); // Constructor
~Player(); // Destructor
int getX() { return x; } // get the player X coords
int getY() { return y; } // get the player Y coords
int getSize() { return size; } // get the players size
void setSize( int nSize ) { size = nSize; } // set the size of the player
void setX( int nX ) { x = nX; } // set the player X coords
void setY( int nY ) { y = nY; } // set the player Y coords
void moveLeft() { x = x - 0.2f; }
void moveRight() { x = x + 0.2f; }
void moveUp() { y = y - 0.2f; }
void moveDown() { y = y + 0.2f; }
private:
float x;
float y;
bool left;
bool right;
bool up;
bool down;
int size;
};
Player::Player()
{
cout << "Creating the player class" << endl;
setX( 10 );
setY( 10 );
setSize( 10 );
}
Player::~Player()
{
cout << "Destroying the player class" << endl;
}
int main( int argc, char **argv)
{
Player *player = new Player;
sf::RenderWindow App(sf::VideoMode(800, 600), "Boss Battle");
const sf::Input& Input = App.GetInput();
while ( App.IsOpened() ) //Game loop
{
sf::Event Event;
while( App.GetEvent(Event) )
{
if ( Event.Type == sf::Event::Closed ) //Allows the app to be closed
App.Close();
}
if (Input.IsKeyDown(sf::Key::A))
player->moveLeft();
if (Input.IsKeyDown(sf::Key::D))
player->moveRight();
if (Input.IsKeyDown(sf::Key::W))
player->moveUp();
if (Input.IsKeyDown(sf::Key::S))
player->moveDown();
App.Clear(); // Clear the screen
sf::Shape Rect = sf::Shape::Rectangle(player->getX(), player->getY(), (player->getX() + player->getSize()), (player->getY() + player->getSize()), sf::Color(255, 255, 255, 200));
App.Draw(Rect);
App.Display(); // Display all the shit to the screen
}
return EXIT_SUCCESS;
}
[/code]
See in the player class i would like to create a function where i could just call "player->checkMove()" then it would handle all the input there.
Like i said before, any improvements to this code would be epic and help would be awesome!
[QUOTE=Robbis_1;32302979]So you want the player to get beaten by a whip until he's dead? Could you give an example of how it should look & work?[/QUOTE]
Okay, I can do that. Well, basically it's a simple simulation rpg about being a slave. And I decided to have fun with. I don't want him to die per say, but it is going to be a possibility. It's a reference to that movie ROOTS.
[quote] I read someplace that things are easier to read in quotes.
[t]http://s4.postimage.org/fayrqrog9/Step_One.png[/t] This is how it starts. You enter if you want to play or not.
[t]http://s4.postimage.org/fazlifxc9/steptwo.png[/t] Here is a branch. [t]http://s4.postimage.org/fb00ea1s9/steptwo_A.png[/t]
[t]http://s4.postimage.org/fb4dic0p5/stepthree.png[/t] Simple branching, GO! [t]http://s4.postimage.org/fb5pgx30p/stepthree_A.png[/t]
Then this CAN happen to you, if you want it to. [img]http://s1.postimage.org/f31o17f1l/halp.png[/img]
[/quote]
See, when I program I have to get myself interested in doing something, then I'll do it and learn on the way. That's how I thought myself a good bit of Java, but anyway it's really racist and I apologize. I'm pretty sure I'm not racist. Anyway when it's done I'll you guys for suggestions on how to improve the code. I learn more that way. But yeah, that was pretty simple.. :v:
Oh, and I want to know why it outputs another one of 'your name is toby, got that' even though When it hits zero, it should stop.
How are you supposed to set up a compiler for C? I've recently started learning C, and I've purchased a book describing "C basics", but setting up a compiler is proving to be vague and difficult. Can anyone recommend a program with a guide of sorts?
[QUOTE=G-foxisus;32303986]How are you supposed to set up a compiler for C? I've recently started learning C, and I've purchased a book describing "C basics", but setting up a compiler is proving to be vague and difficult. Can anyone recommend a program with a guide of sorts?[/QUOTE]
Just get Visual C++ Express 2010. It can compile C files too.
[QUOTE=thf;32304002]Just get Visual C++ Express 2010. It can compile C files too.[/QUOTE]
Okay, I've heard that it might not compile [I]everything[/I], but it wouldn't hurt giving it a try regardless of that. Thanks!
[QUOTE=G-foxisus;32303986]How are you supposed to set up a compiler for C? I've recently started learning C, and I've purchased a book describing "C basics", but setting up a compiler is proving to be vague and difficult. Can anyone recommend a program with a guide of sorts?[/QUOTE]
If you want a proper C compiler, getting Code::Blocks bundled with MinGW is a good start.
I just have a general question about the return statement for C++.
Why do we always need to have
[B]return 0;[/B]
Is it bad if I forget to include it at the end of the main?
[QUOTE=Bambo.;32303598]Hey i'm having some trouble with C++/SFML any help is appreciated...
So i have this code, and I'm trying to take input in a class before it is declared in main(), is there any way to do this? or a possible BETTER way of doing this?
[code]
#include <iostream>
#include <SFML/Graphics.hpp>
using namespace std;
class Player
{
public:
Player(); // Constructor
~Player(); // Destructor
int getX() { return x; } // get the player X coords
int getY() { return y; } // get the player Y coords
int getSize() { return size; } // get the players size
void setSize( int nSize ) { size = nSize; } // set the size of the player
void setX( int nX ) { x = nX; } // set the player X coords
void setY( int nY ) { y = nY; } // set the player Y coords
void moveLeft() { x = x - 0.2f; }
void moveRight() { x = x + 0.2f; }
void moveUp() { y = y - 0.2f; }
void moveDown() { y = y + 0.2f; }
private:
float x;
float y;
bool left;
bool right;
bool up;
bool down;
int size;
};
Player::Player()
{
cout << "Creating the player class" << endl;
setX( 10 );
setY( 10 );
setSize( 10 );
}
Player::~Player()
{
cout << "Destroying the player class" << endl;
}
int main( int argc, char **argv)
{
Player *player = new Player;
sf::RenderWindow App(sf::VideoMode(800, 600), "Boss Battle");
const sf::Input& Input = App.GetInput();
while ( App.IsOpened() ) //Game loop
{
sf::Event Event;
while( App.GetEvent(Event) )
{
if ( Event.Type == sf::Event::Closed ) //Allows the app to be closed
App.Close();
}
if (Input.IsKeyDown(sf::Key::A))
player->moveLeft();
if (Input.IsKeyDown(sf::Key::D))
player->moveRight();
if (Input.IsKeyDown(sf::Key::W))
player->moveUp();
if (Input.IsKeyDown(sf::Key::S))
player->moveDown();
App.Clear(); // Clear the screen
sf::Shape Rect = sf::Shape::Rectangle(player->getX(), player->getY(), (player->getX() + player->getSize()), (player->getY() + player->getSize()), sf::Color(255, 255, 255, 200));
App.Draw(Rect);
App.Display(); // Display all the shit to the screen
}
return EXIT_SUCCESS;
}
[/code]
See in the player class i would like to create a function where i could just call "player->checkMove()" then it would handle all the input there.
Like i said before, any improvements to this code would be epic and help would be awesome![/QUOTE]
You could store the sf::Input reference in the player-class.
Alternatively have an acceptInput-function and do player->acceptInput(App.GetInput).
Any reason the Player resides in heap-memory? You're leaking the memory btw.
[QUOTE=thf;32304002]Just get Visual C++ Express 2010. It can compile C files too.[/QUOTE]
MSVC's C compatibility mode is abysmal. Microsoft basically doesn't support it anymore. They don't have any intention of updating it to the latest standards or going back and fixing all the things they screwed up.
Get GCC, seriously. There are plenty of C compilers out there, but GCC is one of the best.
You can MinGW+GCC bundled in Code::Blocks.
Sorry, you need to Log In to post a reply to this thread.