示例#1
0
文件: hello.go 项目: hundt/poker
func defineNames(w http.ResponseWriter) {
	fmt.Fprint(w, "<script>var names = [];")
	for i := 0; i < 52; i++ {
		fmt.Fprintf(w, "names[%d] = '%s';", i, poker.Card(i).String())
	}
	fmt.Fprint(w, "</script>")
}
示例#2
0
文件: hello.go 项目: hundt/poker
func compare(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-type", "text/html; charset=utf-8")
	h1 := poker.NewHand(nil)
	h2 := poker.NewHand(nil)
	for i := 0; i < 52; i++ {
		v := r.FormValue(fmt.Sprintf("%d", i))
		if v == "1" {
			h1 = h1.Add(poker.Card(i))
		} else if v == "2" {
			h2 = h2.Add(poker.Card(i))
		}
	}
	fmt.Fprintf(w, "Hand 1: %s<br>", h1)
	fmt.Fprintf(w, "Hand 2: %s<br>", h2)
	c := h1.Compare(h2)
	if c < 0 {
		fmt.Fprint(w, "Hand 2 wins!")
	} else if c > 0 {
		fmt.Fprint(w, "Hand 1 wins!")
	} else {
		fmt.Fprint(w, "Tie!")
	}
}