コード例 #1
0
ファイル: img_test.go プロジェクト: vanadium/croupier
// Testing resetting card position
func TestSix(test *testing.T) {
	u = uistate.MakeUIState()
	u.Scene = &sprite.Node{}
	u.Eng = glsprite.Engine(nil)
	u.Eng.Register(u.Scene)
	u.Eng.SetTransform(u.Scene, f32.Affine{
		{1, 0, 0},
		{0, 1, 0},
	})
	u.EmptySuitImgs = []*staticimg.StaticImg{staticimg.MakeStaticImg(), staticimg.MakeStaticImg(), staticimg.MakeStaticImg(), staticimg.MakeStaticImg()}
	u.WindowSize = windowSize
	n := texture.MakeNode(u)
	for _, e := range u.EmptySuitImgs {
		e.SetImage(subtex)
		e.SetAlt(subtex)
		e.SetNode(n)
	}
	c := card.NewCard(card.Two, card.Heart)
	c2 := card.NewCard(card.Four, card.Heart)
	n = texture.MakeNode(u)
	n2 := texture.MakeNode(u)
	initialXY := coords.MakeVec(10, 10)
	curXY := coords.MakeVec(100, 30)
	dimensions := coords.MakeVec(5, 5)
	c.SetNode(n)
	c2.SetNode(n2)
	c.SetInitial(initialXY)
	c2.SetInitial(initialXY)
	c.Move(curXY, dimensions, u.Eng)
	c2.Move(curXY, dimensions, u.Eng)
	u.Cards = append(u.Cards, c)
	u.Cards = append(u.Cards, c2)
	if c.GetCurrent().X != curXY.X {
		test.Errorf("Expected x %f, got %f", curXY.X, c.GetCurrent().X)
	}
	if c.GetCurrent().Y != curXY.Y {
		test.Errorf("Expected y %f, got %f", curXY.Y, c.GetCurrent().Y)
	}
	reposition.ResetCardPosition(c, u.Eng)
	reposition.ResetCardPosition(c2, u.Eng)
	reposition.RealignSuit(c.GetSuit(), c.GetInitial().Y, u)
	if c.GetCurrent().X != u.Padding {
		test.Errorf("Expected x %f, got %f", initialXY.X, c.GetCurrent().X)
	}
	if c.GetCurrent().Y != initialXY.Y {
		test.Errorf("Expected y %f, got %f", initialXY.Y, c.GetCurrent().Y)
	}
	if c2.GetCurrent().X != u.Padding+dimensions.X+u.Padding {
		test.Errorf("Expected x %f, got %f", u.Padding+dimensions.X+u.Padding, c2.GetCurrent().X)
	}
	if c2.GetCurrent().Y != initialXY.Y {
		test.Errorf("Expected y %f, got %f", initialXY.Y, c2.GetCurrent().Y)
	}
}
コード例 #2
0
ファイル: touchhandler.go プロジェクト: vanadium/croupier
func endClickSplit(t touch.Event, u *uistate.UIState) {
	if u.CurCard != nil {
		if u.CurTable.GetTrick()[u.CurPlayerIndex] == nil {
			if dropCardHere(u.CurCard, u.DropTargets[0], t, u) {
				if u.CurTable.WhoseTurn() == u.CurPlayerIndex {
					ch := make(chan bool)
					if err := sync.PlayCard(ch, u.CurPlayerIndex, u); err != "" {
						view.ChangePlayMessage(err, u)
						if sync.RemoveCardFromTarget(u.CurCard, u) {
							u.CardToPlay = nil
							u.BackgroundImgs[0].GetNode().Arranger = nil
							var emptyTex sprite.SubTex
							u.Eng.SetSubTex(u.BackgroundImgs[0].GetNode(), emptyTex)
							u.BackgroundImgs[0].SetHidden(true)
						}
						// add card back to hand
						reposition.ResetCardPosition(u.CurCard, u.Eng)
					}
				} else {
					u.CardToPlay = u.CurCard
					reposition.AlternateImgs(u.BackgroundImgs[0], u)
				}
			} else {
				// add card back to hand
				if sync.RemoveCardFromTarget(u.CurCard, u) {
					u.CardToPlay = nil
					u.BackgroundImgs[0].GetNode().Arranger = nil
					var emptyTex sprite.SubTex
					u.Eng.SetSubTex(u.BackgroundImgs[0].GetNode(), emptyTex)
					u.BackgroundImgs[0].SetHidden(true)
				}
				reposition.ResetCardPosition(u.CurCard, u.Eng)
				reposition.RealignSuit(u.CurCard.GetSuit(), u.CurCard.GetInitial().Y, u)
			}
		} else {
			// add card back to hand
			reposition.ResetCardPosition(u.CurCard, u.Eng)
			reposition.RealignSuit(u.CurCard.GetSuit(), u.CurCard.GetInitial().Y, u)
		}
	}
	pressed := getPressed(u)
	unpress := true
	for _, b := range pressed {
		if b == u.Buttons["takeTrick"] {
			sync.LogTakeTrick(u)
		} else if b == u.Buttons["toggleSplit"] {
			unpress = false
		}
	}
	if unpress {
		unpressButtons(u)
	}
}
コード例 #3
0
ファイル: touchhandler.go プロジェクト: vanadium/croupier
// checks one specific drop target to see if a card was dropped there
func dropCardHere(c *card.Card, d *staticimg.StaticImg, t touch.Event, u *uistate.UIState) bool {
	if !touchingStaticImg(t, d, u) {
		return false
	}
	lastDroppedCard := d.GetCardHere()
	if lastDroppedCard != nil {
		reposition.ResetCardPosition(lastDroppedCard, u.Eng)
		reposition.RealignSuit(lastDroppedCard.GetSuit(), lastDroppedCard.GetInitial().Y, u)
	}
	oldY := c.GetInitial().Y
	suit := c.GetSuit()
	u.CurCard.Move(d.GetCurrent(), c.GetDimensions(), u.Eng)
	d.SetCardHere(u.CurCard)
	// realign suit the card just left
	reposition.RealignSuit(suit, oldY, u)
	return true
}
コード例 #4
0
ファイル: touchhandler.go プロジェクト: vanadium/croupier
// checks all drop targets to see if a card was dropped there
func dropCardOnTarget(c *card.Card, t touch.Event, u *uistate.UIState) bool {
	for _, d := range u.DropTargets {
		// checking to see if card was dropped onto a drop target
		if touchingStaticImg(t, d, u) {
			lastDroppedCard := d.GetCardHere()
			if lastDroppedCard != nil {
				reposition.ResetCardPosition(lastDroppedCard, u.Eng)
				reposition.RealignSuit(lastDroppedCard.GetSuit(), lastDroppedCard.GetInitial().Y, u)
			}
			oldY := c.GetInitial().Y
			suit := c.GetSuit()
			c.Move(d.GetCurrent(), c.GetDimensions(), u.Eng)
			d.SetCardHere(c)
			// realign suit the card just left
			reposition.RealignSuit(suit, oldY, u)
			return true
		}
	}
	return false
}
コード例 #5
0
ファイル: touchhandler.go プロジェクト: vanadium/croupier
func endClickTake(t touch.Event, u *uistate.UIState) {
	pressed := unpressButtons(u)
	for _, b := range pressed {
		if b == u.Buttons["take"] {
			cards := make([]*card.Card, 0)
			for _, d := range u.DropTargets {
				c := d.GetCardHere()
				if c != nil {
					cards = append(cards, c)
				}
			}
			for _, c := range cards {
				sync.RemoveCardFromTarget(c, u)
				// add card back to hand
				reposition.ResetCardPosition(c, u.Eng)
				reposition.RealignSuit(c.GetSuit(), c.GetInitial().Y, u)
			}
			ch := make(chan bool)
			success := takeCards(ch, u.CurPlayerIndex, u)
			quit := make(chan bool)
			u.AnimChans = append(u.AnimChans, quit)
			go func() {
				onDone := func() {
					if !success {
						fmt.Println("Invalid take")
					} else {
						if u.CurView == uistate.Take {
							view.LoadPlayView(false, u)
						}
					}
				}
				reposition.SwitchOnChan(ch, quit, onDone, u)
			}()
		}
	}
}
コード例 #6
0
ファイル: watch.go プロジェクト: vanadium/croupier
func onPlay(value string, u *uistate.UIState) {
	// logic
	playerInt, curCards := parsePlayerAndCards(value, u)
	playedCard := curCards[0]
	u.CurTable.GetPlayers()[playerInt].RemoveFromHand(playedCard)
	u.CurTable.SetPlayedCard(playedCard, playerInt)
	u.CurTable.GetPlayers()[playerInt].SetDonePlaying(true)
	trickOver := u.CurTable.TrickOver()
	var recipient int
	if trickOver {
		recipient = u.CurTable.GetTrickRecipient()
	}
	// UI
	if u.CurView == uistate.Table {
		sound.PlaySound(0, u)
		quit := make(chan bool)
		u.AnimChans = append(u.AnimChans, quit)
		reposition.AnimateTableCardPlay(playedCard, playerInt, quit, u)
		reposition.SetTableDropColors(u)
		if trickOver {
			// display take trick button
			b := u.Buttons["takeTrick"]
			u.Eng.SetSubTex(b.GetNode(), b.GetImage())
			b.SetHidden(false)
		}
	} else if u.CurView == uistate.Split {
		if playerInt != u.CurPlayerIndex {
			quit := make(chan bool)
			u.AnimChans = append(u.AnimChans, quit)
			reposition.AnimateSplitCardPlay(playedCard, playerInt, quit, u)
		}
		reposition.SetSplitDropColors(u)
		view.LoadSplitView(true, u)
		if trickOver {
			if recipient == u.CurPlayerIndex {
				// display take trick button
				b := u.Buttons["takeTrick"]
				u.Eng.SetSubTex(b.GetNode(), b.GetImage())
				b.SetHidden(false)
			}
		} else if u.CardToPlay != nil && u.CurTable.WhoseTurn() == u.CurPlayerIndex {
			ch := make(chan bool)
			if err := PlayCard(ch, u.CurPlayerIndex, u); err != "" {
				view.ChangePlayMessage(err, u)
				RemoveCardFromTarget(u.CardToPlay, u)
				// add card back to hand
				reposition.ResetCardPosition(u.CardToPlay, u.Eng)
			}
			u.CardToPlay = nil
			u.BackgroundImgs[0].GetNode().Arranger = nil
			var emptyTex sprite.SubTex
			u.Eng.SetSubTex(u.BackgroundImgs[0].GetNode(), emptyTex)
			u.BackgroundImgs[0].SetHidden(true)
		}
	} else if u.CurView == uistate.Play && u.CurPlayerIndex != playerInt {
		view.LoadPlayView(true, u)
		if u.CardToPlay != nil && u.CurTable.WhoseTurn() == u.CurPlayerIndex {
			ch := make(chan bool)
			if err := PlayCard(ch, u.CurPlayerIndex, u); err != "" {
				view.ChangePlayMessage(err, u)
				RemoveCardFromTarget(u.CardToPlay, u)
				// add card back to hand
				reposition.ResetCardPosition(u.CardToPlay, u.Eng)
				reposition.RealignSuit(u.CardToPlay.GetSuit(), u.CardToPlay.GetInitial().Y, u)
			}
			u.CardToPlay = nil
			quit := make(chan bool)
			u.AnimChans = append(u.AnimChans, quit)
			go func() {
				onDone := func() {
					if u.CurView == uistate.Play {
						view.LoadPlayView(true, u)
					}
				}
				reposition.SwitchOnChan(ch, quit, onDone, u)
			}()
		}
	}
}
コード例 #7
0
ファイル: touchhandler.go プロジェクト: vanadium/croupier
func endClickPlay(t touch.Event, u *uistate.UIState) {
	if u.CurCard != nil {
		if u.CurTable.GetTrick()[u.CurPlayerIndex] == nil {
			if dropCardOnTarget(u.CurCard, t, u) {
				if u.CurTable.WhoseTurn() == u.CurPlayerIndex {
					ch := make(chan bool)
					if err := sync.PlayCard(ch, u.CurPlayerIndex, u); err != "" {
						view.ChangePlayMessage(err, u)
						sync.RemoveCardFromTarget(u.CurCard, u)
						u.CardToPlay = nil
						// add card back to hand
						reposition.ResetCardPosition(u.CurCard, u.Eng)
						reposition.RealignSuit(u.CurCard.GetSuit(), u.CurCard.GetInitial().Y, u)
					}
					quit := make(chan bool)
					u.AnimChans = append(u.AnimChans, quit)
					go func() {
						onDone := func() {
							if u.CurView == uistate.Play {
								view.LoadPlayView(true, u)
							}
						}
						reposition.SwitchOnChan(ch, quit, onDone, u)
					}()
				} else {
					u.CardToPlay = u.CurCard
				}
			} else {
				// add card back to hand
				if sync.RemoveCardFromTarget(u.CurCard, u) {
					u.CardToPlay = nil
				}
				reposition.ResetCardPosition(u.CurCard, u.Eng)
				reposition.RealignSuit(u.CurCard.GetSuit(), u.CurCard.GetInitial().Y, u)
			}
		} else {
			// add card back to hand
			reposition.ResetCardPosition(u.CurCard, u.Eng)
			reposition.RealignSuit(u.CurCard.GetSuit(), u.CurCard.GetInitial().Y, u)
		}
	}
	pressed := unpressButtons(u)
	for _, b := range pressed {
		if b == u.Buttons["takeTrick"] {
			var emptyTex sprite.SubTex
			u.Eng.SetSubTex(b.GetNode(), emptyTex)
			b.SetHidden(true)
			u.Buttons["takeTrick"] = nil
			for _, takenCard := range u.TableCards {
				sync.RemoveCardFromTarget(takenCard, u)
				reposition.BringNodeToFront(takenCard.GetNode(), u)
			}
			ch := make(chan bool)
			reposition.AnimateHandCardTakeTrick(ch, u.TableCards, u)
			quit := make(chan bool)
			u.AnimChans = append(u.AnimChans, quit)
			go func() {
				onDone := func() {
					sync.LogTakeTrick(u)
				}
				reposition.SwitchOnChan(ch, quit, onDone, u)
			}()
		}
	}
}
コード例 #8
0
ファイル: touchhandler.go プロジェクト: vanadium/croupier
func endClickPass(t touch.Event, u *uistate.UIState) {
	if u.CurCard != nil {
		if !dropCardOnTarget(u.CurCard, t, u) {
			// check to see if card was removed from a drop target
			sync.RemoveCardFromTarget(u.CurCard, u)
			// add card back to hand
			reposition.ResetCardPosition(u.CurCard, u.Eng)
			reposition.RealignSuit(u.CurCard.GetSuit(), u.CurCard.GetInitial().Y, u)
		}
		// check to see whether pull tab should be displayed
		readyToPass := true
		for _, d := range u.DropTargets {
			if d.GetCardHere() == nil {
				readyToPass = false
			}
		}
		passButton := u.Buttons["pass"]
		if readyToPass {
			if passButton.GetDisplayingImage() {
				u.Eng.SetSubTex(passButton.GetNode(), passButton.GetImage())
				passButton.SetHidden(false)
				passButton.SetDisplayingImage(true)
			}
			for _, img := range u.Other {
				if img.GetDisplayingImage() {
					u.Eng.SetSubTex(img.GetNode(), img.GetAlt())
					img.SetHidden(false)
					img.SetDisplayingImage(false)
				}
			}
		} else {
			var emptyTex sprite.SubTex
			u.Eng.SetSubTex(passButton.GetNode(), emptyTex)
			passButton.SetHidden(true)
			passButton.SetDisplayingImage(true)
			for _, img := range u.Other {
				if !img.GetDisplayingImage() {
					u.Eng.SetSubTex(img.GetNode(), img.GetImage())
					img.SetHidden(false)
					img.SetDisplayingImage(true)
				}
			}
		}
	}
	pressed := unpressButtons(u)
	for _, p := range pressed {
		if p == u.Buttons["pass"] {
			ch := make(chan bool)
			success := passCards(ch, u.CurPlayerIndex, u)
			quit := make(chan bool)
			u.AnimChans = append(u.AnimChans, quit)
			go func() {
				onDone := func() {
					if !success {
						fmt.Println("Invalid pass")
					} else if u.CurView == uistate.Pass {
						view.LoadTakeView(u)
					}
				}
				reposition.SwitchOnChan(ch, quit, onDone, u)
			}()
		}
	}
	u.CurCard = nil
}