box.cpp

来自「俄罗斯方块」· C++ 代码 · 共 56 行

CPP
56
字号
#include <iostream.h>
#include <time.h>
#include "Box.h"

Box::Box()
{
	init();
}

void Box::init(void)
{
	location.y = 0;
	location.x = (COLUMNS-4)/2;
	srand((unsigned) time(NULL)); 
	boxNo = rand()%7;
	shapeNo = rand()%4;
}

void Box::left(void)
{
	location.x--;
}

void Box::right(void)
{
	location.x++;
}

void Box::drop(void)
{
	location.y++;
}

void Box::rotate(void)
{
	shapeNo =(shapeNo+1)%4;
}

BoxCode Box::getCode(void)const
{
	return codeTable[boxNo][shapeNo];
}
Coord Box::getLocation(void)const
{
	return location;
}
int Box::getBoxNo(void)const
{
	return boxNo;
}
void Box::show()
{
	cout<<"方块号:"<<boxNo<<endl;
	cout<<"形态号:"<<shapeNo<<endl;
	cout<<"位置:"<<location.y<<","<<location.x<<endl;	
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?