Originally Posted by
tabstop
Since I have no idea what you don't understand, no. Are you saying you have never seen == before? Are you saying you don't know what a function is? Are you saying you don't know how to loop over nine spots in the board?
Here is my code, icant get the game to end when the grids are the same :/
Code:
// heero.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
//Prototyper
void print(char start[][3]);
void jump3(char start[][3],string filnamn);
void jump(char start[][3]);
int main()
{
int yes,abryt,count;
char start[3][3], goal[3][3];
string filnamn1, filnamn2, filnamn3;
filnamn1 = "start.txt",
filnamn2 = "goal.txt";
filnamn3 = "score.txt";
jump3(start,filnamn1);
jump3(goal,filnamn2);
/* jump3(score,filnamn3); */
count = 0;
int loop = 0,score;
while (loop == 0){
print(start);
print(goal);
jump(start);
if (start == goal){
cout << "lol" << endl;
}
// lägger till +1 på count varje gång och skriver sedan ut hur många gåner man har rört på sej.
count++;
cout << "You have done: " << count << " moves" << endl << endl;
/* system ("cls");*/
/* print(score);
if (count > score)
cout << "your in the highscore, please enter your name" << endl;
cin >> */
}
return 0;
}
void jump(char start[][3]){
string jump2;
cout << "You move by using W A S D on you keyboard like in Counter-Strike ";
cin >> jump2;
int nx, ny, temp, x, y,jump;
//tar reda på vart X är
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
if (start[i][j] == 'X'){
y=i;
x=j;
//Visar position av X för spealren
cout << "You are on square: " << "Y: " << y << " X: " << x << endl << endl;
}
}
}
//funktion för att avbryta spelet
if(jump2 == "quit"){
string quit;
cout << "Want to quit the game eh? Yes/no" ;
cin >> quit;
if(quit == "yes"){
system ("cls");
cout << "Even Uther was more brave then you are, he never gave up." << endl;
}
else cout << "Hail to the king baby!";
//gör så spelet forsätter
}
//if satser för att röra på sej
if(jump2 == "w"){
ny = y-1;
nx = x;
}
else if (jump2 == "a"){
nx = x-1;
ny = y;
}
else if (jump2 == "s"){
ny = y+1;
nx = x;
}
else if (jump2 == "d"){
nx = x+1;
ny = y;
}
else{
cout << "YOU CANT GO HERE!!!!!!!!" << endl;
nx = x;
ny = y;
}
//temporär variable för att lagra position av X och flytta på X
if (nx > -1 && nx < 3 && ny > -1 && ny < 3)
{
temp = start[ny][nx];
start[ny][nx] = start[y][x];
start[y][x] = temp;
}
}
void jump3(char start[][3],string filnamn){
ifstream infil(filnamn.c_str());
//array som läser in filen som blivit vald
infil >> start[0][0] >> start[0][1] >> start[0][2]
>> start[1][0] >> start[1][1] >> start[1][2]
>> start[2][0] >> start[2][1] >> start[2][2];
//array somskriver ut filen som blivit vald
}
void print(char start[][3]){
cout << start[0][0] << " " << start[0][1] << " " << start[0][2]
<< endl << start[1][0] << " " << start[1][1] << " " << start[1][2]
<< endl << start[2][0] << " " << start[2][1] << " " << start[2][2]
<< endl << endl;
}