From 687232f86bc498093101309a3d61a8a2c50387e1 Mon Sep 17 00:00:00 2001 From: vedpawar2254 <85354558+vedpawar2254@users.noreply.github.com> Date: Thu, 31 Oct 2024 18:37:28 +0530 Subject: [PATCH 1/2] Add files via upload --- War-cardgame/War.py | 102 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 War-cardgame/War.py diff --git a/War-cardgame/War.py b/War-cardgame/War.py new file mode 100644 index 0000000..c0cca91 --- /dev/null +++ b/War-cardgame/War.py @@ -0,0 +1,102 @@ +from random import shuffle + +class Card: + suits = ["spades", "hearts", "diamonds", "clubs"] + values = [None, None, "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace"] + + def __init__(self, v, s): + """suit + value are ints""" + self.value = v + self.suit = s + + def __lt__(self, c2): + if self.value < c2.value: + return True + if self.value == c2.value: + if self.suit < c2.suit: + return True + else: + return False + return False + + def __gt__(self, c2): + if self.value > c2.value: + return True + if self.value == c2.value: + if self.suit > c2.suit: + return True + else: + return False + return False + + def __repr__(self): + v = self.values[self.value] + " of " + self.suits[self.suit] + return v + +class Deck: + def __init__(self): + self.cards = [] + for i in range(2, 15): + for j in range(4): + self.cards.append(Card(i, j)) + shuffle(self.cards) + + def rm_card(self): + if len(self.cards) == 0: + return + return self.cards.pop() + +class Player: + def __init__(self, name): + self.wins = 0 + self.card = None + self.name = name + +class Game: + def __init__(self): + name1 = input("Player 1 name: ") + name2 = input("Player 2 name: ") + self.deck = Deck() + self.p1 = Player(name1) + self.p2 = Player(name2) + + def wins(self, winner): + w = "{} wins this round".format(winner) + print(w) + + def draw(self, p1n, p1c, p2n, p2c): + d = "{} drew {} and {} drew {}".format(p1n, p1c, p2n, p2c) + print(d) + + def play_game(self): + cards = self.deck.cards + print("Beginning War!") + while len(cards) >= 2: + m = "Press 'q' to quit. Any other key to play: " + response = input(m) + if response == 'q': + break + p1c = self.deck.rm_card() + p2c = self.deck.rm_card() + p1n = self.p1.name + p2n = self.p2.name + self.draw(p1n, p1c, p2n, p2c) + if p1c > p2c: + self.p1.wins += 1 + self.wins(self.p1.name) + else: + self.p2.wins += 1 + self.wins(self.p2.name) + + win = self.winner(self.p1, self.p2) + print("War is over. {} wins".format(win)) + + def winner(self, p1, p2): + if p1.wins > p2.wins: + return p1.name + if p1.wins < p2.wins: + return p2.name + return "It was a tie!" + +game = Game() +game.play_game() From b2aef7fa8cdbc173aec8dac56f86dc730892ba88 Mon Sep 17 00:00:00 2001 From: vedpawar2254 <85354558+vedpawar2254@users.noreply.github.com> Date: Thu, 31 Oct 2024 18:44:01 +0530 Subject: [PATCH 2/2] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index cb63b7d..bc34fc8 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,7 @@ More information on contributing and the general code of conduct for discussion | Video Watermarker | [Video Watermarker](https://github.com/DhanushNehru/Python-Scripts/tree/master/Video%20Watermarker) | Adds watermark to any video of your choice. | | Virtual Painter | [Virtual Painter](https://github.com/DhanushNehru/Python-Scripts/tree/master/Virtual%20Painter) | Virtual painting application. | | Wallpaper Changer | [Wallpaper Changer](https://github.com/DhanushNehru/Python-Scripts/tree/master/Wallpaper%20Changer) | Automatically changes home wallpaper, adding a random quote and stock tickers on it. | +| WAR-cardgame | [War-cardgame](https://github.com/vedpawar2254/Python-Scripts/tree/%22WAR%22-card-game#:~:text=2%20years%20ago-,War%2Dcardgame,-Add%20files%20via) | simple Python script for a card game called War. The game is played between two players, and the player with the higher card wins each round. The game continues until one player has all the cards.| | Weather GUI | [Weather GUI](https://github.com/DhanushNehru/Python-Scripts/tree/master/Weather%20GUI) | Displays information on the weather. | | Website Blocker | [Website Blocker](https://github.com/DhanushNehru/Python-Scripts/tree/master/Website%20Blocker) | Downloads the website and loads it on your homepage in your local IP. | | Website Cloner | [Website Cloner](https://github.com/DhanushNehru/Python-Scripts/tree/master/Website%20Cloner) | Clones any website and opens the site in your local IP. | @@ -154,6 +155,7 @@ More information on contributing and the general code of conduct for discussion | Youtube Downloader | [Youtube Downloader](https://github.com/DhanushNehru/Python-Scripts/tree/master/Youtube%20Downloader) | Downloads any video from [YouTube](https://youtube.com) in video or audio format! | | Youtube Playlist Info Scraper | [Youtube Playlist Info Scraper](https://github.com/DhanushNehru/Python-Scripts/tree/master/Youtube%20Playlist%20Info%20Scraper) | This python module retrieve information about a YouTube playlist in json format using playlist link. | + ## Gitpod Use the cloud-free development environment where you can directly start coding.