java基础俄罗斯方块

package box;


public class Cell {
	int cow,rol;
	public  void left(){
		cow--;
	}
	public  void right(){
		cow++;
	}
	public  void down(){
		rol++;
	}


}
/*
 1,首先需要一个类,建立一个对象来控制方块的移动,建立cell类。
 2这个对象中需要拥有的功能,可以左移一格,右移一格,下移一格。需要定义变量行(row),列(col)。
 3gamecell类放主方法,需要实现输出格子,采用两层for循环。
 4还需要处理用户输入0(表示退出),1(表示下落),2(表示左移),3(表示右移)。解决方法,需要一个while结构,来判断输入是否为零,循环里面嵌套一个if,else
 语句来判断输入的1,2,3.
 5main 方法中需要有一个函数来输出表格printBox(),只需要两层for循环
 
 */
package box;
import java.util.Scanner;
public class Gamecell {
	public static void main(String[] args){
		int fristCow=(int)(Math.random()*20);
		int fristRol=(int)(Math.random()*10);
		Scanner sc=new Scanner(System.in);
		Cell cell=new Cell();
		cell.cow=fristCow;
		cell.rol=fristRol;
		System.out.println("cell的当前位置为:("+cell.cow+","+cell.rol+")");
		printBox(cell);
		System.out.println("1——下落,2——左移,3——右移,0——退出");
		while(sc.hasNextInt())
		{
			int number=sc.nextInt();
			if(number==0)
				break;
			if(number==1)
				cell.down();
			else if(number==2)
				cell.left();
			else if(number==3)
				cell.right();
			System.out.println("cell的当前位置为:("+cell.cow+","+cell.rol+")");
			printBox(cell);
			System.out.println("1——下落,2——左移,3——右移,0——退出");
			
			
		}
		
	}
	public static void printBox(Cell cell){
		int totalCow=20,totalRol=10;
		for(int i=0;i<totalCow;i++){
			for(int j=0;j<totalRol;j++){
				if(i==cell.cow&&j==cell.rol)
				{
					System.out.print("*");
				}
				else
				{
					System.out.print("-");
				}
			}
			System.out.println();
		}
	}


}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值