?? game.cpp
字號:
#include <windows.h>
#include "game.h"
int Random(long maxValue)
{
int temp = rand();
if (maxValue != 0)
return temp /(RAND_MAX/maxValue);
else return 1;
}
CGame::CGame()
{
Reset();
}
CGame::~CGame()
{
}
void CGame::Reset()
{
Height = ROWS-1;
Width = COLUMNS-1;
int n = 0;
for (int i=0; i<=Height; i++)
for (int j=0; j<=Width; j++)
{
Desk[i][j] = n;
n++;
}
Desk[Height][Width] = -1;
moves = 0;
}
int CGame::GetCell(int row, int col)
{
return Desk[row][col];
}
bool CGame::MoveIt(int row, int col)
{
bool can_move = false;
if ((row < 0) | (row > Height) | (col < 0) | (col > Width))
return false;
if (Desk[row][col] == -1)
return false;
if (Desk[row][col-1] == -1)
{
Desk[row][col-1] = Desk[row][col];
Desk[row][col] = -1;
can_move = true;
}
if (Desk[row][col+1] == -1)
{
Desk[row][col+1] = Desk[row][col];
Desk[row][col] = -1;
can_move = true;
}
if (Desk[row-1][col] == -1)
{
Desk[row-1][col] = Desk[row][col];
Desk[row][col] = -1;
can_move = true;
}
if (Desk[row+1][col] == -1)
{
Desk[row+1][col] = Desk[row][col];
Desk[row][col] = -1;
can_move = true;
}
if (can_move)
moves++;
return can_move;
}
void CGame::Mix(int quality)
{
for (int i=0;i<quality;i++)
MoveIt(Random(Height+1),Random(Width+1));
moves = 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -