1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
#include <iostream>
#include <string>
#include <ctime>
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include "CaenTerminal.h"
#include <stdlib.h>
#include <windows.h>
using namespace CaenTerminal;
using namespace std;
//-----------------------------
char board[3][3];
int w,h;
char playerx='x';
int PosX,PosY;
int ch;
int a;
int col,row;
//---------------------------
void curPos(int, int);
void PlayerTurn()
{
cout<<"Test input"<<endl;//will be replaced by the cursor movements.
cin>>col>>row;
board[row][col]=playerx;
if(playerx == 'X')
playerx = 'O';
else
playerx ='X';
}
void isLocValid()
{
if (col<=0)
if (row<=0)
{
cout<<"location invalid"<<endl;
}
}
void control()
{
GetPosition(PosX,PosY);
if(GetKey()==140)//up
{
--PosY;
curPos(PosX,PosY);
}
else if (GetKey()== 141)//down
{
++PosY;
curPos(PosX,PosY);
}
else if (GetKey()==142)//left
{
--PosX;
curPos(PosX,PosY);
}
else if (GetKey()==143)//right
{
++PosX;
curPos(PosX,PosY);
}
}
void MainBoard()
{
cout<<board[0][0]<<"|"<<board[1][0]<<" |"<<board[2][0]<<endl;
cout<<"------"<<endl;
cout<<board[0][1]<<"|"<<board[1][1]<<" |"<<board[2][1]<<endl;
cout<<"------"<<endl;
cout<<board[0][2]<<"|"<<board[1][2]<<" |"<<board[2][2]<<endl;
}
//----------------------------
int main()
{
srand((unsigned)time(NULL));
for (int z=0;z<9;)
{
MainBoard();
control();
}
return EXIT_SUCCESS;
}
void curPos(int x,int y)
{
HANDLE hStdout;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
hStdout=GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hStdout, &csbiInfo);
csbiInfo.dwCursorPosition.X=x;
csbiInfo.dwCursorPosition.Y=y;
SetConsoleCursorPosition(hStdout, csbiInfo.dwCursorPosition);
}
|