PDA

View Full Version : General: Your First Game?



Daniel
03-20-2010, 07:32 AM
It's a good idea that when you start a programming language for the first time, you should make a minor game (excluding 'Hello World', :p).

So, post your "first" games you've made in various languages and their relevant sources :) (Don't update anything, leave the source in-tact :))

The first game I made in Delphi was Tetris, which I cannot find the source files for.
The first game I made in C++ was a guessing game:

#include <iostream>
#include <string>
#include <stdlib.h>

bool isNum(std::string str)
{
for (unsigned int i = 0; i < str.length(); i++)
{
if(!(std::isdigit(str[i])))
return false;
}

return true;
}

int strtoint(const std::string str)
{
if(!(isNum(str)))
return 0;

return(atoi(str.c_str()));
}

int main()
{
int TheNumber = 0;
std::string GuessedNumber = "";
int GNumber = 0;
int Guesses = 0;

std::cout << "Welcome to Guess! A game made by Mayazcherquoi\n\n\n";

while (true)
{
std::randomize();
TheNumber = std::random(10) + 1;

using namespace std;
{
guess:
cout << "I am thinking of a number between 1 and 10, what is it?\n - ";
cin >> GuessedNumber;

if(isNum(GuessedNumber))
GNumber = strtoint(GuessedNumber); else
if((GuessedNumber == "x") || (GuessedNumber == "X"))
return 0; else
{
cout << "\nPlease enter a number only, or the letter 'X' (which will close the program).\n\n";
goto guess;
}

while (GNumber != TheNumber)
{

Guesses++;

if(GNumber < TheNumber)
cout << "Not quite right. Higher.\n"; else
cout << "Not quite right. Lower.\n";

guess2:
cout << "\nWhat is the number?:\n - ";
cin >> GuessedNumber;

if(isNum(GuessedNumber))
GNumber = strtoint(GuessedNumber); else
if((GuessedNumber == "x") || (GuessedNumber == "X"))
return 0; else
{
cout << "\nPlease enter a number only, or the letter 'X' (which will close the program).\n\n";
goto guess2;
}
}

cout << "Congratulations! You got it! The number was " << TheNumber << ".\n It took you " << Guesses << " guess(es) to figure it out!\n\n";
Guesses = 0;
}

}

return 0;
}

My first game in PHP was also a guessing game (used POST and a form), which I also cannot find the source for :(

Quickmarch
03-20-2010, 07:59 AM
A Snake game (http://code.google.com/p/flashsnakesource/), although the code is old and inefficient.

Edit: I also made a drawing game, though I don't know if that counts (http://villavu.com/forum/showthread.php?t=41089), and the code was very inefficient.

Craig`
03-20-2010, 10:12 AM
looks like the C++ tags need some work.

my first game was pretty crap, it was just simply a maze whereas you could navigate your player through it, not being able to pass through walls; the main objective was to get the treasure - when you got it you would respawn and the treasure would be at a different location, with your score incrementing. I was going to add some timer functionality but I had a server format, and I forgot to back it up :(

oh, and it was made using ECMAScript and SVG.

I guess I could make some other little ones, or I may do some simple WebGL

~ Craig` :)

Camaro'
03-21-2010, 11:40 PM
http://www.youtube.com/watch?v=vpe3AZzJ95g

I wanted to show a friend of my progress on the game i was making back then, that is why I have it on video :)...


That code is LONG gone :D

Sex
03-22-2010, 12:12 AM
http://www.youtube.com/watch?v=vpe3AZzJ95g

I wanted to show a friend of my progress on the game i was making back then, that is why I have it on video :)...


That code is LONG gone :D
What language?

Camaro'
03-22-2010, 12:30 AM
What language?

C++

x[Warrior]x3500
03-22-2010, 03:46 AM
The first game I made in C++ was a guessing game:

#include <iostream>
#include <string>
#include <stdlib.h>

bool isNum(std::string str)
{
for (unsigned int i = 0; i < str.length(); i++)
{
if(!(std::isdigit(str[i])))
return false;
}

return true;
}

int strtoint(const std::string str)
{
if(!(isNum(str)))
return 0;

return(atoi(str.c_str()));
}

int main()
{
int TheNumber = 0;
std::string GuessedNumber = "";
int GNumber = 0;
int Guesses = 0;

std::cout << "Welcome to Guess! A game made by Mayazcherquoi\n\n\n";

while (true)
{
std::randomize();
TheNumber = std::random(10) + 1;

using namespace std;
{
guess:
cout << "I am thinking of a number between 1 and 10, what is it?\n - ";
cin >> GuessedNumber;

if(isNum(GuessedNumber))
GNumber = strtoint(GuessedNumber); else
if((GuessedNumber == "x") || (GuessedNumber == "X"))
return 0; else
{
cout << "\nPlease enter a number only, or the letter 'X' (which will close the program).\n\n";
goto guess;
}

while (GNumber != TheNumber)
{

Guesses++;

if(GNumber < TheNumber)
cout << "Not quite right. Higher.\n"; else
cout << "Not quite right. Lower.\n";

guess2:
cout << "\nWhat is the number?:\n - ";
cin >> GuessedNumber;

if(isNum(GuessedNumber))
GNumber = strtoint(GuessedNumber); else
if((GuessedNumber == "x") || (GuessedNumber == "X"))
return 0; else
{
cout << "\nPlease enter a number only, or the letter 'X' (which will close the program).\n\n";
goto guess2;
}
}

cout << "Congratulations! You got it! The number was " << TheNumber << ".\n It took you " << Guesses << " guess(es) to figure it out!\n\n";
Guesses = 0;
}

}

return 0;
}



ewww. icky code :P but not too shabby for your first game. how long ago did you make this? oh and my first game was a pong game made in c++ w/ allegro. cant find source, but if i do, i will post.

oh n i got bored, so i decided to switch your code around (purely out of boredom/fun)



#include <iostream>
#include <string>


using namespace std;

class guess{
int GuessedNumber;
int a;
public:
int GuessNumber;
int TheNumber(){return a;};
void initialize() {GuessNumber=0; srand(unsigned(time(NULL))); a = (rand() % 100);};
void ask();
bool correct();
void stupidguess();
bool done();

};

void guess::ask() {
cout << "Welcome to Guess!"<<endl<<endl;
cout << "I am thinking of a number between 1 and 10, what is it?"<<endl;
cin >> GuessedNumber;
cout << string(50, '\n');
}

bool guess::correct() {
if (TheNumber()==GuessedNumber) {
return true;
}
else {
return false;
}
}

void guess::stupidguess () {
GuessNumber++;
if(GuessedNumber < TheNumber()) {
cout << "Higher. Guesses Left: "<< 10-GuessNumber<<endl;
system("pause");
cout << string(50, '\n');
}
else {
cout << "Lower. Guesses Left: "<< 10-GuessNumber<<endl;
system("pause");
cout << string(50, '\n');
}
}

bool guess::done() {
if (correct()) {
cout<<"Yay you win"<<endl;
GuessNumber=11;
system("pause");
return true;
}
else {
if (GuessNumber<=9) {
stupidguess();
}
if (GuessNumber>9) {
cout<<"You lose. Number was: "<< TheNumber()<<endl;
system("pause");
}
return false;
}
}


int main()
{
guess g;
g.initialize();
while ((g.GuessNumber<=9)) {
g.ask();
g.done();
}
return 0;
}

Tim0suprem0
03-22-2010, 05:34 AM
My first java assignment in school :)

The Happy Kingdom!


import java.util.Random;
import java.util.Scanner;

public class KingdomSim {

public static void main(String[] args) {

System.out.println("Rules: \nEach person must eat 2 bushels " +
"of grain per year to survive.\nEach person can farm 1 acre of land." +
"\nIt takes 1 bushel of grain to plant an acre of land." +
"\nThe game is over after 10 turns.\n");

Scanner stdIn = new Scanner(System.in);

//get seed value
System.out.println("Please enter a seed value");
int seedValue = stdIn.nextInt();

Random ranGen = new Random(seedValue);
int turns = 0;
int population = 750;
int bushelsOfGrain = 2000;
int acresOfLand = 500;
int diedOfStarvation = 0;
int priceOfLand, landToBuy, landToSell, foodReleased, popChange, acresToPlant,
weather, bushelsHarvested, finalScore;

//begin the turn loop
do {
turns++;
priceOfLand = ranGen.nextInt(11)+10; //randomize price of land

//turn start report
System.out.println("\n\nTurn " + turns);
System.out.println("Population: " + population);
System.out.println("Bushels of grain in storage: " + bushelsOfGrain);
System.out.println("Acres of land in the kingdom: " + acresOfLand);
System.out.println("Price of land: " + priceOfLand + " bushels/acre.\n");

//get amount of land to buy
System.out.println("How much land would you like to buy?\n" +
"(0 - " + bushelsOfGrain / priceOfLand+ ")");
landToBuy = stdIn.nextInt();

// make sure input is valid
while (landToBuy < 0 || landToBuy > (bushelsOfGrain/priceOfLand)) {
System.out.println("\nInvalid input, please enter a number between" +
" 0 and " + (bushelsOfGrain / priceOfLand));
landToBuy = stdIn.nextInt();
}
acresOfLand += landToBuy;
bushelsOfGrain -= priceOfLand*landToBuy;

//get amount of land to sell if necessary
if (landToBuy == 0) {
System.out.println("\nHow much land would you like to sell?\n" +
"(0 - " + acresOfLand + ")");
landToSell = stdIn.nextInt();

//make sure input is valid
while (landToSell < 0 || landToSell > acresOfLand) {
System.out.println("\nInvalid input, please enter a number " +
"between 0 and " + acresOfLand);
landToSell = stdIn.nextInt();
}

acresOfLand -= landToSell;
bushelsOfGrain += priceOfLand*landToSell;
}

// get amount of grain to feed to people
System.out.println("\nHow much grain do you want to release to your" +
" people?\n(0 - " + bushelsOfGrain + ")");
foodReleased = stdIn.nextInt();

//make sure input is valid
while (foodReleased < 0 || foodReleased > bushelsOfGrain) {
System.out.println("\nInvalid input, please enter a number between" +
" 0 and " + bushelsOfGrain);
foodReleased = stdIn.nextInt();
}

//reduce stores of grain from feeding peasants
bushelsOfGrain -= foodReleased;

//calculate population change
if (foodReleased < (population * 2)) {
popChange = (foodReleased / 2)- population;
}
else {
popChange = (foodReleased / 2) - population;
}

//calculate number of acres to plant
if (acresOfLand <= bushelsOfGrain && acresOfLand <= population) {
acresToPlant = acresOfLand;
}
else if (bushelsOfGrain <= acresOfLand && bushelsOfGrain <= population) {
acresToPlant = bushelsOfGrain;
}
else {
acresToPlant = population;
}

//print growing report
System.out.println("\nYou have " + population + " peasants, "
+ acresOfLand + " acres and " + bushelsOfGrain
+ " bushels of grain," + " so you were able to plant "
+ acresToPlant + " acres of land this turn.");

//reduce stores of grain from planting
bushelsOfGrain -= acresToPlant;

//get a random number between 0 and 4 (inclusive)
weather = ranGen.nextInt(5);

switch (weather) {
case 0:
System.out.println("Terrible harvest!"); break; //terrible harvest
case 1:
System.out.println("Poor harvest."); break; //poor harvest
case 2:
System.out.println("Average harvest."); break; //average harvest
case 3:
System.out.println("Good harvest."); break; //good harvest
case 4:
System.out.println("Excellent harvest!"); break; //excellent harvest
}

weather += 3; //add 3 to the random number to get the 3 - 7 range
bushelsHarvested = acresToPlant * weather; //calculate yield
System.out.println("You harvested " + bushelsHarvested +
" bushels of grain.");
bushelsOfGrain += bushelsHarvested; //update bushels based on harvest

//update population and report
population += popChange;
if (popChange > 0) {
System.out.println("\n" + popChange +
" immigrants came to the kingdom.");
}
else if (popChange < 0) {
System.out.println("\n" + -popChange +
" peasants died of starvation.");
diedOfStarvation -= popChange; //keep track of dead from starvation
}

} while (turns < 10); //end the turn loop

//end game report
finalScore = (acresOfLand * 15) + (population * 2) + (bushelsOfGrain)
- (diedOfStarvation * 10); // calculate the final score
System.out.println("\n\n\nFinal population: " + population);
System.out.println("Final size of kingdom: " + acresOfLand + " acres");
System.out.println("Final size of grain stores: " + bushelsOfGrain +
" bushels");
System.out.println("Total peasants killed from starvation: " +
diedOfStarvation);
System.out.println("Final score: " + finalScore);

}

}

Daniel
03-22-2010, 07:40 AM
Lol nice one Tim0 :p I gotta give that a shot ;) xD

x3500;696456']ewww. icky code :P but not too shabby for your first game. how long ago did you make this? oh and my first game was a pong game made in c++ w/ allegro. cant find source, but if i do, i will post.

oh n i got bored, so i decided to switch your code around (purely out of boredom/fun)



#include <iostream>
#include <string>


using namespace std;

class guess{
int GuessedNumber;
int a;
public:
int GuessNumber;
int TheNumber(){return a;};
void initialize() {GuessNumber=0; srand(unsigned(time(NULL))); a = (rand() % 100);};
void ask();
bool correct();
void stupidguess();
bool done();

};

void guess::ask() {
cout << "Welcome to Guess!"<<endl<<endl;
cout << "I am thinking of a number between 1 and 10, what is it?"<<endl;
cin >> GuessedNumber;
cout << string(50, '\n');
}

bool guess::correct() {
if (TheNumber()==GuessedNumber) {
return true;
}
else {
return false;
}
}

void guess::stupidguess () {
GuessNumber++;
if(GuessedNumber < TheNumber()) {
cout << "Higher. Guesses Left: "<< 10-GuessNumber<<endl;
system("pause");
cout << string(50, '\n');
}
else {
cout << "Lower. Guesses Left: "<< 10-GuessNumber<<endl;
system("pause");
cout << string(50, '\n');
}
}

bool guess::done() {
if (correct()) {
cout<<"Yay you win"<<endl;
GuessNumber=11;
system("pause");
return true;
}
else {
if (GuessNumber<=9) {
stupidguess();
}
if (GuessNumber>9) {
cout<<"You lose. Number was: "<< TheNumber()<<endl;
system("pause");
}
return false;
}
}


int main()
{
guess g;
g.initialize();
while ((g.GuessNumber<=9)) {
g.ask();
g.done();
}
return 0;
}
Well, for this post I wasn't intending for people to show how to do improve things, because I thought the "first" word would imply it :p

I know you can do it differently, as would I now. However, not exactly like yours xD

Also, I made that about 4-5 months ago (on memory).

Craig`
03-22-2010, 02:17 PM
how is The Man's code "icky"?

he has good use of the std namespace, not just including it at first (thus including all functions making it inefficient if you don't use them all)

~ Craig`

caused
03-22-2010, 02:40 PM
The first game I wrote was tic tac toe in C, sadly i cant provide sauce ;O

Zyt3x
03-22-2010, 02:42 PM
http://www.youtube.com/watch?v=vpe3AZzJ95g

I wanted to show a friend of my progress on the game i was making back then, that is why I have it on video :)...


That code is LONG gone :DI've seen that somewhere before! Have you ever linked to it or anything like that?

x[Warrior]x3500
03-22-2010, 10:55 PM
how is The Man's code "icky"?

he has good use of the std namespace, not just including it at first (thus including all functions making it inefficient if you don't use them all)

~ Craig`

well you are completely correct in that his use of std is more efficient. why i thought his code was icky (note icky is an opinion) was because of two things: no classes, icky main(). first i am gunna throw in "no classes" cus one of the main functions that C++ has over C is that it can use OOP. Why not atleast attempt to do it then?
also IMO main() should not be like 3 pages long. any super big main() just makes a code look super icky to me (depends on how long the actual code is too - like a 5000 lined code will have a bigger main() than a 500 lined code typically, and that is understandable).

just little things like that made it look icky to me. now @Dan:
XD sry if i sounded like i wanted to "make your code better". lol cus that was not my desire. i just got super bored and decided i would create the same game, but a different way (i stole a couple lines of your code here and there). so then i decided to post it :D. so did you teach yourself? or do a class or what? i honestly think your use of std is very smart and efficient. but i do think your code overall looks icky :P (personal opinion, please take no offence).

mastaraymond
03-22-2010, 11:06 PM
MastaMario!!! -> http://villavu.com/forum/showthread.php?t=21127

Cazax
03-22-2010, 11:45 PM
ClickEm!!! -> http://villavu.com/forum/showthread.php?t=41552

Tim0suprem0
03-23-2010, 02:52 AM
MastaMario!!! -> http://villavu.com/forum/showthread.php?t=21127

Holy shit. I forgot how epic this was.

weequ
03-23-2010, 03:29 AM
Snake game in pascal :) controls are wasd.
program Snake;

uses
crt;

type
TPoint = record
x, y: Integer;
end;


var
I, II, x, y, Suunta, Pisteet, x2, y2, elamat: Integer;
K: Char;
IA: Array [0..10000000] of TPoint;
Syoty: Boolean;


procedure Setup;
begin
Clrscr;
Window (1,1,45, 45);
WriteLn('---------------------------------------');
WriteLn('| |');
WriteLn('| |');
WriteLn('| |');
WriteLn('| |');
WriteLn('| |');
WriteLn('| |');
WriteLn('| |');
WriteLn('| |');
WriteLn('| |');
WriteLn('| |');
WriteLn('| |');
WriteLn('| |');
WriteLn('| |');
WriteLn('| |');
WriteLn('| |');
WriteLn('| |');
WriteLn('| |');
WriteLn('| |');
WriteLn('| |');
WriteLn('| |');
WriteLn('| |');
WriteLn('---------------------------------------');

Elamat := 1;
I := 0;
Suunta := 0;
Pisteet := 0;
x := 15;
y := 10;
Syoty := True;
IA[I].x := x;
IA[I].y := y;
end;

procedure NaytaPisteet;
begin
GotoXY(3,24);
WriteLn('Score: ', Pisteet);
GotoXY(20,24);
WriteLn('Lifes: ', Elamat);
end;

begin
repeat
Setup;
repeat
if KeyPressed then
begin
K := ReadKey;
case K of
'w': if not (Suunta = 2) then Suunta := 1;
's': if not (Suunta = 1) then Suunta := 2;
'a': if not (Suunta = 4) then Suunta := 3;
'd': if not (Suunta = 3) then Suunta := 4;
end;
end;
if (Suunta = 1) or (Suunta = 2) then Delay(110)
else Delay(90);
if I > Pisteet-1 then
begin
GotoXY(IA[I-Pisteet].x, IA[I-Pisteet].y);
WriteLn(' ');
end;
case Suunta of
1: if y = 2 then y := 22
else y := y-1;
2: if y = 22 then y := 2
else y := y+1;
3: if x = 2 then x := 38
else x := x-1;
4: if x = 38 then x := 2
else x := x+1;
end;
if Suunta > 0 then
begin
I := I+1;
IA[I].x := x;
IA[I].y := y;
end;
if syoty then
begin
repeat
x2 := 2+Random(37);
y2 := 2+Random(21);
for II := I-Pisteet to I do
begin
if (x2=IA[II].x) and (y2=IA[II].y) then
Break else Continue;
end;
until(II > I-1);
GotoXY(x2, y2);
WriteLn('O');
Syoty := False;
end;
if (x = x2) and (y = y2) then
begin
Syoty := True;
Pisteet := Pisteet+1;
end;
for II := I-Pisteet to I-1 do
if (x=IA[II].x) and (y=IA[II].y) then
begin
Elamat := Elamat-1;
Break;
end;
GotoXY(x, y);
if Syoty then WriteLn('@')
else
Case Suunta of
0..2: WriteLn('|');
3..4: WriteLn('-');
end;
NaytaPisteet;
until(Elamat = 0);
WriteLn('Q = quit, N = new game');
Delay(2000);
repeat
if ReadKey = 'q' then Halt;
if ReadKey = 'n' then Break;
until(False);
until(false);
end.

Camaro'
03-24-2010, 02:45 AM
I've seen that somewhere before! Have you ever linked to it or anything like that?

I probably showed you before, I showed a few people.

That video is win.

Craig`
03-24-2010, 07:33 AM
improving improved code. :D



bool guess::correct() {
if (TheNumber()==GuessedNumber) {
return true;
}
else {
return false;
}
}


could simply be



bool guess::correct() {
return TheNumber() == GuessedNumber;
}


aha ;)

~ CRaig` :)

x[Warrior]x3500
03-24-2010, 10:35 PM
:D very nice

mixster
03-24-2010, 10:48 PM
MastaMario!!! -> http://villavu.com/forum/showthread.php?t=21127

ScaRPG was way cooler, well would have been if Scar wasn't so silly and restricting!

Oh and I made a Java pong too, was quite fun - all 4 walls had players then produced AI's for the other 3, giving them increasing skill as the game progresses!

In Delphi I made a potato.

Daniel
04-13-2010, 06:22 AM
ScaRPG was way cooler, well would have been if Scar wasn't so silly and restricting!

Oh and I made a Java pong too, was quite fun - all 4 walls had players then produced AI's for the other 3, giving them increasing skill as the game progresses!

In Delphi I made a potato.

Err... a potato? Explain :D

bullzeye95
04-13-2010, 11:42 AM
The first game I make for a new language is almost always pong, as it gives me a good feel for the language. Unfortunately, I never save anything I write, so I can't post any sauce :rolleyes:


MastaMario!!! -> http://villavu.com/forum/showthread.php?t=21127

<3