|
- #include<iostream>
- #include<vector>
- #include<ctime>
- #include<conio.h>
- #include <windows.h>
- #include<cstdlib>
- using namespace std;
- void gotoxy(HANDLE hout, int x, int y);
- void getRand(); //棋盘中随机数生成
- void printBoard(); //打印棋盘
- bool judgeOver(); //判断游戏是否结束
- void slide(); //滑动
-
- int m=4, n=4;
- int board[100][100]; //棋盘
- char op; //用户操作
- bool judgeLeftSlide();
- void leftSlide(); //左滑动
- bool judgeRightSlide();
- void rightSlide();
- bool judgeUpSlide();
- void upSlide();
- bool judgeDownSlide();
- void downSlide();
- void reStart();
- int main()
- {
- HANDLE hout = GetStdHandle(STD_OUTPUT_HANDLE);
- getRand();
- printBoard();
- while (!judgeOver())
- {
- slide();
- gotoxy(hout,0,0);
- getRand();
- printBoard();
- }
- cout << "游戏结束!!!\n";
- system("pause");/**/
- return 0;
- }
- void slide()
- {
-
- }
- void getRand()
- {
- srand(time(0));
- int x, y,val;
- do
- {
- x = rand() % m;
- y = rand() % n;
- } while (board[x][y] != 0);
- val = (rand() % 2 + 1)*2;
- board[x][y] = val;
- }
- void printBoard()
- {
- for (int i = 0; i < m; i++) {
- for (int j = 0; j < n; j++) {
- cout << board[i][j];
- if (j < n-1)
- {
- cout << "—";
- }
- if (j == n-1 && i < m-1)
- {
- cout << endl;
- int count = 0;
- while (count++ < n-1)
- {
- cout << "| ";
- }
- cout << "|" << endl;
- }
- }
- }
- }
- bool judgeOver()
- {
-
-
- }
- void gotoxy(HANDLE hout, int x, int y){
- COORD pos;
- pos.X = x;
- pos.Y = y;
- SetConsoleCursorPosition(hout, pos);
- }
- void upSlide()
- {
-
- }
-
- bool judgeUpSlide(bool mark)
- {
-
- }
-
- void reStart()
- {
- for (int i = 0; i < m; i++)
- for (int j = 0; j < n; j++) {
- board[i][j] = 0;
- }
- }
复制代码
|
|