NineBox.h
资源名称:8-Games.rar [点击查看]
上传用户:tjwfgggs
上传日期:2022-06-07
资源大小:4331k
文件大小:2k
源码类别:
其他游戏
开发平台:
Visual C++
- // NineBox.h: interface for the NineBox class.
- //
- //////////////////////////////////////////////////////////////////////
- #if !defined(AFX_NINEBOX_H__06C6DA3D_AA28_43F6_9D4E_3E69C6D59F82__INCLUDED_)
- #define AFX_NINEBOX_H__06C6DA3D_AA28_43F6_9D4E_3E69C6D59F82__INCLUDED_
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
- struct BOX
- {
- int num;
- int x;
- int y;
- };
- class NineBox
- {
- public:
- NineBox();
- virtual ~NineBox();
- public:
- void ResetValue()
- {
- int v[3][3]={1,2,3,8,0,4,7,6,5};
- for (int i=0;i<3;i++)
- {
- for (int j=0;j<3;j++)
- {
- box[i][j].num=v[i][j];
- box[i][j].x=i;
- box[i][j].y=j;
- }
- }
- move_type=-1;
- }
- int GetBoxValue(int x,int y)
- {
- if(abs(x)<3 && abs(y)<3)
- {
- return box[x][y].num;
- }
- else
- return -1;
- }
- bool GetXYByValue(int num,int& x,int& y)
- {
- if (num<9 && num>=0)
- {
- x=-1;y=-1;
- for (int i=0;i<3;i++)
- {
- for (int j=0;j<3;j++)
- {
- if (box[i][j].num==num)
- {
- x=box[i][j].x;
- y=box[i][j].y;
- return true;
- }
- }
- }
- return false;
- }
- else
- return false;
- }
- void MoveUp();
- void MoveDown();
- void MoveLeft();
- void MoveRight();
- void swap(int x0,int y0,int x1,int y1)
- {
- int temp=0;
- temp=box[x0][y0].num;
- box[x0][y0].num=box[x1][y1].num;
- box[x1][y1].num=temp;
- }
- int GetLastMoveType(){return move_type;}
- void SetLastMoveType(int t){move_type=t;}
- private:
- BOX box[3][3];
- int move_type;
- };
- #endif // !defined(AFX_NINEBOX_H__06C6DA3D_AA28_43F6_9D4E_3E69C6D59F82__INCLUDED_)