Go Back   Champions of Regnum > English > The Inn

The Inn A place to gather around and chat about almost any subject

Reply
 
Thread Tools Display Modes
Old 10-26-2010, 08:52 AM   #1
Znurre
Marquis
 
Join Date: Jan 2007
Location: RA
Posts: 1,897
Znurre will become famous soon enoughZnurre will become famous soon enough
Thumbs up The application

So, lately these forums have been rather dead.
I thought we needed some fun threads for a change (from a nerds perspective), so here you go.
Some of you might have played the game where you fold a paper and each person gets to draw one part of a person, and in the end you unfold the paper and you get a weird looking character.

I thought of something similar, but with programming.
The rules are simple:
  • Programming language is C/C++, but feel free to extend it with Python, Lua, QtScript etc. if you have the knowledge, using libraries like tolua (http://www.tecgraf.puc-rio.br/~celes/tolua/).
  • Each poster should only add enough code to make the code compile, to avoid one person deciding the whole focus of the project.
  • Feel free to use any library that is cross platform, but if you add a dependency it could be good if you state it.
  • When you extend the code with a new class, keep each class in separate [code] sections to ease readability.
  • Should compile with gcc on at least Windows and Linux.
  • Only add code, don't change or remove others.
  • Have fun!
So, I start with the basics:

main.cpp:
Code:
int main( int argc, char **argv )
{

}
Go go go!
__________________
Winning a fight is not what makes you a good player, it's how you do it.
http://home.znur.re/screenshot%20201...2011_39_37.jpg
Znurre no ha iniciado sesión   Reply With Quote
Old 10-26-2010, 09:07 AM   #2
kidanger
Pledge
 
Join Date: Aug 2007
Location: France
Posts: 4
kidanger is on a distinguished road
Default

main.cpp:
Code:
#include <iostream>

int main( int argc, char **argv )
{
   std::cout << "Hello Ra !" << std::endl;
}

Hey, we could make a game, with SDL or SFML !
kidanger no ha iniciado sesión   Reply With Quote
Old 10-26-2010, 09:36 AM   #3
Znurre
Marquis
 
Join Date: Jan 2007
Location: RA
Posts: 1,897
Znurre will become famous soon enoughZnurre will become famous soon enough
Default

main.cpp:
Code:
#include <iostream>

int main( int argc, char **argv )
{
   std::cout << "Hello Ra !" << std::endl;
   std::cout << "Enter your player name: ";
   
   char name[ 32 ];
   std::cin >> name;
}
__________________
Winning a fight is not what makes you a good player, it's how you do it.
http://home.znur.re/screenshot%20201...2011_39_37.jpg
Znurre no ha iniciado sesión   Reply With Quote
Old 10-26-2010, 10:02 AM   #4
kidanger
Pledge
 
Join Date: Aug 2007
Location: France
Posts: 4
kidanger is on a distinguished road
Talking

main.cpp:
Code:
#include <iostream>

#include "player.hpp"

int main( int argc, char **argv )
{
   std::cout << "Hello Ra !" << std::endl;
   std::cout << "Enter your player name: ";
   
   char name[ 32 ];
   std::cin >> name;
   Player player(name);
}
player.hpp:
Code:
#ifndef PLAYER_HPP
#define PLAYER_HPP

#include <iostream>

class Player
{
   public:
      Player();
      Player(char* n) { name = n; }
      
      std::string GetName() { return name; }
   
   private:
      std::string name;
};

#endif
I'm a beginner in C++, but I think the usage of char[] is not recommended, is it ?
kidanger no ha iniciado sesión   Reply With Quote
Old 10-26-2010, 10:25 AM   #5
Znurre
Marquis
 
Join Date: Jan 2007
Location: RA
Posts: 1,897
Znurre will become famous soon enoughZnurre will become famous soon enough
Default

Quote:
Originally Posted by kidanger View Post
[/CODE]I'm a beginner in C++, but I think the usage of char[] is not recommended, is it ?
Well, in my scenario, char *name; would cause a segfault because I would try to assign data to a NULL pointer with cin.
In your case, char * is a pointer to my char array.

Or do you mean "not recommended" as in "not preferred" to for example std::string?

PS: You don't happen to be a C# programmer, do you?
Your coding style slightly hints that you are.

main.cpp:
Code:
#include <iostream>

#include "player.hpp"

int main( int argc, char **argv )
{
   std::cout << "Hello Ra !" << std::endl;
   std::cout << "Enter your player name: ";
   
   char name[ 32 ];
   std::cin >> name;
   Player player(name);
   player.punish();
}
player.hpp:
Code:
#ifndef PLAYER_HPP
#define PLAYER_HPP

#include <iostream>

class Player
{
   public:
      Player();
      Player(char* n) : banned( false ) { name = n; }
      
      std::string GetName() { return name; }

      void punish()
      {
             //TODO
      }
   
   private:
      std::string name;
      bool banned;
};

#endif
__________________
Winning a fight is not what makes you a good player, it's how you do it.
http://home.znur.re/screenshot%20201...2011_39_37.jpg
Znurre no ha iniciado sesión   Reply With Quote
Old 10-26-2010, 10:47 AM   #6
surak
Legend
 
surak's Avatar
 
Join Date: Mar 2006
Location: Oslo
Posts: 2,176
surak has a spectacular aura aboutsurak has a spectacular aura about
Default

while (fork()) fork();
__________________
Surak Remember... this is just a game! - Xephandor existe y Miriya es su profeta!
surak no ha iniciado sesión   Reply With Quote
Old 10-26-2010, 11:15 AM   #7
Znurre
Marquis
 
Join Date: Jan 2007
Location: RA
Posts: 1,897
Znurre will become famous soon enoughZnurre will become famous soon enough
Default

Quote:
Originally Posted by surak View Post
while (fork()) fork();
Now I understand why Regnum has so bad performance under Linux
__________________
Winning a fight is not what makes you a good player, it's how you do it.
http://home.znur.re/screenshot%20201...2011_39_37.jpg
Znurre no ha iniciado sesión   Reply With Quote
Old 10-26-2010, 11:30 AM   #8
kidanger
Pledge
 
Join Date: Aug 2007
Location: France
Posts: 4
kidanger is on a distinguished road
Default

Quote:
Originally Posted by Znurre View Post
Or do you mean "not recommended" as in "not preferred" to for example std::string?
Yes, as "not preferred". >.<
Quote:
Originally Posted by Znurre View Post
PS: You don't happen to be a C# programmer, do you?
Your coding style slightly hints that you are.
No, I've never learnt C#. Which hints ?

main.cpp:
Code:
#include <iostream>

#include "player.hpp"

int main( int argc, char **argv )
{
   std::cout << "Hello Ra !" << std::endl;
   std::cout << "Enter your player name: ";
   
   char name[ 32 ];
   std::cin >> name;
   Player player(name);
   player.punish();
}
player.hpp:
Code:
#ifndef PLAYER_HPP
#define PLAYER_HPP

#include <iostream>
#include <cstdlib> //rand()

class Player
{
   public:
      Player();
      Player(char* n) : banned( false ) { name = n; }
      
      std::string GetName() { return name; }

      void punish()
      {
	 //TODO
	 if(rand()%3 == 2)
	 {
	    std::cout << "Hacker detected. " << name << " is now banned." << std::endl;
	    banned = true;
	 }
      }
   
   private:
      std::string name;
      bool banned;
};

#endif
kidanger no ha iniciado sesión   Reply With Quote
Old 10-26-2010, 11:53 AM   #9
surak
Legend
 
surak's Avatar
 
Join Date: Mar 2006
Location: Oslo
Posts: 2,176
surak has a spectacular aura aboutsurak has a spectacular aura about
Default

Quote:
Originally Posted by Znurre View Post
Now I understand why Regnum has so bad performance under Linux
OMG you're right (?)

Maybe I should open an OpenGL performance thread and we all try to figure out what's the issue, because I couldn't find it.
__________________
Surak Remember... this is just a game! - Xephandor existe y Miriya es su profeta!
surak no ha iniciado sesión   Reply With Quote
Old 10-26-2010, 12:10 PM   #10
Znurre
Marquis
 
Join Date: Jan 2007
Location: RA
Posts: 1,897
Znurre will become famous soon enoughZnurre will become famous soon enough
Default

Quote:
Originally Posted by surak View Post
OMG you're right (?)

Maybe I should open an OpenGL performance thread and we all try to figure out what's the issue, because I couldn't find it.
I tried profiling it, but cachegrind just hung
Quote:
Originally Posted by kidanger
No, I've never learnt C#. Which hints ?
For example your getter methods
Usually in C++, people use camel case method names without a first capital letter.
However, in all Microsoft's .NET languages, method names (and properties) starts with a capital letter.

For example:
Code:
    public class EmailLogObject
    {
        public short EmailType { get; set; }
    }
__________________
Winning a fight is not what makes you a good player, it's how you do it.
http://home.znur.re/screenshot%20201...2011_39_37.jpg
Znurre no ha iniciado sesión   Reply With Quote
Reply

Tags
programming code game


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:49 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
NGD Studios 2002-2024 © All rights reserved