Giter VIP home page Giter VIP logo

clash-clash's Introduction

Clash-Clash

Setup

  1. colorama is required for the app to run. To install colorama,
pip3 install colorama
  1. To run the game,
python3 game.py
  1. To view replays,
python3 replay.py

The Game

I. Starting the Game

When the user runs the game, they will be greeted by a welcome screen. Some really cool background music has also been added as an extra creative feature. From here, the user can press S to start the game, or Q to quit.

II. Battle

At any point in the game, pressing Q will allow the user to quit the game.

The King

The village is a grid of squares. The user controls the King, who starts in the top left corner, and can move around the grid by using the following keys.

W - Move up
A - Move left
S - Move down
D - Move right

The village consists of 1 Town Hall, 3 Cannons and 5 Huts, as well as walls surrounding the Town Hall to protect it. The King can only move to a square that is not occupied by a building. The King can attack in 2 different ways.

Space - Targeted attack on the square directly next to the King.
L - Perform a Leviathan Axe attack, unleashing splash damage in an area of 10x10 around the King.

Barbarians

Barbarians are troops that can be used to assist the king in battle. They can be spawned by pressing 1, 2 or 3, which spawns them at one of the 3 spawning points in the village accordingly. They target the nearest building, moving towards it and attack it.

The nearest distance is calculated using Manhattan distance, which is |x1 - x2| + |y1 - y2|.

The Cannons

While the Huts, Town Hall and Walls are static buildings, the Cannons are buildings that defend the village by shooting at player troops. The range of a cannon is 5x5 around the Cannon. The Cannons attack periodically after a certain number of iterations of the game loop.

Spells

Spells can be cast to boost your troops and give you the extra edge.

R - Activates the Rage spell, which doubles the speed and damage of your troops.

H - Activates the Heal spell, which increases the current health of each active troop by 150%.

The above spells can only be used once per game.

III. End of the Game

Once your active troops are all killed, you lose the game. If all buildings have been destroyed, you win the game.

OOPS Concepts Implemented

I. Inheritance

  1. The Building class serves as the base class, from which the Town Hall, Wall, Cannon and Hut classes inherit.

  2. The King and Barbarian classes inherit from the Troop class.

II. Abstraction

Two examples of abstraction are the move() and attack() methods of the Barbarian class. The inner details and implementation of movement and attacking are hidden from the user, and the user can simply add them to the code in the game loop to implement the function.

III. Encapsulation

In this game, all functions or variables pertaining to a particular game entity are bundled under a single class. The functionality can then be accessed by simply calling the method via the class object.

IV. Polymorphism

The Troop class has an attack() method. However, the Barbarian class has its specific attack() method that overrides the default Troop's attack() method.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.