Hejsa
/edit: Det blev 4 spørgsmål :-)
Jeg sidder og roder med noget c++, da jeg gerne vil lære det. Jeg startede på det idag så er ret ny, og har måske allerede gabt over for meget.
Jeg har lånt noget kode fra en af de utallige gratis steder på nettet, og er nu igang med at prøve at viderudvikle det.
1. Hvordan får jeg terningerne op på samme niveau, sådan at spiller 1 og 2's kast ligger over for hinanden?
2. Jeg vil gerne have en highscore funktion. Er det noget jeg burde glemme nu her i starten?
3. Ideen med spillet er at jeg vil kunne lægge en ascii tegning ind for hver spiller. f.eks. en ispind. Når spilleren så kaster sin terning (f.eks 2 + 5), får han f.eks. 7 streger i sin ascii tegning. Vinderen er den der bliver først færdig. Det er så meningen at de 5 hurtigste (Dem med færrest kast) skal kunne gemmes i en highscore liste.
4. Kan jeg fiksere det dos vindue, så den har en fast størrelse fra starten af? Vil gerne have at ascii tegningerne bygges op i bunden, mens feltet hvor terningerne kastes cleares ved hvert kast.
Det var vist det jeg sidder og roder med nu. Håber at nogen derude kan give mig nogle hints om hvordan jeg kan løse nogle af de problemer.
På forhånd tak.
Koden kan ses her forneden.
#include <iostream>
#include <time.h>
#include <cstdlib>
#include <windows.h>
#include <string>
using namespace std;
void et();
void to();
void tre();
void fire();
void fem();
void seks();
void one();
void two();
void three();
void four();
void five();
void six();
int main()
{
string username;
string username1;
system("title Henrik 's Battle of the dice");
cout <<"Spiller 1 indtast dit navn: \\n";
getline( cin, username );
cout << "\\nSpiller 2 indtast dit navn: \\n";
getline (cin, username1 );
system("cls");
cout <<"Hej " << username << " og " << username1 << ". Velkommen til Battle of the dice. \\n\\n";
short unsigned int p1score = 0;
short unsigned int p2Score = 0;
short unsigned int p1num = 0;
short unsigned int p1num2 = 0;
short unsigned int p2Num = 0;
short unsigned int p2Num2 = 0;
short unsigned int p1sum = 0;
short unsigned int p2Sum = 0;
char letter;
srand(time(NULL));
while (letter != 'q')
{
cout << username <<"'s score: " << p1score << endl;
cout << username1 <<"'s score: " << p2Score << endl << endl;
cout << "Tryk r for at rulle terningen, eller tryk q for at afslutte: ";
cin >> letter;
p1num = 1 + rand() % (6 - 1 + 1);
p1num2 = 1 + rand() % (6 - 1 + 1);
p2Num = 1 + rand() % (6 - 1 + 1);
p2Num2 = 1 + rand() % (6 - 1 + 1);
p1sum = p1num + p1num2;
p2Sum = p2Num + p2Num2;
if (letter == 'q')
break;
if (letter != 'r')
{
system("cls");
continue;
}
switch (p1num)
{
case 1:
et();
break;
case 2:
to();
break;
case 3:
tre();
break;
case 4:
fire();
break;
case 5:
fem();
break;
case 6:
seks();
break;
default:
cout << "Error...";
break;
} //end switch
switch (p1num2)
{
case 1:
et();
break;
case 2:
to();
break;
case 3:
tre();
break;
case 4:
fire();
break;
case 5:
fem();
break;
case 6:
seks();
break;
default:
cout << "Error...";
break;
} //end switch
switch (p2Num)
{
case 1:
one();
break;
case 2:
two();
break;
case 3:
three();
break;
case 4:
four();
break;
case 5:
five();
break;
case 6:
six();
break;
default:
cout << "Error...";
break;
} //end switch
switch (p2Num2)
{
case 1:
one();
break;
case 2:
two();
break;
case 3:
three();
break;
case 4:
four();
break;
case 5:
five();
break;
case 6:
six();
break;
default:
cout << "Error...";
break;
} //end switch
cout << endl << username << ": " << p1num << ", " << p1num2 ;
cout <<" " << username1 << ": " << p2Num << ", " << p2Num2 << "\\n\\n\\n";
if (p1sum > p2Sum)
{
cout <<"********************\\n";
cout <<" " << username << " vandt. \\n";
cout <<"********************\\n";
p1score++;
}
else
{
p2Score++;
cout <<"********************\\n";
cout <<" " << username1 << " vandt.\\n";
cout <<"********************\\n";
}
system("pause");
system("cls");
if (p1score == 12)
{
MessageBox(0, "Spiller 1 vandt. :-D", "Results:", MB_ICONEXCLAMATION);
break;
}
if (p2Score == 12)
{
MessageBox(0, "Spiller 2 vandt. :-D", "Results:", MB_ICONEXCLAMATION);
break;
}
}
return 0;
}
void et()
{
cout << " -----" << endl;
cout << "| |" << endl;
cout << "| O |" << endl;
cout << "| |" << endl;
cout << " -----" << endl;
}
void to()
{
cout << " -----" << endl;
cout << "| O|" << endl;
cout << "| |" << endl;
cout << "|O |" << endl;
cout << " -----" << endl;
}
void tre()
{
cout << " -----" << endl;
cout << "| O|" << endl;
cout << "| O |" << endl;
cout << "|O |" << endl;
cout << " -----" << endl;
}
void fire()
{
cout << " -----" << endl;
cout << "|O O|" << endl;
cout << "| |" << endl;
cout << "|O O|" << endl;
cout << " -----" << endl;
}
void fem()
{
cout << " -----" << endl;
cout << "|O O|" << endl;
cout << "| O |" << endl;
cout << "|O O|" << endl;
cout << " -----" << endl;
}
void seks()
{
cout << " -----" << endl;
cout << "|O O|" << endl;
cout << "|O O|" << endl;
cout << "|O O|" << endl;
cout << " -----" << endl;
}
void one()
{
cout << " -----" << endl;
cout << " | |" << endl;
cout << " | O |" << endl;
cout << " | |" << endl;
cout << " -----" << endl;
}
void two()
{
cout << " -----" << endl;
cout << " | O|" << endl;
cout << " | |" << endl;
cout << " |O |" << 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 << " |O O|" << endl;
cout << " -----" << endl;
}
void five()
{
cout << " -----" << endl;
cout << " |O O|" << endl;
cout << " | O |" << endl;
cout << " |O O|" << endl;
cout << " -----" << endl;
}
void six()
{
cout << " -----" << endl;
cout << " |O O|" << endl;
cout << " |O O|" << endl;
cout << " |O O|" << endl;
cout << " -----" << endl;
}
Indlæg senest redigeret d. 03.06.2006 23:01 af Bruger #10068