|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Junior Member
Iscritto dal: Aug 2005
Messaggi: 16
|
mi potete corregere il tris in c++!
ciao a tutti scusate ma contando che so solo fare cosi la grafica e viene sfalsata non ve ne preoccupate quello non mi serve.....mi serve invece usare il file mappato in modo che lanciando due volte lo stesso exe mi apra due finestre del tris una in cui registra le x con la mossa e nell'altra registri o (tris tra due persone che ognuna delle due ha un'interfaccia) grazie in anticipo
![]() // Produttore.cpp : Defines the entry point for the console application. // #include "iostream.h" #include <stdio.h> #include <windows.h> void main() { int cont=0; char* Niente; HANDLE PuntaMemoria,file,mapping,h1; char *PuntFile="K:\\Sistemi\\Programma_Gioco_Tris\\File mappato\\FileMappato.txt"; file=CreateFile(PuntFile, 0, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,h1); mapping=CreateFileMapping(file,0,FILE_ATTRIBUTE_NORMAL,0,0 ,NULL); //PuntaMemoria=OpenFileMapping(FILE_MAP_ALL_ACCESS,TRUE,Punt File); HANDLE FM; FM=MapViewOfFile(mapping,FILE_MAP_ALL_ACCESS,0,0,0); char Prod_Sem_[]="Prod_Sem"; char Cons_Sem_[]="Cons_Sem"; HANDLE Prod_Sem,Cons_Sem; Prod_Sem = CreateSemaphore (NULL,1,1,Prod_Sem_); Cons_Sem = CreateSemaphore (NULL,0,1,Cons_Sem_); int R,C; char RC[3][3]; int* PFM= (int*)PuntaMemoria; RC[0][0]=0; RC[0][1]=0; RC[0][2]=0; RC[1][0]=0; RC[1][1]=0; RC[1][2]=0; RC[2][0]=0; RC[2][1]=0; RC[2][2]=0; while(1) { // WaitForSingleObject(Prod_Sem,INFINITE); cout<<":::::::::::::::TRIS:::::::::::::::::"<<endl<<endl; /////////////////////////////////INSERIMENTO COORDINATE/////////////////////////////////// cout<<"INSERIRE LE COORDINATE: "<<endl; cout<<"Righe: ";cin>>R;cout<<"Colonne: ";cin>>C;cout<<endl; while(RC[R][C]=='X') { cout<<"Errore!!! Reinserire le coordinate"<<endl; cout<<"Righe: ";cin>>R;cout<<"Colonne: ";cin>>C;cout<<endl; } do{ if(R!=1&&R!=2&&R!=0||C!=0&&C!=1&&C!=2) { cout<<"Errore!!!Reinserire coordinate:"<<endl; cout<<"Righe: ";cin>>R;cout<<"Colonne: ";cin>>C;cout<<endl; } }while((R!=1&&R!=2&&R!=0||C!=0&&C!=1&&C!=2)); while(RC[R][C]=='X') { cout<<"Errore!!! Reinserire le coordinate"<<endl; cout<<"Righe: ";cin>>R;cout<<"Colonne: ";cin>>C;cout<<endl; } RC[R][C]='X'; // PFM[cont]=RC[R][C]; cout<<PFM[cont]; /*while(((RC[0][0]=='X')||(RC[0][1]=='X')||(RC[0][2]=='X')||(RC[1][0]=='X')||(RC[1][1]=='X')||(RC[1][2]=='X')||(RC[2][0]=='X')||(RC[2][1]=='X')||(RC[2][2]=='X'))) { if((RC[0][0]=='X')&&(RC[0][1]=='X')&&(RC[0][2]=='X')&&(RC[1][0]=='X')&&(RC[1][1]=='X')&&(RC[1][2]=='X')&&(RC[2][0]=='X')&&(RC[2][1]=='X')&&(RC[2][2]=='X')) {cout<<"Errore!!! Reinserire le coordinate"<<endl; cout<<"Righe: ";cin>>R;cout<<"Colonne: ";cin>>C;cout<<endl; } else{RC[R][C]='X';} }*/ ///////////////////////STAMPA SCHEMA///////////////////////////////////////////////////////// //fclose(PF); cout<<" 0 1 2 "<<endl; cout<<" __________________________________________"<<endl; cout<<" | | | |"<<endl; cout<<" | | | |"<<endl; cout<<" |"<<" "<<RC[0][0]<<" | "<<RC[0][1]<<" | "<<RC[0][2]<<" | "<<endl; cout<<" 0 | | | |"<<endl; cout<<" | | | |"<<endl; cout<<" | | | |"<<endl; cout<<" |______________|______________|____________|"<<endl; cout<<" | | | |"<<endl; cout<<" | | | |"<<endl; cout<<" |"<<" "<<RC[1][0]<<" | "<<RC[1][1]<<" | "<<RC[1][2]<<" | "<<endl; cout<<" 1 | | | |"<<endl; cout<<" | | | |"<<endl; cout<<" | | | |"<<endl; cout<<" |______________|______________|____________|"<<endl; cout<<" | | | |"<<endl; cout<<" | | | |"<<endl; cout<<" | | | |"<<endl; cout<<" |"<<" "<<RC[2][0]<<" | "<<RC[2][1]<<" | "<<RC[2][2]<<" | "<<endl; cout<<" 2 | | | |"<<endl; cout<<" | | | |"<<endl; cout<<" | | | |"<<endl; cout<<" |______________|______________|____________|"<<endl; ///////////////////////////////////VERIFICA VINCITA//////////////////////////////////////// if(RC[0][0]=='X'&&RC[0][1]=='X'&&RC[0][2]=='X'){ cout<<"Ha vinto l'ultimo giocatore che ha giocato!!"<<endl;return;} else if(RC[1][0]=='X'&&RC[1][1]=='X'&&RC[1][2]=='X'){ cout<<"Ha vinto l'ultimo giocatore che ha giocato!!"<<endl;return;} else if(RC[2][0]=='X'&&RC[2][1]=='X'&&RC[2][2]=='X'){ cout<<"Ha vinto l'ultimo giocatore che ha giocato!!"<<endl;return;} else if(RC[0][0]=='X'&&RC[1][1]=='X'&&RC[2][2]=='X'){ cout<<"Ha vinto l'ultimo giocatore che ha giocato!!"<<endl;return;} else if(RC[0][2]=='X'&&RC[1][1]=='X'&&RC[2][0]=='X'){ cout<<"Ha vinto l'ultimo giocatore che ha giocato!!"<<endl;return;} else if(RC[0][0]=='X'&&RC[1][0]=='X'&&RC[2][0]=='X'){ cout<<"Ha vinto l'ultimo giocatore che ha giocato!!"<<endl;return;} else if(RC[0][1]=='X'&&RC[1][1]=='X'&&RC[2][1]=='X'){ cout<<"Ha vinto l'ultimo giocatore che ha giocato!!"<<endl;return;} else if(RC[0][2]=='X'&&RC[1][2]=='X'&&RC[2][2]=='X'){ cout<<"Ha vinto l'ultimo giocatore che ha giocato!!"<<endl;return;} ///////////////////////////////////////////////////////////////////////////////////////// cout<<"Premi un tasto per continuare e poi premere invio..."; int cont; cin>>cont; system("CLS"); // ReleaseSemaphore(Cons_Sem,1,NULL); } // CreateFile("K:\\Sistemi\\Programma_Gioco_Tris.txt"); } |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 10:08.