⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serverplayer.java

📁 ErGo是一个很早的Java通用围棋服务器(IGS/NNGS)客户端程序。有全部源码和文档
💻 JAVA
字号:
package ergo.server;

// $Id: ServerPlayer.java,v 1.2 1999/08/13 01:18:10 sigue Exp $

/*
 *  Copyright (C) 1999  Carl L. Gay and Antranig M. Basman.
 *  See the file copyright.txt, distributed with this software,
 *  for further information.
 */

import ergo.util.*;

public class ServerPlayer {
  // of these, flags and idle may be null....
  public String name;
  public Rank rank;
  Idle idle;
  public String flags = "??";
  public String playing = "--";
  public String observing = "--";
  
  public ServerPlayer() {}

  public void imbue(String flags1, String observe1, String play1, String name1,
	     String idle1, String rank1) throws ParseException {
    Debug.asser(name == null || name.equals(name1),
		 "Cannot change player name");
    name = name1;
    //    System.out.println(name+" imbued");
    rank = new Rank(rank1);
    idle = new Idle(idle1);
    flags = flags1;
    playing = play1;
    observing = observe1;
  }

  public void imbue (String name1, String rank1) throws ParseException {
    Debug.asser(name == null || name.equals(name1),
		 "Cannot change player name");
    name = name1;
    rank = new Rank(rank1);
  }

  public String[] render () {
    String flagsr = flags;
    if (flags.length() > 1 && flags.charAt(0) == ' ')
      flagsr = flags.substring(1);
    String[] fields = { name, rank.render(), idle == null ? "0s" : idle.render(),
			flagsr,  "  " + playing, "  " + observing, null }; 
    // I'm a bit surprised this array isn't being cached...I wonder if
    // it's being recomputed unnecessarily?  -sigue
    return fields;
  }

  // Moved out of inner class Idle, to satisfy compiler.
  public static final int SEC = 0;
  public static final int MIN = 1;
  public static final int HR = 2;

  class Idle { // should think perhaps about unified time
	       // with TimerCanvas.toChars? Perhaps not.....
    private int numeric;		// currently simple.

    Idle(String s) throws ParseException {
      char finalc;
      int number; 
      try {
	finalc = s.charAt(s.length() - 1);
	number = Integer.parseInt(s.substring(0, s.length() - 1));
      } 
      catch(Exception e) { throw new ParseException("Illegal Time Format"); }
      switch(finalc) {
      case 's':
	numeric = number;
	break;
      case 'm':
	numeric = number * 60;
	break;
      case 'h':
	numeric = number * 3600;
	break;
      default:
	throw new ParseException("Illegal Time Format");
      }
    }

    public int compareTo(Idle other) {
      if (numeric < other.numeric) return 1;
      else if (numeric == other.numeric) return 0;
      else return -1;
    }

    String render() {
      if (numeric < 60) 
	return Integer.toString(numeric) + "s";
      else if (numeric < 3600)
	return Integer.toString(numeric / 60) + "m";
      else return Integer.toString(numeric / 3600) + "h";
    }
  }  // end inner class Idle

}  // end class ServerPlayer

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -