예제 #1
0
파일: tests.py 프로젝트: ben-mar/TheGame
 def setUp(self):
     self.color = 'Silver'
     self.size = 60
     self.PlayerInstance = TheGame.Player(self.size, self.color)
     self.decklist = [
         TheGame.Card(i, self.color) for i in range(2, self.size)
     ]
     self.PILEUP = [TheGame.Card(number=1, color=self.color)]
     self.PILEDOWN = [TheGame.Card(number=self.size, color=self.color)]
예제 #2
0
    def setup_pygame(self):
        """
		Initalises the game and pygame
		"""

        self.game = TheGame.GameFrontEnd()
        pygame.display.set_caption('The Game')
예제 #3
0
파일: tests.py 프로젝트: ben-mar/TheGame
    def test_sort(self):

        self.Game = TheGame.Game()
        self.PlayerSelected = 1
        self.Game.Player1.hand = TheGame.CreateListOfCards(
            [2, 14, 16, 18, 47, 57], self.Game.color['P1'])
        self.Game.Hands = {
            'P1': self.Game.Player1.hand,
            'P2': self.Game.Player2.hand
        }

        self.Game.SortHand(2, TheGame.Card(57, self.Game.color['P1']),
                           self.PlayerSelected)
        self.assertEqual(
            self.Game.Hands['P1'],
            TheGame.CreateListOfCards([2, 14, 57, 16, 18, 47],
                                      self.Game.color['P1']))
예제 #4
0
파일: tests.py 프로젝트: ben-mar/TheGame
    def test_ChangeActivePlayer(self):

        self.Game = TheGame.Game()

        self.Game.ActivePlayer = 1
        self.Game.ChangeActivePlayer()
        self.assertEqual(self.Game.ActivePlayer, 2)
        self.Game.ChangeActivePlayer()
        self.assertEqual(self.Game.ActivePlayer, 1)
예제 #5
0
파일: tests.py 프로젝트: ben-mar/TheGame
    def test_DeepcopyForCheckIfLoose(self):

        self.Game = TheGame.Game()
        self.Game.DeepcopyForCheckIfLoose()

        # we competely change the value of the 1UP pile and we insure the copy hasn't changed
        self.Game.Player1.PileUP = []

        self.assertEqual(self.Game.CopyPlayer1PileUP,
                         TheGame.CreateListOfCards([1], self.Game.color['P1']))

        ##### TO GET RID OFF #####

        self.Game = TheGame.Game()

        self.Game.ActivePlayer = 2
        PlayerSelected = 2

        self.Game.Player2.hand = TheGame.CreateListOfCards(
            [20, 34, 36, 38, 49, 57], self.Game.color['P2'])
        self.Game.Player1.PileUP = TheGame.CreateListOfCards(
            [1, 13], self.Game.color['P1'])
        self.Game.Player1.PileDOWN = TheGame.CreateListOfCards(
            [60, 51], self.Game.color['P1'])
        self.Game.Player2.PileUP = TheGame.CreateListOfCards(
            [1, 5, 6], self.Game.color['P2'])
        self.Game.Player2.PileDOWN = TheGame.CreateListOfCards(
            [60, 53, 49], self.Game.color['P2'])

        self.Game.Piles = {
            "P1_UP": self.Game.Player1.PileUP,
            "P1_DOWN": self.Game.Player1.PileDOWN,
            "P2_UP": self.Game.Player2.PileUP,
            "P2_DOWN": self.Game.Player2.PileDOWN
        }

        self.Game.Hands = {
            'P1': self.Game.Player1.hand,
            'P2': self.Game.Player2.hand
        }
        self.Game.PlayedOnOpponnentPiles = {'P1': False, 'P2': False}
        self.Game.PlayedThisTurn = {'P1': [], 'P2': []}

        self.Game.DeepcopyForCheckIfLoose()
        print("copy played this turn :", self.Game.CopyPlayedThisTurn)
        print("played this turn :", self.Game.CopyPlayedThisTurn)
        self.Game.Play("P2_DOWN", TheGame.Card(36, 'Silver'), PlayerSelected)
        print("copy played this turn :", self.Game.CopyPlayedThisTurn)
        print("played this turn :", self.Game.PlayedThisTurn)
예제 #6
0
파일: tests.py 프로젝트: ben-mar/TheGame
    def test_LoadDeepCopyForCheckIfLoose(self):
        """
        Here the test must ensure that the loaded copy can de changed without imacting the backup created by DeepcopyForCheckIfLoose
        """

        self.Game = TheGame.Game()

        # let's modify the game state just a bit
        self.Game.Player1.PileUP.append(
            TheGame.Card(number=10, color=self.Game.color['P1']))

        # DeepCopy
        self.Game.CopyPlayer1PileUP = copy.deepcopy(self.Game.Player1.PileUP)
        self.Game.CopyPlayer1PileDOWN = copy.deepcopy(
            self.Game.Player1.PileDOWN)
        self.Game.CopyPlayer1Hand = copy.deepcopy(self.Game.Player1.hand)
        self.Game.CopyPlayer2PileUP = copy.deepcopy(self.Game.Player2.PileUP)
        self.Game.CopyPlayer2PileDOWN = copy.deepcopy(
            self.Game.Player2.PileDOWN)
        self.Game.CopyPlayer2Hand = copy.deepcopy(self.Game.Player2.hand)

        self.Game.CopyPlayedThisTurn = copy.deepcopy(self.Game.PlayedThisTurn)
        self.Game.CopyPlayedOnOpponnentPiles = copy.deepcopy(
            self.Game.PlayedOnOpponnentPiles)

        self.Game.LoadDeepCopyForCheckIfLoose()
        self.assertEqual(self.Game.CopyPlayedThisTurn, {'P1': [], 'P2': []})
        self.assertEqual(self.Game.PlayedThisTurn, {'P1': [], 'P2': []})
        self.Game.PlayedThisTurn['P' + str(self.Game.ActivePlayer)].append(
            (TheGame.Card(36, 'Silver'), "P2_DOWN"))
        self.assertEqual(self.Game.CopyPlayedThisTurn, {'P1': [], 'P2': []})
        self.assertEqual(self.Game.PlayedThisTurn, {
            'P1': [(TheGame.Card(36, 'Silver'), 'P2_DOWN')],
            'P2': []
        })

        self.Game.LoadDeepCopyForCheckIfLoose()
        self.assertEqual(
            self.Game.Piles['P1_UP'],
            TheGame.CreateListOfCards([1, 10], self.Game.color['P1']))

        self.Game.Piles['P1_UP'].append(
            TheGame.Card(number=14, color=self.Game.color['P1']))

        # we ensure the Pile has changed but not the backup
        self.assertEqual(
            self.Game.Piles['P1_UP'],
            TheGame.CreateListOfCards([1, 10, 14], self.Game.color['P1']))
        self.assertEqual(
            self.Game.CopyPlayer1PileUP,
            TheGame.CreateListOfCards([1, 10], self.Game.color['P1']))
예제 #7
0
파일: tests.py 프로젝트: ben-mar/TheGame
    def test_equality(self) -> None:
        self.number1 = 15
        self.color1 = 'Silver'
        self.card1 = TheGame.Card(self.number1, self.color1)

        self.number2 = 53
        self.color2 = 'Silver'
        self.card2 = TheGame.Card(self.number2, self.color2)

        self.number3 = 15
        self.color3 = 'Gold'
        self.card3 = TheGame.Card(self.number3, self.color3)

        self.number4 = 15
        self.color4 = 'Silver'
        self.card4 = TheGame.Card(self.number4, self.color4)

        self.assertNotEqual(self.card1, self.card2)
        self.assertNotEqual(self.card1, self.card3)
        self.assertNotEqual(self.card2, self.card3)
        self.assertEqual(self.card1, self.card4)
예제 #8
0
	def Decode(self,
			   objectToDecode : str,
			   typeToDecode :str  = 'ListOfCards' 
			   ):

		"""
		Decodes the parameter objectToDecode according to the type of object (typeToDecode)
		"""

		if typeToDecode == 'ListOfCards':		
			# Decodes the messages
			ListOfCards = [] 
			if objectToDecode =='':
				return ListOfCards
			else:
				spliting = objectToDecode.split(';')
				for encoded_card in spliting:
					number,color = encoded_card.split('$') 
					ListOfCards.append(TheGame.Card(int(number),color))
				return ListOfCards

		elif typeToDecode == 'Boolean':
			if objectToDecode == "True":
				return True
			else :
				return False
		elif typeToDecode == 'CoupleCardPile':
			ListOfCouples = [] 
			if objectToDecode =='':
				return ListOfCouples
			else:
				spliting = objectToDecode.split(';')
				for encoded_couple in spliting:
					encoded_card, pile = encoded_couple.split('#')
					number,color = encoded_card.split('$') 
					ListOfCouples.append((TheGame.Card(int(number),color),pile))
				return ListOfCouples
		else :
			raise("Not treated yet, the typeToEncode is not correct ! : {}".format(typeToDecode))		
예제 #9
0
파일: tests.py 프로젝트: ben-mar/TheGame
    def test_setup(self):
        """
        This test doesn't test again the DrawBeginningHand function
        """
        PlayerTestInstance = TheGame.Player(self.size, self.color)
        self.deck = PlayerTestInstance.deck
        self.PileUP = PlayerTestInstance.PileUP
        self.PileDOWN = PlayerTestInstance.PileDOWN

        PlayerTestInstance.setup()
        self.assertTrue(self.deck != self.decklist)
        self.assertListEqual(self.PileUP, self.PILEUP)
        self.assertListEqual(self.PileDOWN, self.PILEDOWN)
예제 #10
0
파일: tests.py 프로젝트: ben-mar/TheGame
    def test_Concede(self):

        self.Game = TheGame.Game()
        self.assertFalse(self.Game.GameOver['P1'])
        self.assertFalse(self.Game.GameOver['P2'])

        self.Game.Concede()
        self.assertTrue(self.Game.GameOver['P1'])
        self.assertFalse(self.Game.GameOver['P2'])

        self.Game.ActivePlayer = 2
        self.Game.Concede()
        self.assertTrue(self.Game.GameOver['P1'])
        self.assertTrue(self.Game.GameOver['P2'])
예제 #11
0
파일: tests.py 프로젝트: ben-mar/TheGame
    def test_HasTheRightToEndTurn(self):

        self.Game = TheGame.Game()

        self.Game.ActivePlayer = 2
        PlayerSelected = 2

        self.Game.Player1.hand = TheGame.CreateListOfCards(
            [2, 14, 16, 18, 47, 57], self.Game.color['P1'])
        self.Game.Player2.hand = TheGame.CreateListOfCards(
            [20, 34, 36, 38, 49, 57], self.Game.color['P2'])
        self.Game.Player1.PileUP = TheGame.CreateListOfCards(
            [1, 13], self.Game.color['P1'])
        self.Game.Player1.PileDOWN = TheGame.CreateListOfCards(
            [60, 51], self.Game.color['P1'])
        self.Game.Player2.PileUP = TheGame.CreateListOfCards(
            [1, 5, 6], self.Game.color['P2'])
        self.Game.Player2.PileDOWN = TheGame.CreateListOfCards(
            [60, 53, 49], self.Game.color['P2'])

        self.Game.Piles = {
            "P1_UP": self.Game.Player1.PileUP,
            "P1_DOWN": self.Game.Player1.PileDOWN,
            "P2_UP": self.Game.Player2.PileUP,
            "P2_DOWN": self.Game.Player2.PileDOWN
        }
        self.Game.Hands = {
            'P1': self.Game.Player1.hand,
            'P2': self.Game.Player2.hand
        }

        self.Game.Play('P2_UP', TheGame.Card(20, self.Game.color['P2']),
                       PlayerSelected)
        self.assertEqual(self.Game.HasTheRightToEndTurn(), 0)

        self.Game.Play('P2_UP', TheGame.Card(34, self.Game.color['P2']),
                       PlayerSelected)
        self.assertEqual(self.Game.HasTheRightToEndTurn(), 1)
예제 #12
0
	def __init__(self,
				server : str = "127.0.0.1",
				port : int = 9009
				)-> None : # TODO the max_num_players = 2

		"""
		Initialises the GameServer class, with the server port and address.
		So far it's only possible to play in local but one of the potential improvements would be to allow internet connexion
		between players
		"""
	
		self.listener = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
		# Bind to localhost - set to external ip to connect from other computers
		self.listener.bind((server, port))
		self.read_list = [self.listener]
		self.write_list = []   
		self.game = TheGame.Game()
		self.players = {}
예제 #13
0
파일: tests.py 프로젝트: ben-mar/TheGame
    def test_DrawEndOfTurn(self):

        self.Game = TheGame.Game()
        self.Game.Player1.deck = TheGame.CreateListOfCards(
            [5, 23, 15, 58, 46], self.Game.color['P1'])
        self.Game.Player2.deck = TheGame.CreateListOfCards(
            [5, 32, 9, 51, 53, 48], self.Game.color['P2'])
        self.Game.Player1.hand = TheGame.CreateListOfCards(
            [2, 3], self.Game.color['P1'])
        self.Game.Player2.hand = TheGame.CreateListOfCards(
            [7, 52, 45], self.Game.color['P2'])

        self.Game.Hands = {
            'P1': self.Game.Player1.hand,
            'P2': self.Game.Player2.hand
        }
        self.Game.PlayedOnOpponnentPiles = {'P1': False, 'P2': True}

        self.PLAYER1HAND = TheGame.CreateListOfCards([2, 3, 58, 46],
                                                     self.Game.color['P1'])
        self.PLAYER2HAND = TheGame.CreateListOfCards([7, 52, 45, 51, 53, 48],
                                                     self.Game.color['P2'])

        self.Game.DrawEndOfTurn()

        self.assertListEqual(self.PLAYER1HAND, self.Game.Player1.hand)
        self.assertListEqual(
            self.Game.Player1.deck,
            TheGame.CreateListOfCards([5, 23, 15], self.Game.color['P1']))

        self.Game.ActivePlayer = 2
        self.Game.DrawEndOfTurn()

        self.assertListEqual(self.PLAYER2HAND, self.Game.Player2.hand)
        self.assertListEqual(
            self.Game.Player2.deck,
            TheGame.CreateListOfCards([5, 32, 9], self.Game.color['P2']))
예제 #14
0
파일: tests.py 프로젝트: ben-mar/TheGame
    def test_Undo(self):

        self.Game = TheGame.Game()

        self.Game.ActivePlayer = 1
        PlayerSelected = 1

        self.Game.Player1.hand = TheGame.CreateListOfCards(
            [2, 14, 16, 18, 47, 57], self.Game.color['P1'])
        self.Game.Player1.PileUP = TheGame.CreateListOfCards(
            [1, 13], self.Game.color['P1'])
        self.Game.Player1.PileDOWN = TheGame.CreateListOfCards(
            [60, 51], self.Game.color['P1'])
        self.Game.Player2.PileUP = TheGame.CreateListOfCards(
            [1, 5, 6], self.Game.color['P2'])
        self.Game.Player2.PileDOWN = TheGame.CreateListOfCards(
            [60, 53, 49], self.Game.color['P2'])
        self.Game.Piles = {
            "P1_UP": self.Game.Player1.PileUP,
            "P1_DOWN": self.Game.Player1.PileDOWN,
            "P2_UP": self.Game.Player2.PileUP,
            "P2_DOWN": self.Game.Player2.PileDOWN
        }

        self.Game.Hands = {
            'P1': self.Game.Player1.hand,
            'P2': self.Game.Player2.hand
        }
        self.Game.PlayedOnOpponnentPiles = {'P1': False, 'P2': False}
        self.Game.PlayedThisTurn = {'P1': [], 'P2': []}

        self.Game.Play('P2_DOWN', TheGame.Card(57, self.Game.color['P1']),
                       PlayerSelected)
        self.Game.Play('P1_UP', TheGame.Card(16, self.Game.color['P1']),
                       PlayerSelected)

        self.assertEqual(self.Game.PlayedThisTurn['P1'],
                         [(TheGame.Card(57, 'Gold'), 'P2_DOWN'),
                          (TheGame.Card(16, 'Gold'), 'P1_UP')])
        self.assertEqual(
            self.Game.Hands['P1'],
            TheGame.CreateListOfCards([2, 14, 18, 47], self.Game.color['P1']))
        self.assertTrue(self.Game.PlayedOnOpponnentPiles['P1'])
        self.Game.Undo()
        self.assertEqual(
            self.Game.Hands['P1'],
            TheGame.CreateListOfCards([2, 14, 18, 47, 16],
                                      self.Game.color['P1']))
        self.assertEqual(self.Game.PlayedThisTurn['P1'],
                         [(TheGame.Card(57, 'Gold'), 'P2_DOWN')])
        self.assertTrue(self.Game.PlayedOnOpponnentPiles['P1'])
        self.Game.Undo()
        self.assertEqual(
            self.Game.Hands['P1'],
            TheGame.CreateListOfCards([2, 14, 18, 47, 16, 57],
                                      self.Game.color['P1']))
        self.assertEqual(self.Game.PlayedThisTurn['P1'], [])
        self.assertFalse(self.Game.PlayedOnOpponnentPiles['P1'])
예제 #15
0
    def ShowPilesScreen(self, index: int) -> None:
        """
		Displays the piles Screen according to the index pile
		"""

        DisplayedPile = self.game.Piles[self.mapping_play_card[(
            index, self.game.PlayerSelected)]]

        Cards_to_Hide_gold = TheGame.CreateListOfCards([1, 60], 'Gold')
        Cards_to_Hide_silver = TheGame.CreateListOfCards([1, 60], 'Silver')
        Cards_to_Hide = Cards_to_Hide_silver + Cards_to_Hide_gold

        DisplayedPile = [
            card for card in DisplayedPile if card not in Cards_to_Hide
        ]
        NumberOfCardsToDisplay = len(DisplayedPile)

        if NumberOfCardsToDisplay > 0:

            GraySurf = pygame.Surface(
                (self.game.WINDOWWIDTH, self.game.WINDOWHEIGHT),
                pygame.SRCALPHA)  # per-pixel alpha
            GraySurf.fill((150, 150, 150, 150))
            self.game.DISPLAYSURF.blit(GraySurf, (0, 0))

            # PileBoxSize = (int(0.6*self.game.WINDOWWIDTH), int(self.game.HEIGHTCARD))
            # PileBox = pygame.draw.rect(self.game.DISPLAYSURF, self.game.ColorsCodes["Gray"],
            # 	( x0, y0 , PileBoxSize[0] , PileBoxSize[1] ), 4)

            # create cursor surface and cursor:

            SurfCursorSize = (int(0.4 * self.game.WINDOWWIDTH),
                              int(0.033 * self.game.WINDOWHEIGHT))
            SurfCursor = pygame.Surface(SurfCursorSize,
                                        pygame.SRCALPHA)  # per-pixel alpha
            SurfCursor.fill((40, 40, 40, 255))
            x0SurfCursor = int(0.3 * self.game.WINDOWWIDTH)
            y0SurfCursor = int((
                (self.game.WINDOWHEIGHT - self.game.HEIGHTCARD) / 2) +
                               1.5 * self.game.HEIGHTCARD)
            SurfCursorBlit = self.game.DISPLAYSURF.blit(
                SurfCursor, (x0SurfCursor, y0SurfCursor))

            pygame.draw.rect(self.game.DISPLAYSURF,
                             self.game.ColorsCodes["Gray"],
                             (x0SurfCursor, y0SurfCursor, SurfCursorSize[0],
                              SurfCursorSize[1]), 4)

            # initialise cursor

            CursorPos = self.game.WINDOWWIDTH / 2  # middle of cursor
            CursorSize = (int(0.04 * self.game.WINDOWWIDTH),
                          int(0.033 * self.game.WINDOWHEIGHT))

            Cursor = pygame.Surface(CursorSize,
                                    pygame.SRCALPHA)  # per-pixel alpha
            Cursor.fill((0, 0, 0, 255))
            CursorBlit = self.game.DISPLAYSURF.blit(
                Cursor,
                (int(CursorPos - CursorSize[0] / 2),
                 int(((self.game.WINDOWHEIGHT - self.game.HEIGHTCARD) / 2) +
                     1.5 * self.game.HEIGHTCARD)))

            CursorSelected = False

            CursorPosMax = x0SurfCursor + SurfCursorSize[0] - CursorSize[0] / 2
            CursorPosMin = x0SurfCursor + CursorSize[0] / 2

            NotClickedOut = True

            NumberMaxOfCardsToDisplay = 6
            Ltot = self.game.WIDTHCARD * (NumberOfCardsToDisplay -
                                          1) / 3 + self.game.WIDTHCARD

            x0 = int((self.game.WINDOWWIDTH - Ltot) / 2)
            y0 = int((self.game.WINDOWHEIGHT - self.game.HEIGHTCARD) / 2)

            # xc = int(self.game.WIDTHCARD/2)
            # yc = int(self.game.HEIGHTCARD/2)

            # Max rotation
            alpha_max = 15

            # TODO : handle case where the pile is empty (just 1 card in it : division by 0 )
            # TODO : fetch the active player before so that WidthSeenCard depends on the selected player
            #WidthSeenCard = (int(0.6*self.game.WINDOWWIDTH) - self.game.WIDTHCARD)/(NumberOfCards+1) # represent the width of a card displayed but not completely shown on a pile
            WidthSeenCard = (1 / 3) * self.game.WIDTHCARD

            while NotClickedOut:

                # i = round(NumberOfCards*(CursorPos-CursorPosMin)/(CursorPosMax-CursorPosMin))
                j = 0
                # for card in DisplayedPile:
                # 	if j<i : # before the card i
                # 		self.game.DrawCardOnBoard(card,LeftTop=[x0+j*WidthSeenCard,y0])
                # 	elif j==i:
                # 		self.game.DrawCardOnBoard(card,LeftTop=[x0+(j-1)*WidthSeenCard +self.game.WIDTHCARD,y0])
                # 	elif j>i:
                # 		self.game.DrawCardOnBoard(card,LeftTop=[x0+j*WidthSeenCard,y0])
                # 	j+=1
                if NumberOfCardsToDisplay <= NumberMaxOfCardsToDisplay:
                    alpha = (NumberOfCardsToDisplay /
                             NumberMaxOfCardsToDisplay) * alpha_max
                    # Rot_alpha = np.array([[np.cos(alpha), -np.sin(alpha)],
                    # 					  [np.sin(alpha),  np.cos(alpha)]])

                    # A = np.dot(Rot_alpha,np.array([[-xc],
                    # 								[-yc]]) )

                    # x_prime, y_prime = A[0][0], A[1][0]
                    # print(x_prime, y_prime)

                    RotationList = self.game.GenereteRotation(
                        NumberOfCardsToDisplay, alpha)

                    for count, card in enumerate(DisplayedPile):
                        self.game.DrawCardOnBoard(
                            card,
                            LeftTop=[x0 + count * WidthSeenCard, y0],
                            rotation=RotationList[count])
                        j += 1

                for event in pygame.event.get():
                    if event.type == MOUSEBUTTONDOWN and event.button == 1 and not (
                            SurfCursorBlit.collidepoint(
                                self.mousex, self.mousey)
                    ):  #or PileBox.collidepoint(self.mousex,self.mousey) or ):
                        NotClickedOut = False
                    elif event.type == MOUSEBUTTONDOWN and event.button == 1 and CursorBlit.collidepoint(
                            self.mousex, self.mousey):
                        CursorSelected = True
                    elif event.type == MOUSEBUTTONUP and event.button == 1 and CursorSelected:
                        CursorSelected = False
                    elif event.type == MOUSEMOTION:
                        self.mousex, self.mousey = event.pos

                if CursorSelected:
                    CursorPos = self.mousex

                    # limit the cursor to the surfcursor
                    if CursorPos > CursorPosMax:
                        CursorPos = CursorPosMax
                    elif CursorPos < CursorPosMin:
                        CursorPos = CursorPosMin

                # display Cursor and CursorBar
                SurfCursorBlit = self.game.DISPLAYSURF.blit(
                    SurfCursor, (x0SurfCursor, y0SurfCursor))

                pygame.draw.rect(self.game.DISPLAYSURF,
                                 self.game.ColorsCodes["Gray"],
                                 (x0SurfCursor, y0SurfCursor,
                                  SurfCursorSize[0], SurfCursorSize[1]), 4)

                CursorBlit = self.game.DISPLAYSURF.blit(
                    Cursor, (int(CursorPos - CursorSize[0] / 2),
                             int(y0 + 1.5 * self.game.HEIGHTCARD)))

                pygame.display.update()
                self.game.clock.tick(self.game.FPS)
예제 #16
0
파일: tests.py 프로젝트: ben-mar/TheGame
    def test_play(self):

        self.Game = TheGame.Game()

        self.Game.ActivePlayer = 2
        PlayerSelected = 2

        self.Game.Player1.hand = TheGame.CreateListOfCards(
            [2, 14, 16, 18, 47, 57], self.Game.color['P1'])
        self.Game.Player2.hand = TheGame.CreateListOfCards(
            [20, 34, 36, 38, 49, 57], self.Game.color['P2'])
        self.Game.Player1.PileUP = TheGame.CreateListOfCards(
            [1, 13], self.Game.color['P1'])
        self.Game.Player1.PileDOWN = TheGame.CreateListOfCards(
            [60, 51], self.Game.color['P1'])
        self.Game.Player2.PileUP = TheGame.CreateListOfCards(
            [1, 5, 6], self.Game.color['P2'])
        self.Game.Player2.PileDOWN = TheGame.CreateListOfCards(
            [60, 53, 49], self.Game.color['P2'])

        self.Game.Piles = {
            "P1_UP": self.Game.Player1.PileUP,
            "P1_DOWN": self.Game.Player1.PileDOWN,
            "P2_UP": self.Game.Player2.PileUP,
            "P2_DOWN": self.Game.Player2.PileDOWN
        }

        self.Game.Hands = {
            'P1': self.Game.Player1.hand,
            'P2': self.Game.Player2.hand
        }
        self.Game.PlayedOnOpponnentPiles = {'P1': False, 'P2': False}
        self.Game.PlayedThisTurn = {'P1': [], 'P2': []}

        self.Game.Play('P2_UP', TheGame.Card(20, self.Game.color['P2']),
                       PlayerSelected)
        self.assertListEqual(
            self.Game.Hands['P2'],
            TheGame.CreateListOfCards([34, 36, 38, 49, 57],
                                      self.Game.color['P2']))
        self.assertListEqual(
            self.Game.Piles['P2_UP'],
            TheGame.CreateListOfCards([1, 5, 6, 20], self.Game.color['P2']))
        self.assertListEqual(
            self.Game.PlayedThisTurn['P2'],
            [(TheGame.Card(20, self.Game.color['P2']), 'P2_UP')])

        self.Game.ActivePlayer = 1
        PlayerSelected = 1

        self.Game.Play('P1_DOWN', TheGame.Card(57, self.Game.color['P1']),
                       PlayerSelected)  # won't work
        self.Game.Play('P1_DOWN', TheGame.Card(47, self.Game.color['P1']),
                       PlayerSelected)
        self.Game.Play('P1_DOWN', TheGame.Card(57, self.Game.color['P1']),
                       PlayerSelected)
        self.assertListEqual(
            self.Game.Hands['P1'],
            TheGame.CreateListOfCards([2, 14, 16, 18], self.Game.color['P1']))
        self.assertListEqual(
            self.Game.Piles['P1_DOWN'],
            TheGame.CreateListOfCards([60, 51, 47, 57], self.Game.color['P1']))
예제 #17
0
파일: tests.py 프로젝트: ben-mar/TheGame
 def setUp(self):
     self.listOfNumbers = [1, 50, 32, 41, 10]
     self.color = 'Silver'
     self.ListOfCards = []
     for number in self.listOfNumbers:
         self.ListOfCards.append(TheGame.Card(number, self.color))
예제 #18
0
파일: tests.py 프로젝트: ben-mar/TheGame
 def test_Shuffle(self):
     DeckTestInstance = TheGame.Deck(size=self.size, color=self.color)
     DeckTestInstance.ShuffleDeck()
     self.assertNotEqual(self.deck, DeckTestInstance)
예제 #19
0
파일: tests.py 프로젝트: ben-mar/TheGame
    def test_put(self):

        self.Game = TheGame.Game()
        self.Game.ActivePlayer = 2
        PlayerSelected = 2

        self.Game.Player1.PileUP = TheGame.CreateListOfCards(
            [1, 13], self.Game.color['P1'])
        self.Game.Player1.PileDOWN = TheGame.CreateListOfCards(
            [60, 51], self.Game.color['P1'])
        self.Game.Player2.PileUP = TheGame.CreateListOfCards(
            [1, 5, 6], self.Game.color['P2'])
        self.Game.Player2.PileDOWN = TheGame.CreateListOfCards(
            [60, 53, 49], self.Game.color['P2'])

        self.Game.Piles = {
            "P1_UP": self.Game.Player1.PileUP,
            "P1_DOWN": self.Game.Player1.PileDOWN,
            "P2_UP": self.Game.Player2.PileUP,
            "P2_DOWN": self.Game.Player2.PileDOWN
        }

        # the player 2 puts on player 1's pile Up the number 5 < 13 : Works !
        self.Game.Put('P1_UP', TheGame.Card(5, self.Game.color['P1']),
                      PlayerSelected)
        self.assertListEqual(
            self.Game.Piles['P1_UP'],
            TheGame.CreateListOfCards([1, 13, 5], self.Game.color['P1']))

        # the player 2 already played on opponent piles : Doesn't work ! Moreover the card is too high to be put on this pile (59 >5)
        self.Game.Put('P1_UP', TheGame.Card(59, self.Game.color['P1']),
                      PlayerSelected)
        self.assertListEqual(
            self.Game.Piles['P1_UP'],
            TheGame.CreateListOfCards([1, 13, 5], self.Game.color['P1']))

        # the player 2 already played on opponent piles : Doesn't work !
        self.Game.Put('P1_DOWN', TheGame.Card(56, self.Game.color['P1']),
                      PlayerSelected)
        self.assertListEqual(
            self.Game.Piles['P1_DOWN'],
            TheGame.CreateListOfCards([60, 51], self.Game.color['P1']))

        # let's reset the played on opponent piles for player 2
        self.Game.PlayedOnOpponnentPiles['P2'] = False

        self.Game.Put('P1_UP', TheGame.Card(2, self.Game.color['P2']),
                      PlayerSelected)
        self.assertListEqual(
            self.Game.Piles['P1_UP'],
            TheGame.CreateListOfCards([1, 13, 5], self.Game.color['P1']) +
            [TheGame.Card(2, self.Game.color['P2'])])

        self.Game.ActivePlayer = 1
        PlayerSelected = 1

        self.Game.Put('P1_DOWN', TheGame.Card(46, self.Game.color['P1']),
                      PlayerSelected)
        self.assertListEqual(
            self.Game.Piles['P1_DOWN'],
            TheGame.CreateListOfCards([60, 51, 46], self.Game.color['P1']))

        self.Game.Put('P1_DOWN', TheGame.Card(56, self.Game.color['P1']),
                      PlayerSelected)
        self.assertListEqual(
            self.Game.Piles['P1_DOWN'],
            TheGame.CreateListOfCards([60, 51, 46, 56], self.Game.color['P1']))

        self.Game.ActivePlayer = 2
        PlayerSelected = 2

        self.Game.Put('P2_UP', TheGame.Card(3, self.Game.color['P2']),
                      PlayerSelected)
        self.assertListEqual(
            self.Game.Piles['P2_UP'],
            TheGame.CreateListOfCards([1, 5, 6], self.Game.color['P2']))

        self.Game.Put('P2_UP', TheGame.Card(14, self.Game.color['P2']),
                      PlayerSelected)
        self.Game.Put('P2_UP', TheGame.Card(21, self.Game.color['P2']),
                      PlayerSelected)
        self.Game.Put('P2_UP', TheGame.Card(11, self.Game.color['P2']),
                      PlayerSelected)
        self.assertEqual(
            self.Game.Piles['P2_UP'],
            TheGame.CreateListOfCards([1, 5, 6, 14, 21, 11],
                                      self.Game.color['P2']))
예제 #20
0
파일: tests.py 프로젝트: ben-mar/TheGame
 def test_listofcards(self):
     TestHand = TheGame.Hand(self.listOfNumbers, self.color)
     print(TestHand)
     for card in TestHand.hand:
         print(card)
예제 #21
0
파일: tests.py 프로젝트: ben-mar/TheGame
 def test_Init(self):
     PlayerTestInstance = TheGame.Player(self.size, self.color)
     self.deck = PlayerTestInstance.deck
     self.assertEqual(self.deck, self.decklist)
예제 #22
0
파일: tests.py 프로젝트: ben-mar/TheGame
    def test_Card(self) -> None:

        for numberTest in self.TestNumberList:
            cardtest = TheGame.Card(numberTest, self.color)
            self.assertTrue(cardtest.color == 'Silver')
            self.assertTrue(cardtest.number == numberTest)
예제 #23
0
파일: tests.py 프로젝트: ben-mar/TheGame
    def test_rule(self):

        self.Game = TheGame.Game()

        self.Game.Player1.PileUP = TheGame.CreateListOfCards(
            [1], self.Game.color['P1'])
        self.Game.Player1.PileDOWN = TheGame.CreateListOfCards(
            [60, 30], self.Game.color['P1'])
        self.Game.Player2.PileUP = TheGame.CreateListOfCards(
            [1, 5], self.Game.color['P2'])
        self.Game.Player2.PileDOWN = TheGame.CreateListOfCards(
            [60, 53], self.Game.color['P2'])
        self.Game.Piles = {
            "P1_UP": self.Game.Player1.PileUP,
            "P1_DOWN": self.Game.Player1.PileDOWN,
            "P2_UP": self.Game.Player2.PileUP,
            "P2_DOWN": self.Game.Player2.PileDOWN
        }

        self.assertTrue(
            self.Game.rule('P1_UP',
                           TheGame.Card(3, 'gold'),
                           PlayOnHisOwnPile=True))
        self.assertTrue(
            self.Game.rule('P1_UP',
                           TheGame.Card(59, 'gold'),
                           PlayOnHisOwnPile=True))
        self.assertFalse(
            self.Game.rule('P1_DOWN',
                           TheGame.Card(56, 'gold'),
                           PlayOnHisOwnPile=True))
        self.assertTrue(
            self.Game.rule('P1_DOWN',
                           TheGame.Card(20, 'gold'),
                           PlayOnHisOwnPile=True))
        self.assertTrue(
            self.Game.rule('P1_DOWN',
                           TheGame.Card(40, 'gold'),
                           PlayOnHisOwnPile=True))
        self.assertTrue(
            self.Game.rule('P2_UP',
                           TheGame.Card(3, 'gold'),
                           PlayOnHisOwnPile=False))
        self.assertFalse(
            self.Game.rule('P2_UP',
                           TheGame.Card(6, 'gold'),
                           PlayOnHisOwnPile=False))
        self.assertTrue(
            self.Game.rule('P2_DOWN',
                           TheGame.Card(56, 'gold'),
                           PlayOnHisOwnPile=False))
        self.assertFalse(
            self.Game.rule('P2_DOWN',
                           TheGame.Card(52, 'gold'),
                           PlayOnHisOwnPile=False))

        self.Game.Player1.PileUP = TheGame.CreateListOfCards(
            [1, 13], self.Game.color['P1'])
        self.Game.Player1.PileDOWN = TheGame.CreateListOfCards(
            [60, 51], self.Game.color['P1'])
        self.Game.Player2.PileUP = TheGame.CreateListOfCards(
            [1, 5, 6], self.Game.color['P2'])
        self.Game.Player2.PileDOWN = TheGame.CreateListOfCards(
            [60, 53, 49], self.Game.color['P2'])
        self.Game.Piles = {
            "P1_UP": self.Game.Player1.PileUP,
            "P1_DOWN": self.Game.Player1.PileDOWN,
            "P2_UP": self.Game.Player2.PileUP,
            "P2_DOWN": self.Game.Player2.PileDOWN
        }

        self.assertTrue(
            self.Game.rule('P1_UP',
                           TheGame.Card(3, 'silver'),
                           PlayOnHisOwnPile=False))
        self.assertFalse(
            self.Game.rule('P1_UP',
                           TheGame.Card(59, 'gold'),
                           PlayOnHisOwnPile=False))
        self.assertTrue(
            self.Game.rule('P1_DOWN',
                           TheGame.Card(56, 'gold'),
                           PlayOnHisOwnPile=False))
        self.assertFalse(
            self.Game.rule('P1_DOWN',
                           TheGame.Card(1, 'gold'),
                           PlayOnHisOwnPile=False))
        self.assertFalse(
            self.Game.rule('P2_UP',
                           TheGame.Card(3, 'gold'),
                           PlayOnHisOwnPile=True))
        self.assertFalse(
            self.Game.rule('P2_UP',
                           TheGame.Card(6, 'gold'),
                           PlayOnHisOwnPile=True))
        self.assertTrue(
            self.Game.rule('P2_DOWN',
                           TheGame.Card(59, 'gold'),
                           PlayOnHisOwnPile=True))
        self.assertFalse(
            self.Game.rule('P2_DOWN',
                           TheGame.Card(52, 'gold'),
                           PlayOnHisOwnPile=True))
예제 #24
0
파일: tests.py 프로젝트: ben-mar/TheGame
    def test_checkAction(self):

        self.Game = TheGame.Game()

        self.Game.Player1.PileUP = TheGame.CreateListOfCards(
            [1], self.Game.color['P1'])
        self.Game.Player1.PileDOWN = TheGame.CreateListOfCards(
            [60], self.Game.color['P1'])
        self.Game.Player2.PileUP = TheGame.CreateListOfCards(
            [1, 5], self.Game.color['P2'])
        self.Game.Player2.PileDOWN = TheGame.CreateListOfCards(
            [60, 53], self.Game.color['P2'])

        self.Game.Piles = {
            "P1_UP": self.Game.Player1.PileUP,
            "P1_DOWN": self.Game.Player1.PileDOWN,
            "P2_UP": self.Game.Player2.PileUP,
            "P2_DOWN": self.Game.Player2.PileDOWN
        }

        PlayerSelected = 1

        self.assertTrue(
            self.Game.CheckAction('P1_UP', TheGame.Card(3, 'gold'),
                                  PlayerSelected))
        self.assertTrue(
            self.Game.CheckAction('P1_UP', TheGame.Card(59, 'gold'),
                                  PlayerSelected))
        self.assertTrue(
            self.Game.CheckAction('P1_DOWN', TheGame.Card(56, 'gold'),
                                  PlayerSelected))
        self.assertTrue(
            self.Game.CheckAction('P1_DOWN', TheGame.Card(1, 'gold'),
                                  PlayerSelected))
        self.assertTrue(
            self.Game.CheckAction('P2_UP', TheGame.Card(3, 'gold'),
                                  PlayerSelected))
        self.assertFalse(
            self.Game.CheckAction('P2_UP', TheGame.Card(6, 'gold'),
                                  PlayerSelected))
        self.assertTrue(
            self.Game.CheckAction('P2_DOWN', TheGame.Card(56, 'gold'),
                                  PlayerSelected))
        self.assertFalse(
            self.Game.CheckAction('P2_DOWN', TheGame.Card(52, 'gold'),
                                  PlayerSelected))

        self.Game.ActivePlayer = 2
        self.Game.Player1.PileUP = TheGame.CreateListOfCards(
            [1, 13], self.Game.color['P1'])
        self.Game.Player1.PileDOWN = TheGame.CreateListOfCards(
            [60, 51], self.Game.color['P1'])
        self.Game.Player2.PileUP = TheGame.CreateListOfCards(
            [1, 5, 6], self.Game.color['P2'])
        self.Game.Player2.PileDOWN = TheGame.CreateListOfCards(
            [60, 53, 49], self.Game.color['P2'])
        self.Game.Piles = {
            "P1_UP": self.Game.Player1.PileUP,
            "P1_DOWN": self.Game.Player1.PileDOWN,
            "P2_UP": self.Game.Player2.PileUP,
            "P2_DOWN": self.Game.Player2.PileDOWN
        }

        PlayerSelected = 2

        self.assertTrue(
            self.Game.CheckAction('P1_UP', TheGame.Card(3, 'silver'),
                                  PlayerSelected))
        self.assertFalse(
            self.Game.CheckAction('P1_UP', TheGame.Card(59, 'gold'),
                                  PlayerSelected))
        self.assertTrue(
            self.Game.CheckAction('P1_DOWN', TheGame.Card(56, 'gold'),
                                  PlayerSelected))
        self.assertFalse(
            self.Game.CheckAction('P1_DOWN', TheGame.Card(1, 'gold'),
                                  PlayerSelected))
        self.assertFalse(
            self.Game.CheckAction('P2_UP', TheGame.Card(3, 'gold'),
                                  PlayerSelected))
        self.assertFalse(
            self.Game.CheckAction('P2_UP', TheGame.Card(6, 'gold'),
                                  PlayerSelected))
        self.assertTrue(
            self.Game.CheckAction('P2_DOWN', TheGame.Card(59, 'gold'),
                                  PlayerSelected))
        self.assertFalse(
            self.Game.CheckAction('P2_DOWN', TheGame.Card(52, 'gold'),
                                  PlayerSelected))
예제 #25
0
파일: tests.py 프로젝트: ben-mar/TheGame
    def test_EndOfTurn(self):
        self.Game = TheGame.Game()

        self.Game.Player1.deck = TheGame.CreateListOfCards(
            [5, 23, 15, 58, 46], self.Game.color['P1'])
        self.Game.Player2.deck = TheGame.CreateListOfCards(
            [5, 32, 9, 51, 53, 48], self.Game.color['P2'])
        self.Game.Player1.hand = TheGame.CreateListOfCards(
            [2, 3], self.Game.color['P1'])
        self.Game.Player2.hand = TheGame.CreateListOfCards(
            [7, 52, 45], self.Game.color['P2'])

        self.Game.Piles = {
            "P1_UP": self.Game.Player1.PileUP,
            "P1_DOWN": self.Game.Player1.PileDOWN,
            "P2_UP": self.Game.Player2.PileUP,
            "P2_DOWN": self.Game.Player2.PileDOWN
        }

        self.Game.Hands = {
            'P1': self.Game.Player1.hand,
            'P2': self.Game.Player2.hand
        }
        self.Game.PlayedOnOpponnentPiles = {'P1': False, 'P2': True}
        self.Game.PlayedThisTurn = {'P1': [], 'P2': []}

        self.PLAYER1HAND = TheGame.CreateListOfCards([2, 3, 58, 46],
                                                     self.Game.color['P1'])
        self.PLAYER1DECK = TheGame.CreateListOfCards([5, 23, 15],
                                                     self.Game.color['P1'])

        self.PLAYER2HAND = TheGame.CreateListOfCards([7, 52, 45, 51, 53, 48],
                                                     self.Game.color['P2'])
        self.PLAYER2DECK = TheGame.CreateListOfCards([5, 32, 9],
                                                     self.Game.color['P2'])

        self.assertEqual(self.Game.EndOfTurn(), 0)

        self.Game.PlayedThisTurn['P1'] = ['Whatever1', 'Whatever2']
        self.assertEqual(self.Game.EndOfTurn(), 1)

        self.assertListEqual(self.PLAYER1HAND, self.Game.Hands['P1'])
        self.assertListEqual(self.Game.Player1.deck, self.PLAYER1DECK)
        self.assertDictEqual(self.Game.PlayedOnOpponnentPiles, {
            'P1': False,
            'P2': False
        })
        self.assertEqual(self.Game.ActivePlayer, 2)

        self.Game.PlayedOnOpponnentPiles = {'P1': False, 'P2': True}
        self.Game.PlayedThisTurn['P2'] = ['Whatever1', 'Whatever2']

        self.assertEqual(self.Game.EndOfTurn(), 1)
        self.assertListEqual(self.PLAYER2HAND, self.Game.Hands['P2'])
        self.assertListEqual(self.Game.Player2.deck, self.PLAYER2DECK)
        self.assertDictEqual(self.Game.PlayedOnOpponnentPiles, {
            'P1': False,
            'P2': False
        })
        self.assertEqual(self.Game.ActivePlayer, 1)

        self.Game.Player1.hand = TheGame.CreateListOfCards(
            [2, 3, 58], self.Game.color['P1'])
        self.Game.Hands = {
            'P1': self.Game.Player1.hand,
            'P2': self.Game.Player2.hand
        }

        self.PLAYER1HAND = TheGame.CreateListOfCards([2, 3, 58, 5, 23, 15],
                                                     self.Game.color['P1'])
        self.PLAYER1DECK = []

        self.Game.PlayedOnOpponnentPiles = {'P1': True, 'P2': False}
        self.Game.PlayedThisTurn['P1'] = ['Whatever1', 'Whatever2']

        self.assertEqual(self.Game.EndOfTurn(), 1)
        print(self.Game.Hands['P1'])
        self.assertListEqual(self.PLAYER1HAND, self.Game.Hands['P1'])
        self.assertListEqual(self.Game.Player1.deck, self.PLAYER1DECK)
        self.Game.ActivePlayer = 1
        self.Game.PlayedThisTurn['P1'] = ['Whatever1', 'Whatever2']

        self.Game.Hands['P1'] = []
        self.assertEqual(self.Game.EndOfTurn(), 1)
        self.assertTrue(self.Game.GameOver['P2'])
예제 #26
0
파일: tests.py 프로젝트: ben-mar/TheGame
 def setUp(self) -> None:
     self.color = 'Silver'
     self.size = 60
     self.deck = TheGame.Deck(size=self.size, color=self.color)
예제 #27
0
파일: tests.py 프로젝트: ben-mar/TheGame
    def test_CheckIfLoose(self):
        # TODO THIS TEST MUST BE PERFECT FOR THE IMPLEMENTATION FOR THE RL ALGORITHM
        # 2 things to check : that it is exact (no FP or FN) :
        #                   : that it doesn't impact the game after except for the value of Gameover: DONE

        self.Game = TheGame.Game()

        self.Game.ActivePlayer = 1
        PlayerSelected = 1

        self.Game.Player1.hand = TheGame.CreateListOfCards(
            [32, 34, 36, 38, 37, 35], self.Game.color['P1'])
        self.Game.Player1.PileUP = TheGame.CreateListOfCards(
            [1, 20], self.Game.color['P1'])
        self.Game.Player1.PileDOWN = TheGame.CreateListOfCards(
            [60, 30], self.Game.color['P1'])

        self.Game.Piles = {
            "P1_UP": self.Game.Player1.PileUP,
            "P1_DOWN": self.Game.Player1.PileDOWN,
            "P2_UP": self.Game.Player2.PileUP,
            "P2_DOWN": self.Game.Player2.PileDOWN
        }

        self.Game.Hands = {
            'P1': self.Game.Player1.hand,
            'P2': self.Game.Player2.hand
        }
        self.Game.PlayedOnOpponnentPiles = {'P1': False, 'P2': False}
        self.Game.PlayedThisTurn = {'P1': [], 'P2': []}

        self.assertFalse(self.Game.CheckIfLoose(PlayerSelected))

        # obvious case with cards only in the overlap interval :
        # the test case where player 1 cannot play on his own piles (not even 1 card)
        self.Game.Player1.hand = TheGame.CreateListOfCards(
            [32, 34, 36, 38, 37, 35], self.Game.color['P1'])
        self.Game.Player1.PileUP = TheGame.CreateListOfCards(
            [1, 40], self.Game.color['P1'])
        self.Game.Player1.PileDOWN = TheGame.CreateListOfCards(
            [60, 30], self.Game.color['P1'])

        self.Game.Piles = {
            "P1_UP": self.Game.Player1.PileUP,
            "P1_DOWN": self.Game.Player1.PileDOWN,
            "P2_UP": self.Game.Player2.PileUP,
            "P2_DOWN": self.Game.Player2.PileDOWN
        }

        self.Game.Hands = {
            'P1': self.Game.Player1.hand,
            'P2': self.Game.Player2.hand
        }
        self.Game.PlayedOnOpponnentPiles = {'P1': False, 'P2': False}
        self.Game.PlayedThisTurn = {'P1': [], 'P2': []}

        self.assertTrue(self.Game.CheckIfLoose(PlayerSelected))
        self.assertTrue(self.Game.GameOver['P1'])

        self.assertEqual(
            self.Game.Player1.hand,
            TheGame.CreateListOfCards([32, 34, 36, 38, 37, 35],
                                      self.Game.color['P1']))

        #reset the Gameover for the player 1
        self.Game.GameOver['P1'] = False

        # a bit less obvious case :
        # the test case where player 1 cannot ( play 2 cards on his own piles AND cannot play 1 card on oppo piles)
        self.Game.Player1.hand = TheGame.CreateListOfCards(
            [8, 17, 19, 38, 39, 43], self.Game.color['P1'])
        self.Game.Player1.PileUP = TheGame.CreateListOfCards(
            [1, 44], self.Game.color['P1'])
        self.Game.Player1.PileDOWN = TheGame.CreateListOfCards(
            [60, 16], self.Game.color['P1'])
        self.Game.Player2.PileUP = TheGame.CreateListOfCards(
            [1, 8], self.Game.color['P2'])
        self.Game.Player2.PileDOWN = TheGame.CreateListOfCards(
            [60, 43], self.Game.color['P2'])

        self.Game.Piles = {
            "P1_UP": self.Game.Player1.PileUP,
            "P1_DOWN": self.Game.Player1.PileDOWN,
            "P2_UP": self.Game.Player2.PileUP,
            "P2_DOWN": self.Game.Player2.PileDOWN
        }

        self.Game.Hands = {
            'P1': self.Game.Player1.hand,
            'P2': self.Game.Player2.hand
        }
        self.Game.PlayedOnOpponnentPiles = {'P1': False, 'P2': False}
        self.Game.PlayedThisTurn = {'P1': [], 'P2': []}

        self.assertTrue(self.Game.CheckIfLoose(PlayerSelected))
        self.assertTrue(self.Game.GameOver['P1'])

        #reset the Gameover for the player 1
        self.Game.GameOver['P1'] = False

        # a bit less obvious case with cards only in the overlap interval except for 1
        # it will be 1 card on the personal piles + 1 card on the oppo piles
        self.Game.Player1.hand = TheGame.CreateListOfCards(
            [32, 15, 36, 38, 37, 35], self.Game.color['P1'])
        self.Game.Player1.PileUP = TheGame.CreateListOfCards(
            [1, 40], self.Game.color['P1'])
        self.Game.Player1.PileDOWN = TheGame.CreateListOfCards(
            [60, 30], self.Game.color['P1'])
        self.Game.Player2.PileUP = TheGame.CreateListOfCards(
            [1, 8], self.Game.color['P2'])
        self.Game.Player2.PileDOWN = TheGame.CreateListOfCards(
            [60, 37], self.Game.color['P2'])

        self.Game.Piles = {
            "P1_UP": self.Game.Player1.PileUP,
            "P1_DOWN": self.Game.Player1.PileDOWN,
            "P2_UP": self.Game.Player2.PileUP,
            "P2_DOWN": self.Game.Player2.PileDOWN
        }

        self.Game.Hands = {
            'P1': self.Game.Player1.hand,
            'P2': self.Game.Player2.hand
        }
        self.Game.PlayedOnOpponnentPiles = {'P1': False, 'P2': False}
        self.Game.PlayedThisTurn = {'P1': [], 'P2': []}

        self.assertFalse(self.Game.CheckIfLoose(PlayerSelected))
        self.assertFalse(self.Game.GameOver['P1'])

        # checks that the game state hasn't changed
        self.assertEqual(
            self.Game.Player1.hand,
            TheGame.CreateListOfCards([32, 15, 36, 38, 37, 35],
                                      self.Game.color['P1']))
        self.assertEqual(
            self.Game.Player1.PileUP,
            TheGame.CreateListOfCards([1, 40], self.Game.color['P1']))
        self.assertEqual(
            self.Game.Player1.PileDOWN,
            TheGame.CreateListOfCards([60, 30], self.Game.color['P1']))
        self.assertEqual(
            self.Game.Player2.PileUP,
            TheGame.CreateListOfCards([1, 8], self.Game.color['P2']))
        self.assertEqual(
            self.Game.Player2.PileDOWN,
            TheGame.CreateListOfCards([60, 37], self.Game.color['P2']))

        #reset the Gameover for the player 1
        self.Game.GameOver['P1'] = False

        self.Game.ActivePlayer = 2
        PlayerSelected = 2

        # test for player 2
        # a bit less obvious case with cards only in the overlap interval except for 1
        # it will be 1 card on the personal piles + 1 card on the oppo piles
        # 38  on pile  DOWN  of player  1, then :  39  on pile  UP  of player  2

        self.Game.Player2.hand = TheGame.CreateListOfCards(
            [32, 39, 36, 38, 37, 35], self.Game.color['P2'])
        self.Game.Player2.PileUP = TheGame.CreateListOfCards(
            [1, 49], self.Game.color['P2'])
        self.Game.Player2.PileDOWN = TheGame.CreateListOfCards(
            [60, 30], self.Game.color['P2'])
        self.Game.Player1.PileUP = TheGame.CreateListOfCards(
            [1, 8], self.Game.color['P1'])
        self.Game.Player1.PileDOWN = TheGame.CreateListOfCards(
            [60, 37], self.Game.color['P1'])

        self.Game.Piles = {
            "P1_UP": self.Game.Player1.PileUP,
            "P1_DOWN": self.Game.Player1.PileDOWN,
            "P2_UP": self.Game.Player2.PileUP,
            "P2_DOWN": self.Game.Player2.PileDOWN
        }

        self.Game.Hands = {
            'P1': self.Game.Player1.hand,
            'P2': self.Game.Player2.hand
        }
        self.Game.PlayedOnOpponnentPiles = {'P1': False, 'P2': False}
        self.Game.PlayedThisTurn = {'P1': [], 'P2': []}

        self.assertFalse(self.Game.CheckIfLoose(PlayerSelected))
        self.assertFalse(self.Game.GameOver['P2'])

        # Here we want to check that if One of the players has lost but goes back with Undo he hasn't lost

        # First he plays the card in the wrong order :
        self.Game.Play('P1_DOWN', TheGame.Card(39, self.color['P2']),
                       PlayerSelected)

        # he is therefore loosing :
        self.assertTrue(self.Game.CheckIfLoose(PlayerSelected))
        self.assertTrue(self.Game.GameOver['P2'])

        self.Game.Undo()

        # he is not loosing anymore:
        self.assertFalse(self.Game.CheckIfLoose(PlayerSelected))
        self.assertFalse(self.Game.GameOver['P2'])

        # Now he plays the card in the correct order :
        self.Game.Play('P1_DOWN', TheGame.Card(38, self.color['P2']),
                       PlayerSelected)

        # he is therefore not loosing :
        self.assertFalse(self.Game.CheckIfLoose(PlayerSelected))
        self.assertFalse(self.Game.GameOver['P2'])
예제 #28
0
파일: tests.py 프로젝트: ben-mar/TheGame
 def test_Equal(self):
     DeckTestInstance = TheGame.Deck(size=self.size, color=self.color)
     self.assertEqual(self.deck, DeckTestInstance)
예제 #29
0
파일: tests.py 프로젝트: ben-mar/TheGame
    def test_DrawHand(self):
        PlayerTestInstance = TheGame.Player(self.size, self.color)
        PlayerTestInstance.hand = TheGame.CreateListOfCards([2, 3, 4],
                                                            self.color)
        self.HANDFINAL = TheGame.CreateListOfCards([2, 3, 4, 57, 58, 59],
                                                   self.color)
        PlayerTestInstance.Draw(3)
        self.assertEqual(self.HANDFINAL, PlayerTestInstance.hand)

        PlayerTestInstance = TheGame.Player(5, self.color)
        PlayerTestInstance.hand = TheGame.CreateListOfCards([20, 30, 40],
                                                            self.color)
        self.HANDFINAL = TheGame.CreateListOfCards([20, 30, 40, 2, 3, 4],
                                                   self.color)
        PlayerTestInstance.Draw(3)
        self.assertEqual(self.HANDFINAL, PlayerTestInstance.hand)
        self.assertEqual(PlayerTestInstance.deck, [])
        PlayerTestInstance.Draw(2)
        self.assertEqual(self.HANDFINAL, PlayerTestInstance.hand)
        self.assertEqual(PlayerTestInstance.deck, [])

        PlayerTestInstance = TheGame.Player(5, self.color)
        PlayerTestInstance.hand = TheGame.CreateListOfCards([20, 30, 40],
                                                            self.color)
        self.HAND = TheGame.CreateListOfCards([20, 30, 40, 3, 4], self.color)
        self.HANDFINAL = TheGame.CreateListOfCards([20, 30, 40, 3, 4, 2],
                                                   self.color)
        PlayerTestInstance.Draw(2)
        self.assertListEqual(self.HAND, PlayerTestInstance.hand)
        self.assertListEqual(PlayerTestInstance.deck,
                             [TheGame.Card(2, self.color)])
        PlayerTestInstance.Draw(2)
        self.assertListEqual(self.HANDFINAL, PlayerTestInstance.hand)
        self.assertListEqual(PlayerTestInstance.deck, [])
예제 #30
0
파일: GameMenu.py 프로젝트: jonhei13/Jonsi
def game_menu():
    menu_song.play(-1)
    red_list = []
    blue_list = []
    blue_column = 175
    red_column = 175
    rem = txt.render('Del', True, c.BLACK)
    add = txt.render('Add player', True, c.WHITE)
    click = pygame.mixer.Sound('Sounds/SoundEffects/CursorSelect.wav')
    play_click = pygame.mixer.Sound('Sounds/SoundEffects/SHOTGUNRELOAD.wav')

    bg = pygame.image.load('Pics/Menu/menubg.png')
    title = im_resize('Pics/Menu/game_title.png', 360, 169)
    pb = im_resize('Pics/Menu/play.png', 90, 50)
    pb_p = im_resize('Pics/Menu/play_pressed.png', 90, 50)
    tb = im_resize('Pics/Menu/team_blue.png', 200, 300)
    tr = im_resize('Pics/Menu/team_red.png', 200, 300)
    tb_logo = im_resize('Pics/Menu/team_blue_logo.png', 200, 50)
    tr_logo = im_resize('Pics/Menu/team_red_logo.png', 200, 50)
    r_inp = im_resize('Pics/Menu/red_input.png', 166, 30)
    b_inp = im_resize('Pics/Menu/blue_input.png', 165, 30)
    r_inp_p = im_resize('Pics/Menu/red_input_pressed.png', 166, 30)
    b_inp_p = im_resize('Pics/Menu/blue_input_pressed.png', 165, 30)

    img_list = list()
    img_list_name = [
        'American', 'AngryScots', 'English', 'German', 'Hispanic', 'Irish',
        'Jock', 'Norwegian', 'Polish', 'Scouser', 'SoulMan', 'Spanish',
        'Swedish'
    ]
    img_list.append(
        im_resize('Pics/Menu/languageAmerica.png', c.SCREEN_WIDTH, 50))
    img_list.append(
        im_resize('Pics/Menu/languageAngry.png', c.SCREEN_WIDTH, 50))
    img_list.append(
        im_resize('Pics/Menu/languageEnglish.png', c.SCREEN_WIDTH, 50))
    img_list.append(
        im_resize('Pics/Menu/languageGerman.png', c.SCREEN_WIDTH, 50))
    img_list.append(
        im_resize('Pics/Menu/languageHispanic.png', c.SCREEN_WIDTH, 50))
    img_list.append(
        im_resize('Pics/Menu/languageIrish.png', c.SCREEN_WIDTH, 50))
    img_list.append(im_resize('Pics/Menu/languageJock.png', c.SCREEN_WIDTH,
                              50))
    img_list.append(
        im_resize('Pics/Menu/languageNorwegian.png', c.SCREEN_WIDTH, 50))
    img_list.append(
        im_resize('Pics/Menu/languagePolish.png', c.SCREEN_WIDTH, 50))
    img_list.append(
        im_resize('Pics/Menu/languageScouser.png', c.SCREEN_WIDTH, 50))
    img_list.append(
        im_resize('Pics/Menu/languageSoulMan.png', c.SCREEN_WIDTH, 50))
    img_list.append(
        im_resize('Pics/Menu/languageSpanish.png', c.SCREEN_WIDTH, 50))
    img_list.append(
        im_resize('Pics/Menu/languageSwedish.png', c.SCREEN_WIDTH, 50))
    lang = img_list[0]
    curr_selected_lang = 0

    while True:
        clock.tick(60)
        mouse = pygame.mouse.get_pos()
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()

        # Display background and title
        screen.blit(bg, (0, 0))
        screen.blit(title, ((c.SCREEN_WIDTH / 2) - 180, 20))

        # Display blue and red logo
        screen.blit(tb_logo, (130, 90))
        screen.blit(tr_logo, (950, 90))

        # Display blue and red columns
        screen.blit(tb, (130, 150))
        screen.blit(tr, (950, 150))

        # Display team members in column
        for name in blue_list:
            the_text = txt.render(name, True, c.WHITE)
            screen.blit(the_text, (155, blue_column))
            screen.blit(rem, (275, blue_column))
            blue_column += 20
        blue_column = 175

        for name in red_list:
            the_text = txt.render(name, True, c.WHITE)
            screen.blit(the_text, (972, red_column))
            screen.blit(rem, (1092, red_column))
            red_column += 20
        red_column = 175

        # Play button
        if button(pb, 600, 300, 90, 50):
            screen.blit(pb_p, (600, 304))
            if len(blue_list) > 0 and len(red_list) > 0:
                menu_song.stop()
                play_click.play()
                TheGame.main(blue_list, red_list,
                             img_list_name[curr_selected_lang])

        # Removing player from team
        if 300 > mouse[0] > 130:
            if 450 > mouse[1] > 150:
                if pygame.mouse.get_pressed()[0]:
                    click.play()
                    remove_player(mouse, blue_list)
                    sleep(0.2)
        if 1120 > mouse[0] > 950:
            if 450 > mouse[1] > 150:
                if pygame.mouse.get_pressed()[0]:
                    click.play()
                    remove_player(mouse, red_list)
                    sleep(0.2)

        try:
            if c.SCREEN_HEIGHT > mouse[1] > c.SCREEN_HEIGHT - 50:
                if pygame.mouse.get_pressed()[0]:
                    click.play()
                    lang, curr_selected_lang = select_language(mouse, img_list)
        except TypeError:
            pass

        screen.blit(lang, (0, c.SCREEN_HEIGHT - 50))
        screen.blit(add, (970, 132))

        # Blue and red input boxes
        if button(r_inp, 963, 132, 155, 35) and len(red_list) < 8:
            screen.blit(b_inp, (145, 132))
            screen.blit(r_inp_p, (963, 132))
            screen.blit(add, (155, 139))
            input_box(red_list, r_inp_p, 963, 132)

        if button(b_inp, 145, 132, 155, 35) and len(blue_list) < 8:
            screen.blit(b_inp_p, (145, 132))
            screen.blit(r_inp, (963, 132))
            screen.blit(add, (973, 139))
            input_box(blue_list, b_inp_p, 145, 132)

        # Display add text in input boxes
        screen.blit(add, (155, 139))
        screen.blit(add, (973, 139))
        pygame.display.update()