⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 squareshape.cpp

📁 一个漂亮的万花筒游戏
💻 CPP
字号:
// SquareShape.cpp: implementation of the SquareShape class.
//
//////////////////////////////////////////////////////////////////////
#include <assert.h>
#include "ezwin.h"
#include "math.h"
#include "WindowObject.h"
#include "Shape.h"
#include "SquareShape.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

SquareShape::SquareShape(SimpleWindow &Window,
 const Position &center, const color &c, float s) :
 Shape(Window, center, c), SideLength(s) {
 // No code needed!
}

float SquareShape::GetSideLength() const {
	return SideLength;
}

void SquareShape::Draw() {
	const Position Center = GetPosition();
	const float SideLength = GetSideLength();

	const Position UpperLeft = Center
	 + Position(-.5f * SideLength, -.5f * SideLength);
	const Position LowerRight = Center
	 + Position(.5f * SideLength, .5f * SideLength);
	GetWindow().RenderRectangle(UpperLeft, LowerRight,
	 GetColor(), HasBorder());
   return;
}


void SquareShape::SetSize(float s) {
	SideLength = s;
   return;
}

void SquareShape::Erase() {
	const Position Center = GetPosition();
	const float SideLength = GetSideLength();

	const Position UpperLeft = Center
	 + Position(-.5f * SideLength, -.5f * SideLength);
	const Position LowerRight = Center
	 + Position(.5f * SideLength, .5f * SideLength);
	GetWindow().RenderRectangle(UpperLeft, LowerRight,
	 White, HasBorder());
   return;
}

⌨️ 快捷键说明

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