Freitag, 11. Januar 2008

That was fast ...

Technically I have made my first little game. Obviously I'm not going to be stopping here since I want to develop something a little more complex like a shoot-em-up, but to have produced this after only two days of learning fills me with a bit of pride (just a tad ;) ). Here's the source code. I'm sure to the veteran programmer this is a piece of absolute junk (I'm sure it could have been made much more efficient using advanced programming techniques), but knowing what I know now, it's the best thing I could come up with (note: the program does contain one minor bug. If you happen to have a small straight and a pair ... it unfortunately will only give you 10$ for the pair. I'll edit as soon as I fix it).

Here's a screenshot:
Image Hosted by ImageShack.us


NOTE: The include directives at the beginning are empty, because of use of brackets ">" and "<". If you would like to compile... simply use "iostream" and "cstdlib"
-------------------------------
#include
#include

using namespace std;


//Decleration of functions
void one();
void two();
void three();
void four();
void five();
void six();
void randomnumber();
void check();

int first = 0;
int second = 0;
int third = 0;
int fourth = 0;
int fifth = 0;

int main()
{

//decleration of variables

int counter = 5;
int number;

//initializes rand() function
srand (time(NULL));

//get number wanted from user
cout << "DICE GAME v0.2\n"; while ( counter > 0 )
{
counter = counter - 1;

number = (rand()%6)+1;

//write all generated numbers to variables for later processing
switch (counter)
{
case 4: first = number;
case 3: second = number;
case 2: third = number;
case 1: fourth = number;
case 0: fifth = number;
}

//display ASCII dice-face of the number rolled
switch (number)
{
case 1: one();
break;
case 2: two();
break;
case 3: three();
break;
case 4: four();
break;
case 5: five();
break;
case 6: six();
break;
}


}

// cout << counting =" 5;" treffer =" 0;" pair =" 0;" triple =" 0;" fourinarow =" 0;" fiveinarow =" 0;" onehit =" 0;" twohit =" 0;" threehit =" 0;" fourhit =" 0;" fivehit =" 0;" sixhit =" 0;" straight =" 0;"> 0)
{
counting = counting - 1;
switch (counting)
{
case 4: if (first == 1) { treffer = treffer + 1;}
break;
case 3: if (second == 1) { treffer = treffer + 1;}
break;
case 2: if (third == 1) { treffer = treffer + 1;}
break;
case 1: if (fourth == 1) {treffer = treffer + 1;}
break;
case 0: if (fifth == 1) {treffer = treffer + 1;}
break;
}
}

if (treffer == 1) {onehit = 1;}
if (treffer == 2) {pair = pair + 1;}
if (treffer == 3) {triple = triple + 1;}
if (treffer == 4) {fourinarow = 1;}
if (treffer == 5) {fiveinarow = 1;}
//cout << "Anzahl treffer 1 = " << counting =" 5;" treffer =" 0;"> 0)
{
counting = counting - 1;
switch (counting)
{
case 4: if (first == 2) { treffer = treffer + 1;}
break;
case 3: if (second == 2) { treffer = treffer + 1;}
break;
case 2: if (third == 2) { treffer = treffer + 1;}
break;
case 1: if (fourth == 2) {treffer = treffer + 1;}
break;
case 0: if (fifth == 2) {treffer = treffer + 1;}
break;
}
}
if (treffer == 1) {twohit = 1;}
if (treffer == 2) {pair = pair + 1;}
if (treffer == 3) {triple = triple + 1;}
if (treffer == 4) {fourinarow = 1;}
if (treffer == 5) {fiveinarow = 1;}
// cout << "Anzahl treffer 2 = " << counting =" 5;" treffer =" 0;"> 0)
{
counting = counting - 1;
switch (counting)
{
case 4: if (first == 3) { treffer = treffer + 1;}
break;
case 3: if (second == 3) { treffer = treffer + 1;}
break;
case 2: if (third == 3) { treffer = treffer + 1;}
break;
case 1: if (fourth == 3) {treffer = treffer + 1;}
break;
case 0: if (fifth == 3) {treffer = treffer + 1;}
break;
}
}
if (treffer == 1) {threehit = 1;}
if (treffer == 2) {pair = pair + 1;}
if (treffer == 3) {triple = triple + 1;}
if (treffer == 4) {fourinarow = 1;}
if (treffer == 5) {fiveinarow = 1;}
//cout << "Anzahl treffer 3 = " << counting =" 5;" treffer =" 0;"> 0)
{
counting = counting - 1;
switch (counting)
{
case 4: if (first == 4) { treffer = treffer + 1;}
break;
case 3: if (second == 4) { treffer = treffer + 1;}
break;
case 2: if (third == 4) { treffer = treffer + 1;}
break;
case 1: if (fourth == 4) {treffer = treffer + 1;}
break;
case 0: if (fifth == 4) {treffer = treffer + 1;}
break;
}
}
if (treffer == 1) {fourhit = 1;}
if (treffer == 2) {pair = pair + 1;}
if (treffer == 3) {triple = triple + 1;}
if (treffer == 4) {fourinarow = 1;}
//cout << "Anzahl treffer 4 = " << counting =" 5;" treffer =" 0;"> 0)
{
counting = counting - 1;
switch (counting)
{
case 4: if (first == 5) { treffer = treffer + 1;}
break;
case 3: if (second == 5) { treffer = treffer + 1;}
break;
case 2: if (third == 5) { treffer = treffer + 1;}
break;
case 1: if (fourth == 5) {treffer = treffer + 1;}
break;
case 0: if (fifth == 5) {treffer = treffer + 1;}
break;
}
}
if (treffer == 1) {fivehit = 1;}
if (treffer == 2) {pair = pair + 1;}
if (treffer == 3) {triple = triple + 1;}
if (treffer == 4) {fourinarow = 1;}
if (treffer == 5) {fiveinarow = 1;}
//cout << "Anzahl treffer 5 = " << counting =" 5;" treffer =" 0;"> 0)
{
counting = counting - 1;
switch (counting)
{
case 4: if (first == 6) { treffer = treffer + 1;}
break;
case 3: if (second == 6) { treffer = treffer + 1;}
break;
case 2: if (third == 6) { treffer = treffer + 1;}
break;
case 1: if (fourth == 6) {treffer = treffer + 1;}
break;
case 0: if (fifth == 6) {treffer = treffer + 1;}
break;
}
}

if (treffer == 1) {sixhit = 1;}
if (treffer == 2) {pair = pair + 1;}
if (treffer == 3) {triple = triple + 1;}
if (treffer == 4) {fourinarow = 1;}
if (treffer == 5) {fiveinarow = 1;}
//cout << "Anzahl treffer 6 = " << fourinarow ="="" fiveinarow ="="" fourhit ="="" straight =" 1;}" fivehit ="="" straight =" 1;}" sixhit ="="" straight =" 1;}" fivehit ="="" straight =" 2;}" sixhit ="="" straight =" 2;}" straight ="="" triple ="="" triple ="="" triple ="="" pair ="="" fiveinarow ="="">

A glimpse of hope

Well, I've gotten some of the basics down. Enough to manipulate basic data types, make decisions and output text in the terminal.

I've even got the bare bones structure of a game going. Basically, it's like a dice version of poker. The program rolls 5 dice and sees if you have any winning combinations (2 of a kind, full house,...). Unfortunately, my program only is able to do random rolling of 5 dice as well as being able to display the results in ASCII art. Not much, but certainly a step foward from your basic "Hello World!" program. This does give me a neat little project to work on, as I can hopefully incorporate newly acquired skills into this little game and make it do interesting stuff like display combinations or letting you replace dice like in the game "Tali". Here's the source code I came up with. Feel free to use it any way you want. I would GPL it, but as it is still a p.o.s. I'll just make it public domain for now :)

-----------------------------------
#include
#include

using namespace std;


//Decleration of functions
void one();
void two();
void three();
void four();
void five();
void six();
void randomnumber();


int main()
{

//decleration of variables

int counter = 5;
int number;

//initializes rand() function
srand (time(NULL));

//get number wanted from user
cout << "DICE GAME v0.2\n";

while ( counter > 0 )
{
counter = counter - 1;

number = (rand()%6)+1;
switch (number)
{
case 1: one();
break;
case 2: two();
break;
case 3: three();
break;
case 4: four();
break;
case 5: five();
break;
case 6: six();
break;
}
}


cin.get();
return 0;

}



void one()
{
cout << " ----- " << endl;
cout << "| |" << endl;
cout << "| O |" << endl;
cout << "| |" << endl;
cout << " ----- " << endl;
}

void two()
{
cout << " ----- " << endl;
cout << "| 0 |" << endl;
cout << "| |" << endl;
cout << "| 0 |" << endl;
cout << " ----- " << endl;
}

void three()
{
cout << " ----- " << endl;
cout << "| O |" << endl;
cout << "| O |" << endl;
cout << "| O |" << endl;
cout << " ----- " << endl;
}

void four()
{
cout << " ----- " << endl;
cout << "| O O |" << endl;
cout << "| |" << endl;
cout << "| 0 0 |" << endl;
cout << " ----- " << endl;
}

void five()
{
cout << " ----- " << endl;
cout << "| 0 0 |" << endl;
cout << "| 0 |" << endl;
cout << "| 0 0 |" << endl;
cout << " ----- " << endl;
}

void six()
{
cout << " ----- " << endl;
cout << "| 0 0 |" << endl;
cout << "| 0 0 |" << endl;
cout << "| 0 0 |" << endl;
cout << " ----- " << endl;
}
--------------------------------

-Teddy

Mittwoch, 9. Januar 2008

... and thus my journey begins

Here's the deal: Ever since I first laid eyes on a video game as a wee little kid, I've had the dream of making one myself. It's something that has stuck with me all these years. I have other dreams as well and have generally taken some sort of step towards them. But for some reason, I have always kept prolonging learning what I need to know to develop a game of my very own.


I don't want to create the next blockbuster video game hit; just something simple like a breakout style game, a shm'up, a puzzle game or something fairly simple. I know that I have a rather long road ahead of me, since developing a game isn't the easiest task in a programmer's repetoire and I will need to learn just about everything from scratch. I don't know any programming language or have any other real skills needed to make a game.

All I have is my childhood dream, a copy of Ivor Horton's "Beginning C++", a GNU/Linux OS (Ubuntu Gutsy Gibbon), plenty of tea and coffee and the will to make it all happen. So it's time to let go of the reasons I have been putting this project off and just get to it.


-Teddy