Har prøvet CLR Empty Projekt og CLR Console Application.
I den sidst nævnte bliver der oprettet en hel del filer i projektet som jeg ikke ved hvad jeg skal gøre ved, og om jeg i det hele taget skal gøre noget ved.
Jeg smider så min kilde kode ind i den fil hvor der står main fil, og så virker det helt fint, på min computer.
// TestAfProjekt.cpp : main project file.
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
using namespace System;
using namespace std;
int iWidth = 25;
int iHeight = 25;
int iRound = 1;
int iPlayerX1st;
int iLastX = 0;
int iLastY = 0;
string sPlayer1;
string sPlayer2;
bool bWinnerFound = false;
void printStatus()
{
if (!bWinnerFound)
{
cout<<"Runde: "<<iRound<<endl;
if(iRound%2 == 1)
if(iPlayerX1st == 1)
cout<<"Spiller X - "<<sPlayer1<<"'s tur."<<endl;
else
cout<<"Spiller O - "<<sPlayer2<<"'s tur."<<endl;
else
if(iPlayerX1st == 1)
cout<<"Spiller O - "<<sPlayer2<<"'s tur."<<endl;
else
cout<<"Spiller X - "<<sPlayer1<<"'s tur."<<endl;
}
else
{
cout << "Runde: " << iRound << endl;
cout << "Vi har en vinder! Tillykke ";
if(iRound%2 == 1)
if(iPlayerX1st == 1)
cout << sPlayer1 << endl;
else
cout << sPlayer2 << endl;
else
if(iPlayerX1st == 1)
cout << sPlayer2 << endl;
else
cout << sPlayer1 << endl;
}
}
void enterNewBrick(int iPladen[][25])
{
string sKoordinater = "";
string sTemp;
int x = 0;
int y = 0;
bool bFejl = true;
cout << "Skriv koordinater til ønsket position(x,y): ";
do {
getline(cin,sKoordinater);
string::size_type stFejl = sKoordinater.find_first_not_of("0123456789,");
if (stFejl != string::npos)
{
cout << "Input Error 1" << endl;
}
else
{
string::size_type stKomma = sKoordinater.find(',');
if (stKomma == string::npos || stKomma == 0)
{
cout << "Input Error 2" << endl;
}
else
{
sTemp = sKoordinater.substr(stKomma + 1);
string::size_type stFejl = sTemp.find_first_of(",");
if (stFejl != string::npos)
{
cout << "Input Error 3" << endl;
}
else
{
sTemp = sKoordinater.substr(0,stKomma);
stringstream ssTemp (sTemp);
ssTemp >> x;
if (x == 0 || x > iWidth)
{
cout << "Input Error 4" << endl;
}
else
{
sTemp = sKoordinater.substr(stKomma + 1);
stringstream SS(sTemp);
SS >> y;
if (y == 0 || y > iHeight)
{
cout << "Input Error 5" << endl;
}
else
{
x--;
y--;
if(iPladen[x][y] != 0)
{
cout << "Input Error 6" << endl;
}
else
{
bFejl = false;
iLastX = x;
iLastY = y;
if(iRound%2 == 1)
{
if(iPlayerX1st == 1)
{
iPladen[x][y] = 1;
}
else
{
iPladen[x][y] = 2;
}
}
else
{
if(iPlayerX1st == 1)
{
iPladen[x][y] = 2;
}
else
{
iPladen[x][y] = 1;
}
}
}
}
}
}
}
}
} while (bFejl);
}
void updateGame(int arg[][25])
{
int iCellType = 0;
string sKoordinater = "";
system("cls");
printStatus();
cout<<"\\n";
for (int y = 0; y < (2*iHeight)+2; y++)
{
for (int x = 0; x < (2*iWidth)+2; x++)
{
if(x == 0 && y == 0)
{
iCellType = 1;
}
else if(x == 0 && y%2 != 0)
{
iCellType = 2;
}
else if(x == 0 && y%2 == 0)
{
iCellType = 3;
}
else if(y == 0 && x%2 != 0)
{
iCellType = 4;
}
else if(y == 0 && x%2 == 0)
{
iCellType = 5;
}
else if(x == (2*iWidth)+1 && y == (2*iHeight)+1)
{
iCellType = 6;
}
else if(x == (2*iWidth)+1 && y%2 != 0)
{
iCellType = 7;
}
else if(y == (2*iHeight)+1 && x%2 != 0)
{
iCellType = 8;
}
else if(x%2 != 0 && y%2 != 0)
{
iCellType = 9;
}
else if(y%2 == 0 && x%2 != 0)
{
iCellType = 10;
}
else if(x%2 == 0 && y%2 != 0)
{
iCellType = 11;
}
else if(x%2 == 0 && y%2 == 0)
{
iCellType = 12;
}
switch(iCellType)
{
case 1:
cout << setw(3) << " ";
break;
case 2:
cout << " ";
cout << char(196) << char(196);
break;
case 3:
cout << " ";
cout << setw(2) << y/2;
break;
case 4:
cout << char(179);
break;
case 5:
cout << setw(2) << x/2;
break;
case 6:
cout << char(217);
break;
case 7:
cout << char(180);
break;
case 8:
cout << char(193);
break;
case 9:
cout << char(197);
break;
case 10:
cout << char(179);
break;
case 11:
cout << char(196) << char(196);
break;
case 12:
switch(arg[(x-2)/2][(y-2)/2])
{
case 0:
cout << setw(2) << " ";
break;
case 1:
cout << setw(2) << "X";
break;
case 2:
cout << setw(2) << "O";
break;
default:
cout << "??";
}
break;
default:
cout << "??";
}
}
cout << "\\n";
}
}
int getNumber()
{
string S;
int tal;
bool bDone = 0;
do{
getline(cin,S);
stringstream SS(S);
if(SS >> tal)
{
//cout<<"Succes!"<<endl;
SS >> tal;
bDone = 1;
}
else
cout<<"Skriv kun tal, prøv igen."<<endl;
} while (!bDone);
return tal;
}
void getInfo()
{
system("cls");
cout<<"Indstilling af spillet:"<<endl;
cout<<"Navn på Spiller X:"<<endl;
getline(cin,sPlayer1);
cout<<"Navn på Spiller O:"<<endl;
do {
if(sPlayer1 == sPlayer2)
cout<<"De to spillere kan ikke hedde det samme, indtast nyt navn til spiller 2"<<endl;
getline(cin,sPlayer2);
}while(sPlayer1 == sPlayer2);
cout<<"Spilleplade bredde?(5-25)";
do {
iWidth = getNumber();
if(iWidth > 25)
cout << "Maks 25! Prøv igen." << endl;
else if (iWidth < 5)
cout << "Min 5! Prøv igen." << endl;
} while(iWidth > 25 || iWidth < 5);
cout<<"Spilleplade højde?(5-25)";
do{
iHeight = getNumber();
if(iHeight > 25)
cout << "Maks 25! Prøv igen." << endl;
else if (iHeight < 5)
cout << "Min 5! Prøv igen." << endl;
} while(iHeight > 25 || iHeight < 5);
if(rand()%2 == 0)
iPlayerX1st = 1;
else
iPlayerX1st = 2;
}
void intro()
{
string sInput;
cout << "*********************************************************" << endl;
cout << "*********************************************************" << endl;
cout << "*********************************************************" << endl;
cout << "**** ****" << endl;
cout << "**** Velkommen til Mulle's 5-paa-stribe ****" << endl;
cout << "**** Version 2.4 ****" << endl;
cout << "**** ****" << endl;
cout << "**** Dedicated to someone out there. ****" << endl;
cout << "**** You decide who! ****" << endl;
cout << "**** ****" << endl;
cout << "**** Tryk enter for at fortsætte. ****" << endl;
cout << "**** ****" << endl;
cout << "*********************************************************" << endl;
cout << "*********************************************************" << endl;
cout << "*********************************************************" << endl;
getline(cin,sInput);
}
void lookForWinner(int iPladen [][25])
{
int x = iLastX;
int y = iLastY;
if(iRound > 8)
{
if ( x != 0 && y != 0 && iPladen[x][y] == iPladen[x-1][y-1] )
{
if ( x != 1 && y != 1 && iPladen[x][y] == iPladen[x-2][y-2] )
{
if ( x != 2 && y != 2 && iPladen[x][y] == iPladen[x-3][y-3] )
{
if ( x != 3 && y != 3 && iPladen[x][y] == iPladen[x-4][y-4] )
{
bWinnerFound = true;
}
else if ( x < iWidth-1 && y < iHeight-1 && iPladen[x][y] == iPladen[x+1][y+1] )
{
bWinnerFound = true;
}
}
else if ( x < iWidth-2 && y < iHeight-2 && iPladen[x][y] == iPladen[x+1][y+1] && iPladen[x][y] == iPladen[x+2][y+2] )
{
bWinnerFound = true;
}
}
else if ( x < iWidth-3 && y < iHeight-3 && iPladen[x][y] == iPladen[x+1][y+1] && iPladen[x][y] == iPladen[x+2][y+2] && iPladen[x][y] == iPladen[x+3][y+3] )
{
bWinnerFound = true;
}
}
else if ( x < iWidth-4 && y < iHeight-4 && iPladen[x][y] == iPladen[x+1][y+1] && iPladen[x][y] == iPladen[x+2][y+2] && iPladen[x][y] == iPladen[x+3][y+3] && iPladen[x][y] == iPladen[x+4][y+4])
{
bWinnerFound = true;
}
if ( x != 0 && iPladen[x][y] == iPladen[x-1][y] )
{
if ( x != 1 && iPladen[x][y] == iPladen[x-2][y] )
{
if ( x != 2 && iPladen[x][y] == iPladen[x-3][y] )
{
if ( x != 3 && iPladen[x][y] == iPladen[x-4][y] )
{
bWinnerFound = true;
}
else if ( x < iWidth-1 && iPladen[x][y] == iPladen[x+1][y] )
{
bWinnerFound = true;
}
}
else if ( x < iWidth-2 && iPladen[x][y] == iPladen[x+1][y] && iPladen[x][y] == iPladen[x+2][y] )
{
bWinnerFound = true;
}
}
else if ( x < iWidth-3 && iPladen[x][y] == iPladen[x+1][y] && iPladen[x][y] == iPladen[x+2][y] && iPladen[x][y] == iPladen[x+3][y] )
{
bWinnerFound = true;
}
}
else if ( x < iWidth-4 && iPladen[x][y] == iPladen[x+1][y] && iPladen[x][y] == iPladen[x+2][y] && iPladen[x][y] == iPladen[x+3][y] && iPladen[x][y] == iPladen[x+4][y] )
{
bWinnerFound = true;
}
if ( y != 0 && iPladen[x][y] == iPladen[x][y-1] )
{
if ( y != 1 && iPladen[x][y] == iPladen[x][y-2] )
{
if ( y != 2 && iPladen[x][y] == iPladen[x][y-3] )
{
if ( y != 3 && iPladen[x][y] == iPladen[x][y-4] )
{
bWinnerFound = true;
}
else if ( y < iHeight-1 && iPladen[x][y] == iPladen[x][y+1] )
{
bWinnerFound = true;
}
}
else if ( y < iHeight-2 && iPladen[x][y] == iPladen[x][y+1] && iPladen[x][y] == iPladen[x][y+2] )
{
bWinnerFound = true;
}
}
else if ( y < iHeight-3 && iPladen[x][y] == iPladen[x][y+1] && iPladen[x][y] == iPladen[x][y+2] && iPladen[x][y] == iPladen[x][y+3] )
{
bWinnerFound = true;
}
}
else if ( y < iHeight-4 && iPladen[x][y] == iPladen[x][y+1] && iPladen[x][y] == iPladen[x][y+2] && iPladen[x][y] == iPladen[x][y+3] && iPladen[x][y] == iPladen[x][y+4] )
{
bWinnerFound = true;
}
if ( x != iWidth-1 && y != 0 && iPladen[x][y] == iPladen[x+1][y-1] )
{
if ( x != iWidth-2 && y != 1 && iPladen[x][y] == iPladen[x+2][y-2] )
{
if ( x != iWidth-3 && y != 2 && iPladen[x][y] == iPladen[x+3][y-3] )
{
if ( x != iWidth-4 && y != 3 && iPladen[x][y] == iPladen[x+4][y-4] )
{
bWinnerFound = true;
}
else if ( x > 0 && y < iHeight-1 && iPladen[x][y] == iPladen[x-1][y+1] )
{
bWinnerFound = true;
}
}
else if ( x > 1 && y < iHeight-2 && iPladen[x][y] == iPladen[x-1][y+1] && iPladen[x][y] == iPladen[x-2][y+2] )
{
bWinnerFound = true;
}
}
else if ( x > 2 && y < iHeight-3 && iPladen[x][y] == iPladen[x-1][y+1] && iPladen[x][y] == iPladen[x-2][y+2] && iPladen[x][y] == iPladen[x-3][y+3] )
{
bWinnerFound = true;
}
}
else if ( x > 3 && y < iHeight-4 && iPladen[x][y] == iPladen[x-1][y+1] && iPladen[x][y] == iPladen[x-2][y+2] && iPladen[x][y] == iPladen[x-3][y+3] && iPladen[x][y] == iPladen[x-4][y+4])
{
bWinnerFound = true;
}
}
}
int main ()
{
int iPladen[25][25];
int x,y;
for (x = 0; x < 25; x++)
{
for (y = 0; y < 25; y++)
{
iPladen[x][y] = 0;
}
}
intro();
getInfo();
do
{
updateGame(iPladen);
enterNewBrick(iPladen);
lookForWinner(iPladen);
updateGame(iPladen);
iRound++;
} while (!bWinnerFound);
cin.get();
return 0;
}
Der har i kildekoden dejlig rodet og uden kommentar
Håber at vi kan finde en løsning på problemet.
Mvh. Troels