Java游戏用户登录注册_java___控制台可以实现简单的登录注册的小游戏平台

话不多说直接上代码:

package pt;

import java.util.Scanner;

public class Test {

public static void main(String[] args) {

System.out.println("*************");

System.out.println("**来啦老弟!**");

System.out.println("*************");

while(true) {

System.out.println("1-登陆");

System.out.println("2-注册");

System.out.println("0-退出");

UserDaoImpl udi = new UserDaoImpl();

Scanner sc = new Scanner(System.in);

String choice = sc.nextLine();

switch (choice) {

case "1":

System.out.println("欢迎来到登录界面!");

System.out.println("请输入用户名:");

String inputUserName = sc.nextLine();

System.out.println("请输入密码:");

String inputPassWord = sc.nextLine();

boolean flag = udi.isLogin(inputUserName,inputPassWord);

if (flag) {

System.out.println("登录成功!");

System.out.println("1-玩游戏");

System.out.println("2-查询账号密码");

String choice2 = sc.nextLine();

switch(choice2) {

case"1":

System.out.println("请选择你要玩的游戏:");

System.out.println("1-猜数字!");

System.out.println("2-模拟斗地主之你就是出不了牌!");

String choice3 = sc.nextLine();

switch (choice3) {

case "1":

GuessNumber.playGame(null);

break;

case "2":

FightLandlords.playGames(null);

break;

}

break;

case"2":

System.out.println("不好意思暂时还没有此功能,敬请期待!");

break;

}

}else{

System.out.println("登录失败!");

}

break;

case "2":

System.out.println("欢迎来到注册界面!");

System.out.println("请输入用户名:");

String userName = sc.nextLine();

System.out.println("请输入密码:");

String passWord = sc.nextLine();

User user = new User(userName,passWord);

udi.regist(user);

System.out.println("注册成功!");

break;

case "0":

System.out.println("*************");

System.out.println("**再见了您嘞!**");

System.out.println("*************");

System.exit(0);

break;

}

}

}

}

package pt;

public class User {

private String userName;

private String passWard;

public String getUserName() {

return userName;

}

public void setUserName(String userName) {

this.userName = userName;

}

public String getPassWard() {

return passWard;

}

public void setPassWard(String passWard) {

this.passWard = passWard;

}

public User() {

super();

}

public User(String userName, String passWard) {

super();

this.userName = userName;

this.passWard = passWard;

}

}

package pt;

public interface UserDao {

public abstract void regist(User user);

public abstract boolean isLogin(String userName,String passWard);

}

package pt;

import java.util.ArrayList;

public class UserDaoImpl implements UserDao {

static ArrayList users = new ArrayList();

public void regist(User user) {

users.add(user);

}

public boolean isLogin(String userName, String passWard) {

boolean flas = false;

for(User user: users) {

if(userName.equals(user.getUserName())&&passWard.equals(user.getPassWard())) {

flas = true;

break;

}

}

return flas;

}

}

package pt;

import java.util.Scanner;

public class GuessNumber {

public static void playGame(String[] args) {

int random = (int) (Math.random()*100+1);

Scanner sc = new Scanner(System.in);

System.out.println("猜数字游戏开始");

System.out.println("数字范围为(1-100)");

System.out.println("请输入所猜测的数字:");

int number = sc.nextInt();

while (true) {

if (number>random) {

System.out.println("大了,请重新输入:");

number = sc.nextInt();

}

if (number

System.out.println("小了,请重新输入:");

number=sc.nextInt();

}

if (number==random) {

System.out.println("恭喜你答对了!但是没有奖励哟!");

System.out.println("最后的答案就是"+random);

System.out.println("你说气人不气人!");

System.out.println("我连游戏记录都不给你!");

break;

}

}

}

}

package pt;

import java.util.ArrayList;

import java.util.Collections;

import java.util.List;

import java.util.Scanner;

public class FightLandlords {

public static void playGames(String[] args) {

List paihe = new ArrayList();

String[] huase = {"♥","♤","♣","♢"};

String[] shuzi = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};

for(String hua : huase){

for(String shu : shuzi){

paihe.add(hua + shu);

}

}

paihe.add("大王");

paihe.add("小王");

Collections.shuffle(paihe);

List PlayerA = new ArrayList();

List PlayerB = new ArrayList();

List PlayerC = new ArrayList();

List dipai = new ArrayList();

for(int i = 0;i < paihe.size() ;i++){

if(i < 51){

if(i % 3 == 0){

PlayerA.add(paihe.get(i));

}

if(i % 3 == 1){

PlayerB.add(paihe.get(i));

}

if(i % 3 == 2){

PlayerC.add(paihe.get(i));

}

}else{

dipai.add(paihe.get(i));

}

}

Scanner sc = new Scanner(System.in);

System.out.println("*********************");

System.out.println("**java版斗地主之出不了牌**");

System.out.println("*********************");

System.out.println("游戏开始请输入1");

System.out.println("退出游戏请输入2");

String play = sc.next();

if(play.equals("1")){

System.out.println("请输入玩家一的姓名");

String A = sc.next();

System.out.println("请输入玩家二的姓名");

String B = sc.next();

System.out.println("请输入玩家三的姓名");

String C = sc.next();

System.out.println("开始发牌!");

System.out.println(A+"的牌为:");

show(PlayerA);

System.out.println(B+"的牌为:");

show(PlayerB);

System.out.println(C+"的牌为:");

show(PlayerC);

System.out.println("是否查看底牌。");

System.out.println("1-查看 2-不看");

String lookdp = sc.next();

if(lookdp.equals("1")){

System.out.println("底牌为");

show(dipai);

}

}else{

System.out.println("游戏已退出,祝您生活愉快从此没有大小王!!");

}

}

public static void show(List list){

StringBuffer sb = new StringBuffer();

for(String s : list){

sb.append(s+",");

}

sb.deleteCharAt(sb.length()-1);

System.out.println(sb.toString());

}

}

全部的源码都在上面了!

有什么不懂的不要来问我

我不会告诉你我也不会

你可能感兴趣的:(Java游戏用户登录注册)