Giter VIP home page Giter VIP logo

ping-pong-game's Introduction

CSE 230 - Final Project

Members: Yuka Chu, Chi-Hsuan Lee, Yi-Ting Wang, Heidi Cheng

Link to Hackmd : https://hackmd.io/@heidiche/By63QCVvt

Ping-Pong Game with a Twist

Rules

  • Two-player ping pong game
  • Control vertical position of two rackets with keyboard (w and s for Player 1; up and down for Player 2)
  • One earns a point when the other player misses the ball
  • The next ball is served towards the previous scored player
  • The second ball is added after someone gets 3 points
  • Game ends when one of the players hit a score of 5

Features

  • Randomly generate ball's initial direction
  • Ball reflects when hitting the rackets, ceiling, and floor
  • Determine a player earns points when balls hit the opponent's sidewall
  • Enable two players to controls the rackets
  • Add an extra ball to increase difficulty in the pong game

Program Architecture

Libraries: brick, vty References: ranjitjhala/brick-tac-toe, samtay/snake

src
 ├── Model 
 │   ├── Ball.hs
 │   ├── Player.hs
 │   └── Score.hs
 ├── Control.hs 
 ├── Main.hs
 ├── Model.hs
 ├── Types.hs
 └── View.hs

Ball.hs controls the movement of the ball. Player.hs records the position of the rackets. Score.hs is responsible for adding scores for players and determining if there is a winner. Control.hs transforms states when there are keyboard interrupt, etc. Main.hs contains the main function defined by the brick package. Model.hs wraps up the interaction between files under the directory, Model. Types.hs stores all of the data types we define. View.hs creates the UI of the program.

Difficulties and Solutions

  1. Assemble each part of work from our group members and make it execute correctly
    • We designed clear APIs (data types) to let each group member commit individually without worrying about conflicts
  2. To randomly serve balls, we had to deal with IO
    • We made the output of serving a ball a IO monad (Since generating a random number in Haskell is a IO)
  3. We needed to deal with the movement of two balls separately and defined when to consider the second ball
    • In our PlayState, there are two objects: ball1 and ball2, each of them is a data - Ball.
    • We used an extra Boolean variable in PlayState to record whether the second ball is added to the game.

Limitations

  1. Due to the nature of pixel games, it is inevitable that the ball moves discretely

  1. Both players have to press and release the keyboard to move. (when two players press to move at the same time, one player gets stuck)

Milestone 1: Proposal

In this project, we are developing a two-player ping-pong game with additional feature such as smashing or spinning the ball.

As a normal ping-pong game, both players start with zero point, the first player reaching eleven point wins the game. Players serve two serves each, alternating. And if a game ties at 10-10, a player must win by 2 points. In this situation, players serve one serve each, alternating.

Each player can control a ping pong racket with keyboard keys. They are targeting to catch the ball and return it with the racket. If one fails to catch the ball, the other player scores.

Strategies below increase the chance to score:

  • Smashing a ball means, in some circumstances, you can hit the ball harder to increase its speed. This gives your oppenent less time to react, and therefore more difficult to hit the ball back to you.

  • Spinning the ball is to let the ball not go in a straight line, but in a curve. This makes the landing position harder to predict.

Milestone 2: Updates

  • What is the architecture of your application (the key components)? We mapped our functionalities with the ones in the starter-code (brick-tac-toe: https://github.com/ranjitjhala/brick-tac-toe), and modified the architecture of it.
src
 ├── Model 
 │   ├── Ball.hs
 │   ├── Player.hs
 │   └── Score.hs
 ├── Control.hs 
 ├── Main.hs
 ├── Model.hs
 └── View.hs
  • What challenges (if any) did you have so far and how did you solve them?
  1. Our program's structure is similar to the exsiting Haskell/brick TUI game "snake" (https://github.com/jtdaugherty/brick/blob/master/docs/samtay-tutorial.md). However, when we try to install and execute the snake game, some error occured (unable to download the depending packages) and we can't run it. This make us difficult to build our program using the snake as a template. We ended up modifying the brick-tack-toe.
  2. We divided our work into four components so that each group member could commit individually without worrying about conflicts. To do so, we first design clear APIs to let each component communicate. We have not run our code yet. We are not sure if each component will connect well with the expected features.
  • Do you expect to meet your goals until the deadline?

We were planning to add some additional features, such as smashing and spinning the ball. However, since we have three moving objects, it is hard for us to control the three objects. Therefore, we will focus on the implementation of ball's movement and two rackets for now.

  • If not, how will you modify your goals?
  1. We will add some addtional UI features, like changing the color of the direction arrow pressed by the player.
  2. We will try to implement spinning and smashing the ball after finishing the above modified goal.

Distribution of work

Member
Yuka Chu Player.hs + Ball.hs
Yi-Ting Wang Score.hs + Control.hs
Chi-Hsuan Lee View.hs
Heidi Cheng Model.hs + Main.hs

ping-pong-game's People

Contributors

heidicheng avatar taipeiyuka avatar chl131 avatar amberwow123 avatar

Watchers

James Cloos avatar

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.