M
mog13
Guest
ok well it isnt my FIRST programme
but i doubted anyone would care about a "hello world" app, or a 2 number adder. so im counting this as my first, well first finished, programme.
i know there are thigns i could of probably/definatley done better, like not check for a win every step =/, but its only small so doesnt really effect it
it would be helpful if you could give CC
especially a easyer way to check for a win? thanks
Code:
#include <cstdlib>
#include <iostream>
#include <windows.h>
using namespace std;
string map[10][10]; //[x],[y]
bool p1 = 1,p2 = 0;
inline int draw_map(void) {
int i =1,ii=1;
cout << "[1][2][3][4][5][6]\n\n";
lines: for ( ; i<=6;){
cout <<"[" << map [i][ii] << "]";
i++;
}
ii++;
i = 1;
cout <<"\n";
if ( ii <=6)goto lines;
int l;
for(l=0;l<15;l++)cout << "\n";
}
inline int clear_map(void){
int i = 1,ii=0;
exs: ii ++;
for(;i<=6;i++) {
map [i][ii] = "-";
}
i = 1;
if (ii <6) goto exs;
}
inline int checkwin(int pox, int poy){
if ((map[pox+1][poy] == map[pox][poy] && map[pox+2][poy] == map[pox][poy] && map[pox+3][poy] == map[pox][poy])
or(map[pox][poy+1] == map[pox][poy] && map[pox][poy+2] == map[pox][poy] && map[pox][poy+3] == map[pox][poy])
or(map[pox-1][poy] == map[pox][poy] && map[pox-2][poy] == map[pox][poy] && map[pox-3][poy] == map[pox][poy])
or(map[pox+1][poy+1] == map[pox][poy] && map[pox+2][poy+2] == map[pox][poy] && map[pox+3][poy+3] == map[pox][poy])
or(map[pox-1][poy-1] == map[pox][poy] && map[pox-2][poy-2] == map[pox][poy] && map[pox-3][poy-3] == map[pox][poy])
or(map[pox+1][poy-1] == map[pox][poy] && map[pox+2][poy-2] == map[pox][poy] && map[pox+3][poy-3] == map[pox][poy])
or(map[pox-1][poy+1] == map[pox][poy] && map[pox-2][poy+2] == map[pox][poy] && map[pox-3][poy+3] == map[pox][poy])
or(map[pox-1][poy-1] == map[pox][poy] && map[pox+1][poy+1] == map[pox][poy] && map[pox+2][poy+2] == map[pox][poy])
or(map[pox-1][poy-1] == map[pox][poy] && map[pox+1][poy+1] == map[pox][poy] && map[pox-2][poy-2] == map[pox][poy])
or(map[pox-1][poy-1] == map[pox][poy] && map[pox+1][poy+1] == map[pox][poy] && map[pox+2][poy+2] == map[pox][poy])
or(map[pox-1][poy-1] == map[pox][poy] && map[pox+1][poy-1] == map[pox][poy] && map[pox+2][poy-2] == map[pox][poy])
or(map[pox+1][poy-1] == map[pox][poy] && map[pox-1][poy+1] == map[pox][poy] && map[pox-2][poy+2] == map[pox][poy])
or(map[pox+1][poy] == map[pox][poy] && map[pox-1][poy] == map[pox][poy] && map[pox-2][poy] == map[pox][poy])
or(map[pox-1][poy] == map[pox][poy] && map[pox+1][poy] == map[pox][poy] && map[pox+2][poy] == map[pox][poy])
or(map[pox-1][poy+1] == map[pox][poy] && map[pox-1][poy-1] == map[pox][poy] && map[pox-2][poy-2] == map[pox][poy])
or(map[pox-1][poy+1] == map[pox][poy] && map[pox-2][poy+2] == map[pox][poy] && map[pox+1][poy-1] == map[pox][poy])
or(map[pox+1][poy+1] == map[pox][poy] && map[pox-1][poy-1] == map[pox][poy] && map[pox-2][poy-2] == map[pox][poy])
or(map[pox-1][poy-1] == map[pox][poy] && map[pox+1][poy+1] == map[pox][poy] && map[pox+2][poy+2] == map[pox][poy])
) {
if (p1 == 1) cout << " player 1 wins\n";
if (p2 == 1) cout << " player 2 wins\n";
Sleep(8000);
exit(0);
}
}
inline int anim_move(int pos){
int i=1;
for (;i<=6;i++){
if (map[pos][i] != "-") break;
if (map[pos][i]=="-") {
if (p1 == 1)map[pos][i] = "X";
if (p2 == 1)map[pos][i] = "O";
map[pos][i-1] = "-";
}
draw_map();
Sleep(100);
}
checkwin(pos,i-1);
return 0;
}
inline int go(){
int place;
while(place > 6 || place < 1) {
cout << "Where would you like to go?" ;
cin >> place;
}
anim_move(place);
return 0;
}
int main(int argc, char *argv[])
{
clear_map();
draw_map();
for(;;){
if (p1 = 1){
cout << "player 1's go\n" ;
go();
p2 = 1;
p1 = 0;
}
if (p2 = 1){
cout << "player 2's go\n" << p2;
go();
p2 = 0;
p1 = 1;
}
}
}
i know there are thigns i could of probably/definatley done better, like not check for a win every step =/, but its only small so doesnt really effect it



