...I'm struggling to understand what I am supposed to be doing. I had a great idea in my head but I feel like I just can't get it into code. I might just have to give up with it for a few years until I fully understand what C++ is about...
Don't give up Zorg. You are doing a good thing in attempting to write a real program. You can spend years mulling over textbooks and learning the syntax, but until you actually try to code something it can be tough understanding what it is really all about. The inventor of C++ says in his book that "the best way to learn a new language is to write programs in it". Keep going and you will learn a lot.
I would suggest though that you spend some time doing a very brief & informal requirements & design document. You can then identify the various modules and the interfaces that exist between the modules. Once you have figured that out it will be a lot easier to start writing code.
IRC is Internet Relay Chat. It's been around forever, and still fairly popular. A bot is a program which connects to IRC and does whatever you want really. It's a fun project. If I had to bet, most of us here have made at least one IRC bot at some point. There's actually two or three sitting in the #cplusplus channel right now.
As for getting on IRC, you need a client. If you want to just get going, then go here: http://webchat.quakenet.org/
It's super basic, but it works. Just join the channel #cplusplus, and pick whatever nickname you want.
If you want something more robust, then grab a standalone client. HexChat is a very solid and popular client.
I would suggest though that you spend some time doing a very brief & informal requirements & design document. You can then identify the various modules and the interfaces that exist between the modules. Once you have figured that out it will be a lot easier to start writing code.
Could you elaborate a little on this please? I've been writing down ideas and such, but I'm struggling to understand how it all fits together.
I know I need some players, a map, an interface screen and a shop.
The user starts off on the interface screen where they can choose to buy parts, put their robot together, program their bot ( This is the sucky part I REALLY have no idea how to do, but I think it would be a fun game mechanic rather then the over used aim and shoot system ) and go fight other bots in the arena.
How would I plan all this exactly? I know what I want, I just have no clue how I should go about doing it.
I think it would help if you put down on paper a list of the main system and user requirements that must be in your program. In software engineering it is a way of specifying what the program should do. I'm not suggesting that you need to go into planning every detail, but do spend some time thinking about:
a) What are the user requirements
- A user must be able to choose to buy parts
- A user must be able to pass instructions to their bot
etc..
b) System requirements
- The program must display xyz instructions to the user
- The program must display a 2D map
etc..
Now if you list all of main the user & system requirements methodically like this, you will then be in a position to write up a short design document. That is a specification of all of the modules that your program might need to meet the requirements and it is at this stage that you can think about how the different parts work together. I have found it most helpful to draw diagrams of the modules. From there, you can start to identify what the main classes & functions of the program will be. If you spend a lot of time thinking and planning your game, the coding part will follow a lot more naturally than you may think. Try not to rush this stage - a couple of days thinking about it would be great.
You can find good information on software design on the net. A good book that I have is "Software Engineering" by Sommerville. You probably don't need a book though as there lots of info online that will help you develop your game in this way.
hth
It all seems way over my head making an IRC Bot though it does look fun to code
As excellent as Beej's guide to network programming is, it's unnecessary for this task.
If an IRC bot looks interesting, I suggest grabbing Python or Ruby at first. They both have extremely simple networking modules which can you get you used to network programming and the IRC protocol.
For example, this is a bot which just connects to a server, joins a channel, then just sits there. Written in Python.
import socket
import sys
import re
server = "irc.freenode.net"
channel = "#botwar"
nick = "ResidentBot"
user = "ResidentBiscuit"
irc_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
irc_socket.connect((server, 6667))
#IRC connection handshake consists of sending NICK and USER messages. All IRC messages must end in \r\n
irc_socket.send("NICK " + nick + "\r\nUSER " + user + " 0 * :" + nick + "\r\n")
irc_socket.send("JOIN " + channel + "\r\n")
while True:
recv_text = irc_socket.recv(1024)
sys.stdout.write(recv_text)
# Servers send occasional pings that must be replied to, else get kicked
if recv_text.find("PING"):
irc_socket.send("PONG " + recv_text.split()[1] + "\r\n")
Thank you for the information, I have your response copied and saved in a txt for reference. I am going to scrap my project and try and figure out every damn detail before I start coding. I am also trying to get used to SFML to see if that can help me code my game easier ( Though I am not getting very far. :P )
import socket
import sys
import re
server = "irc.freenode.net"
channel = "#botwar"
nick = "ResidentBot"
user = "ResidentBiscuit"
irc_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
irc_socket.connect((server, 6667))
#IRC connection handshake consists of sending NICK and USER messages. All IRC messages must end in \r\n
irc_socket.send("NICK " + nick + "\r\nUSER " + user + " 0 * :" + nick + "\r\n")
irc_socket.send("JOIN " + channel + "\r\n")
while True:
recv_text = irc_socket.recv(1024)
sys.stdout.write(recv_text)
# Servers send occasional pings that must be replied to, else get kicked
if recv_text.find("PING"):
irc_socket.send("PONG " + recv_text.split()[1] + "\r\n")
Well that looks x1000 times less effort, and I can weirdly understand it and I haven't done Python before. The only lines that I can't decipher are:
If you are sending strings to the IRC server with 'NICK' and 'USER', does this mean the IRC interprets the information it receives?
Also are you suggesting I should scrap C++ and go for Python instead? I have recently installed SFML which has a networking module which ( Maybe ) has it's own wrapper class for this sort of stuff to make it easier, do you have any experience?
Oh if you installed SFML then just use that. The networking module on SFML is about as easy as it is on Python. I think I even have an example of an IRC bot using SFML somewhere too...
If you are sending strings to the IRC server with 'NICK' and 'USER', does this mean the IRC server interprets the information it receives?
Yup. That's why we have protocols :)
1 2 3
irc_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM
#AF_INET just says this is an Internet socket, ie IP
#SOCK_STREAM says basically to use TCP instead of UDP (should know the difference :) )
1 2 3 4 5 6
irc_socket.send("PONG " + recv_text.split()[1] + "\r\n") #Mainly recv_text.split()[1]
#This code is what handles the server's ping requests. The format of a ping request is 'PING :somecharacters' and the reply must be 'PONG "somecharacters'
#So, the recv_text.split() part splits the PING message into tokens, delimited by spaces
#The [1] part says grab the 2nd element of that array of tokens (0 indexed), which would be the ':somecharacters'
#Then we send this new string which is 'PONG :somecharacters' :)
That's great! If you could fish out that example for me I would be very grateful :) I would try to add a way for me to send messages while I am logged in too!
Be warned though I installed SFML a few hours ago and did a simple graphics program before I went to sleep ( It was a snowman, Disch helped me do it, man that dude is real smart isn't he? ) so I have the intelligence of a slug when it comes to SFML.
I think I understand the basics of TCP and UDP:
TCP is a lossless transmission protocol for when things need to arrive without corruption, there is sometimes a delay so it isn't used for real time services.
And UDP is a protocol where the packets may not always arrive perfectly or even arrive at all, it has less overhead than the TCP and is used for real time communication ( I am guess that's like voice chat or video calls? )
is recv_text a string then? Because it seems Python doesn't identify a type to it's variables? Which then makes sense if recv_text()[0] is "PING" and the rest of the elements a string literals, then that makes perfect sense to me.
I've only just glanced at this thread, I just wanted to add on that SFML has a great networking library (It's actually my favorite), so you can write an IRC bot with the library.
If your still planning on doing this, I read a good short introductory paper that will help on this topic. Here is the link:
http://www.cs.tufts.edu/comp/40/handouts/design.pdf
Thanks for the information, I have recently moved to Linux by popular opinion on the IRC ( Though the distro I got didn't get the same treatment :) ) so I don't have SFML anymore :/
@flint
I am still figuring out the angles to my game so any links are well appreciated! I am checking it out now thank you
It works on all distros as far as I know, but some distros have the lib and files in their repository so you just have to do something like
sudo apt-get install sfml-dev
. If his distro doesn't have it or isn't up-to-date, it is still just a matter of installing the tools and any libraries he needs, getting the library source to build it and install it.
[EDIT]
Heh, hit reply and walked away from laptop. While I was away ResidentBiscuit answered it. Just making note of this so it doesn't appear I am trying explain RBs reply or anything.
I installed SFML on debian and it took only around 20 - 30 minutes to find & download all the dependencies and then to compile & build the latest version using cmake. I just followed the instruction in the sfml tutorial to set it up.
Well when you do install it I don't recommend you use the debian repository version as it is really old -something like 1.6. There are still tutorials for this, but the latest release is version 2.1. cmake-gui is the program that is used to build sfml. It is all explained in the sfml tutorial 'compiling with cmake'.