package com. caishui. model;
import java. awt. List;
import java. util. ArrayList;
import java. util. HashMap;
import java. util. Map;
import java. util. Scanner;
public class GameMain {
public static void main ( String[ ] args) {
Scanner scanner = new Scanner ( System. in) ;
ArrayList list = new ArrayList ( ) ;
Map map = new HashMap ( ) ;
System. out
. println ( "----------------欢迎使用V1.0英雄在线管理系统---------------------" ) ;
System. out. println ( " 功能菜单如下" ) ;
System. out. println ( "--1.查询所有英雄" ) ;
System. out. println ( "--2.增加英雄" ) ;
System. out. println ( "--3.英雄PK" ) ;
System. out. println ( "--4.退出系统" ) ;
System. out. println ( "--5.删除英雄" ) ;
System. out. println ( "--6.一键删除全部英雄" ) ;
System. out. println ( "--7.注册" ) ;
System. out. println ( "--8.登录" ) ;
System. out. println ( "提示:请输入序号进行下一步操作!" ) ;
String cmd = scanner. next ( ) ;
boolean startGame = true;
boolean inputIn = false;
while ( startGame) {
if ( cmd. equals ( "1" ) ) {
for ( int i = 0 ; i < list. size ( ) ; i++ ) {
Honron honorn = ( Honron) list. get ( i) ;
System. out. println ( "英雄名称:" + honorn. getName ( ) + "攻击力:"
+ honorn. getGongjili ( ) ) ;
}
System. out. println ( list) ;
inputIn = true;
} else if ( cmd. equals ( "2" ) ) {
System. out. println ( "请输入英雄名称:" ) ;
String hname = scanner. next ( ) ;
boolean isname = false;
for ( int i = 0 ; i < list. size ( ) ; i++ ) {
Honron honron = ( Honron) list. get ( i) ;
if ( hname. equals ( honron. getName ( ) ) ) {
System. out. println ( "名称已经存在,请重新输入!" ) ;
isname = true;
break ;
}
}
if ( ! isname) {
System. out. println ( "请输入英雄攻击力:" ) ;
int gongjili = scanner. nextInt ( ) ;
Honron honron = new Honron ( ) ;
honron. setName ( hname) ;
honron. setGongjili ( gongjili) ;
list. add ( honron) ;
System. out. println ( "添加英雄成功!" ) ;
}
inputIn = true;
} else if ( cmd. equals ( "3" +
"" ) ) {
System. out. println ( "该功能暂未上线!" ) ;
inputIn = true;
} else if ( cmd. equals ( "4" ) ) {
startGame = false;
inputIn = false;
System. out. println ( "欢迎下一次使用!" ) ;
} else if ( cmd. equals ( "5" ) ) {
System. out. println ( "输入需要删除的英雄编号!" ) ;
String id = scanner. next ( ) ;
int honron = Integer. parseInt ( id) - 1 ;
list. remove ( honron) ;
System. out. println ( "删除成功!" ) ;
startGame = true;
inputIn = true;
} else if ( cmd. equals ( "6" ) ) {
list. clear ( ) ;
System. out. println ( "清空英雄成功!" ) ;
startGame = true;
inputIn = true;
} else if ( cmd. equals ( "7" ) ) {
System. out. println ( "注册普通用户!" ) ;
System. out. println ( "请输入用户名:" ) ;
String name = scanner. next ( ) ;
System. out. println ( "请输入密码:" ) ;
String pwd1 = scanner. next ( ) ;
System. out. println ( "请再次输入密码:" ) ;
String pwd2 = scanner. next ( ) ;
if ( map. containsKey ( name) ) {
System. out. println ( "该用户已经被注册,你来晚一步!" ) ;
} else {
if ( pwd1. equals ( pwd2) ) {
map. put ( name, pwd1) ;
System. out. println ( "欢迎" + name + "注册成功!" ) ;
} else {
System. out. println ( "两次输入的密码不一致!" ) ;
}
}
startGame = true;
inputIn = true;
} else if ( cmd. equals ( "8" ) ) {
System. out. println ( "普通用户登录!" ) ;
System. out. println ( "请输入用户名:" ) ;
String name = scanner. next ( ) ;
System. out. println ( "请输入密码:" ) ;
String pwd1 = scanner. next ( ) ;
String pwdmap = ( String) map. get ( name) ;
if ( pwd1. equals ( pwdmap) ) {
System. out. println ( "欢迎" + name + "登录成功!" ) ;
} else {
System. out. println ( "账户或密码错误!" ) ;
}
System. out. println ( "登录成功!" ) ;
startGame = true;
inputIn = true;
} else if ( cmd. equals ( "9" ) ) {
System. out. println ( "请输入管理员账号:" ) ;
String username = scanner. next ( ) ;
System. out. println ( "请输入管理员密码:" ) ;
String password = scanner. next ( ) ;
if ( username. equals ( "admin" ) && password. equals ( "1234" ) ) {
System. out. println ( "管理员登录成功!" ) ;
}
startGame = true;
inputIn = true;
} if ( inputIn) {
cmd = scanner. next ( ) ;
}
}
}
}
package com. caishui. model;
public class Honron {
private String name;
private int gongjili;
public String getName ( ) {
return name;
}
public void setName ( String name) {
this. name = name;
}
public int getGongjili ( ) {
return gongjili;
}
public void setGongjili ( int gongjili) {
this. gongjili = gongjili;
}
}