排球比赛积分系统——源码
作者:互联网
1.程序比赛计分器初始化程序界面设计
(内含积分器初始化页面设计及比赛现场记分)
html源码
点击查看代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>排球计分器</title>
<style>
/* 计分 */
.score{
width: 300px;
height: 560px;
border: 1px solid black;
position: absolute;
top: 100px;
overflow: hidden;
}
.team{
height: 100px;
overflow: hidden;
border: 1px solid black;
}
.team input{
height: 100px;
width: 300px;
font-size: 50px;
text-align: center;
}
#score1{
left: 105px;
}
#score2{
left: 1000px;
}
.score11{
width: 300px;
height: 360px;
background-color: red;
color: white;
font-size: 180px;
text-align: center;
line-height: 360px;
}
.add{
width: 53px;
height: 98px;
display: inline-block;
border: 1px solid black;
background-color: yellow;
color: black;
font-size: 25px;
text-align: center;
line-height: 98px;
}
.less{
background-color: grey;
}
</style>
</head>
<body>
<div id="score1" class="score">
<div class="team">
<input type="text" placeholder="输入客队名">
</div>
<div class="score11">00</div>
<div>
<div class="add">+1</div>
<div class="add less">-1</div>
<div class="add less">清零</div>
</div>
</div>
<div id="score2" class="score">
<div class="team">
<input type="text" placeholder="输入主队名">
</div>
<div class="score11">00</div>
<div>
<div class="add">+1</div>
<div class="add less">-1</div>
<div class="add less">清零</div>
</div>
</div>
<script>
var score_a=0
var score_b=0
var score1=document.getElementById("score1").getElementsByClassName("score11")
var score2=document.getElementById("score2").getElementsByClassName("score11")
var add1=document.getElementById("score1").getElementsByClassName("add")
add1[0].onclick=function(){
score_a+=1
score1[0].innerHTML=score_a
}
add1[1].onclick=function(){
if(score_a>0){
score_a-=1
score1[0].innerHTML=score_a
if(score_a==0){
score1[0].innerHTML="00"
}
}
}
add1[2].onclick=function(){
score_a=0
score1[0].innerHTML="00"
}
var add2=document.getElementById("score2").getElementsByClassName("add")
add2[0].onclick=function(){
score_b+=1
score2[0].innerHTML=score_b
}
add2[1].onclick=function(){
if(score_b>0){
score_b-=1
score2[0].innerHTML=score_b
if(score_b==0){
score2[0].innerHTML="00"
}
}
}
add2[2].onclick=function(){
score_b=0
score2[0].innerHTML="00"
}
</script>
</body>
</html>
2.比赛计分存入数据库
**不同的类继承进行方法的增强,单一类实现单一功能,降低耦合。**
点击查看Dao层代码
package jdbc;
import member.Member;
public interface MemberDao {
public int addMember(Member member); //添加成员信息到数据库
public int updateMember(Member member); //为队员加分
public int selectMember(int id); //返回指定球员的分数
public int deleteMember(); //清空数据库
}
点击查看Service层代码
package jdbc;
import member.Member;
import org.springframework.jdbc.core.JdbcTemplate;
public class MemberDaoImpl implements MemberDao {
private JdbcTemplate jdbcTemplate;
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
@Override
public int addMember(Member member) {
String sql = "insert into member(id,name,age,score,team,boo) value(?,?,?,?,?,?)";
Object[] obj = new Object[]{
member.getId(),
member.getName(),
member.getAge(),
member.getScore(),
member.getTeam(),
member.getBoo()
};
//执行添加操作,返回受SQL语句影响的记录条数
int num=this.jdbcTemplate.update(sql, obj);
return num;
}
@Override
public int updateMember(Member member) {
String sql = "update member set score=score+1 where id = ? ";
int num2=this.jdbcTemplate.update(sql, member.getId());
return num2;
}
@Override
public int selectMember(int id) {
String sql = "select score from member where id = ?";
Integer a=jdbcTemplate.queryForObject(sql,Integer.class,id);
return a;
}
public int deleteMember() {
String sql="delete from member";
int a =jdbcTemplate.update(sql);
return a;
}
}
3.测试给2号球员加分
点击查看代码
import jdbc.MysqlUpdate;
import member.Member;
import org.junit.Test;
import winer.TeamScoreWiner;
import winer.TeamScoreWiner2;
public class JdbcTest {
Member member=new Member();
@Test
public void text(){
//指定队员
member.setId(2);
member.setTeam("一");
//数据库植入球员信息
//MysqlAdd mysqlAdd=new MysqlAdd();
//mysqlAdd.mySqlAddMember();
//测试给队员加分
//1-6是一队
//6-10是二队
MysqlUpdate mysqlUpdate=new MysqlUpdate();
mysqlUpdate.mysqlUpMember(member);
//测试返回两队单局分数
/*Winer winer=new Winer();
winer.firstTeamScore(member);
winer.secondTeamScore(member);*/
//测试单局返回比赛结果
//一队
TeamScoreWiner teamScoreWiner=new TeamScoreWiner();
int a=teamScoreWiner.getWinTeam(member);
//二队
TeamScoreWiner2 teamScoreWiner2=new TeamScoreWiner2();
int b=teamScoreWiner2.getWinTeam2(member);
//测试清空数据
//MysqlDelete mysqlDelete=new MysqlDelete();
//mysqlDelete.mysqlSelect();
//测试返回比赛结果
//还没有优化完还在迭代中
}
}
标签:Member,score,int,积分,member,源码,new,public,排球比赛 来源: https://www.cnblogs.com/xile-010/p/16270645.html