纯C#控制台俄罗斯方块
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
}else if(inf.Key==ConsoleKey.DownArrow){
cmd="D";
pressed=true;
break;
}
}
return re;
}
public static void releaseBlock (Block b)
{
//release all box of this block to box pool.
goto Start;
}
}
protected static void initGame ()
{//init game
// ConsoleColor col=Block.RandomColor ();
if (pre <= 0.2f) {
col = ConsoleColor.Red;
} else if (pre > 0.2f && pre <= 0.4f) {
col = ConsoleColor.Magenta;
if(endAble){
goto End;
}
goto Conf;
End: Console.Clear ();
Console.WriteLine (" □□□□□□□□□□□□□□□□□□□□");
foreach(Box box in boxcore){
if(!box.deleteAble){
narr.Add (box);
}
}else if(inf.Key==ConsoleKey.LeftArrow){
cmd="L";
pressed=true;
break;
public static bool endAble;
public static ConsoleColor currentColor;
public static void unlockpress ()
{
pressed=false;
}
}
}else{
break;
}
}
bn.move (cmd);
cmd="";
Console.WriteLine (" Replay? Y/N");
Console.WriteLine (" □□□□□□□□□□□□□□□□□□□□");
if (Console.ReadLine()=="Y") {
if(inf.Key==ConsoleKey.RightArrow){
cmd="R";
pressed=true;
break;
bn=new Block(new Box[4]{new Box((int)MAXX/2,0),new Box((int)MAXX/2,1),new Box((int)MAXX/2+1,0),new Box((int)MAXX/2+1,1)});
if(boxcore!=null){
float pre =(float)getMINY ()/MainClass.MAXY ;//
ConsoleColor col=ConsoleColor.Cyan;
//Debug.Print (pre.ToString ());
boxcore.Clear ();
}
boxcore=new ArrayList();
pressed=false;
currentColor=ConsoleColor.Cyan;
foreach (Box box in boxcore) {
box.ca_dropline (boxcore);
}
ArrayList narr=new ArrayList();
public const int MAXX=20;
public const int MAXY=21;
static Block bn;
public static ArrayList boxcore;
protected static bool pressed;
}else if(inf.Key==ConsoleKey.UpArrow){
cmd="U";
pressed=true;
break;
dropline += check (i);
}
if (dropline > 1) {
title.addScore (25 * dropline);
}
} else if (pre > 0.4f && pre <= 0.6f) {
col = ConsoleColor.Yellow;
}
title.piece += 1;
b.ca_delay();
//then must check the line that whether will be clear
Console.ForegroundColor=currentColor;
title.init ();
screen.update(bn);
endAble=false;
}
public static bool isOver (Block b)
if (!isOver (b)) {
Box[] arr = b.Arr;
foreach (Box box in arr) {
boxcore.Add (box);
ArrayList checkline = b.getCheckArr ();
//Debug.Print (debugline (checkline));
int dropline = 0;
foreach (int i in checkline) {
Console.WriteLine (" Game Over ");
Console.WriteLine (" Score:" + title.score);
Console.WriteLine (" Piece:" + title.piece);
}
public static void Main (string[] args)
{
Start:initGame();
Conf:while(true){
Thread.Sleep(40);
if(!endAble){
bn.run();
pressed=false;
if(Console.KeyAvailable && !pressed){
ConsoleKeyInfo inf=Console.Read;
foreach(Box box in b.Arr){
if(box.Y==0){
re=true;
break;
} else {
MainClass.endAble=true;
}
}
public static void ca_color ()
{
//According to minY transfrom color
using System;
using System.Threading;
using System.Collections;
using System.Diagnostics;
namespace box
{
class MainClass
{
public static string cmd;
}
boxcore=narr;
foreach (Box box in boxcore) {
box.drop ();
}
ca_color();
cmd="D";
pressed=true;
break;
}
}
return re;
}
public static void releaseBlock (Block b)
{
//release all box of this block to box pool.
goto Start;
}
}
protected static void initGame ()
{//init game
// ConsoleColor col=Block.RandomColor ();
if (pre <= 0.2f) {
col = ConsoleColor.Red;
} else if (pre > 0.2f && pre <= 0.4f) {
col = ConsoleColor.Magenta;
if(endAble){
goto End;
}
goto Conf;
End: Console.Clear ();
Console.WriteLine (" □□□□□□□□□□□□□□□□□□□□");
foreach(Box box in boxcore){
if(!box.deleteAble){
narr.Add (box);
}
}else if(inf.Key==ConsoleKey.LeftArrow){
cmd="L";
pressed=true;
break;
public static bool endAble;
public static ConsoleColor currentColor;
public static void unlockpress ()
{
pressed=false;
}
}
}else{
break;
}
}
bn.move (cmd);
cmd="";
Console.WriteLine (" Replay? Y/N");
Console.WriteLine (" □□□□□□□□□□□□□□□□□□□□");
if (Console.ReadLine()=="Y") {
if(inf.Key==ConsoleKey.RightArrow){
cmd="R";
pressed=true;
break;
bn=new Block(new Box[4]{new Box((int)MAXX/2,0),new Box((int)MAXX/2,1),new Box((int)MAXX/2+1,0),new Box((int)MAXX/2+1,1)});
if(boxcore!=null){
float pre =(float)getMINY ()/MainClass.MAXY ;//
ConsoleColor col=ConsoleColor.Cyan;
//Debug.Print (pre.ToString ());
boxcore.Clear ();
}
boxcore=new ArrayList();
pressed=false;
currentColor=ConsoleColor.Cyan;
foreach (Box box in boxcore) {
box.ca_dropline (boxcore);
}
ArrayList narr=new ArrayList();
public const int MAXX=20;
public const int MAXY=21;
static Block bn;
public static ArrayList boxcore;
protected static bool pressed;
}else if(inf.Key==ConsoleKey.UpArrow){
cmd="U";
pressed=true;
break;
dropline += check (i);
}
if (dropline > 1) {
title.addScore (25 * dropline);
}
} else if (pre > 0.4f && pre <= 0.6f) {
col = ConsoleColor.Yellow;
}
title.piece += 1;
b.ca_delay();
//then must check the line that whether will be clear
Console.ForegroundColor=currentColor;
title.init ();
screen.update(bn);
endAble=false;
}
public static bool isOver (Block b)
if (!isOver (b)) {
Box[] arr = b.Arr;
foreach (Box box in arr) {
boxcore.Add (box);
ArrayList checkline = b.getCheckArr ();
//Debug.Print (debugline (checkline));
int dropline = 0;
foreach (int i in checkline) {
Console.WriteLine (" Game Over ");
Console.WriteLine (" Score:" + title.score);
Console.WriteLine (" Piece:" + title.piece);
}
public static void Main (string[] args)
{
Start:initGame();
Conf:while(true){
Thread.Sleep(40);
if(!endAble){
bn.run();
pressed=false;
if(Console.KeyAvailable && !pressed){
ConsoleKeyInfo inf=Console.Read;
foreach(Box box in b.Arr){
if(box.Y==0){
re=true;
break;
} else {
MainClass.endAble=true;
}
}
public static void ca_color ()
{
//According to minY transfrom color
using System;
using System.Threading;
using System.Collections;
using System.Diagnostics;
namespace box
{
class MainClass
{
public static string cmd;
}
boxcore=narr;
foreach (Box box in boxcore) {
box.drop ();
}
ca_color();